From c1235bf3f37ec78351203f6d7d8b6bf93e24860d Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期日, 29 六月 2025 17:42:30 +0800
Subject: [PATCH] 初步测试蓝牙协议和修改删除部分逻辑,完成蓝牙协议功能逻辑开发和实测,距离判断开关逻辑需要进一步确认优化,加入改附近频率设定并实测通过

---
 keil/include/drivers/global_param.c |   48 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/keil/include/drivers/global_param.c b/keil/include/drivers/global_param.c
index 55e3010..5c1c945 100644
--- a/keil/include/drivers/global_param.c
+++ b/keil/include/drivers/global_param.c
@@ -3,9 +3,10 @@
 //#include "dw_app.h"
 #include <string.h>
 #define FLASH_IAP_CTRL_MAP		(uint32_t)0x0402E000    //the control map start address, 63K MK8000修改
-
-
-
+#define FLASH_Authorization_MAP  (uint32_t)0x0402f000 //授权标签列表起始地址
+#define AUTHORIZATION_NUM 1024
+uint32_t tag_id_authorization_list[AUTHORIZATION_NUM];
+uint32_t tag_id_authorization_list_num;
 uint16_t g_com_map[COM_MAP_SIZE];
 uint8_t parameter_check(void)
 {
@@ -49,13 +50,31 @@
     if(!result) {
         flash_erase(FLASH_ID0,FLASH_IAP_CTRL_MAP,FLASH_SECTOR_SIZE);
         flash_write_nbytes(FLASH_ID0, FLASH_IAP_CTRL_MAP, (const uint8_t*)g_com_map, sizeof(g_com_map));
+    }
+    //flash_close(FLASH_ID0);
+    __enable_irq();
+    return result;
+}
+uint32_t save_taglist_map_to_flash(void)
+{
+    uint32_t result = 0;
+    if(parameter_check()) //参数错误,不保存
+    {
+        return 1;
+    }
+    __disable_irq();
+    //result = FLASH_Prepare(FLASH_IAP_CTRL_MAP, (COM_MAP_SIZE<<1));MK8000修改
+    result=flash_open(FLASH_ID0,NULL);
+    //MK8000没有对应函数
+    if(!result) {
+        flash_erase(FLASH_ID0,FLASH_Authorization_MAP,4*FLASH_SECTOR_SIZE);
+        flash_write_nbytes(FLASH_ID0, FLASH_Authorization_MAP, (const uint8_t*)tag_id_authorization_list, sizeof(tag_id_authorization_list));
         //result = FLASH_Write(FLASH_IAP_CTRL_MAP, (const uint8_t*)g_com_map, (COM_MAP_SIZE<<1));
     }
     //flash_close(FLASH_ID0);
     __enable_irq();
     return result;
 }
-
 void parameter_init(void)//注意看前面有没有关闭flash如果有则打开flash在读取,否则会出错
 {   flash_open(FLASH_ID0,NULL);
     //FLASH_Read(FLASH_IAP_CTRL_MAP, (uint8_t*)&g_com_map, (COM_MAP_SIZE<<1));MK8000修改
@@ -85,7 +104,7 @@
         g_com_map[CNT_REBOOT]=0;
         g_com_map[CNT_UPDATE]=0;
         g_com_map[MOTOR_ONTIME_INDEX]=10;
-        g_com_map[ACTIVE_INDEX]=0;
+        g_com_map[NERA_FREQUENCY]=5;//默认切换到5hz将标签
 
         g_com_map[TCP_IP_0]=0x111;
         g_com_map[TCP_IP_0]=0x198;
@@ -96,8 +115,22 @@
         g_com_map[HEIGHTOFFEST_INDEX]=0;
         save_com_map_to_flash();
     }
+	
+		
 }
 
+uint32_t check_tag_id_authorization_list_num(void)
+{
+    uint32_t count = 0;
+    
+    for (uint32_t i = 0; i < AUTHORIZATION_NUM; i++) {
+        if (tag_id_authorization_list[i] != 0xffffffff&&tag_id_authorization_list[i] != 0) {
+            count++;
+        }
+    }
+    
+    return count;
+}
 void parameter_init_anchor(void)
 {
     flash_open(FLASH_ID0,NULL);
@@ -128,7 +161,7 @@
         g_com_map[CNT_REBOOT]=0;
         g_com_map[CNT_UPDATE]=0;
         g_com_map[MODBUS_MODE]=0;
-        g_com_map[ACTIVE_INDEX]=0;
+        g_com_map[NERA_FREQUENCY]=5;//默认切换到5hz将标签
 
         g_com_map[TCP_IP_0]=0x111;
         g_com_map[TCP_IP_1]=0x198;
@@ -139,4 +172,7 @@
         g_com_map[HEIGHTOFFEST_INDEX]=0;
         save_com_map_to_flash();
     }
+		//新增上电获取授权标签列表
+		flash_read(FLASH_ID0, FLASH_Authorization_MAP, (uint8_t*)&tag_id_authorization_list, sizeof(tag_id_authorization_list));//从flash中拿出来授权表
+		tag_id_authorization_list_num=check_tag_id_authorization_list_num();//获取实际有效长度减少轮训开销
 }
\ No newline at end of file

--
Gitblit v1.9.3