From e5f73b1e954eb54e0af326b3a5aee5fab719f0ce Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期六, 08 六月 2019 10:06:45 +0800 Subject: [PATCH] 6月7号 --- 源码/核心板/Src/main.c | 128 ++++++++++++------------------------------ 1 files changed, 38 insertions(+), 90 deletions(-) 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 b2dd27c..b47d1c0 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,27 +6,18 @@ #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 "deca_device_api.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) { -// Rcc_Init(); - SystemInit(); + RCC_Configuration(); + //SystemInit(); Nvic_Init(); Systick_Init(); -#ifdef WORK_MODE_TAG - RTC_Configuration(); -#endif Led_Init(); Beep_Init(); DW_GPIO_Init(); @@ -37,9 +28,25 @@ GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); } -void Parameter_Init(void) -{ +void Program_Init(void) +{uint16_t i; Usart1ParseDataCallback = UsartParseDataHandler; + parameter_init(); + #ifdef WORK_MODE_TAG + printf("DEVICE MODE: TAG .\r\n"); + printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]); + printf("DEVICE INTERVAL: %d .\r\n",g_com_map[COM_INTERVAL]); + #else + printf("DEVICE MODE: ANCHOR .\r\n"); + printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]); + printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]); + printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]); + #endif + + for(i=0;i<255;i++) + { + g_Tagdist[i]=0xffff; + } } /*! ------------------------------------------------------------------------------------------------------------------ @@ -51,96 +58,37 @@ * * @return none */ -extern uint8_t send_start; + int main(void) { - LPFilter_Frac* p_Dis_Filter; - + Device_Init(); - Parameter_Init(); + Program_Init(); Dw1000_Init(); - p_Dis_Filter = New_LP_Frac(0.7); - - #ifdef WORK_MODE_TAG - dwt_configuresleep(0x940, 0x7); - _dwt_aonarrayupload(); - //dwt_entersleep(); - #endif - + delay_ms(10); +#ifdef WORK_MODE_TAG + RTC_Configuration(g_com_map[COM_INTERVAL]*20); + tag_sleep_configuraion(); +#endif + Dw1000_App_Init(); /* Loop forever initiating ranging exchanges. */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); + usart_send[0]=0x55; + usart_send[1]=0xAA; while(1) { #ifdef WORK_MODE_TAG - - if(send_start) - {send_start=0; + if(g_start_send_flag) + { + g_start_send_flag = 0; Tag_App(); } - RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); -PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); +// UART_CheckReceive(); + PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); #else Anchor_App(); - #endif - - //除UWB之外的其他代码... - dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); - - if(dis_after_filter <= g_alarm_dist) - { -// 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_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_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; - } - } - - } } -- Gitblit v1.9.3