radar_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "smart_tunnel_edge/protocol/envSensor"
  6. "testing"
  7. )
  8. func Test_verify(t *testing.T) {
  9. //Name := "光传感器"
  10. //decodeAddress, _ := hex.DecodeString("01")
  11. //dataPack := envSensor.DataPack{Address: decodeAddress, Start: []byte{0x01, 0xF8}, DataLen: []byte{0x00, 0x08}}
  12. //
  13. //if Name == "光传感器" {
  14. // dataPack = envSensor.DataPack{Address: decodeAddress, Start: []byte{0x00, 0x06}, DataLen: []byte{0x00, 0x01}}
  15. //}
  16. //buffer := dataPack.GetEnvGatherCommand()
  17. //fmt.Println("++++++++", hex.EncodeToString(buffer.Bytes()))
  18. //
  19. //xxx := "010310030900ba012c000000000000000100016324" //42 14
  20. //
  21. //gz, _ := strconv.ParseInt(xxx[30:38], 16, 0)
  22. ////s := xxx[30:38]
  23. //fmt.Println("截取: ", gz)
  24. //hexStr := "7830303940790d0a"
  25. //// 调用解析函数
  26. //
  27. //hex.EncodeToString([]byte{})
  28. //result := parseHexString(hexStr)
  29. //// 输出结果
  30. //fmt.Println(result)
  31. //xxx := "7830313940790d0a"
  32. //char := parseHexString("7830313940790d0a")
  33. //fmt.Println("+++++++", char)
  34. //fmt.Println("len++", len(xxx))
  35. //fmt.Println(",,,", xxx[0:2], xxx[8:16])
  36. dataPack := envSensor.DataPack{Address: "02", Start: []byte{0x00, 0x06}, DataLen: []byte{0x00, 0x01}}
  37. command := dataPack.GetEnvGatherCommand()
  38. fmt.Println("+++++", hex.EncodeToString(command.Bytes()))
  39. }
  40. func parseHexString(hexStr string) string {
  41. // 将十六进制字符串转换为字节数组
  42. bytes, err := hex.DecodeString(hexStr)
  43. if err != nil {
  44. fmt.Println("错误: 十六进制字符串解析失败", err)
  45. return ""
  46. }
  47. // 将字节数组转换为对应的字符
  48. return string(bytes)
  49. }