From 2671208ff2eb0ecd022919a2a38d4540b0e90961 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期五, 16 五月 2025 11:15:02 +0800
Subject: [PATCH] 成功与免布线基站稳定测距和上位机交互版本

---
 keil/include/drivers/Usart.h                   |    2 
 keil/include/main/main.c                       |   52 ++++++++++++++++++++++++--
 keil/include/components/app/src/ranging_fira.c |    1 
 keil/uci_fira.uvprojx                          |   15 +++++++
 keil/include/drivers/global_param.h            |    8 ++++
 keil/include/drivers/serial_at_cmd_app.c       |    2 
 keil/include/drivers/uwb_app.c                 |    8 ++--
 7 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/keil/include/components/app/src/ranging_fira.c b/keil/include/components/app/src/ranging_fira.c
index e369e61..55e8933 100644
--- a/keil/include/components/app/src/ranging_fira.c
+++ b/keil/include/components/app/src/ranging_fira.c
@@ -349,6 +349,7 @@
 //uwb_close();
 	CloseUWB();
 uwb_normal_init();
+	OpenUWB();
 normal_flag=1;	
 }
 void normal_uwb_change_to_fira(void)//少个回调设置
diff --git a/keil/include/drivers/Usart.h b/keil/include/drivers/Usart.h
index fb74204..4f3f7bf 100644
--- a/keil/include/drivers/Usart.h
+++ b/keil/include/drivers/Usart.h
@@ -38,7 +38,7 @@
 
 #define EUART_TX_FRM_SIZE		2				//发送队列中的最大帧数
 #define EUART_TX_FRMBUF_SIZE	100		//发送队列每帧缓存大小
-#define EUART_RX_BUF_SIZE		512				//接收缓存大小
+#define EUART_RX_BUF_SIZE		1024			//接收缓存大小
 
 #define EXT_UART				USART1
 #define EXT_UART_RCC			RCC_APB2Periph_USART1
diff --git a/keil/include/drivers/global_param.h b/keil/include/drivers/global_param.h
index 87b4b75..a48b200 100644
--- a/keil/include/drivers/global_param.h
+++ b/keil/include/drivers/global_param.h
@@ -30,6 +30,13 @@
 
 #define      MOTOR_ONTIME_INDEX                    0x10
 #define 	 MOTORBEEPER_INDEX 				    0x11
+
+#define     TCP_IP_0                        0x11
+#define     TCP_IP_1                        0x12
+#define     TCP_IP_2                        0x13
+#define     TCP_IP_3                        0x14
+#define     TCP_PORT                        ALARM_DISTANCE3
+
 #define      NEARBASE_ID1                    0x11
 #define      NEARBASE_ID2                    0x12
 #define      NEARBASE_ID3                    0x13
@@ -39,6 +46,7 @@
 #define      NEARBASE_ID7                    0x17
 #define      NEARBASE_ID8                    0x18
 #define      NEARBASE_ID9                    0x19
+#define      LOG_4G_ENABLE                   0x19
 #define      NEARBASE_ID10                   0x1a
 
 #define 	POWER           		0x1B
diff --git a/keil/include/drivers/serial_at_cmd_app.c b/keil/include/drivers/serial_at_cmd_app.c
index 46b369f..14b5902 100644
--- a/keil/include/drivers/serial_at_cmd_app.c
+++ b/keil/include/drivers/serial_at_cmd_app.c
@@ -182,7 +182,7 @@
                     enable_sleep_count=0;
 					//read包中data字节,即mUsartReceivePack[0]表示数据长度;
 				//从g_com_data结构体中的第index位置读取长度为mUsartReceivePack[0]的字节,发送出来
-					SendComMap0(pack_datalen,pack_index>>1);		
+					SendComMap(pack_datalen,pack_index>>1);		
 					break;
 				default:
 					break;
diff --git a/keil/include/drivers/uwb_app.c b/keil/include/drivers/uwb_app.c
index a91ff99..bf2bb11 100644
--- a/keil/include/drivers/uwb_app.c
+++ b/keil/include/drivers/uwb_app.c
@@ -279,9 +279,9 @@
 
 /* RX done process handler. */
 int8_t rssi;
