diff --git a/common/terminalClient.go b/common/terminalClient.go index 748c9f7..0270b9f 100644 --- a/common/terminalClient.go +++ b/common/terminalClient.go @@ -84,6 +84,22 @@ func (tc *TerminalClient) Authenticate(addr TetraFlexAddress) (err error) { } return nil } +func (tc *TerminalClient) SubscribeEvents(messageTypes []tmkind.TetraFlexTerminalMessageKinds) (err error) { + tfNotReq, err := NewTMNotificationRequest(messageTypes) + if err != nil { + return err + } + tc.HandlerMap[tfNotReq.handler] = make(chan HandlerResponse) + err = tc.Send(tfNotReq) + if err != nil { + return err + } + response := <-tc.HandlerMap[tfNotReq.handler] + if !response.Success { + return response.Error + } + return nil +} func (tc *TerminalClient) AttachGroups(groups []GroupConfig) (err error) { tfGroupAttachReq, err := NewTMIpApiGroupAttachRequest(groups) if err != nil { diff --git a/main.go b/main.go index 0adb5bf..2267b06 100644 --- a/main.go +++ b/main.go @@ -32,11 +32,23 @@ func main() { if err != nil { panic(err) } + + err = terminalClient.SubscribeEvents([]tmkind.TetraFlexTerminalMessageKinds{ + tmkind.IpApiCallUpdateNotification, + tmkind.IpApiSdsTlReportNotification, + tmkind.IpApiSdsTlShortReportNotification, + tmkind.IpApiSdsDataType4Notification, + tmkind.IpApiSdsStatusNotification, + tmkind.IpApiSdsTlTransferNotification, + }) + if err != nil { + panic(err) + } //fmt.Println(hex.EncodeToString(parsedMsg.Bytes())) regInfoBytes, _ := json.Marshal(terminalClient.RegistrationInfo) fmt.Println(string(regInfoBytes)) - terminalClient.AttachGroups([]common.GroupConfig{ + err = terminalClient.AttachGroups([]common.GroupConfig{ { Group: common.NewAddressFromSSINumber(101), ScanMode: common.Scanned, @@ -50,6 +62,9 @@ func main() { ScanMode: common.Scanned, }, }) + if err != nil { + panic(err) + } for { select { @@ -65,19 +80,6 @@ func main() { //terminalClient.SendTM() } } - - if parsedMsg.Kind == tmkind.IpApiRegistrationConfirm { - - regInfo, err := parsedMsg.AsRegistrationInfo() - if err != nil { - panic(err) - } - fmt.Println(hex.EncodeToString(parsedMsg.Bytes())) - regInfoBytes, _ := json.Marshal(regInfo) - fmt.Println(string(regInfoBytes)) - - } - //if parsedMsg.Kind == tmkind.IpApiNo } }