|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.cheetah.cat/cheetah/opentetraflex-go/common"
|
|
|
|
"git.cheetah.cat/cheetah/opentetraflex-go/common/tmkind"
|
|
|
|
// "strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
|
|
|
var err error
|
|
|
|
terminalClient := common.NewTerminalClient("192.168.133.106:42381")
|
|
|
|
|
|
|
|
//data := make([]byte, 256)
|
|
|
|
err = terminalClient.Connect()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
myAddr := common.TetraFlexAddress{
|
|
|
|
Kind: common.UserNo,
|
|
|
|
UserNo: "1005",
|
|
|
|
}
|
|
|
|
err = terminalClient.Authenticate(myAddr)
|
|
|
|
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))
|
|
|
|
|
|
|
|
err = terminalClient.AttachGroups([]common.GroupConfig{
|
|
|
|
{
|
|
|
|
Group: common.NewAddressFromSSINumber(101),
|
|
|
|
ScanMode: common.Scanned,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Group: common.NewAddressFromSSINumber(102),
|
|
|
|
ScanMode: common.Scanned,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Group: common.NewAddressFromSSINumber(103),
|
|
|
|
ScanMode: common.Scanned,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case parsedMsg := <-terminalClient.RX:
|
|
|
|
fmt.Println(hex.EncodeToString(parsedMsg.Bytes()))
|
|
|
|
if parsedMsg.Kind == tmkind.IpApiAuthenticationChallenge {
|
|
|
|
authChall, err := parsedMsg.AsAuthenticationChallenge()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if authChall.PinRequested {
|
|
|
|
fmt.Println("Sending Auth Pin")
|
|
|
|
//terminalClient.SendTM()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if parsedMsg.Kind == tmkind.IpApiNo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|