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.

189 lines
4.3 KiB
Go

package main
import (
"bufio"
"encoding/hex"
"encoding/json"
"fmt"
"math/rand"
"os"
"strings"
"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")
//
err = terminalClient.Connect()
if err != nil {
panic(err)
}
//
myAddr := common.TetraFlexAddress{
Kind: common.UserNo,
UserNo: "9400001",
}
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)
}
fmt.Println("Groups attached")
go func() {
groupAddr := common.NewAddressFromSSINumber(101)
fmt.Println("Test callSetup")
callRef, err := terminalClient.CallSetup(*groupAddr, common.CallTypeGroup, common.CallPriorityDefault, false, common.TetraFlexIdentityInfo{
Description: "2m/FM Gateway SWM",
/* Kind: common.IdentityKindApplication,
Address: *common.NewAddressFromSSINumber(1002),
UnifiedSSIKinds: common.UnifiedKindExternalNumber,
*/
Kind: common.IdentityKindTerminal,
Address: *common.NewAddressFromSSINumber(9400001),
UnifiedSSIKinds: common.UnifiedKindPersonalNumber,
})
if err != nil {
panic(err)
}
fmt.Printf("callRef=%d\n", callRef)
err = terminalClient.CallStreamRequest(0, callRef, 0, common.AudioChannel_CMoIP_Tetra) // CMoIP_aLaw
if err != nil {
panic(err)
}
// IpApiCallStreamRequest
err = terminalClient.PTTRequest(callRef, common.TetraFlexIdentityInfo{
Description: "Blaa",
/* Kind: common.IdentityKindApplication,
Address: *common.NewAddressFromSSINumber(1002),
UnifiedSSIKinds: common.UnifiedKindExternalNumber,
*/
Kind: common.IdentityKindTerminal,
Address: *common.NewAddressFromSSINumber(1002),
UnifiedSSIKinds: common.UnifiedKindPersonalNumber,
}, 0)
if err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
// Connect RTP
err = terminalClient.RTPConnect()
if err != nil {
panic(err)
}
file, err := os.Open("./test.tetra.txt")
if err != nil {
panic(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
var counter byte = 0
var voiceArray [][]byte
for scanner.Scan() {
hexData := scanner.Text()
hexData = strings.Trim(hexData, " ")
byteData, _ := hex.DecodeString(hexData)
fmt.Println(hexData)
voiceArray = append(voiceArray, byteData)
}
for {
for _, byteData := range voiceArray {
fmt.Println(byteData)
byteData[8] = counter
err = terminalClient.RTPSend(byteData)
if err != nil {
panic(err)
}
if counter == 255 {
counter = 128
} else {
counter++
}
time.Sleep(20 * time.Millisecond)
}
}
/*
time.Sleep(3 * time.Second)
// PTT Release
err = terminalClient.PTTRelease(callRef)
if err != nil {
panic(err)
}
time.Sleep(3 * time.Second)
err = terminalClient.CallDisconnect(callRef, common.DisconnectReason_CallRejectedByCalled)
if err != nil {
panic(err)
}
*/
// IpApiCallPttRequest
}()
// idk send help xD
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()
}
}
}
}
}