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.

133 lines
3.5 KiB
Go

1 year ago
package main
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"test/common"
"test/common/tmkind"
// "strings"
)
func main() {
var err error
terminalClient := common.NewTerminalClient("192.168.133.106:42381")
//data := make([]byte, 256)
err = terminalClient.Connect()
if err != nil {
panic(err)
}
randomBytes := make([]byte, 10)
_, err = rand.Read(randomBytes)
if err != nil {
panic(err)
}
myAddr := common.TetraFlexAddress{
Kind: common.UserNo,
UserNo: "1005",
}
// 20160111
tfAuthReq, err := common.NewTMAuthReq(myAddr, 0, randomBytes, 1, "OpenTetraFlex", 20230831, "1.0.0")
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(tfAuthReq.Encode()))
terminalClient.Send(tfAuthReq)
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.IpApiKeepAliveChallenge {
challenge, err := parsedMsg.AsKeepAliveChallenge()
if err != nil {
panic(err)
}
keepAliveBytes, _ := json.Marshal(challenge)
fmt.Println(string(keepAliveBytes))
response, err := common.NewTMKeepAliveResponse(challenge)
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(response.Encode()))
terminalClient.Send(response)
// Send Subscribe
response, err = common.NewTMNotificationRequest([]tmkind.TetraFlexTerminalMessageKinds{
tmkind.IpApiCallUpdateNotification,
tmkind.IpApiSdsTlReportNotification,
tmkind.IpApiSdsTlShortReportNotification,
tmkind.IpApiSdsDataType4Notification,
tmkind.IpApiSdsStatusNotification,
tmkind.IpApiSdsTlTransferNotification,
})
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(response.Encode()))
terminalClient.Send(response)
response, err = common.NewTMIpApiGroupAttachRequest([]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)
}
fmt.Println(hex.EncodeToString(response.Encode()))
terminalClient.Send(response)
groupAddr := common.NewAddressFromSSINumber(103)
identityNum := common.NewAddressFromSSINumber(1007)
response, err = common.NewTMIpApiCallSetupRequest(*groupAddr, common.CallTypeGroup, common.CallPriorityDefault, false, common.TetraFlexIdentityInfo{
Description: "blurb",
Kind: common.IdentityKindTerminal,
Address: *identityNum,
UnifiedSSIKinds: common.UnifiedKindPersonalNumber,
})
if err != nil {
panic(err)
}
fmt.Println(hex.EncodeToString(response.Encode()))
terminalClient.Send(response)
}
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
}
}
}