Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
733dc9665e | |||
accc7639e4 | |||
c8235962f5 |
3 changed files with 10 additions and 7 deletions
|
@ -33,6 +33,7 @@ type ZelloClient struct {
|
|||
// Event Chans
|
||||
GeneralEventChan chan ZelloResponsePacked
|
||||
BinaryDataChan chan []byte
|
||||
ErrorEventChan chan error
|
||||
}
|
||||
|
||||
func NewZelloClient() (zelloClient *ZelloClient) {
|
||||
|
@ -43,6 +44,7 @@ func NewZelloClient() (zelloClient *ZelloClient) {
|
|||
DefaultTimeout: time.Millisecond * 1e3,
|
||||
SeqResponseChans: make(map[int64]chan map[string]interface{}),
|
||||
GeneralEventChan: make(chan ZelloResponsePacked),
|
||||
ErrorEventChan: make(chan error),
|
||||
BinaryDataChan: make(chan []byte),
|
||||
}
|
||||
}
|
||||
|
@ -484,25 +486,26 @@ func (zc *ZelloClient) handleRXbinary(data []byte) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (zc *ZelloClient) Work() {
|
||||
func (zc *ZelloClient) Work() (err error) {
|
||||
for {
|
||||
msgType, message, err := zc.Connection.ReadMessage()
|
||||
if err != nil {
|
||||
log.Println("read:", err)
|
||||
return
|
||||
//log.Println("read:", err)
|
||||
zc.ErrorEventChan <- err
|
||||
return err
|
||||
}
|
||||
if msgType == websocket.TextMessage {
|
||||
err = zc.handleRXjson(message)
|
||||
if err != nil {
|
||||
log.Println("handleRXjson:", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
if msgType == websocket.BinaryMessage {
|
||||
err = zc.handleRXbinary(message)
|
||||
if err != nil {
|
||||
log.Println("handleRXbinary:", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package client
|
|||
|
||||
type (
|
||||
ZelloCodecHeader struct {
|
||||
SampleRate int16
|
||||
SampleRate uint16
|
||||
FramesPerPaket int
|
||||
FrameSize int
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module git.cheetah.cat/tetrapack/go-zello-client
|
|||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/gorilla/websocket v1.5.3 // indirect
|
||||
require github.com/gorilla/websocket v1.5.3
|
||||
|
|
Loading…
Add table
Reference in a new issue