| | |
| | | #include "delay.h" |
| | | #include "main.h" |
| | | #include <stdlib.h> |
| | | #include "WS2812.h" |
| | | static RadioEvents_t RadioEvents; |
| | | #define USE_MODEM_LORA |
| | | //#define USE_MODEM_FSK |
| | |
| | | #define LORA_TX_47X 2 |
| | | #define LORA_RX_47X 3 |
| | | uint8_t Lora_status=0; |
| | | |
| | | extern uint32_t uwbled,gpsled,loraled,powerled; |
| | | #define RF_FREQUENCY 433000000 // Hz |
| | | #define RF_FREQUENCY_R 500000000 // Hz |
| | | #define RF_FREQUENCY_T 470200000 // Hz |
| | |
| | | // 2: 4/6, |
| | | // 3: 4/7, |
| | | // 4: 4/8] |
| | | #define LORA_PREAMBLE_LENGTH_T 10 // Same for Tx |
| | | #define LORA_PREAMBLE_LENGTH_R 64 // Same for Rx |
| | | #define LORA_PREAMBLE_LENGTH_T 8 // Same for Tx |
| | | #define LORA_PREAMBLE_LENGTH_R 8 // Same for Rx |
| | | //#define LORA_PREAMBLE_LENGTH 990 // Same for Tx and Rx |
| | | #define LORA_SYMBOL_TIMEOUT 0 // Symbols |
| | | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
| | |
| | | uint32_t lora_zhuangtai; |
| | | void OnTxDone( void ) |
| | | { |
| | | if(bat_percent>20) |
| | | {LED_TR_OFF;} |
| | | else |
| | | {LED_TB_OFF;} |
| | | // if(bat_percent>20) |
| | | // { |
| | | // loraled=LEDOFF; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | // } |
| | | // else |
| | | // { |
| | | // loraled=LEDOFF; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | // } |
| | | |
| | | Radio.Standby(); |
| | | Radio.Rx( RX_TIMEOUT_VALUE ); |
| | | Radio.Rx( RX_TIMEOUT_VALUE ); |
| | | } |
| | | |
| | | extern uint32_t lp_time; |
| | |
| | | extern uint8_t stationary_flag; |
| | | extern uint8_t anjian_flag; |
| | | uint16_t Lora_wangguanid=0; |
| | | extern uint8_t GPSchangdu; |
| | | extern uint8_t GPS_GGAdate[200]; |
| | | void Lora_tx_zubao( void ) |
| | | { |
| | | uint16_t checksum; |
| | |
| | | memcpy(&usart_send[11],&Lora_tx_ancid,2*Lora_tx_ancnum); |
| | | memcpy(&usart_send[11+Lora_tx_ancnum*2],&Lora_tx_ancdist,2*Lora_tx_ancnum); |
| | | memcpy(&usart_send[11+Lora_tx_ancnum*4],&Lora_wangguanid,2); |
| | | checksum = Checksum_u16(&usart_send[2],11+4*Lora_tx_ancnum); |
| | | memcpy(&usart_send[13+4*Lora_tx_ancnum],&checksum,2); |
| | | memcpy(&usart_send[13+Lora_tx_ancnum*4],GPS_GGAdate,GPSchangdu); |
| | | checksum = Checksum_u16(&usart_send[2],11+4*Lora_tx_ancnum+GPSchangdu); |
| | | memcpy(&usart_send[13+4*Lora_tx_ancnum+GPSchangdu],&checksum,2); |
| | | } |
| | | extern uint8_t lora_tx_flag; |
| | | uint16_t current_count; |
| | |
| | | uint8_t xie_flag; |
| | | extern uint8_t no_yingdaflag; |
| | | uint16_t Beepchixutime; |
| | | uint8_t xiafayuyin_data[200]; |
| | | uint8_t yuyin_sendflag; |
| | | uint8_t yuyinzidongguan_time; |
| | | uint8_t yuyin_no_sleep_flag; |
| | | extern uint8_t usart5_state; |
| | | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | { |
| | | BufferSize = size; |
| | |
| | | Radio.Standby(); |
| | | printf("收到lora\r\n"); |
| | | // if(Lora_status==LORA_RX_433) |
| | | no_data_chongqi_num=0; |
| | | if(RX_Buffer[0]==0x50&&RX_Buffer[1]==0x49) |
| | | { |
| | | Lora_recevcount=HAL_LPTIM_ReadCounter(&hlptim1); |
| | |
| | | // SnrValue = snr; |
| | | // no_data_chongqi_num=0; |
| | | // Radio.Standby(); |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | |
| | | HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_SET); //片选lora无效 |
| | | |
| | |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); |
| | | HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效 |
| | | delay_ms(1); |
| | | Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time); |
| | | // Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time); |
| | | Radio.Rx( 9999 ); |
| | | printf("接收到uwb测距:%d",Lora_tx_ancdist[0]); |
| | | } |
| | | if(RX_Buffer[0]==0x55&&RX_Buffer[1]==0xEE) |
| | |
| | | // Radio.Standby(); |
| | | if(RX_Buffer[0]==0x55&&RX_Buffer[1]==0xEE&&!memcmp(&dev_id,&RX_Buffer[4],2)) |
| | | { |
| | | /*RX_Buffer[6]:都还是写*/ |
| | | /*RX_Buffer[4,5]:发过来的ID*/ |
| | | /*RX_Buffer[7]:地址*/ |
| | | /*RX_Buffer[8]:长度*/ |
| | | /*RX_Buffer[9-后边]:具体数值*/ |
| | | if(RX_Buffer[6]==0)//不需要操作,正常应答 |
| | | { |
| | | Lora_rece_error=0; |
| | |
| | | { |
| | | if(RX_Buffer[7]==0x10) |
| | | { |
| | | Beep_On(); |
| | | memcpy(&Beepchixutime, &RX_Buffer[9], 2); |
| | | // Beep_On(); |
| | | // memcpy(&Beepchixutime, &RX_Buffer[9], 2); |
| | | } |
| | | else |
| | | { |
| | | if(RX_Buffer[7]==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; |
| | | } |
| | | else |
| | | { |
| | | uint16_t pinlv1; |
| | | if(RX_Buffer[7]==0x06) |
| | | { |
| | | memcpy(&pinlv1, &RX_Buffer[9], RX_Buffer[8]); |
| | | pinlv1=(1000/pinlv1)*1000; |
| | | memcpy((uint8_t*)&g_com_map + RX_Buffer[7], &pinlv1, RX_Buffer[8]); |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | NVIC_SystemReset(); |
| | | } |
| | | |
| | | memcpy((uint8_t*)&g_com_map + RX_Buffer[7], &RX_Buffer[9], RX_Buffer[8]); |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | NVIC_SystemReset(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | tm= (rand()%100); |
| | | // SetNextPollTime(tm); |
| | | // HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, tm); |
| | | } |
| | | } |
| | | Lora433_change(); |
| | |
| | | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH_R, |
| | | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, |
| | | 0, false, 0, 0, LORA_IQ_INVERSION_ON_R, 1 ); |
| | | Radio.Rx( 9999 ); |
| | | // Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time); |
| | | |
| | | Radio.SetRxDutyCycle(RxDutyCycle_RX_time,RxDutyCycle_SLEEP_time); |
| | | |
| | | } |
| | | void Lora47X_change(void) |
| | | { |
| | | Radio.SetChannel( Loratx_frequency ); |
| | | SX126x.ModulationParams.Params.LoRa.SpreadingFactor=7; |
| | | SX126x.ModulationParams.Params.LoRa.Bandwidth=2; |
| | | SX126x.ModulationParams.Params.LoRa.CodingRate=1; |
| | | SX126xSetModulationParams( &SX126x.ModulationParams ); |
| | | } |