From 26b1bee0d753aff0d2967002193d24ac2a3e50f7 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期三, 21 二月 2024 09:40:59 +0800
Subject: [PATCH] 调试成功网关读写配置

---
 Src/application/dw_mbx_tag.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/Src/application/dw_mbx_tag.c b/Src/application/dw_mbx_tag.c
index 9492859..a8b322a 100644
--- a/Src/application/dw_mbx_tag.c
+++ b/Src/application/dw_mbx_tag.c
@@ -91,8 +91,8 @@
                     break;
             };
             tagofflinetime[taglist_pos] = 0; 
-            printf("测距成功,序号%d,距离%d\r\n",frame_seq_nb2,tagdist_list[taglist_pos]);
-            delay_ms(10);
+//            printf("测距成功,序号%d,距离%d\r\n",frame_seq_nb2,tagdist_list[taglist_pos]);
+//            delay_ms(10);
 }
 uint8_t report_ancnum;
 void TagListUpdate(void)
@@ -218,36 +218,40 @@
         dwt_entersleep();
 
 }
-typedef enum{	WG_Lost, //上报丢失    失去和网关通讯
-                WG_Connected,// 上报中       和网关通讯正常
-}wg_state_enum;
-static wg_state_enum wg_state = WG_Lost;
-static uint8_t lora_sendbuffer[200];
-u8 wg_report_lost_count,seq_num;
+wg_state_enum wg_state = WG_Lost;
+uint8_t lora_sendbuffer[200];
+u8 seq_num;
+extern u8 wg_lost_count;
 uint16_t wg_report_freq,wg_report_id;
 #define WG_LOST_SWITCH_THRES   3
 void LoraReportFreqPoll(void)
 {
     if(wg_state==WG_Lost)
     {
+        wg_report_id = 0xffff;
         wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; //如果丢失链接就进入WG管理信道。
     }else{
-      if(wg_report_lost_count++>WG_LOST_SWITCH_THRES)
+      if(wg_lost_count++>WG_LOST_SWITCH_THRES)
       {
         wg_state = WG_Lost;
       }          
     }
 }
 static u16 checksum;
-u8 gps_state,gps_chafenlingqi,gps_satel_num;
+u8 gps_state,gps_chafenlingqi,gps_satel_num,test_num;
 double gps_jingdu,gps_weidu;
 extern u8 bat_percent,stationary_flag;
+int16_t sendcount = 0,tp1;
 void LoraReportPoll(void)
 {
+
+    if(sendcount++>0)
     TagListUpdate();
+    
     LoraReportFreqPoll();
+    taglist_num = test_num;
     SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]);
-    lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG;
+    lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS;
     lora_sendbuffer[MSG_LENGTH] = 4*taglist_num+30;
     memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2);
     memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2);
@@ -262,8 +266,9 @@
     lora_sendbuffer[ANCNUM_IDX] = taglist_num;
     memcpy(&lora_sendbuffer[ANCID_IDX],tagid_list,taglist_num*2);
     memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*2],tagdist_list,taglist_num*2);
-    checksum = Checksum_u16(lora_sendbuffer,4*taglist_num+30);
+    checksum = Checksum_u16(lora_sendbuffer,4*taglist_num+ANCID_IDX);
     memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*4],&checksum,2);
     Radio.Send(lora_sendbuffer,ANCID_IDX+taglist_num*4+2);
-    bat_percent=Get_Battary();    
+    bat_percent=Get_Battary();  
+    
 }
\ No newline at end of file

--
Gitblit v1.9.3