package btm_vobc import ( "bytes" "encoding/hex" "encoding/json" "fmt" "github.com/snksoft/crc" "joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/udp" "sync/atomic" "testing" "time" ) const ( code1 = "fffef890149e75e15511000006230000000000d4da14ebfffd" code2 = "fffee601804f004d00800600002a004984ec6f4e902ef6912284000000000000000000000000000000067e000000000000411b0000f5bbee397698fffd" ) func TestMsg22(t *testing.T) { msg := &message.TrainPcSimBaseMessage{} msg.Type = message.RECIVE_TRAIN_CREATE_REMOVE data := []byte{1} msg.Data = data code := msg.Encode() hexCode := hex.EncodeToString(code) fmt.Println(hexCode) fmt.Println(crc.CalculateCRC(crc.CRC16, []byte{0})) } var message_id atomic.Uint32 func TestConn(t *testing.T) { source := ":fffee601804f004d00c1b401002a00e7ae839c4b59b2bf912275000000000000000000000000000001b4bf00000000000000000000dc4902d6e431fffd" d, _ := hex.DecodeString(source) udpClient := udp.NewClient(fmt.Sprintf("%v:%d", "127.0.0.1", 49491)) err := udpClient.Send(d) if err != nil { fmt.Println(err) return } time.Sleep(time.Second * 2) udpClient.Close() } func TestDecode(t *testing.T) { fmt.Println(code1[:4]) d, _ := hex.DecodeString(code1) fmt.Println(d[:2]) dd := d[2 : len(d)-2] fmt.Println(hex.EncodeToString(dd)) fmt.Println(bytes.Equal(d[:2], []byte{0xff, 0xfe})) fmt.Println(message_id.Load()) } func TestMsg(t *testing.T) { now := time.Now().UTC() sec := now.Unix() fmt.Println(sec) fmt.Println(now.UnixMilli()) fmt.Println(now.UnixMilli() - sec*1000) } func TestBytes(t *testing.T) { dd := make([]byte, 0) dd = append(dd, 0) dd = append(dd, 1) dd = append(dd, 2) dd = append(dd, 3) dd = append(dd, 4) fmt.Println(dd[1:]) } func TestArr(t *testing.T) { data := make([]byte, 0) data = append(data, 1) dd := &message.BtmVobcMsgFree{BtmStatus: message.BTM_STSTUS_NORMAL, WorkTemperature: 10, Fun1: uint16(0), Fun2: uint16(0), Fun3: uint16(0), Fun4: uint16(0), FreeMsg: data, RespTime: byte(3), VobcLifeNum: 2, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: 1}} s, _ := json.Marshal(dd) fmt.Println(string(s)) dd2 := &message.BtmVobcMsgFree{} json.Unmarshal(s, dd2) fmt.Println(dd2) } func TestRes(t *testing.T) { ss := "fffee601804f004d00e40321002a004fd6c86f3c2bcde891220700000000000000000000000000002103e20000000000000000000052bed1a5e9edfffd" ss = "fffee601804f004d006a1521002a00f3329169ec2f9c9991229e000000000000000000000000000021156800000000000000000000bff47aff004e24fffd" ss = "fffee601804f004d00cd1921002a005ea577ff00db4b628891220600000000000000000000000000002119cb0000000000000000000077ba3334d06ffffd" ss = "fffee601804f004d006c1d21002a00e2c732ff00f86276339122a80000000000000000000000000000211d6a0000000000000000000049c46daebcf6fffd" ss = "fffee601804f004d00871d21002a00ee97d0fb1c4b2a849122c30000000000000000000000000000211d8500000000000000000000c4e2343e4117fffd" ss = "fffee601804f004d00444a1c002a00473bbfa11d4b3b029122a800000000000000000000000000001c4a42000000000000000000008970492fff00d0fffd" ss = "fffe9287d4000570006464000a000000000000000000000490007f8181b60b10183280003fff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff000a00221eede6c80a6efffd" cfs, _ := hex.DecodeString(ss) frameType, dataText, _ := message.BtmVobcDecode(cfs) if frameType == message.COMMAND_TYPE { fmt.Println("1111111111111111") } else if frameType == message.REQUEST_TYPE { req := &message.BtmVobcReq{} req.Decode(dataText) fmt.Println("22222222222222222222") } else { fmt.Println("zzzzzzzzzzzzzzzzzzzzz") } } func TestRes3(t *testing.T) { ss := "fffef890141175e15511001c4a3b0000000000fd5956a5fffd" arr, _ := hex.DecodeString(ss) _, dataText, err := message.BtmVobcDecode(arr) if err != nil { fmt.Println(err.Error()) } req := &message.BtmVobcIdCommand{} req.Decode(dataText) }