gatewayProtocol_test.go 731 B

123456789101112131415161718192021222324
  1. package gatewayServer
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "testing"
  6. )
  7. func TestCRC16(t *testing.T) {
  8. 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}
  9. crc := CRC16(data[:len(data)-2], len(data)-2)
  10. fmt.Printf("CRC: 0x%04X\n", crc)
  11. }
  12. func TestPack(t *testing.T) {
  13. var adu = AppDataUnit{
  14. CmdCode: 0x4000,
  15. SubCode: 0,
  16. Data: "",
  17. DevId: "23040631492\000",
  18. }
  19. fmt.Printf("%+v\n", adu)
  20. fmt.Println(hex.EncodeToString(Pack(adu)))
  21. }