| | |
| | | { |
| | | |
| | | } |
| | | #define HEATBEAT_UPDATE_TIME_S 10 //心跳包一个小时上传一次 |
| | | #define HEATBEAT_UPDATE_TIME_S 3600 //心跳包一个小时上传一次 |
| | | static uint16_t current_count,target_count,wg_report_id; |
| | | uint16_t heartbeat_count; |
| | | static uint8_t heatbeat_buffer[100]; |
| | | uint8_t diyicichongqi=1; |
| | | void HeartbeatPoll(uint16_t wangguanid) |
| | | {//心跳包上传 ID 版本号 小组 UWB功率 LORA功率 UWB发送时间 |
| | | heartbeat_count+=sync_interval_s; |
| | | if(heartbeat_count>HEATBEAT_UPDATE_TIME_S) |
| | | { uint16_t checksum1 = 0; |
| | | if(heartbeat_count>HEATBEAT_UPDATE_TIME_S||diyicichongqi) |
| | | { |
| | | diyicichongqi=0; |
| | | uint16_t checksum1 = 0; |
| | | heartbeat_count = 0; |
| | | heatbeat_buffer[MSG_TYPE_IDX] = LORA_MSGTYPE_ANC_HEARTBEAT; |
| | | heatbeat_buffer[MSG_LENGTH] = 17; |
| | |
| | | switch(lora_recbuffer[SUBMSGTYPE_IDX]) //子状态函数 |
| | | { |
| | | case SUBMSG_READ_ANCPARA: |
| | | heartbeat_count=HEATBEAT_UPDATE_TIME_S-2; |
| | | LoraSendComMap(SUBMSG_READ_ANCPARA); |
| | | config_state_count = CONFIG_REMAIN_TIME; |
| | | break; |
| | |
| | | } |
| | | taglist_total_num=j; |
| | | } |
| | | static u16 rec_nearbaseid,temp_index; |
| | | extern uint16_t verfint_cal; |
| | | u16 rec_nearbaseid,temp_index,adc_val1,adc_val_min=0xffff; |
| | | static u8 rec_tag_index,tag_num_tosend; |
| | | extern uint8_t Anchor_Vcc_Flag; |
| | | extern float bat_volt; |
| | | uint16_t AD_value[500],ti; |
| | | void MBXANCPoll(void) //将要发的标签序号,在列表中的位置 |
| | | { |
| | | |
| | |
| | | tag_num_tosend = 25; |
| | | } |
| | | count1++; |
| | | ti = 0; |
| | | dwt_setrxaftertxdelay(300);//设置发送完成后开启接收延迟时间 |
| | | dwt_setrxtimeout(0);//接收超时时间 |
| | | memcpy(&uwb_sendbuffer[TAG_ID_IDX],&dev_id,2); |
| | |
| | | dwt_writetxfctrl(13+4*tag_num_tosend, 0);//设置超宽带发送数据长度 |
| | | |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); |
| | | |
| | | if(Anchor_Vcc_Flag) |
| | | { |
| | | READC_Init(); |
| | | adc_val_min=0xffff; |
| | | verfint_cal = *(__IO uint16_t *)(0X1FF80078); |
| | | } |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | poll_timeout=tag_num_tosend*SLOT_SCALE+20; //单位0.1ms |
| | | end_count=start_count+(poll_timeout<<2); |
| | |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | |
| | | { |
| | | if(Anchor_Vcc_Flag) |
| | | { |
| | | |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); |
| | | adc_val1 = Get_ADC_Value(); |
| | | AD_value[ti++] = adc_val1; |
| | | if(ti>=500) |
| | | ti = 400; |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); |
| | | if(adc_val1<adc_val_min) |
| | | { |
| | | adc_val_min= adc_val1; |
| | | } |
| | | } |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count>=end_count&¤t_count<end_count+15000) |
| | | break; |
| | |
| | | SetANCTimestap(temp_index,&rx_buffer[RESP_MSG_POLL_RX_TS_IDX],&rx_buffer[RESP_MSG_RESP_TX_TS_IDX],resp_rx_ts,&rx_buffer[RESP_MSG_ANC_DISTOFFSET]); |
| | | } |
| | | |
| | | } |
| | | } |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | dwt_rxenable(0); |
| | | |
| | | } |
| | | } |
| | | dwt_forcetrxoff(); |
| | | CalculateDists(); |
| | | TagListUpdate(); |
| | |
| | | taglist_current_index+=tag_num_tosend; |
| | | if(taglist_current_index>=taglist_total_num||taglist_total_num<=25) //如果标签当前index大于总index,或者总基站数量小于等于25,则从0开始index。 |
| | | taglist_current_index = 0; |
| | | if(Anchor_Vcc_Flag) |
| | | { |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); |
| | | Anchor_Vcc_Flag=0; |
| | | MX_ADC_DeInit(); |
| | | bat_volt = 3*(float)verfint_cal/AD_value[50]-0.28; |
| | | bat_percent=bat_volt*100-200; |
| | | } |
| | | } |
| | | |
| | | |