| | |
| | | #include "dw_app_anchor.h" |
| | | #include "HIDO_TypeDef.h" |
| | | #include "PCA9555.h" |
| | | #include "mk_misc.h" |
| | | /********************************************结构体**************************************************************/ |
| | | typedef enum |
| | | { |
| | |
| | | lora_sendbuffer[HB_LORAPOWER_IDX] = g_com_map[LORA_POWER]; |
| | | checksum = Checksum_u16(lora_sendbuffer,14); |
| | | memcpy(&lora_sendbuffer[14],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,16); |
| | | // Radio.Send(lora_sendbuffer,16); |
| | | |
| | | /*****************************心跳包上传内容*************************************/ |
| | | |
| | |
| | | uint8_t BT_NUM=0; |
| | | extern uint16_t report_ancdist[ANC_MAX_NUM],report_ancid[ANC_MAX_NUM]; |
| | | extern uint8_t bat_percent; |
| | | extern uint16_t REV_RX_NUM; |
| | | extern uint16_t REV_POLL_NUM; |
| | | extern uint16_t REPLY_POLL_NUM; |
| | | uint16_t num[3]={0,0,0}; |
| | | extern uint8_t stationary_flag; |
| | | extern uint8_t SOS_KEY_STATE; |
| | | uint32_t LORA_POLL_COUNT=0; |
| | | void LoraReportPoll(void) |
| | | { |
| | | // delay_ms(100); |
| | |
| | | printf("气压值:%d",intheight); |
| | | #endif |
| | | |
| | | TagListUpdate(); |
| | | // TagListUpdate(); |
| | | |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; |
| | | // wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; |
| | | //Lora_init(); |
| | | uint32_t para; |
| | | |
| | | para=freq_list[2] * 100000; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,22); |
| | | |
| | | // rf_set_sf(REPORT_CHANNEL_SF); |
| | | SwitchLoraSettings(para,REPORT_CHANNEL_SF,0); |
| | | //rf_set_default_para(wg_report_freq,REPORT_CHANNEL_SF); |
| | | // SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | // dangqian_frqe=rf_read_freq(); |
| | | if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | { |
| | | heatbeat_count = 0; |
| | |
| | | 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; |
| | | BT_NUM=DMA_RXBuf_BT[0]; |
| | | if(SOS_KEY_STATE) |
| | | { |
| | | BT_NUM=0; |
| | | } |
| | | // lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_BT; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+4*BT_NUM+ANCID_IDX+3; |
| | | #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; |
| | | //GET_USERKEY这个是那个lora——busy那个引脚 |
| | | // lora_sendbuffer[STATE_IDX]=0x01; |
| | | // lora_sendbuffer[GATEWAY_CHANL]=0x02; |
| | | // lora_sendbuffer[CHANL_NUM]=0x03; |
| | | // 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); |
| | |
| | | lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | #endif |
| | | // memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); |
| | | // memcpy(&report_ancid,test_temp,10); |
| | | // memcpy(&report_ancdist,test_temp2,10); |
| | | |
| | | 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); |
| | | memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&intheight,2); |
| | | lora_sendbuffer[BT_ANCID_IDX] = report_ancnum; |
| | | memcpy(&lora_sendbuffer[BT_ANCID_IDX+1],report_ancid,report_ancnum*2); |
| | | memcpy(&lora_sendbuffer[BT_ANCID_IDX+report_ancnum*2+1],report_ancdist,report_ancnum*2); |
| | | uint8_t LORA_RETRANSNUSSION_BT=0; |
| | | BT_NUM=DMA_RXBuf_BT[0]; |
| | | if(0<BT_NUM&&BT_NUM<11) |
| | | { |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_BT; |
| | | LORA_RETRANSNUSSION_BT=ANCID_IDX+report_ancnum*4; |
| | | //LORA_RETRANSNUSSION_BT report_ancnum_bt |
| | | // |
| | | // num[0]=REV_RX_NUM; |
| | | // num[1]=REV_POLL_NUM; |
| | | // num[2]=REPLY_POLL_NUM; |
| | | LORA_RETRANSNUSSION_BT=BT_ANCID_IDX+report_ancnum*4+1; |
| | | lora_sendbuffer[LORA_RETRANSNUSSION_BT] = 0x2D; //蓝牙上传标识符 |
| | | |
| | | memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+1],&DMA_RXBuf_BT[0],BT_NUM*2+1); //基站ID |
| | | memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*2+2],&DMA_RXBuf_BT[1+BT_NUM*2],BT_NUM*2);//基站距离 |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+4*BT_NUM+ANCID_IDX+2; |
| | | } |
| | | if(lora_sendbuffer[LORA_RETRANSNUSSION_BT]==0x2D) |
| | | { |
| | | checksum = Checksum_u16(lora_sendbuffer,4*BT_NUM+4*report_ancnum+ANCID_IDX+2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+BT_NUM*4+report_ancnum*4+2],&checksum,2); |
| | | BT_SEND_flag++; |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4); |
| | | lora_sendbuffer[MSG_LENGTH] = LORA_RETRANSNUSSION_BT+4*BT_NUM+2; |
| | | // } |
| | | // if(lora_sendbuffer[LORA_RETRANSNUSSION_BT]==0x2D) |
| | | // { |
| | | checksum = Checksum_u16(lora_sendbuffer,4*BT_NUM+4*report_ancnum+BT_ANCID_IDX+3); |
| | | memcpy(&lora_sendbuffer[LORA_RETRANSNUSSION_BT+BT_NUM*4+2],&checksum,2); |
| | | BT_SEND_flag=BT_ANCID_IDX+report_ancnum*4+BT_NUM*4+5; |
| | | Radio.Send(lora_sendbuffer,BT_SEND_flag); |
| | | LORA_POLL_COUNT++; |
| | | // LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4,0); |
| | | } |
| | | else |
| | | { |
| | | checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+2); |
| | | } |
| | | // } |
| | | // else |
| | | // { |
| | | // checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | // Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+2); |
| | | // } |
| | | |
| | | |
| | | // LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+BT_NUM*4+4,0); |
| | |
| | | checksum = Checksum_u16(lora_sendbuffer,11+data_length); |
| | | memcpy(&lora_sendbuffer[11+data_length],&checksum,2); |
| | | // LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+13,0); |
| | | Radio.Send(lora_sendbuffer,data_length+13); |
| | | // Radio.Send(lora_sendbuffer,data_length+13); |
| | | //++; |
| | | // Delay_Ms(100); |
| | | } |
| | |
| | | memcpy(&lora_sendbuffer[7], &g_com_map[index/2], data_length); |
| | | checksum = Checksum_u16(lora_sendbuffer,9+data_length); |
| | | memcpy(&lora_sendbuffer[9+data_length],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,data_length+11); |
| | | // Radio.Send(lora_sendbuffer,data_length+11); |
| | | |
| | | // LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+11,0); |
| | | // Delay_Ms(100); |
| | |
| | | uint16_t lora_send_count; |
| | | uint8_t mode_flag=0; |
| | | uint32_t frqe,dangqian_frqe; |
| | | uint32_t freq_list[4] = {470000000/100000,4730,4780,4910}; |
| | | |
| | | |
| | | void Lora_Tx_Poll() |
| | | { |
| | |
| | | { |
| | | // gpio_pin_set(IO_PIN_5); |
| | | |
| | | |
| | | if(lora_send_count++%10==0||lora_jianting_flag) |
| | | { |
| | | lora_tx_flag=0; |
| | |
| | | if(rec_secdelay>0) |
| | | { |
| | | rec_secdelay--; |
| | | // if(lora_jianting_flag) |
| | | // { |
| | | // if(++group_id>GROUP_NUM) |
| | | // { |
| | | // group_id = 1; |
| | | // } |
| | | // t22[ti++] = group_id; |
| | | // if(ti>=20) |
| | | // ti=0; |
| | | // group_min_dist[group_id] = 0xffff; |
| | | // Radio.Standby(); |
| | | // SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); |
| | | // Radio.Rx(0); |
| | | // } |
| | | return; |
| | | } |
| | | // //找3个小组中最近距离最大的小组,上传报文后切换到这个小组,因为上传报文会时间占用。 |
| | | // if(group_min_dist[1]>group_min_dist[2]) //如果1大于2 |
| | | // { |
| | | // group_maxdist_index = group_min_dist[1]>group_min_dist[3]?1:3; //取 1和3 最大值 |
| | | // group_mindist_index = group_min_dist[2]<group_min_dist[3]?2:3;//取 2和3 最小值 |
| | | // |
| | | // }else{ |
| | | // group_maxdist_index = group_min_dist[2]>group_min_dist[3]?2:3; //取 2和3 最大值 |
| | | // group_mindist_index = group_min_dist[1]<group_min_dist[3]?1:3;//取 1和3 最小值 |
| | | // } |
| | | //// group_id = 1; |
| | | // group_id = group_maxdist_index; |
| | | #endif |
| | | t22[ti++] = group_id; |
| | | if(ti>=20) |
| | | ti=0; |
| | | // group_min_dist[group_id] = 0xffff; |
| | | // Radio.Standby(); |
| | | //rf_antenna_close(); |
| | | // rf_set_mode(RF_MODE_STB3); |
| | | // uint32_t para; |
| | | // frqe=((UWB_CHANNEL_FRQ+group_id)*100000); |
| | | // para=freq_list[1] * 100000; |
| | | //// rf_set_default_para(frqe,UWB_CHANNEL_SF); |
| | | // rf_set_carrier_wave_off(); |
| | | //// rf_set_carrier_wave_on(); |
| | | // rf_set_freq(para); |
| | | // rf_set_sf(5); |
| | | //// rf_set_tx_power(para); |
| | | //// rf_set_carrier_wave_freq(freq_list[1] * 100000); |
| | | // //SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); |
| | | // dangqian_frqe=rf_read_freq(); |
| | | // LoraSendComMap(WGRSP_RWTAG_READ); |
| | | |
| | | //delay_us(5000); |
| | | // rf_enter_continous_rx(); |
| | | //LedTask(); |
| | | //LoraHeartBeartPoll(); |
| | | // if(rf_continous_tx_send_data(tx_test_buf, TX_LEN) != OK) |
| | | // { |
| | | // while(1); |
| | | // } |
| | | // rf_get_mode(); |
| | | LoraReportPoll(); |
| | | // LedOff_task(); |
| | | |
| | | LoraReportPoll(); |
| | | |
| | | } |
| | | } |
| | |
| | | //uint32_t lora_zhuangtai; |
| | | //uint16_t current_count; |
| | | //extern wg_state_enum wg_state; |
| | | |
| | | uint8_t txdone=0; |
| | | void OnTxDone( void ) |
| | | { |
| | | { |
| | | txdone++; |
| | | if(flag_writepara_needreset) //配置写入完成设备需要重启 |
| | | { |
| | | printf("网关下发配置写入完成,重启"); |
| | |
| | | uint16_t rec_value,rx_count,datalen_offset; |
| | | int32_t target_count; |
| | | uint32_t sleep_time_count=0; |
| | | uint32_t sleep_time_count_LAST=0; |
| | | uint16_t time_count; |
| | | uint8_t LoraUp_flag; |
| | | |
| | | uint16_t REV_WG_pack=0; |
| | | uint8_t rxdone=0; |
| | | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | { |
| | | |
| | | |
| | | uint16_t checksum1; |
| | | uint16_t checksum1; |
| | | BufferSize = size; |
| | | memcpy( RX_Buffer, payload, BufferSize ); |
| | | RssiValue = rssi; |
| | | SnrValue = snr; |
| | | Radio.Standby(); |
| | | rxdone++; |
| | | no_rx_flag = 0; |
| | | lora_up_rec_flag=1; |
| | | if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG) |
| | |
| | | switch(RX_Buffer[PWTAG_RW_FLAG_IDX]) |
| | | { |
| | | case WGRSP_RWTAG_NONE: |
| | | REV_WG_pack++; |
| | | wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400; |
| | | memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2); |
| | | |
| | | if(report_ancnum<2) |
| | | { |
| | | datalen_offset = report_ancnum*85; |
| | |
| | | { |
| | | rec_secdelay = 0; |
| | | } |
| | | sleep_time_count = rec_delaytime - delaytime-datalen_offset; |
| | | while(sleep_time_count>=1000) |
| | | sleep_time_count-=1000; |
| | | sleep_timer_start(sleep_time_count); |
| | | |
| | | if(rec_delaytime<500) |
| | | { |
| | | int t; |
| | | t++; |
| | | } |
| | | // sleep_time_count =(__MS_TO_32K_CNT(rec_delaytime)/10)- delaytime-datalen_offset; |
| | | sleep_time_count =(__MS_TO_32K_CNT(rec_delaytime)/10); |
| | | while(sleep_time_count>=32768) |
| | | { |
| | | sleep_time_count-=32768; |
| | | } |
| | | while(sleep_time_count<2000) |
| | | { |
| | | sleep_time_count+=10000; |
| | | } |
| | | // if(REV_WG_pack==1) |
| | | // { |
| | | // sleep_time_count_LAST=sleep_time_count; |
| | | // } |
| | | // if(abs(sleep_time_count_LAST-sleep_time_count)>2000||REV_WG_pack==1) |
| | | // { |
| | | sleep_timer_start(sleep_time_count); |
| | | time_count++; |
| | | // } |
| | | break; |
| | | case WGRSP_RWTAG_READ: |
| | | no_rx_flag = 1; |
| | |
| | | break; |
| | | } |
| | | } |
| | | if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL) |
| | | { |
| | | |
| | | // uwb_open(); |
| | | |
| | | //// UwbRange(); |
| | | |
| | | // uwb_ceju_count++; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |