123456789101112131415161718192021222324 |
- package gatewayServer
- import (
- "encoding/hex"
- "fmt"
- "testing"
- )
- func TestCRC16(t *testing.T) {
- data := []byte{0x24, 0x24, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x32, 0x33, 0x30, 0x34, 0x30, 0x36, 0x33, 0x31, 0x34, 0x39, 0x32, 0x00, 0xfe, 0x0b}
- crc := CRC16(data[:len(data)-2], len(data)-2)
- fmt.Printf("CRC: 0x%04X\n", crc)
- }
- func TestPack(t *testing.T) {
- var adu = AppDataUnit{
- CmdCode: 0x4000,
- SubCode: 0,
- Data: "",
- DevId: "23040631492\000",
- }
- fmt.Printf("%+v\n", adu)
- fmt.Println(hex.EncodeToString(Pack(adu)))
- }
|