| | |
| | | |
| | | u16 total_slotnum,current_slotnum; |
| | | extern int32_t offsettimeus; |
| | | u16 last_lpcount = 0; |
| | | //u16 last_lpcount = 0; |
| | | void SetNextPollTime(u16 time) |
| | | { |
| | | int32_t lpcount,lptime,target_time; |
| | | |
| | | int32_t lpcount1,lptime1,target_time1; |
| | | int32_t last_lpcount1; |
| | | // if(current_slotnum>=total_slotnum) |
| | | // current_slotnum-=total_slotnum; |
| | | // |
| | |
| | | // { |
| | | // lpcount+=LPTIMER_1S_COUNT; |
| | | // } |
| | | last_lpcount=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | lpcount = last_lpcount+32768+32.768*time; |
| | | while(lpcount>LPTIMER_1S_COUNT) |
| | | last_lpcount1=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | lpcount1 = last_lpcount1+32.768*time; |
| | | while(lpcount1>LPTIMER_1S_COUNT) |
| | | { |
| | | lpcount-=LPTIMER_1S_COUNT; |
| | | lpcount1-=LPTIMER_1S_COUNT; |
| | | } |
| | | // last_lpcount = lpcount; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount1+32768); |
| | | |
| | | } |
| | | |
| | |
| | | //{Loratx_frequency=490000000;} |
| | | srand(HAL_LPTIM_ReadCounter(&hlptim1)); |
| | | Loratx_frequency=((rand()%5)+470)*1000000; |
| | | //Loratx_frequency=474000000; |
| | | } |
| | | void Program_Init(void) |
| | | { float temp; |
| | |
| | | { |
| | | if(lora_tx_flag) |
| | | { |
| | | // Lora47X_change(); |
| | | // Delay_Ms(50); |
| | | // SX126xReset(); |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | Lora47X_Init(); |
| | | lora_tx_flag=0; |
| | | LED_TB_ON; |
| | | lora_seq_nb2++; |
| | | Lora_tx_zubao(); |
| | | Lora_tx_mode(); |
| | | // Lora_tx_mode(); |
| | | Radio.Send( usart_send, 13+Lora_tx_ancnum*4); |
| | | Lora_tx_ancnum=0; |
| | | memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | |
| | | } |
| | | if(lora_txanchor_power_flag) |
| | | { |
| | | // SX126xReset(); |
| | | // Lora47X_change(); |
| | | // Delay_Ms(50); |
| | | Lora47X_Init(); |
| | | LED_TB_ON; |
| | | lora_seq_nb1++; |
| | | lora_txanchor_power_flag=0; |
| | |
| | | memcpy(&usart_send[8+Lora_tx_ancnum*2],&Lora_tx_anc_electricity,Lora_tx_ancnum); |
| | | checksum = Checksum_u16(&usart_send[2],8+3*Lora_tx_ancnum); |
| | | memcpy(&usart_send[8+3*Lora_tx_ancnum],&checksum,2); |
| | | Lora_tx_mode(); |
| | | // Lora_tx_mode(); |
| | | Radio.Send( usart_send, 10+Lora_tx_ancnum*3); |
| | | Lora_tx_ancnum=0; |
| | | |
| | |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | |
| | | MX_IWDG_Init(); |
| | | // MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | // LED_LG_ON; |
| | | Program_Init(); |
| | |
| | | // Uwb_Lora_Switch(0,1); |
| | | // Lora433rx_Init(); |
| | | // Lora47xrx_Init(); |
| | | Lora_Init(); |
| | | // Lora_Init(); |
| | | // Lora47xrx_Init(); |
| | | // Radio.Sleep( ); |
| | | Delay_Ms(10); |
| | | // Uwb_Lora_Switch(0,0); |
| | |
| | | usart_send[1]=0xaa; |
| | | bat_percent=Get_VDDVlotage(); |
| | | GetLoratx_frequency(); |
| | | // Lora47X_Init(); |
| | | // mcu_sleep(); |
| | | //LED0_BLINK; |
| | | // SystemPower_Config(); |
| | | //HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | // HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_SET); //片选lora无效 |
| | | // lora_tx_flag=1; |
| | | // Lora_Tx_Poll(); |
| | | /* USER CODE END 2 */ |
| | | |
| | | /* Infinite loop */ |
| | |
| | | |
| | | /* USER CODE BEGIN 3 */ |
| | | //Lora_rx_open(); |
| | | // Lora_Tx_Poll(); |
| | | Lora_Tx_Poll(); |
| | | |
| | | HAL_IWDG_Refresh(&hiwdg); |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | IdleTask(); |
| | | // Radio.IrqProcess( ); // Process Radio IRQ |
| | | // Anchor_App(); |
| | |
| | | // } |
| | | // else |
| | | // { |
| | | |
| | | |
| | | lora_tx_flag=1; |
| | | lora_txanchor_power_flag=0; |
| | | // } |
| | |
| | | lora_tx_flag=0; |
| | | bat_percent=Get_VDDVlotage(); |
| | | } |
| | | |
| | | |
| | | if(stationary_num>=10) |
| | | {stationary_num=0; |
| | | stationary_flag=1; |