| | |
| | | #include "mk_spi.h" |
| | | #include "global_param.h" |
| | | #include "pan_port.h" |
| | | #include "pan_rf.h" |
| | | //#include "WS2812.h" |
| | | //#include "pan_port.h" |
| | | //#include "pan_param.h" |
| | |
| | | uint32_t ret = 0; |
| | | uint32_t cnt = 0; |
| | | ret=rf_init(); |
| | | |
| | | set_test_mode1_reg(); |
| | | if(ret== 1) |
| | | { |
| | |
| | | // printf("LORA Init OK\r\n"); |
| | | } |
| | | } |
| | | wg_state_enum wg_state = WG_Lost; |
| | | extern wg_state_enum wg_state; |
| | | uint8_t lora_sendbuffer[200]; |
| | | uint8_t seq_num; |
| | | extern uint16_t lora_up_uwb_flag; |
| | |
| | | wg_report_id = DEFAULT_WG_ID; |
| | | wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; //如果丢失链接就进入WG管理信道。 |
| | | wg_report_sf = REPORT_CHANNEL_SF; |
| | | // wg_report_freq = TEST_MANAGE_CHANNEL_FRQ; |
| | | // wg_report_sf = TEST_MANAGE_CHANNEL_SF; |
| | | } |
| | | } else { |
| | | if(wg_lost_count>WG_LOST_SWITCH_THRES) |
| | |
| | | |
| | | //uint16_t wg_report_freq,wg_report_id; |
| | | uint8_t lora_sendbuffer[200]; |
| | | void Lora_UploadHeartBeartPoll(void) |
| | | void LoraHeartBeartPoll(void) |
| | | { |
| | | |
| | | // lora_up_uwb_flag=2; |
| | | // rf_set_default_para(); |
| | | |
| | | rf_enter_continous_tx(); |
| | | /*****************************心跳包上传内容************************************/ |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGHEARTBEAT; |
| | | lora_sendbuffer[MSG_LENGTH] = 14; |
| | |
| | | lora_sendbuffer[HB_LORAPOWER_IDX] = g_com_map[LORA_POWER]; |
| | | checksum = Checksum_u16(lora_sendbuffer,14); |
| | | memcpy(&lora_sendbuffer[14],&checksum,2); |
| | | LORA_3029_SINGLE_SEND(lora_sendbuffer,16,0); |
| | | |
| | | /*****************************心跳包上传内容*************************************/ |
| | | rf_set_transmit_flag(RADIO_FLAG_TXDONE); |
| | | |
| | | if(rf_get_transmit_flag()==RADIO_FLAG_TXDONE) |
| | | { |
| | | if(rf_continous_tx_send_data(lora_sendbuffer, 16)==OK) |
| | | { |
| | | //LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n"); |
| | | } |
| | | while (rf_get_transmit_flag() == RADIO_FLAG_IDLE) |
| | | ; |
| | | //rf_enter_continous_rx();; |
| | | rf_set_transmit_flag(RADIO_FLAG_IDLE); |
| | | } |
| | | |
| | | } |
| | | #define HEATBEAT_UPDATE_TIME 3600 |
| | | #define HEATBEAT_UPDATE_TIME 100 |
| | | uint16_t heatbeat_count = HEATBEAT_UPDATE_TIME-1 ; |
| | | uint16_t flag_getwgresp = 0; |
| | | uint16_t test_temp[10]={0x1306,9688,1000}; |
| | | uint16_t test_temp2[10]={0xff,0xcd,0x19}; |
| | | int16_t intheight; //气压 |
| | | void Lora_Report_poll(void) |
| | | extern uint16_t recnum[3]; |
| | | void LoraReportPoll(void) |
| | | { |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; //网关回复标志位 && WG_Connected == wg_state |
| | | uint32_t ret = 0; |
| | | ret = rf_init(); |
| | | // delay_ms(100); |
| | | #ifdef _USE_BAR |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | #endif |
| | | #ifdef _SMT_TEST |
| | | printf("气压值:%d",intheight); |
| | | #endif |
| | | |
| | | set_test_mode1_reg(); |
| | | if(ret==OK) |
| | | { |
| | | rf_set_default_para(wg_report_freq*1000000,wg_report_sf); |
| | | } |
| | | // |
| | | // |
| | | if(heatbeat_count++>HEATBEAT_UPDATE_TIME) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | TagListUpdate(); |
| | | |
| | | LoraReportFreqPoll(); |
| | | flag_getwgresp = 0; |
| | | // wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; |
| | | rf_set_default_para(wg_report_freq,REPORT_CHANNEL_SF); |
| | | // 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; |
| | | Lora_UploadHeartBeartPoll(); |
| | | //rf_irq_process(); |
| | | LoraHeartBeartPoll(); |
| | | return; |
| | | } |
| | | for(uint16_t i=0; i<report_ancnum-1; i++) |
| | |
| | | } |
| | | } |
| | | } |
| | | if(report_ancnum>0) |
| | | { |
| | | //uwbled=0x11; //blue |
| | | } |
| | | else |
| | | { |
| | | //uwbled=0x1100; //red |
| | | } |
| | | |
| | | 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+ANCID_IDX; |
| | | 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 |
| | | |
| | | // 2000f026 02020002 //000220200 |
| | | 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; |
| | | //GET_USERKEY这个是那个lora——busy那个引脚 |
| | | |
| | | // 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_weidu,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],&intheight,2); |
| | | // memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&bar_height,2); |
| | | memcpy(&report_ancid,test_temp,10); |
| | | memcpy(&report_ancdist,test_temp2,10); |
| | | report_ancnum=3; |
| | | 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); |
| | | rf_enter_continous_tx(); |
| | | //rf_irq_process(); |
| | | rf_set_transmit_flag(RADIO_FLAG_TXDONE); |
| | | |
| | | if(rf_get_transmit_flag()==RADIO_FLAG_TXDONE) |
| | | { |
| | | if(rf_continous_tx_send_data(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2)==OK) |
| | | { |
| | | //LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n"); |
| | | } |
| | | while (rf_get_transmit_flag() == RADIO_FLAG_IDLE) |
| | | ; |
| | | //rf_enter_continous_rx();; |
| | | rf_set_transmit_flag(RADIO_FLAG_IDLE); |
| | | |
| | | } |
| | | //rf_enter_continous_tx(); |
| | | // LORA_3029_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | LORA_3029_SINGLE_SEND(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2,0); |
| | | |
| | | // rf_single_tx_data(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2,2); |
| | | // rf_enter_continous_rx(); |
| | | |
| | | //LED_TB_ON; |
| | | // bat_percent=Get_Battary(); |
| | | |
| | | for(uint8_t i=0;i<3;i++) |
| | | recnum[i] = 0; |
| | | |
| | | } |
| | | extern uint8_t report_ancnum; |
| | | static uint16_t delaytime = 1200; |
| | | static uint16_t source_id; |
| | | uint8_t rec_index,rec_secdelay; |
| | | uint16_t rec_value,rec_delaytime,rx_count; |
| | | uint16_t rec_value,rec_delaytime,rx_count,datalen_offset; |
| | | //uint16_t rec_value,rec_delaytime,rx_count; |
| | | //uint16_t rec_value,rec_delaytime,rx_count,datalen_offset; |
| | | int32_t target_count; |
| | | uint8_t shengji_flag,time=5; |
| | | extern uint32_t uwbled,gpsled,loraled,powerled; |
| | | extern struct RxDoneMsg RxDoneParams; |
| | | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | { uint16_t checksum1; |
| | | BufferSize = size; |
| | | memcpy(RX_Buffer,RxDoneParams.Payload,RxDoneParams.Size); |
| | | // memcpy( RX_Buffer, payload, BufferSize ); |
| | | RssiValue = rssi; |
| | | SnrValue = snr; |
| | | //Radio.Standby(); |
| | | no_rx_flag = 0; |
| | | lora_up_rec_flag=1; |
| | | // if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL) |
| | | //void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | //{ uint16_t checksum1; |
| | | // BufferSize = size; |
| | | // memcpy(RX_Buffer,RxDoneParams.Payload,RxDoneParams.Size); |
| | | // // memcpy( RX_Buffer, payload, BufferSize ); |
| | | // RssiValue = rssi; |
| | | // SnrValue = snr; |
| | | // //Radio.Standby(); |
| | | // no_rx_flag = 0; |
| | | // lora_up_rec_flag=1; |
| | | //// if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL) |
| | | //// { |
| | | //// UwbRange(); |
| | | //// rf_delay_us(time*1000); |
| | | //// // UWB_RXStart(10); |
| | | //// // delay_ms(time); |
| | | //// } |
| | | // if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG) |
| | | // { |
| | | // UwbRange(); |
| | | // rf_delay_us(time*1000); |
| | | // // UWB_RXStart(10); |
| | | // // delay_ms(time); |
| | | // } |
| | | if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG) |
| | | { |
| | | checksum1=Checksum_u16(RX_Buffer,BufferSize-2); |
| | | if(!memcmp(&checksum1,&RX_Buffer[BufferSize-2],2)) |
| | | if(!memcmp(&dev_id,&RX_Buffer[DEST_ID_IDX],2)) |
| | | { |
| | | memcpy(&source_id,&RX_Buffer[SOURCE_ID_IDX],2); |
| | | if(wg_state==WG_Lost) |
| | | { |
| | | wg_state = WG_Connected; |
| | | wg_report_id = source_id; |
| | | } |
| | | if(!memcmp(&wg_report_id,&RX_Buffer[SOURCE_ID_IDX],2)) |
| | | { |
| | | wg_lost_count = 0; |
| | | // loraled=GREEN; |
| | | switch(RX_Buffer[PWTAG_RW_FLAG_IDX]) |
| | | { |
| | | case WGRSP_RWTAG_NONE: |
| | | // current_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400; |
| | | memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2); |
| | | rec_secdelay = RX_Buffer[PWTAG_SECDELAY_IDX]; |
| | | if(BufferSize!=13||rec_secdelay>20) |
| | | { |
| | | rec_secdelay = 0; |
| | | } |
| | | |
| | | if(report_ancnum<2) |
| | | { |
| | | datalen_offset = report_ancnum*85; |
| | | }else{ |
| | | datalen_offset = (report_ancnum-1)*46+85; |
| | | } |
| | | |
| | | target_count = current_count + rec_delaytime*3.2768 - delaytime-datalen_offset; |
| | | while(target_count>=32768) |
| | | target_count-=32768; |
| | | // __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | // rx_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // printf("tx %d,rx %d,delay %d",current_count>>5,rx_count>>5,rec_delaytime); |
| | | break; |
| | | case WGRSP_RWTAG_READ: |
| | | no_rx_flag = 1; |
| | | //LoraSendComMap(WGRSP_RWTAG_READ); |
| | | break; |
| | | case WGRSP_RWTAG_WRITE: |
| | | rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | if(rec_index<=DEV_ID) |
| | | return; |
| | | if(rec_index==0xDD) |
| | | { |
| | | // if(usart5_state==1) |
| | | // checksum1=Checksum_u16(RX_Buffer,BufferSize-2); |
| | | // if(!memcmp(&checksum1,&RX_Buffer[BufferSize-2],2)) |
| | | // if(!memcmp(&dev_id,&RX_Buffer[DEST_ID_IDX],2)) |
| | | // { |
| | | // Usart5Init(); |
| | | // usart5_state=0; |
| | | // } |
| | | // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET); |
| | | // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); |
| | | // memcpy(&xiafayuyin_data,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],BufferSize-PWTAG_WRITE_VALUE_IDX-2); |
| | | // yuyin_sendflag=1; |
| | | // yuyinzidongguan_time=0; |
| | | // yuyin_no_sleep_flag=1; |
| | | // SYN_FrameInfo(0,xiafayuyin_data); //播放内容 |
| | | // memset(xiafayuyin_data,0,sizeof(xiafayuyin_data)); |
| | | // LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA); |
| | | no_rx_flag = 1; |
| | | }else{ |
| | | memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); |
| | | g_com_map[rec_index/2] = rec_value; |
| | | save_com_map_to_flash(); |
| | | // LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA); |
| | | // flag_writepara_needreset = 1; |
| | | no_rx_flag = 1; |
| | | } |
| | | break; |
| | | case WGRSP_RWTAG_UPDATE: |
| | | rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | switch(rec_index) |
| | | { |
| | | case 0xaa: //升级下发 |
| | | // memcpy(&rec_wenjian_daxiao,&RX_Buffer[WRITEPARA_VALUE_IDX],2);//文件大小 |
| | | // if(rec_wenjian_daxiao>APP_SIZE||rec_wenjian_daxiao==0) |
| | | // {}//文件过大,超出范围 |
| | | // else |
| | | // memcpy(&source_id,&RX_Buffer[SOURCE_ID_IDX],2); |
| | | // if(wg_state==WG_Lost) |
| | | // { |
| | | // memcpy(&wangguan_up_id,&RX_Buffer[SOURCE_ID_IDX],2);//网关ID 占用2个字节 |
| | | // shengji_flag=1; |
| | | // LoraUp_flag=1; |
| | | // wg_state = WG_Connected; |
| | | // wg_report_id = source_id; |
| | | // } |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // if(!no_rx_flag&&LoraUp_flag==0) |
| | | // if(!memcmp(&wg_report_id,&RX_Buffer[SOURCE_ID_IDX],2)) |
| | | // { |
| | | // if(RX_Buffer[MSG_TYPE_IDX]!=LORA_MSGTYPE_RANGEPOLL) |
| | | // SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0); |
| | | // Radio.Rx(0); |
| | | // wg_lost_count = 0; |
| | | // // loraled=GREEN; |
| | | // switch(RX_Buffer[PWTAG_RW_FLAG_IDX]) |
| | | // { |
| | | // case WGRSP_RWTAG_NONE: |
| | | // // current_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400; |
| | | // memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2); |
| | | // rec_secdelay = RX_Buffer[PWTAG_SECDELAY_IDX]; |
| | | // if(BufferSize!=13||rec_secdelay>20) |
| | | // { |
| | | // rec_secdelay = 0; |
| | | // } |
| | | } |
| | | // |
| | | // if(report_ancnum<2) |
| | | // { |
| | | // datalen_offset = report_ancnum*85; |
| | | // }else{ |
| | | // datalen_offset = (report_ancnum-1)*46+85; |
| | | // } |
| | | // |
| | | // target_count = current_count + rec_delaytime*3.2768 - delaytime-datalen_offset; |
| | | // while(target_count>=32768) |
| | | // target_count-=32768; |
| | | //// __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | //// rx_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // // printf("tx %d,rx %d,delay %d",current_count>>5,rx_count>>5,rec_delaytime); |
| | | // break; |
| | | // case WGRSP_RWTAG_READ: |
| | | // no_rx_flag = 1; |
| | | // //LoraSendComMap(WGRSP_RWTAG_READ); |
| | | // break; |
| | | // case WGRSP_RWTAG_WRITE: |
| | | // rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | // if(rec_index<=DEV_ID) |
| | | // return; |
| | | // if(rec_index==0xDD) |
| | | // { |
| | | //// if(usart5_state==1) |
| | | //// { |
| | | //// Usart5Init(); |
| | | //// usart5_state=0; |
| | | //// } |
| | | //// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET); |
| | | //// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); |
| | | //// memcpy(&xiafayuyin_data,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],BufferSize-PWTAG_WRITE_VALUE_IDX-2); |
| | | //// yuyin_sendflag=1; |
| | | //// yuyinzidongguan_time=0; |
| | | //// yuyin_no_sleep_flag=1; |
| | | //// SYN_FrameInfo(0,xiafayuyin_data); //播放内容 |
| | | //// memset(xiafayuyin_data,0,sizeof(xiafayuyin_data)); |
| | | // // LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA); |
| | | // no_rx_flag = 1; |
| | | // }else{ |
| | | // memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); |
| | | // g_com_map[rec_index/2] = rec_value; |
| | | // save_com_map_to_flash(); |
| | | // // LoraRspWriteCommap(SUBMSG_WRITE_ANCPARA); |
| | | //// flag_writepara_needreset = 1; |
| | | // no_rx_flag = 1; |
| | | // } |
| | | // break; |
| | | // case WGRSP_RWTAG_UPDATE: |
| | | // rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | // switch(rec_index) |
| | | // { |
| | | // case 0xaa: //升级下发 |
| | | //// memcpy(&rec_wenjian_daxiao,&RX_Buffer[WRITEPARA_VALUE_IDX],2);//文件大小 |
| | | //// if(rec_wenjian_daxiao>APP_SIZE||rec_wenjian_daxiao==0) |
| | | //// {}//文件过大,超出范围 |
| | | //// else |
| | | //// { |
| | | //// memcpy(&wangguan_up_id,&RX_Buffer[SOURCE_ID_IDX],2);//网关ID 占用2个字节 |
| | | //// shengji_flag=1; |
| | | //// LoraUp_flag=1; |
| | | //// } |
| | | // break; |
| | | // } |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | //// if(!no_rx_flag&&LoraUp_flag==0) |
| | | //// { |
| | | //// if(RX_Buffer[MSG_TYPE_IDX]!=LORA_MSGTYPE_RANGEPOLL) |
| | | //// SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0); |
| | | //// Radio.Rx(0); |
| | | //// } |
| | | //} |
| | | //void LORA_mode_select(void) |
| | | //{ |
| | | // if(TX_RX_SELECT==1) |
| | |
| | | |
| | | |
| | | //} |
| | | //extern uint8_t Lora_tx_ancnum; |
| | | //extern u8 lora_seq_nb2; |
| | | extern uint16_t lora_yingda_num; |
| | | uint8_t lora_tx_flag=0; |
| | | uint8_t lora_txanchor_power_flag; |
| | | extern uint16_t Lora_tx_ancid[50]; |
| | | extern uint16_t Lora_tx_ancdist[50]; |
| | | extern uint8_t Lora_tx_anc_electricity[50]; |
| | | uint8_t lora_seq_nb1; |
| | | |
| | | extern uint8_t lora_sendbuffer[200]; |
| | | void LoraSendComMap(uint8_t cmd) |
| | | { |
| | | uint8_t data_length = 0x50; |
| | | uint16_t checksum = 0; |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_READPARARESP; |
| | | lora_sendbuffer[MSG_LENGTH] = data_length+11; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[RP_CMD_IDX] = cmd; |
| | | lora_sendbuffer[RP_INDEX_IDX] = 2; |
| | | lora_sendbuffer[RP_LEN_IDX] = data_length; |
| | | memcpy(&lora_sendbuffer[9], &g_com_map[1], data_length); |
| | | 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); |
| | | // Delay_Ms(100); |
| | | } |
| | | void LoraRspWriteCommap(uint8_t index) |
| | | { |
| | | uint8_t data_length = 2; |
| | | uint16_t checksum = 0; |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_READPARARESP; |
| | | lora_sendbuffer[MSG_LENGTH] = data_length+9; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[RP_CMD_IDX] = WGRSP_RWTAG_WRITE; |
| | | lora_sendbuffer[RP_INDEX_IDX] = index; |
| | | lora_sendbuffer[RP_LEN_IDX] = data_length; |
| | | 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); |
| | | LORA_3029_SINGLE_SEND(lora_sendbuffer,data_length+11,0); |
| | | // Delay_Ms(100); |
| | | } |
| | | uint8_t t22[20],ti; |
| | | uint8_t no_yingdaflag; |
| | | uint8_t aRxBuffer[1]; |
| | | |
| | | extern uint8_t group_id; |
| | | uint16_t lora_send_count; |
| | | uint8_t mode_flag=0; |
| | | void Lora_Tx_Poll() |
| | | { |
| | | |
| | | // if(lora_tx_flag) |
| | | // { |
| | | // OnMaster(); |
| | | //// |
| | | // //rf_enter_continous_rx(); |
| | | // } |
| | | if(lora_tx_flag) |
| | | { |
| | | if(lora_send_count++%10==0||lora_jianting_flag) |
| | | { |
| | | lora_tx_flag=0; |
| | | #ifdef GROUPID_SWITCH |
| | | 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_set_default_para(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF); |
| | | // SwitchLoraSettings(UWB_CHANNEL_FRQ+group_id,UWB_CHANNEL_SF,0); |
| | | //rf_enter_single_timeout_rx(0); |
| | | // rf_enter_continous_rx(); |
| | | //LedTask(); |
| | | //LoraHeartBeartPoll(); |
| | | |
| | | // rf_get_mode(); |
| | | LoraReportPoll(); |
| | | // LedOff_task(); |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | uint8_t TX_RX_SELECT=0; |
| | | //void OnMaster() |
| | | //{ |
| | | // |
| | | // rf_set_default_para(DEFAULT_WG_SET_FREQ,DEFAULT_WG_SET_SF); |
| | | // rf_enter_continous_tx();//send_frame1, 19 |
| | | // // LORA_3029_SEND(send_frame1, 19); |
| | | |
| | | // |
| | | //} |
| | | int LORA_3029_SINGLE_SEND(uint8_t *buffer, uint8_t size,uint8_t time) |
| | | { |
| | | if((rf_single_tx_data(lora_sendbuffer,size,time))!= OK) |
| | | { |
| | | //while(1); |
| | | } |
| | | rf_delay_us(1); |
| | | |
| | | //rf_enter_single_rx(); |
| | | //rf_enter_single_timeout_rx(700); |
| | | } |
| | | |
| | | int LORA_3029_CONTINOUS_SEND(uint8_t *buffer, uint8_t size) |
| | | { |
| | | |
| | | |
| | | } |
| | | // rf_enter_continous_tx(); |
| | | |
| | | |
| | | |
| | | // //rf_set_default_para(DEFAULT_WG_SET_FREQ,DEFAULT_WG_SET_SF); |
| | | // |
| | | // |
| | | // |
| | | // rf_set_transmit_flag(RADIO_FLAG_TXDONE); |
| | | // |
| | | // |
| | | // if(rf_get_transmit_flag() == RADIO_FLAG_TXDONE) |
| | | // { |
| | | // // |
| | | // if(rf_continous_tx_send_data(send_frame1, 20) == OK) |
| | | // { |
| | | // //printf("tx ok!\n"); |
| | | // } |
| | | //// while (rf_get_transmit_flag() ==!RADIO_FLAG_TXDONE) |
| | | //// ; |
| | | // while (rf_get_transmit_flag() ==!RADIO_FLAG_TXDONE) |
| | | // ; |
| | | // |
| | | // } |
| | | // |
| | | |
| | | |
| | | |