From 9105bf90e4dca008221da442e8077bf4040292bb Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期三, 03 八月 2022 14:55:00 +0800
Subject: [PATCH] 增加标签端MODBUS输出

---
 源码/核心板/Src/application/dw_app.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
index 01463b2..5c2ad4a 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
@@ -30,6 +30,8 @@
 #include "beep.h"
 #include "modbus.h"
 //#define DEBUG_OUTPUT
+#define TDFILTER
+//#define CONSTANT_FILTER
 /*------------------------------------ Marcos ------------------------------------------*/
 /* Inter-ranging delay period, in milliseconds. */
 #define RNG_DELAY_MS 100
@@ -342,6 +344,33 @@
  //   min_power =  - 10 * log10((F1 *F1 + F2 * F2 + F3 * F3) / (C *B));
     return min_power;
   }
+#define CONSTANT_LEN 50
+extern u16 dist_threshold;
+int32_t ConstantFilter(int32_t currentdist,u8 channel)
+  {
+      static int32_t cs_lastdist[10],cs_lastvalid[10];
+      static u8 cfstart_flag[10] = {1};
+      static u8 constant_count[10] = {100};
+      if(cfstart_flag[channel])
+      {
+        cfstart_flag[channel] = 0;
+        cs_lastdist[channel] = currentdist;
+      }
+      if( abs(currentdist - cs_lastdist[channel])<100)
+      {
+          if(constant_count[channel]<CONSTANT_LEN)
+              constant_count[channel]++;     
+      }else{
+         constant_count[channel] = 0; 
+      }
+      if(constant_count[channel] == CONSTANT_LEN)
+      {
+        cs_lastvalid[channel] = currentdist;
+      }
+      cs_lastdist[channel] = currentdist;
+      return cs_lastvalid[channel];
+  }
+
 uint16_t g_Resttimer;
 uint8_t result;
 u8 tag_succ_times=0;
@@ -478,7 +507,8 @@
 					{	
 					g_Tagdist[anc_id_recv]=	hex_dist2;
 					g_flag_Taggetdist[anc_id_recv]=0;
-
+                    Modbus_HoldReg[anc_id_recv*2]=hex_dist2>>16;
+					Modbus_HoldReg[anc_id_recv*2+1]=hex_dist2;
 					if(!g_com_map[MODBUS_MODE])
 					{
 					hex_dist2 = hex_dist2;		
@@ -495,6 +525,7 @@
 					checksum = Checksum_u16(&usart_send[2],17);
 					memcpy(&usart_send[19],&checksum,2);
 					UART_PushFrame(usart_send,21);
+
 					}
 				}
 		//			memcpy(&Modbus_HoldReg[anc_id_recv*2],&hex_dist,4);
@@ -540,10 +571,10 @@
 
 int8_t correction_time;
 extern uint8_t sync_seq;
-#define TDFILTER
+
 //#define CHECK_UID
 extern uint8_t UID_ERROR;
-extern u16 dist_threshold;
+
 u8 misdist_num[TAG_NUM_IN_SYS];
 void Anchor_App(void)
 {
@@ -705,9 +736,15 @@
 						#else
 						filter_dist=hex_dist/10;
 						#endif
+                        
+                        #ifdef  CONSTANT_FILTER
+                        filter_dist = ConstantFilter(filter_dist,tag_id_recv-TAG_ID_START);
+                        #endif                       
 						anchor_dist_last_frm[tag_id_recv-TAG_ID_START]=filter_dist;
 						g_Tagdist[tag_id_recv]=	filter_dist;
 					
+
+                        
 					his_dist[tag_id_recv-TAG_ID_START]=hex_dist;
 					g_flag_Taggetdist[tag_id_recv]=0;
 					if(!g_com_map[MODBUS_MODE])

--
Gitblit v1.9.3