12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package main
- import (
- "encoding/hex"
- "fmt"
- "smart_tunnel_edge/protocol/envSensor"
- "testing"
- )
- func Test_verify(t *testing.T) {
- //Name := "光传感器"
- //decodeAddress, _ := hex.DecodeString("01")
- //dataPack := envSensor.DataPack{Address: decodeAddress, Start: []byte{0x01, 0xF8}, DataLen: []byte{0x00, 0x08}}
- //
- //if Name == "光传感器" {
- // dataPack = envSensor.DataPack{Address: decodeAddress, Start: []byte{0x00, 0x06}, DataLen: []byte{0x00, 0x01}}
- //}
- //buffer := dataPack.GetEnvGatherCommand()
- //fmt.Println("++++++++", hex.EncodeToString(buffer.Bytes()))
- //
- //xxx := "010310030900ba012c000000000000000100016324" //42 14
- //
- //gz, _ := strconv.ParseInt(xxx[30:38], 16, 0)
- ////s := xxx[30:38]
- //fmt.Println("截取: ", gz)
- //hexStr := "7830303940790d0a"
- //// 调用解析函数
- //
- //hex.EncodeToString([]byte{})
- //result := parseHexString(hexStr)
- //// 输出结果
- //fmt.Println(result)
- //xxx := "7830313940790d0a"
- //char := parseHexString("7830313940790d0a")
- //fmt.Println("+++++++", char)
- //fmt.Println("len++", len(xxx))
- //fmt.Println(",,,", xxx[0:2], xxx[8:16])
- dataPack := envSensor.DataPack{Address: "02", Start: []byte{0x00, 0x06}, DataLen: []byte{0x00, 0x01}}
- command := dataPack.GetEnvGatherCommand()
- fmt.Println("+++++", hex.EncodeToString(command.Bytes()))
- }
- func parseHexString(hexStr string) string {
- // 将十六进制字符串转换为字节数组
- bytes, err := hex.DecodeString(hexStr)
- if err != nil {
- fmt.Println("错误: 十六进制字符串解析失败", err)
- return ""
- }
- // 将字节数组转换为对应的字符
- return string(bytes)
- }
|