| | |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | Radio.Standby(); |
| | | Radio.Rx( 50 ); |
| | | Radio.Rx( 100 ); |
| | | // LED_TB_OFF; |
| | | } |
| | | extern LPTIM_HandleTypeDef hlptim1; |
| | |
| | | extern uint8_t lora_sendbuffer[200]; |
| | | void LoraSendComMap(uint8_t cmd) |
| | | { |
| | | uint8_t data_length = 0x28; |
| | | uint8_t data_length = 0x50; |
| | | uint16_t checksum = 0; |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_READPARARESP; |
| | | lora_sendbuffer[MSG_LENGTH] = data_length+9; |
| | | 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[7], &g_com_map[1], 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); |
| | | 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); |
| | | Radio.Send(lora_sendbuffer,data_length+13); |
| | | // Delay_Ms(100); |
| | | } |
| | | void LoraRspWriteCommap(uint8_t index) |
| | |
| | | uint8_t rec_index; |
| | | uint16_t rec_value,rec_delaytime,rx_count; |
| | | int16_t target_count; |
| | | uint16_t test111; |
| | | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | { |
| | | BufferSize = size; |
| | |
| | | if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_RANGEPOLL) |
| | | { |
| | | UWB_Wkup(); |
| | | MbxTagUwbRec(); |
| | | // memcpy(&test111,&RX_Buffer[1],2); |
| | | MbxTagUwbRec(); |
| | | // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_RESET); |
| | | // printf("LORA IdleTask:%x",test111); |
| | | HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效 |
| | | } |
| | | if(RX_Buffer[MSG_TYPE_IDX]==LORA_MSGTYPE_WGRESPTAG) |
| | |
| | | wg_report_freq = RX_Buffer[POLL_FREQ_IDX]+400; |
| | | memcpy(&rec_delaytime,&RX_Buffer[NEXTPOLL_TIME_IDX],2); |
| | | target_count = current_count + rec_delaytime*3.2768 - delaytime; |
| | | if(target_count>=32768) |
| | | while(target_count>=32768) |
| | | target_count-=32768; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | // __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; |
| | |
| | | rec_index = RX_Buffer[PWTAG_WRITE_IDX_IDX]; |
| | | 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[9],RX_Buffer[8]); |
| | | // yuyin_sendflag=1; |
| | | // yuyinzidongguan_time=0; |
| | | // yuyin_no_sleep_flag=1; |
| | | 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); |
| | | yuyin_sendflag=1; |
| | | yuyinzidongguan_time=0; |
| | | yuyin_no_sleep_flag=1; |
| | | }else{ |
| | | memcpy(&rec_value,&RX_Buffer[PWTAG_WRITE_VALUE_IDX],2); |
| | | g_com_map[rec_index/2] = rec_value; |
| | |
| | | Radio.Standby(); |
| | | current_count = HAL_LPTIM_ReadCounter(&hlptim1); |
| | | target_count-=current_count%3276; |
| | | if(target_count<0) |
| | | while(target_count<0) |
| | | target_count+=32768; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | // __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],UWB_CHANNEL_SF,0); |
| | | Radio.Rx(0); |
| | | } |