From 5379bc11f3121e77a0344a158eb768c384e7aea4 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 23 Jan 2024 09:58:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B7=E8=BE=BE=E4=B8=8EVOBC=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E8=A7=A3=E7=A0=81,=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/message/radar.go | 20 +++++++------ third_party/message/radar_test.go | 47 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 third_party/message/radar_test.go diff --git a/third_party/message/radar.go b/third_party/message/radar.go index 3add9a6..933f642 100644 --- a/third_party/message/radar.go +++ b/third_party/message/radar.go @@ -70,7 +70,7 @@ func (rd *RadarData) getSumVal() byte { return rd.SourceData + rd.valRange } func (s *RadarState) parseState() { - //第6位 == SW_Mode0, 第7位 == SW_Mode1 + //第7位 == SW_Mode0, 第6位 == SW_Mode1 // 11:两个天线和双通道都OK // 10:DRS05_Single-Mode 40度,50度的天线或通道故障 // 01:DRS05_Single-Mode 50度,40度的天线或通道故障 @@ -78,7 +78,7 @@ func (s *RadarState) parseState() { // 模式的工作差别:工作在11.模式时效果最好。单模式10或01时可信度下降。 arr := s.getBitsStateArr() s.Model = bitStateStr(arr[6:]) - // 第3位=计算状态位,第4位=信号质量标志位,第5位=Black5out标志位 + // 第5位=计算状态位,第4位=信号质量标志位,第3位=Black5out标志位 // 110:计算状态,高质量 // 地面信号反射良好,高精度的信号计算 // 100: 计算状态,低质量 @@ -98,20 +98,24 @@ func (s *RadarState) parseState() { s.Dir = bitStateStr(arr[0:1]) } -func (s *RadarState) getBitsStateArr() []byte { - bits := make([]byte, 8) +func (s *RadarState) getBitsStateArr() [8]byte { + //bits := make([]byte, 8) + var bits2 [8]byte = [8]byte{} for i := 0; i < 8; i++ { bit := s.SourceState >> uint(i) & 1 - bits[i] = bit + bits2[i] = bit } - return bits + return bits2 } func bitStateStr(data []byte) string { var build = strings.Builder{} - for _, d := range data { - build.WriteString(fmt.Sprintf("%v", d)) + for i := len(data) - 1; i >= 0; i-- { + build.WriteString(fmt.Sprintf("%v", data[i])) } + /*for _, d := range data { + build.WriteString(fmt.Sprintf("%v", d)) + }*/ return build.String() } func (r *Radar) checkTail() bool { diff --git a/third_party/message/radar_test.go b/third_party/message/radar_test.go new file mode 100644 index 0000000..519db6c --- /dev/null +++ b/third_party/message/radar_test.go @@ -0,0 +1,47 @@ +package message + +import ( + "fmt" + "testing" +) + +func TestRadar(t *testing.T) { + data := make([]byte, 0) + data = append(data, radar_head1) //0 + data = append(data, radar_head2) //1 + data = append(data, 1) //自增 + data = append(data, 1) //速度3 + data = append(data, 0) //4 + data = append(data, 1) //s1 5 + data = append(data, 0) //6 + data = append(data, 1) //s2 7 + data = append(data, 0) //8 + data = append(data, 0) //内部使用 9 + data = append(data, 0) //内部使用 9 + data = append(data, createState()) + var sum int + for _, s := range data { + sum += int(s) + } + data = append(data, byte(^sum+1)) + radar := &Radar{} + radar.Decode(data) + fmt.Println(radar) +} + +func createState() byte { + var b byte = 0 + b1 := b | (byte(1) << 7) | (byte(1) << 6) | (byte(1) << 5) | (byte(1) << 4) | (byte(1) << 1) | (byte(1) << 1) + return b1 +} +func TestR1(t *testing.T) { + var b byte = 0 + fmt.Printf("%08b\n", b) + //6,7位 11 + //3,4,5位 011 + // 1位 1 + //0位 1 + b1 := b | (byte(1) << 7) | (byte(1) << 6) | (byte(1) << 5) | (byte(1) << 4) | (byte(1) << 1) | (byte(1) << 0) + fmt.Printf("%08b\n", b1) + fmt.Println(b1) +}