| | |
| | | return i; |
| | | } |
| | | uint32_t temp231; |
| | | static uint8_t anchordata_bat[TAG_NUM_IN_SYS]; |
| | | void MbxTagUwbRec(void) |
| | | { |
| | | |
| | |
| | | memcpy(&tempid,&rx_buffer[FZ_NEARBASEID_INDEX+i*2],2); |
| | | if(tempid==dev_id) |
| | | { |
| | | anchordata_bat[taglist_pos] = battary; |
| | | Anchor_RecNearPoll(i); |
| | | tagdist_list[taglist_pos]=rec_ancdistlist[i]; |
| | | if(taglist_pos==taglist_num)// taglist_pos==taglist_num 说明这个基站不在当前列表中 |
| | |
| | | |
| | | } |
| | | wg_state_enum wg_state = WG_Lost; |
| | | uint8_t lora_sendbuffer[200]; |
| | | uint8_t lora_sendbuffer[100]; |
| | | u8 seq_num; |
| | | extern u8 wg_lost_count; |
| | | uint16_t wg_report_freq,wg_report_id; |
| | |
| | | extern float Height; |
| | | u8 tarray[20]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; |
| | | extern u8 lora_busy_flag; |
| | | uint8_t dangqian_num; |
| | | uint16_t wangguanid=0xffff; |
| | | u8 fasongwancheng_flag; |
| | | void LoraReportPoll(void) |
| | | { |
| | | // delay_ms(100); |
| | | #ifdef _USE_BAR |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | #endif |
| | | #ifdef _SMT_TEST |
| | | printf("气压值:%d",intheight); |
| | | #endif |
| | | // // delay_ms(100); |
| | | //#ifdef _USE_BAR |
| | | // GetPressAndHeight(); |
| | | // intheight = Height*100; |
| | | //#endif |
| | | //#ifdef _SMT_TEST |
| | | // printf("气压值:%d",intheight); |
| | | //#endif |
| | | |
| | | TagListUpdate(); |
| | | |
| | | // TagListUpdate(); |
| | | //taglist_num=20; |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; |
| | | // flag_getwgresp = 0; |
| | | // wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | { |
| | | heatbeat_count = 0; |
| | | LoraHeartBeartPoll(); |
| | | return; |
| | | } |
| | | for(u16 i=0; i<report_ancnum-1; i++) |
| | | { |
| | | for(u16 j=0; j<report_ancnum-1-i; j++) |
| | | // if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | // { |
| | | // heatbeat_count = 0; |
| | | // LoraHeartBeartPoll(); |
| | | // return; |
| | | // } |
| | | // for(u16 i=0; i<report_ancnum-1; i++) |
| | | // { |
| | | // for(u16 j=0; j<report_ancnum-1-i; j++) |
| | | // { |
| | | // if(report_ancdist[j]>report_ancdist[j+1]) |
| | | // { |
| | | // u16 id,dist; |
| | | // u8 bat; |
| | | // id = report_ancid[j]; |
| | | // dist = report_ancdist[j]; |
| | | // report_ancid[j] = report_ancid[j+1]; |
| | | // report_ancdist[j] = report_ancdist[j+1]; |
| | | // report_ancid[j+1] = id; |
| | | // report_ancdist[j+1] = dist; |
| | | // } |
| | | // } |
| | | // } |
| | | // if(report_ancnum>LORA_REPORT_MAXANC_NUM) //考虑lora传输时间,最多发送10个基站数据。 |
| | | // report_ancnum = LORA_REPORT_MAXANC_NUM; |
| | | //#ifdef USE_GPS |
| | | // lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | // lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30; |
| | | //#else |
| | | // lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | // lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; |
| | | //#endif |
| | | // memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | // memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | // lora_sendbuffer[SEQNUM_IDX] = seq_num++; |
| | | // lora_sendbuffer[BAT_IDX] = bat_percent; |
| | | // lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1; |
| | | //#ifdef USE_GPS |
| | | // memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8); |
| | | // memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8); |
| | | // memcpy(&lora_sendbuffer[GPS_HEIGHT_IDX],&gps_height,8); |
| | | // lora_sendbuffer[GPS_STATE_IDX] = gps_state; |
| | | // lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num; |
| | | // lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | // lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | //#endif |
| | | // memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); |
| | | // lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | | // checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | //// HAL_NVIC_DisableIRQ(EXTI4_15_IRQn); |
| | | //// HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); |
| | | //// HAL_GPIO_WritePin(SPIx_CS_GPIO, SPIx_CS, GPIO_PIN_SET); |
| | | // lora_busy_flag=1; |
| | | // Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | // LED_TB_ON; |
| | | // bat_percent=Get_Battary(); |
| | | uint16_t checksum1 = 0; |
| | | lora_sendbuffer[MSG_TYPE_IDX] = 0x32; |
| | | lora_sendbuffer[MSG_LENGTH] = 17; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&tagid_list[dangqian_num],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wangguanid,2); |
| | | // memcpy(&heatbeat_buffer[ANC_HB_VERSION_IDX],&g_com_map[VERSION],2); |
| | | // memcpy(&heatbeat_buffer[ANC_HB_UWBPOLLTIME_IDX],&g_com_map[UWBPOLLTIME_MS_IDX],2); |
| | | // heatbeat_buffer[ANC_HB_UWBPOWER_IDX] = g_com_map[POWER]; |
| | | // heatbeat_buffer[ANC_HB_LORAPOWER_IDX] = g_com_map[LORA_POWER]; |
| | | lora_sendbuffer[12] = anchordata_bat[dangqian_num]; |
| | | // heatbeat_buffer[ANC_HB_RESERVE] = group_id; |
| | | checksum1=Checksum_u16(lora_sendbuffer,17); |
| | | memcpy(&lora_sendbuffer[17],&checksum1,2); |
| | | Radio.Send(lora_sendbuffer, 19); |
| | | Delay_Ms(60); |
| | | dangqian_num++; |
| | | if(dangqian_num>taglist_num) |
| | | { |
| | | if(report_ancdist[j]>report_ancdist[j+1]) |
| | | { |
| | | u16 id,dist; |
| | | u8 bat; |
| | | id = report_ancid[j]; |
| | | dist = report_ancdist[j]; |
| | | report_ancid[j] = report_ancid[j+1]; |
| | | report_ancdist[j] = report_ancdist[j+1]; |
| | | report_ancid[j+1] = id; |
| | | report_ancdist[j+1] = dist; |
| | | } |
| | | fasongwancheng_flag=1; |
| | | } |
| | | } |
| | | if(report_ancnum>LORA_REPORT_MAXANC_NUM) //考虑lora传输时间,最多发送10个基站数据。 |
| | | report_ancnum = LORA_REPORT_MAXANC_NUM; |
| | | #ifdef USE_GPS |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30; |
| | | #else |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; |
| | | #endif |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[SEQNUM_IDX] = seq_num++; |
| | | lora_sendbuffer[BAT_IDX] = bat_percent; |
| | | lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1; |
| | | #ifdef USE_GPS |
| | | memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_HEIGHT_IDX],&gps_height,8); |
| | | lora_sendbuffer[GPS_STATE_IDX] = gps_state; |
| | | lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num; |
| | | lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | #endif |
| | | memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); |
| | | lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | // HAL_NVIC_DisableIRQ(EXTI4_15_IRQn); |
| | | // HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); |
| | | // HAL_GPIO_WritePin(SPIx_CS_GPIO, SPIx_CS, GPIO_PIN_SET); |
| | | lora_busy_flag=1; |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | LED_TB_ON; |
| | | bat_percent=Get_Battary(); |
| | | |
| | | } |
| | | uint8_t Lora_send_flag; |
| | | void LedTask(void) |