From 2ad2b82d448645cc81409aa4765288da95931cb8 Mon Sep 17 00:00:00 2001
From: guanjiao <sqrgj@163.com>
Date: 星期六, 15 九月 2018 17:20:16 +0800
Subject: [PATCH] 1. 增加了“收不到信息1s后,停止报警”的功能 2. 将判断喇叭是否响的功能,在systick中断中实现

---
 源码/核心板/Src/application/dw_app.h             |    4 +
 源码/核心板/Src/application/global_param.c       |    5 +
 源码/核心板/Src/main.c                           |   68 ----------------
 源码/核心板/Src/application/beep_logic_app.c     |   66 ++++++++++++++++
 源码/核心板/Src/stm32f10x_it.c                   |   28 ++----
 源码/核心板/Src/OnChipDevices/Rcc_Nvic_Systick.c |    2 
 源码/核心板/Src/application/global_param.h       |    6 
 源码/核心板/Src/application/beep_logic_app.h     |    9 ++
 源码/核心板/Src/stm32f10x_it.h                   |    4 -
 源码/核心板/Src/application/dw_app.c             |    9 ++
 10 files changed, 108 insertions(+), 93 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Rcc_Nvic_Systick.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Rcc_Nvic_Systick.c"
index e021ee3..38d4add 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Rcc_Nvic_Systick.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Rcc_Nvic_Systick.c"
@@ -59,7 +59,7 @@
 int Systick_Init(void)
 {
 	int time_retry = 500;
-	if (SysTick_Config(64000))
+	if (SysTick_Config(72000))
 	{
         /* Capture error */
         while (time_retry--);
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c"
new file mode 100644
index 0000000..d93e96f
--- /dev/null
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c"
@@ -0,0 +1,66 @@
+#include "beep_logic_app.h"
+#include "led.h"
+#include "beep.h"
+#include "global_param.h"
+#include "dw_app.h"
+
+void main_logic(void)	//主逻辑在这里执行
+{
+	//除UWB之外的其他代码...
+	static uint16_t beep_judge_cnt = 0;
+	if(beep_judge_cnt++ >= 200)
+	{	
+		beep_judge_cnt = 0;
+		
+		if(dis_after_filter <= g_com_map[ALARM_DISTANCE])
+		{
+			switch(g_com_map[ALARM_DEV]) 
+			{
+				case 0:
+					BEEP2_ON;
+					BEEP_OFF;
+					OUT2_OFF;
+					break;
+				case 1:
+					BEEP_ON;
+					BEEP2_OFF;
+					OUT2_OFF;
+					break;
+				case 2:
+					OUT2_ON;
+					BEEP_OFF;
+					BEEP2_OFF;
+					break;
+				default:
+					BEEP2_ON;
+					BEEP_ON;
+					OUT2_ON;
+					break;
+			}
+		}
+		else
+		{
+			switch(g_com_map[ALARM_DEV]) 
+			{
+				case 0:
+					BEEP2_OFF;
+					break;
+				case 1:
+					BEEP_OFF;
+					break;
+				case 2:
+					OUT2_OFF;
+					break;
+				default:
+					BEEP2_OFF;
+					BEEP_OFF;
+					OUT2_OFF;
+					break;
+			}
+		}
+	}
+}	
+
+
+
+
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.h"
new file mode 100644
index 0000000..0b1e40f
--- /dev/null
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.h"
@@ -0,0 +1,9 @@
+#ifndef __BEEP_LOGIC_H__
+#define __BEEP_LOGIC_H__
+
+#include "stm32f10x.h"
+
+void main_logic(void);	//主逻辑在这里执行
+
+#endif
+
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 bd1960c..64a0756 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"
@@ -28,6 +28,8 @@
 #include "led.h"
 #include "serial_at_cmd_app.h"
 #include "Usart.h"
+#include "global_param.h"
+#include "filters.h"
 
 
 /*------------------------------------ Marcos ------------------------------------------*/
@@ -129,6 +131,10 @@
 uint8_t random_delay_tim = 0;
 
 double distance, dist_no_bias, dist_cm;
+
+uint32_t g_UWB_com_interval = 0; 
+float dis_after_filter;				//当前距离值
+LPFilter_Frac* p_Dis_Filter;		//测距用的低通滤波器
 
 /*------------------------------------ Functions ------------------------------------------*/
 
@@ -435,7 +441,10 @@
 					dist_cm = dist_no_bias * 100; //dis 为单位为cm的距离
 //					dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定
 					
+					/*--------------------------以下为非测距逻辑------------------------*/
 					LED0_BLINK; //每成功一次通讯则闪烁一次
+					g_UWB_com_interval = 0;
+					dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);
 
 				}
 			}
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 e30d2d7..3a2c837 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"
@@ -3,11 +3,15 @@
 #define __DW_APP_H__
 
 #include "stm32f10x.h"
+#include "filters.h"
 
 #define TAG_NUM_IN_SYS				256
 #define DFT_RAND_DLY_TIM_MS			1
 
 extern double dist_cm;
+extern uint32_t g_UWB_com_interval;
+extern float dis_after_filter;
+extern LPFilter_Frac* p_Dis_Filter;		//测距用的低通滤波器
 
 void Dw1000_Init(void);
 void Tag_App(void);
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c"
index 6934c80..609adcd 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c"
@@ -1,7 +1,9 @@
 #include "global_param.h"
 #include "Flash.h"
+#include "dw_app.h"
 
 uint16_t g_com_map[COM_MAP_SIZE];
+
 
 uint32_t save_com_map_to_flash(void)
 {
@@ -21,6 +23,9 @@
 	
 	g_com_map[ALARM_DISTANCE] = 200;	//默认报警距离200cm
 	g_com_map[ALARM_DEV] = 0;
+	dis_after_filter = 1000;			//默认距离
+	p_Dis_Filter = New_LP_Frac(0.7);
+
 	
 }
 
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h"
index 977da01..ca85222 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h"
@@ -3,8 +3,8 @@
 
 #include "stm32f10x.h"
 
-#define COM_MAP_SIZE	1024
-
+#define COM_MAP_SIZE		1024		//MAP表的最大空间
+#define	DEFAULT_DISTANCE	1000		//初始测距距离为10米
 
 /*---------------Map Definition-------------------*/
 #define 	DEV_ROLE				0x10		//该设备是anchor还是tag	
@@ -17,8 +17,8 @@
 
 /*------------END Map Definition-------------------*/
 
-extern uint16_t g_com_map[COM_MAP_SIZE];
 
+extern uint16_t g_com_map[COM_MAP_SIZE];
 
 extern uint32_t save_com_map_to_flash(void);
 extern void parameter_init(void);
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
index b0e5590..8e7059e 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
@@ -6,17 +6,12 @@
 #include "beep.h"
 #include "dw_driver.h"
 #include "dw_app.h"
-#include "filters.h"
 #include "stm32f10x_it.h"
 #include "serial_at_cmd_app.h"
 #include "global_param.h"
 
 //#define WORK_MODE_TAG
 #define WORK_MODE_ANCHOR
-#define START_ALARM_DIST_CM			200
-#define BEEM_ON_TIME_MS				200
-
-float dis_after_filter = 500;
 
 void Device_Init(void)
 {
@@ -51,12 +46,10 @@
  */
 int main(void)
 {
-	LPFilter_Frac* p_Dis_Filter;
-	
+
 	Device_Init();
 	Program_Init();
 	Dw1000_Init();
-	p_Dis_Filter = New_LP_Frac(0.7);
 
     /* Loop forever initiating ranging exchanges. */
 	while(1)
@@ -65,67 +58,8 @@
 		Tag_App();
 #else 
 		Anchor_App();
-
 #endif
-		
-		//除UWB之外的其他代码...
-		dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);
-		
-		if(dis_after_filter <= g_com_map[ALARM_DISTANCE])
-		{
-//			g_beep_off_time = (uint32_t)dis_after_filter * 10;
-//			if(g_beep_off_time <= 0) 
-//				g_beep_off_time = 0;
-//			g_beep_on_time = BEEM_ON_TIME_MS;
-			switch(g_com_map[ALARM_DEV]) 
-			{
-				case 0:
-					BEEP2_ON;
-					BEEP_OFF;
-					OUT2_OFF;
-					break;
-				case 1:
-					BEEP_ON;
-					BEEP2_OFF;
-					OUT2_OFF;
-					break;
-				case 2:
-					OUT2_ON;
-					BEEP_OFF;
-					BEEP2_OFF;
-					break;
-				default:
-					BEEP2_ON;
-					BEEP_ON;
-					OUT2_ON;
-					break;
-			}
-		}
-		else
-		{
-//			g_beep_on_time = 0;
-//			g_beep_off_time = 0;
-			switch(g_com_map[ALARM_DEV]) 
-			{
-				case 0:
-					BEEP2_OFF;
-					break;
-				case 1:
-					BEEP_OFF;
-					break;
-				case 2:
-					OUT2_OFF;
-					break;
-				default:
-					BEEP2_OFF;
-					BEEP_OFF;
-					OUT2_OFF;
-					break;
-			}
-		}
-		
 
-		
 	}
 }
 
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.c"
index 8de836d..620a1ca 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.c"
@@ -23,32 +23,24 @@
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f10x_it.h"
 #include "stm32f10x.h"
-#include "beep.h"
+#include "dw_app.h"
+#include "global_param.h"
+#include "beep_logic_app.h"
 
 /* Tick timer count. */
 volatile uint32_t time32_incr;
 
-volatile uint32_t g_beep_on_time = 0;
-volatile uint32_t g_beep_off_time = 0;
-
 void SysTick_Handler(void)
 {
-	static uint32_t s_cycle_time = 0;
     time32_incr++;
+	g_UWB_com_interval++;
+	if(g_UWB_com_interval > 1000)
+	{	
+		dis_after_filter = DEFAULT_DISTANCE;
+	}
+	main_logic();
 	
-//	if(s_cycle_time >= g_beep_off_time)
-//	{
-//		s_cycle_time = 0;
-//	}
-//	else if(s_cycle_time > g_beep_on_time && s_cycle_time < g_beep_off_time)
-//	{
-//		BEEP_OFF;
-//	}
-//	else if(s_cycle_time <= g_beep_on_time)
-//	{
-//		BEEP_ON;
-//	}
-	s_cycle_time++;
+
 }
 
 /** 
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.h"
index 6ab61dc..086c5d4 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.h"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/stm32f10x_it.h"
@@ -27,10 +27,6 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-	
-extern volatile uint32_t g_beep_on_time;
-extern volatile uint32_t g_beep_off_time;
-
 
 /*
  * Tick timer interrupt handler to replace the default one.

--
Gitblit v1.9.3