| | |
| | | #include <stdlib.h> |
| | | #include "WS2812.h" |
| | | #include "syn6288.h" |
| | | #include "dw_mbx_tag.h" |
| | | #define NSH1 0x0001 |
| | | #define GP 0x0002 |
| | | #define FLASH_HARDWARE_VERSION_MAP (uint32_t)0x08004F00 //硬件版本号和批次信息位置 |
| | | //#define DEBUG_MODE |
| | | #define DEBUG_MODE |
| | | uint8_t chongqi_flag; |
| | | uint32_t uwbled,gpsled,loraled,powerled; |
| | | UART_WakeUpTypeDef Selection; |
| | |
| | | float motor_keeptime; |
| | | void IdleTask(void) |
| | | { |
| | | //if(huart1.Instance->ISR&USART_ISR_FE) |
| | | // { |
| | | // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | //// } |
| | | // if(du_flag==1) |
| | | // { |
| | | // du_flag=0; |
| | | // |
| | | // } |
| | | // if(xie_flag==1) |
| | | // { |
| | | // xie_flag=0; |
| | | // memcpy((uint8_t*)&g_com_map + pack_index, mUsartReceivePack, pack_datalen); |
| | | // } |
| | | if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | { |
| | | |
| | |
| | | } |
| | | if(bat_percent>99) |
| | | { |
| | | powerled=GREEN; |
| | | Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | powerled=GREEN; |
| | | |
| | | }else{ |
| | | powerled=RED; |
| | | Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | powerled=RED; |
| | | } |
| | | }else{ |
| | | if(state5v==1) |
| | |
| | | u16 total_slotnum,current_slotnum; |
| | | extern int32_t offsettimeus; |
| | | //u16 last_lpcount = 0; |
| | | void SetNextPollTime(u16 time) |
| | | { |
| | | int32_t lpcount1,lptime1,target_time1; |
| | | int32_t last_lpcount1; |
| | | // if(current_slotnum>=total_slotnum) |
| | | // current_slotnum-=total_slotnum; |
| | | // |
| | | // target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000; |
| | | // //if(target_time<90000) |
| | | // { |
| | | // lptime=target_time-offsettimeus; |
| | | // lpcount = lptime/LPTIMER_LSB; |
| | | // if(lpcount>LPTIMER_1S_COUNT) |
| | | // lpcount-=LPTIMER_1S_COUNT; |
| | | // if(lpcount<0) |
| | | // { |
| | | // lpcount+=LPTIMER_1S_COUNT; |
| | | // } |
| | | last_lpcount1=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | lpcount1 = last_lpcount1+32.768*time; |
| | | while(lpcount1>LPTIMER_1S_COUNT) |
| | | { |
| | | lpcount1-=LPTIMER_1S_COUNT; |
| | | } |
| | | // last_lpcount = lpcount; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount1+32768); |
| | | |
| | | } |
| | | |
| | | /* 返回ch字符在sign数组中的序号 */ |
| | | int getIndexOfSigns(char ch) |
| | |
| | | return sum; |
| | | } |
| | | |
| | | u32 Loratx_frequency; |
| | | |
| | | u8 active_flag,nomovesleeptime; |
| | | void GetLoratx_frequency(void) |
| | | { |
| | | Loratx_frequency=470000000; |
| | | srand(HAL_LPTIM_ReadCounter(&hlptim1)); |
| | | Loratx_frequency=((rand()%5)+470)*1000000; |
| | | if(470000000<=Loratx_frequency&&Loratx_frequency<480000000) |
| | | g_com_map[NEARBASE_ID1]=1136+(Loratx_frequency/1000000-470); |
| | | if(480000000<=Loratx_frequency&&Loratx_frequency<490000000) |
| | | g_com_map[NEARBASE_ID1]=1152+(Loratx_frequency/1000000-480); |
| | | Loratx_frequency=470000000; |
| | | } |
| | | |
| | | void Program_Init(void) |
| | | { float temp; |
| | | uint16_t temp2; |
| | |
| | | |
| | | current_slotnum=1; |
| | | // current_time=GetLPTime(); |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, 0) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, 0) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | { |
| | | Error_Handler(); |
| | | } |
| | |
| | | } |
| | | if(GPIO_Pin == GPIO_PIN_1)//按键 |
| | | { |
| | | SystemClock_Config(); |
| | | anjian_flag=1; |
| | | } |
| | | if(GPIO_Pin == GPIO_PIN_0)//加速度 |
| | | { |
| | | SystemClock_Config(); |
| | | stationary_flag =0; |
| | | stationary_num=0; |
| | | if(chongqi_flag==1) |
| | | { |
| | | HAL_NVIC_SystemReset(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | extern void Lora_tx_zubao( void ); |
| | |
| | | extern uint16_t lora_yingda_num; |
| | | uint8_t lora_tx_flag; |
| | | 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]; |
| | | u8 lora_seq_nb1; |
| | | static uint8_t send_frame1[EUART_RX_BUF_SIZE]; |
| | | uint8_t data_length1; |
| | | void LoraSendComMap(uint8_t data_length, uint8_t index) |
| | | { |
| | | uint16_t checksum = 0; |
| | | send_frame1[0] = 0x55; |
| | | send_frame1[1] = 0xAA; |
| | | send_frame1[2] = 0x39; |
| | | send_frame1[3] = data_length+5; |
| | | send_frame1[4] = 3; |
| | | send_frame1[5] = index; |
| | | send_frame1[6] = data_length; |
| | | memcpy(&send_frame1[7], &g_com_map[index], data_length); |
| | | for(int i = 0; i<(data_length+5); i++) |
| | | { |
| | | checksum += send_frame1[2+i]; |
| | | } |
| | | checksum = Checksum_u16(&send_frame1[2],5+data_length); |
| | | memcpy(&send_frame1[7+data_length],&checksum,2); |
| | | data_length1=data_length+9; |
| | | // UART_PushFrame(send_frame1, data_length+9); |
| | | } |
| | | |
| | | extern uint8_t GPSchangdu; |
| | | uint8_t no_yingdaflag; |
| | | extern uint8_t GPS_GGAdate[200]; |
| | | uint8_t GPS_GGAdate111[200]="报警"; |
| | | void Lora_Tx_Poll() |
| | | { |
| | | |
| | | if(lora_tx_flag) |
| | | { |
| | | lora_tx_flag=0; |
| | | // SYN_FrameInfo(0,GPS_GGAdate111); |
| | | // while(1); |
| | | if(du_flag==1) |
| | | { |
| | | Lora47X_Init(); |
| | | du_flag=0; |
| | | Radio.Send( send_frame1, data_length1); |
| | | no_yingdaflag=1; |
| | | } |
| | | else |
| | | { |
| | | Lora47X_Init(); |
| | | if(bat_percent>20) |
| | | { |
| | | loraled=BLUE; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | } |
| | | else |
| | | { |
| | | loraled=RED; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | } |
| | | lora_seq_nb2++; |
| | | Lora_tx_zubao(); |
| | | Radio.Send( usart_send, 15+Lora_tx_ancnum*4+GPSchangdu); |
| | | Lora_tx_ancnum=0; |
| | | GPSchangdu=0; |
| | | memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | | memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid)); |
| | | memset(GPS_GGAdate,0,sizeof(GPS_GGAdate)); |
| | | anjian_flag=0; |
| | | // delay_ms(10); |
| | | // loraled=LEDOFF; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | // HAL_UART_Transmit(&huart1,usart_send,15+Lora_tx_ancnum*4+GPSchangdu,3000); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | void MX_ADC1_Init() |
| | | { |
| | | MX_ADC_Init(); |
| | | MX_ADC_Init(); |
| | | } |
| | | void GPS_Close_Init() |
| | | { |
| | |
| | | else |
| | | { |
| | | gpsled=RED; |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | // Set4LEDColor(powerled,loraled,gpsled,uwbled);z |
| | | } |
| | | } |
| | | HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1); |
| | |
| | | if(yuyin_sendflag) |
| | | { |
| | | yuyin_sendflag=0; |
| | | SYN_FrameInfo(0,yuyin_yinliang);//设置音量等级V10 |
| | | delay_ms(10); |
| | | // SYN_FrameInfo(0,yuyin_yinliang);//设置音量等级V10 |
| | | // delay_ms(10); |
| | | SYN_FrameInfo(0,xiafayuyin_data); //播放内容 |
| | | // HAL_UART_Receive_IT(&huart6, &Get_Uart6_data, 1); |
| | | memset(xiafayuyin_data,0,sizeof(xiafayuyin_data)); |
| | |
| | | } |
| | | } |
| | | } |
| | | uint8_t usart5_state; |
| | | uint8_t usart5_state,flag_onesecond; |
| | | void Jingzhi_Poll(void) |
| | | { |
| | | powerled=LEDOFF; |
| | | loraled=LEDOFF; |
| | | gpsled=LEDOFF; |
| | | uwbled=LEDOFF; |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); //GuanGPS and lora 电源 |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); //guan uwb 电源 |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); //GuanGPS and lora 电源 |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); //guan uwb 电源 |
| | | HAL_SPI_DeInit(&hspi1); |
| | | HAL_GPIO_WritePin( RADIO_NSS_GPIO_Port, RADIO_NSS_Pin,GPIO_PIN_RESET);//lora cs |
| | | HAL_GPIO_WritePin( GPIOA, GPIO_PIN_4,GPIO_PIN_RESET);//uwb cs |
| | |
| | | Usart5DeInit(); |
| | | LpusartDeInit(); |
| | | HAL_ADC_DeInit(&hadc); |
| | | // __HAL_RCC_GPIOA_CLK_DISABLE(); |
| | | // __HAL_RCC_GPIOB_CLK_DISABLE(); |
| | | // __HAL_RCC_GPIOC_CLK_DISABLE(); |
| | | // __HAL_RCC_GPIOD_CLK_DISABLE(); |
| | | // __HAL_RCC_GPIOE_CLK_DISABLE(); |
| | | |
| | | Set4LEDColor_Off(); //关led总电源 |
| | | chongqi_flag=1; |
| | | } |
| | | void OneSecondTask(void) |
| | | { |
| | | if(flag_onesecond==1) |
| | | { |
| | | flag_onesecond = 0; |
| | | } |
| | | } |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | Program_Init(); |
| | | LIS3DH_Data_Init(); |
| | | Dw1000_Init(); |
| | | Dw1000_App_Init(); |
| | | // HardWareTypeDiffConfig(); |
| | | dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN); |
| | | dwt_entersleep(); |
| | |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | Delay_Ms(2); |
| | | Delay_Ms(10); |
| | | bat_percent=Get_VDDVlotage(); |
| | | GetLoratx_frequency(); |
| | | delay_ms(2000); |
| | | GPS_Close_Init(); |
| | | |
| | | HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1); |
| | | Set4LEDColor(RED,RED,RED,RED); |
| | | Set4LEDColor(GREEN,RED,RED,RED); |
| | | HAL_Delay(500); |
| | | Set4LEDColor(GREEN,GREEN,GREEN,GREEN); |
| | | Set4LEDColor(GREEN,GREEN,GREEN,RED); |
| | | HAL_Delay(500); |
| | | Set4LEDColor_Off(); |
| | | LoraInit(); |
| | | // Lora47X_Init(); |
| | | // Radio.Sleep(); |
| | | /* USER CODE END 2 */ |
| | |
| | | /* USER CODE END WHILE */ |
| | | |
| | | /* USER CODE BEGIN 3 */ |
| | | //Lora_rx_open(); |
| | | // Lora_Tx_Poll(); |
| | | if(stationary_flag==1) |
| | | { |
| | | Jingzhi_Poll(); |
| | | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | } |
| | | else |
| | | { |
| | | Lora_Tx_Poll(); |
| | | IdleTask(); |
| | | TTSchaxun_Busy(); |
| | | OneSecondTask(); |
| | | IdleTask(); |
| | | PowerDownDetect(); |
| | | |
| | | // Ble_rx_Poll(); |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | |
| | | // Lora_rece_error=0; |
| | | // Radio.IrqProcess( ); // Process Radio IRQ |
| | | // Anchor_App(); |
| | | |
| | | #ifndef DEBUG_MODE |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | { |
| | |
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | } |
| | | /* USER CODE END 3 */ |
| | | } |
| | |
| | | uint8_t lora_yingdatime; |
| | | extern uint8_t lora_chongfuyingda_flag; |
| | | uint16_t no_data_chongqi_num; |
| | | uint16_t anchor_send_num; |
| | | |
| | | uint8_t no_yingdatime; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | // uint8_t pinlv; |
| | | SystemClock_Config(); |
| | | lp_time++; |
| | | anchor_send_num++; |
| | | no_data_chongqi_num++; |
| | | stationary_num++; |
| | | Set4LEDColor(powerled,loraled,gpsled,uwbled); |
| | | // if(Beepchixutime>0) |
| | | // { |
| | | // Beepchixutime--; |
| | | // if(Beepchixutime==0) |
| | | // {Beep_Off();} |
| | | // } |
| | | if(no_yingdaflag==1) |
| | | { |
| | | no_yingdatime++; |
| | | if(no_yingdatime>=5) |
| | | { |
| | | no_yingdaflag=0; |
| | | no_yingdatime=0; |
| | | } |
| | | } |
| | | |
| | | if( no_data_chongqi_num>600) |
| | | {NVIC_SystemReset();} |
| | | SetNextPollTime(0); |
| | | // if(lora_yingda_flag) |
| | | // { |
| | | // lora_yingdatime++; |
| | | // if(lora_yingdatime>=2) |
| | | // {lora_yingdatime=0; |
| | | // lora_yingda_flag=0; |
| | | // Lora_tx_mode(); |
| | | // Radio.Send( usart_send, 2); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // pinlv=g_com_map[COM_MAP_SIZE]/1000; |
| | | if(lp_time%(g_com_map[COM_INTERVAL]/1000)==0) |
| | | { |
| | | lora_tx_flag=1; |
| | | lora_txanchor_power_flag=0; |
| | | // } |
| | | if(anchor_send_num>=3600) |
| | | {anchor_send_num=0; |
| | | lora_txanchor_power_flag=1; |
| | | lora_tx_flag=0; |
| | | bat_percent=Get_VDDVlotage(); |
| | | } |
| | | } |
| | | |
| | | if(stationary_num>=30) |
| | | {stationary_num=0; |
| | | stationary_flag=1; |
| | | } |
| | | yuyinzidongguan_time++; |
| | | if(yuyinzidongguan_time>10) |
| | | { |
| | | yuyinzidongguan_time=0; |
| | | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); |
| | | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); |
| | | yuyin_no_sleep_flag=0; |
| | | } |
| | | uwbled = BLUE; |
| | | Set4LEDColor(uwbled,gpsled,loraled,powerled); |
| | | LoraReportPoll(); |
| | | flag_onesecond = 1; |
| | | uwbled = LEDOFF; |
| | | Set4LEDColor(uwbled,gpsled,loraled,powerled); |
| | | } |
| | | /* USER CODE END 4 */ |
| | | |