-uint32_t range_timeout_us = 2000000,dev_id;//yuan5000
-uint8_t flag_temp2,flag_temp1,group_id;
-uint16_t uwb_losttimer,disoffset;
+uint32_t range_timeout_us = 2000000;//yuan5000
+uint8_t flag_temp2,flag_temp1;
+uint16_t uwb_losttimer;
 static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report)
 {		uint8_t valid_sts=0;
     // Power off radio
@@ -529,7 +529,7 @@
 uint32_t wltag_statetimer,wltag_uwbtimer;
 uint32_t uwbtasktimer=0,uwbtagsendtimer=0;
 void IdleTask(void)
-{
+{UART_CheckReceive();
 //if(read_5v_input_pca())
 //		{
 //		        if(state5v==0)
diff --git a/keil/include/main/main.c b/keil/include/main/main.c
index c9a34a8..b2df95a 100644
--- a/keil/include/main/main.c
+++ b/keil/include/main/main.c
@@ -50,6 +50,9 @@
 #include "mk_uart.h"
 #include "mk_spi.h"
 #include "mk_flash.h"
+#include "Usart.h"
+#include <serial_at_cmd_app.h>
+#include <global_param.h>
 
 #include "board.h"
 
@@ -110,6 +113,11 @@
 //*****************************************************************************
 #define WSF_BUF_POOLS 5
 void Fira_Change_Task(void);
+extern uint8_t normal_flag,log_4g_enable_flag;
+extern uint16_t ip0,ip1,ip2,ip3,port;
+uint8_t group_id,enable_sleep_count;
+uint32_t dev_id;
+uint16_t disoffset;
 // Default pool descriptor.
 static wsfBufPoolDesc_t poolDescriptors[WSF_BUF_POOLS] = {
     {32, 26}, {64, 24}, {128, 4}, {256 + 32, 4}, {1024 + 32, 2},
@@ -119,7 +127,37 @@
 {
     // LOG_INFO(TRACE_MODULE_APP, "Wake up by sleep timer %d\r\n", time);
 }
-
+void Program_Init(void)
+{
+    Usart1ParseDataCallback = UsartParseDataHandler;//需改为默认为gps处理,UsartParseDataHandler为升级处理当调试时候改为
+    parameter_init_anchor();//g_com_map表初始化角色默认为基站
+    dev_id=g_com_map[DEV_ID];//这里不太对
+    group_id=(uint8_t)g_com_map[GROUP_ID];//组ID
+//    tag_frequency = 1000/g_com_map[COM_INTERVAL];//测距频率这个存的是测距时间
+    memcpy(&disoffset,&g_com_map[DIST_OFFSET],2);
+//    g_com_map[ALARM_DISTANCE1] = 40;
+//    g_com_map[ALARM_DISTANCE2] = 40;
+//    warning_distance=g_com_map[ALARM_DISTANCE1];
+//    prewarning_distance=g_com_map[ALARM_DISTANCE2];
+		//g_com_map[SEND_4G_SECOND]
+//    if(g_com_map[SEND_4G_SECOND]<30)
+//		{
+//		gps_open_flag=0;
+//		}else{
+//		gps_open_flag=1;
+//		}
+    g_com_map[MODBUS_MODE] = 0;
+		log_4g_enable_flag=g_com_map[LOG_4G_ENABLE];
+    ip0 = (g_com_map[TCP_IP_0]>>12&0xf)*1000+(g_com_map[TCP_IP_0]>>8&0xf)*100+(g_com_map[TCP_IP_0]>>4&0xf)*10+(g_com_map[TCP_IP_0]&0xf);
+    ip1 = (g_com_map[TCP_IP_1]>>12&0xf)*1000+(g_com_map[TCP_IP_1]>>8&0xf)*100+(g_com_map[TCP_IP_1]>>4&0xf)*10+(g_com_map[TCP_IP_1]&0xf);
+    ip2 = (g_com_map[TCP_IP_2]>>12&0xf)*1000+(g_com_map[TCP_IP_2]>>8&0xf)*100+(g_com_map[TCP_IP_2]>>4&0xf)*10+(g_com_map[TCP_IP_2]&0xf);
+    ip3 = (g_com_map[TCP_IP_3]>>12&0xf)*1000+(g_com_map[TCP_IP_3]>>8&0xf)*100+(g_com_map[TCP_IP_3]>>4&0xf)*10+(g_com_map[TCP_IP_3]&0xf);
+    port = g_com_map[TCP_PORT];
+    g_com_map[VERSION] = (1<<8)|0;
+    LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id);
+    LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位手环 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
+    LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port);
+}
 static void board_init(void)
 {
     uint32_t internal_flash = (REG_READ(0x40000018) >> 17) & 0x1;
@@ -163,8 +201,9 @@
     // Configure IO_04 for RF Switch
     gpio_pin_set_dir(IO_PIN_4, GPIO_DIR_OUT, 0);
 #else
+		Program_Init();
     // led
-    board_led_init();
+   // board_led_init();
 //    board_led_on(BOARD_LED_1);
 #endif
     board_configure();
@@ -195,7 +234,12 @@
 void Fira_Change_Task(void)
 {
 }
-extern uint8_t normal_flag;
+
+static void uart_receive_callback(void *dev, uint32_t err_code)
+{
+    uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
+}
+
 int main(void)
 {
     // Initialize MCU system
@@ -291,7 +335,7 @@
 
     // Enable sleep timer
     sleep_timer_open(true, SLEEP_TIMER_MODE_ONESHOT, sleep_timer_callback);
-
+		uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
     while (1)
     {
         wsfOsDispatcher();
diff --git a/keil/uci_fira.uvprojx b/keil/uci_fira.uvprojx
index e330fd1..97a5eaa 100644
--- a/keil/uci_fira.uvprojx
+++ b/keil/uci_fira.uvprojx
@@ -608,6 +608,21 @@
               <FileType>1</FileType>
               <FilePath>.\include\drivers\global_param.c</FilePath>
             </File>
+            <File>
+              <FileName>Usart.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>.\include\drivers\Usart.c</FilePath>
+            </File>
+            <File>
+              <FileName>Usart1.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>.\include\drivers\Usart1.c</FilePath>
+            </File>
+            <File>
+              <FileName>serial_at_cmd_app.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>.\include\drivers\serial_at_cmd_app.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>

--
Gitblit v1.9.3