| | |
| | | #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 500 |
| | | #define BEEM_ON_TIME_MS 200 |
| | | |
| | | float dis_after_filter = 0; |
| | | |
| | | void Device_Init(void) |
| | | { |
| | | // Rcc_Init(); |
| | | SystemInit(); |
| | | RCC_Configuration(); |
| | | //SystemInit(); |
| | | Nvic_Init(); |
| | | Systick_Init(); |
| | | Led_Init(); |
| | | Beep_Init(); |
| | | DW_GPIO_Init(); |
| | | Usart_Init(); |
| | | Uart1_Init(); |
| | | Spi_Init(); |
| | | |
| | | |
| | | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /*! ------------------------------------------------------------------------------------------------------------------ |
| | |
| | | * |
| | | * @return none |
| | | */ |
| | | |
| | | int main(void) |
| | | { |
| | | LPFilter_Frac* p_Dis_Filter; |
| | | |
| | | |
| | | Device_Init(); |
| | | Program_Init(); |
| | | Dw1000_Init(); |
| | | p_Dis_Filter = New_LP_Frac(0.9); |
| | | |
| | | delay_ms(1000); |
| | | #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); |
| | | while(1) |
| | | { |
| | | #ifdef WORK_MODE_TAG |
| | | if(g_start_send_flag) |
| | | { |
| | | g_start_send_flag = 0; |
| | | Tag_App(); |
| | | } |
| | | // 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 <= START_ALARM_DIST_CM) |
| | | { |
| | | 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; |
| | | } |
| | | else |
| | | { |
| | | g_beep_on_time = 0; |
| | | g_beep_off_time = 0; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |