|
|
@ -33,6 +33,7 @@ type ZelloClient struct {
|
|
|
|
// Event Chans
|
|
|
|
// Event Chans
|
|
|
|
GeneralEventChan chan ZelloResponsePacked
|
|
|
|
GeneralEventChan chan ZelloResponsePacked
|
|
|
|
BinaryDataChan chan []byte
|
|
|
|
BinaryDataChan chan []byte
|
|
|
|
|
|
|
|
ErrorEventChan chan error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewZelloClient() (zelloClient *ZelloClient) {
|
|
|
|
func NewZelloClient() (zelloClient *ZelloClient) {
|
|
|
@ -43,6 +44,7 @@ func NewZelloClient() (zelloClient *ZelloClient) {
|
|
|
|
DefaultTimeout: time.Millisecond * 1e3,
|
|
|
|
DefaultTimeout: time.Millisecond * 1e3,
|
|
|
|
SeqResponseChans: make(map[int64]chan map[string]interface{}),
|
|
|
|
SeqResponseChans: make(map[int64]chan map[string]interface{}),
|
|
|
|
GeneralEventChan: make(chan ZelloResponsePacked),
|
|
|
|
GeneralEventChan: make(chan ZelloResponsePacked),
|
|
|
|
|
|
|
|
ErrorEventChan: make(chan error),
|
|
|
|
BinaryDataChan: make(chan []byte),
|
|
|
|
BinaryDataChan: make(chan []byte),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -484,25 +486,26 @@ func (zc *ZelloClient) handleRXbinary(data []byte) (err error) {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (zc *ZelloClient) Work() {
|
|
|
|
func (zc *ZelloClient) Work() (err error) {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
msgType, message, err := zc.Connection.ReadMessage()
|
|
|
|
msgType, message, err := zc.Connection.ReadMessage()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println("read:", err)
|
|
|
|
//log.Println("read:", err)
|
|
|
|
return
|
|
|
|
zc.ErrorEventChan <- err
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if msgType == websocket.TextMessage {
|
|
|
|
if msgType == websocket.TextMessage {
|
|
|
|
err = zc.handleRXjson(message)
|
|
|
|
err = zc.handleRXjson(message)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println("handleRXjson:", err)
|
|
|
|
log.Println("handleRXjson:", err)
|
|
|
|
return
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if msgType == websocket.BinaryMessage {
|
|
|
|
if msgType == websocket.BinaryMessage {
|
|
|
|
err = zc.handleRXbinary(message)
|
|
|
|
err = zc.handleRXbinary(message)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println("handleRXbinary:", err)
|
|
|
|
log.Println("handleRXbinary:", err)
|
|
|
|
return
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|