From 89fd0aa609f215a33731e8babbef13e97fff27c3 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期二, 12 十月 2021 17:31:56 +0800 Subject: [PATCH] 超级小组汇总模式V1.45 --- 源码/核心板/Src/main.c | 278 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 181 insertions(+), 97 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..cc9d930 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,40 +6,125 @@ #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" +#include "ADC.h" +#include "modbus.h" #include "deca_device_api.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; - +#include "Flash.h" +//#define DEBUG_MODE void Device_Init(void) { -// Rcc_Init(); - SystemInit(); + RCC_Configuration(); + //SystemInit(); + NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000); Nvic_Init(); - Systick_Init(); -#ifdef WORK_MODE_TAG - RTC_Configuration(); -#endif +// Systick_Init(); + TIM3_Int_Init(); Led_Init(); Beep_Init(); DW_GPIO_Init(); Uart1_Init(); Spi_Init(); - + ADC_Configuration(); GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); } - -void Parameter_Init(void) +u8 anchor_type; +u32 dev_id; +u8 hbsend[16]; +void HeartBeatInit(void) { + u16 checksum; + hbsend[0]=0x55; + hbsend[1]=0xAA; + hbsend[2]=0x2; + hbsend[3]=0xc; + memcpy(&hbsend[4],&g_com_map[DEV_ID],2); + checksum = Checksum_u16(&hbsend[2],12); + memcpy(&hbsend[14],&checksum,2); +} +u16 tyncpoll_time; +TrackingDiffClass *pUWBDistanceTrackingDiff; +u8 group_id,sync_mainbase=0,synclost_timer=0; +uint16_t vel_factor,pos_factor; + +extern u8 module_power; +u16 slottime,max_slotnum,current_slotpos,dist_threshold; +u16 supergroupid; +void Program_Init(void) +{uint16_t i; + float temp; + u16 temp2; Usart1ParseDataCallback = UsartParseDataHandler; + parameter_init(); + //deca_sleep(1000); + HeartBeatInit(); +// g_com_map[DEV_ROLE]=1; +// g_com_map[DEV_ID]=1; +// g_com_map[COM_INTERVAL]=10; + OUT485_ENABLE; + +#ifdef DEBUG_MODE + +// g_com_map[COM_INTERVAL]=50; +// g_com_map[MAX_REPORT_ANC_NUM]=3; +// g_com_map[DEV_ID]=1; +// g_com_map[ANC_POLL]=0; +// g_com_map[ALARM_DISTANCE1]=100; + g_com_map[FILTER_COEFFICIENT]=12; +#endif + //pUWBDistanceTrackingDiff = NewTrackingDiffClass(2, 4, 0.03); + dev_id = g_com_map[DEV_ID]; + group_id=g_com_map[GROUP_ID]; + vel_factor=g_com_map[FILTER_COEFFICIENT]; + pos_factor=g_com_map[FILTER_COEFFICIENT]; + dist_threshold = (g_com_map[SPEEDFILTER_THRES]*10)/(1000/g_com_map[COM_INTERVAL]); + if(dist_threshold<300) + {dist_threshold = 300;} + if(dist_threshold>15000) + {dist_threshold = 15000;} + if(dev_id==0) + sync_mainbase=1; + module_power = g_com_map[POWER]; + if(module_power>67) + { + module_power=67; + } + supergroupid = g_com_map[IMU_THRES]; + g_com_map[VERSION] = 0x012d; + g_com_map[SW_TYPE] = SW_MODBUS; + temp=(float)g_com_map[MAX_REPORT_ANC_NUM]*4/3; + temp2=g_com_map[MAX_REPORT_ANC_NUM]*4/3; + if(temp2<temp) + { + temp2++; + } + slottime=temp2; + max_slotnum=g_com_map[COM_INTERVAL]/temp2; + current_slotpos=g_com_map[DEV_ID]; + tyncpoll_time=(current_slotpos%max_slotnum)*slottime; + if(g_com_map[DEV_ROLE]) + { + printf("标签ID: %d .\r\n",dev_id); + printf("通讯间隔: %d ms.\r\n",g_com_map[COM_INTERVAL]); + printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]); + }else{ + anchor_type = dev_id%g_com_map[MAX_REPORT_ANC_NUM]; + printf("基站ID: %x .\r\n",dev_id); + printf("基站类型: %c .\r\n",anchor_type+0x41); + printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]); + } + OUT485_DISABLE; +// 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]); + + + for(i=0;i<255;i++) + { + g_Tagdist[i]=0xffff; + } } /*! ------------------------------------------------------------------------------------------------------------------ @@ -51,94 +136,93 @@ * * @return none */ -extern uint8_t send_start; +void HeatBeat(void) +{ +UART_PushFrame(hbsend,16); +} +extern u8 g_start_sync_flag; +u16 heartbeat_timer,poll_timer,sync_timer; +void IdleTask(void) +{ + g_start_sync_flag=0; + UART_CheckReceive(); + UART_CheckSend(); + if(heartbeat_timer>1000) + { + heartbeat_timer=0; + if(g_com_map[HEARTBEAT]&&g_com_map[DEV_ROLE]==0) + HeatBeat(); + } + + if(g_com_map[CNT_UPDATE]==1) + { + uint32_t result = 0; + u16 tmp = 0xAAAA; + __disable_irq(); + result = FLASH_Prepare(0x8004A38, 2); + if(result) + result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); + __enable_irq(); + printf("进入升级模式\r\n"); + g_com_map[CNT_UPDATE]=0; + save_com_map_to_flash(); + delay_ms(100); + // STMFLASH_Write_NoCheck(0x8004A38,0xAAAA); + // Delay_ms(100); + SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader + } +// if(g_com_map[CNT_REBOOT]==1) +// { +// g_com_map[CNT_REBOOT]=0; +// g_com_map[MAP_SIGN_INDEX]=0; +// save_com_map_to_flash(); +// delay_ms(100); +// SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader +// } + if(g_com_map[CNT_RESTART]==1) + { + g_com_map[CNT_RESTART]=0; + save_com_map_to_flash(); + delay_ms(100); + SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader + } + + } +uint16_t temp; +float dw_vbat; 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); + Dw1000_App_Init(); /* Loop forever initiating ranging exchanges. */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); + usart_send[0]=0x55; + usart_send[1]=0xAA; + Modbus_RegMap(); while(1) { -#ifdef WORK_MODE_TAG - - if(send_start) - {send_start=0; + if(g_com_map[0] != 0x55AA) + { + while(1) + IdleTask(); + } + if(g_start_send_flag) + { + g_start_send_flag = 0; + temp=dwt_readtempvbat(1); + dw_vbat=(float)((temp&0xff)-173)/173+3.3; + if(dw_vbat>2.8) Tag_App(); - } - RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); -PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); -#else + }//else{ + IdleTask(); +// } +// +if(g_com_map[DEV_ROLE]==0) 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