You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB
Go

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)
}
//fmt.Println(hex.EncodeToString(parsedMsg.Bytes()))
regInfoBytes, _ := json.Marshal(terminalClient.RegistrationInfo)
fmt.Println(string(regInfoBytes))
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,
},
})
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.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
}
}
}