From dcac514bc4be1c6acfd7cf92ce609d282ba55f1c Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期二, 10 十一月 2020 20:48:07 +0800
Subject: [PATCH] V2.13 1增加临近距离判断  2增加注册包超时清空机制

---
 源码/核心板/Src/application/dw_app.h |  125 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 119 insertions(+), 6 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
index b9a4427..411bd5b 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
@@ -2,24 +2,132 @@
 #ifndef __DW_APP_H__
 #define __DW_APP_H__
 
+#include <string.h>
 #include "stm32f10x.h"
 #include "filters.h"
 #include "ADC.h"
-#define WORK_MODE_TAG
-//#define WORK_MODE_ANCHOR
+#include "deca_device_api.h"
+#include "deca_regs.h"
+#include "dw_driver.h"
+#include "Spi.h"
+#include "led.h"
+#include "serial_at_cmd_app.h"
+#include "Usart.h"
+#include "global_param.h"
+#include "filters.h"
+#include <stdio.h>
+#include "beep.h"
+#include <math.h>
 
+//#define USART_INTEGRATE_OUTPUT
+//#define TAG_OUTPUT
+//#define DEBUG_INF
 //#define NEWBOARD
 //#define TAG_OUTPUT
 #define HEX_OUTPUT
 
+#define MAX_NEARBASE_NUM 12
+#define MAX_RFPOWER   60
+#define DEFAULT_RFPOWER   30
 #define REPOET_ANC_NUM 1
 #define REPOET_ANC_NUM_MIN 1
-#define TOTAL_TAG_NUM  200
 #define TAG_ID_START 		0// 0x00980000
-
+#define GROUP_TAG_NUM 2
 #define TAG_NUM_IN_SYS				256
 #define DFT_RAND_DLY_TIM_MS			1
+#define QUIT_SLOT_TIME    5
+#define KEEP_TIMES 3
+#define SLOT_SCALE 0.24
+#define RNG_DELAY_MS 100
 
+/* Default antenna delay values for 64 MHz PRF. See NOTE 1 below. */
+#define TX_ANT_DLY 0
+#define RX_ANT_DLY 32899
+
+/* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.
+ * 1 uus = 512 / 499.2 祍 and 1 祍 = 499.2 * 128 dtu. */
+#define UUS_TO_DWT_TIME 65536
+
+/* Delay between frames, in UWB microseconds. See NOTE 4 below. */
+/* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
+#define POLL_TX_TO_RESP_RX_DLY_UUS 150
+/* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the
+ * frame length of approximately 2.66 ms with above configuration. */
+#define RESP_RX_TO_FINAL_TX_DLY_UUS 410
+/* Receive response timeout. See NOTE 5 below. */
+#define RESP_RX_TIMEOUT_UUS 2000
+
+#define DELAY_BETWEEN_TWO_FRAME_UUS 250
+
+#define POLL_RX_TO_RESP_TX_DLY_UUS 470
+/* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
+#define RESP_TX_TO_FINAL_RX_DLY_UUS 0
+/* Receive final timeout. See NOTE 5 below. */
+#define FINAL_RX_TIMEOUT_UUS 4300
+
+#define SPEED_OF_LIGHT 299702547
+
+//MESSAGE_TYPE
+#define POLL     							0x01
+#define RESPONSE 							0x02
+#define FINAL   							0x03
+#define SYNC   								0x04
+#define NEAR_MSG   						0x05
+#define NEAR_POLL   					0x06
+#define NEAR_RESPONSE   			0x07
+#define NEAR_FINAL   					0x08
+
+#define REG_POLL   						0x10
+#define REG_RESPONSE   				0x11
+//General
+#define GROUP_ID_IDX   				0
+#define ANCHOR_ID_IDX    			1
+#define TAG_ID_IDX    				5
+#define MESSAGE_TYPE_IDX 			9	
+//Poll
+#define ANC_TYPE_IDX 					14
+//respose
+#define DIST_IDX 							10
+#define ANCTIMEMS             14
+#define ANCTIMEUS             16
+#define MAINBASE_INDEX        18
+#define MOTORSTATE_INDEX      19
+#define NR_NEARSWITCH_DISTANCE   20
+#define REMOTEPARA_INDEX      22
+
+#define TAGSLOTPOS						7
+//Final
+#define TAGCONFIGSUCCESS_INDEX 7
+#define FINAL_MSG_POLL_TX_TS_IDX 10
+#define FINAL_MSG_RESP_RX_TS_IDX 14
+#define FINAL_MSG_FINAL_TX_TS_IDX 18
+#define FINAL_MSG_RESP_RX_NEARBASE_IDX  22
+#define FINAL_MSG_TS_LEN 4
+//SYNC
+#define ANCHOR_ID_IDX    			1
+#define SYNC_SEQ_IDX    			5
+//NEAR MSG
+#define NEARMSG_EMPTYSLOTPOS_INDEX		 1 //RESPONSE
+#define NEARBASENUM_INDEX    18
+#define NEARBASEID_INDEX		 19
+//NEAR POLL
+#define SEQUENCE_IDX					3
+#define BATTARY_IDX						4
+#define BUTTON_IDX						7
+#define NEARP_TAGFREQ_INDEX  10
+#define NEARP_TAGSLOTPOS_INDEX  12
+//REG RESPONSE
+#define REGR_TAGFREQ_INDEX  10
+#define REGR_TAGSLOTPOS_INDEX  12
+#define REGR_BASENUM_INDEX    18
+#define REGR_BASEID_INDEX		 19
+
+#define REMOTEPARA_LEN 18
+#define THRESHOLD_CHANGE_MAINBASE_DIST   500
+extern u8 neartimout_timer;
+extern u16 slottime,tyncpoll_time,max_slotpos;
+extern u16 poll_timer,tag_timer;
+extern int8_t tag_delaytime;
 extern u32 dev_id;
 extern u8 anchor_type;
 extern volatile uint32_t time32_incr;
@@ -28,14 +136,19 @@
 extern uint32_t g_UWB_com_interval;
 extern float dis_after_filter;
 extern LPFilter_Frac* p_Dis_Filter;		//测距用的低通滤波器
-extern u8 usart_send[25];
+extern u8 usart_send[100],usart_send_anc[100],flag_syncbase,remotesend_state, remotetag_para[30];;
 
+void IdleTask(void);
+uint16_t Checksum_u16(uint8_t* pdata, uint32_t len);
 void Dw1000_Init(void);
 void Tag_App(void);
 void Anchor_App(void);
 void tag_sleep_configuraion(void);
-extern uint16_t g_Tagdist[TOTAL_TAG_NUM];
+extern uint16_t g_Tagdist[TAG_NUM_IN_SYS];
 extern uint8_t g_flag_Taggetdist[256];
 extern void TagDistClear(void);
 void Dw1000_App_Init(void);
+void TagListUpdate(void);
+void SyncPoll(u8 sync_seq);
+u8 GetRandomSlotPos(uint32_t emptyslot);
 #endif

--
Gitblit v1.9.3