| | |
| | | |
| | | SPI_HandleTypeDef hspi1; |
| | | |
| | | TIM_HandleTypeDef htim2; |
| | | |
| | | UART_HandleTypeDef huart1; |
| | | DMA_HandleTypeDef hdma_usart1_rx; |
| | | DMA_HandleTypeDef hdma_usart1_tx; |
| | |
| | | static void MX_ADC_Init(void); |
| | | static void MX_DMA_Init(void); |
| | | static void MX_IWDG_Init(void); |
| | | static void MX_TIM2_Init(void); |
| | | /* USER CODE BEGIN PFP */ |
| | | |
| | | /* USER CODE END PFP */ |
| | |
| | | } |
| | | uint16_t hardware_version,hardware_pici,hardware_type; |
| | | uint8_t state5v = 1; |
| | | extern uint8_t du_flag; |
| | | extern uint8_t xie_flag; |
| | | 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) |
| | | { |
| | | // LED_LR_OFF; |
| | | LED_LG_ON; |
| | | LED2_TR_OFF; |
| | | LED2_TB_ON; |
| | | }else{ |
| | | // LED_LR_ON; |
| | | LED_LG_OFF; |
| | | LED2_TR_ON; |
| | | LED2_TB_OFF; |
| | | } |
| | | }else{ |
| | | if(state5v==1) |
| | |
| | | state5v=0; |
| | | UsartDeInit(); |
| | | } |
| | | // LED_LR_OFF; |
| | | LED_LG_OFF; |
| | | LED2_TR_OFF; |
| | | LED2_TB_OFF; |
| | | // } |
| | | } |
| | | if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0) |
| | |
| | | //{Loratx_frequency=489000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x490) |
| | | //{Loratx_frequency=490000000;} |
| | | Loratx_frequency=470000000; |
| | | srand(HAL_LPTIM_ReadCounter(&hlptim1)); |
| | | Loratx_frequency=((rand()%5)+470)*1000000; |
| | | //Loratx_frequency=474000000; |
| | | 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; |
| | |
| | | // g_com_map[MAX_REPORT_ANC_NUM]=1; |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | #endif |
| | | g_com_map[GROUP_ID]=33; |
| | | g_com_map[COM_INTERVAL] = 1000; |
| | | g_com_map[GROUP_ID]=5; |
| | | // g_com_map[COM_INTERVAL] = 1000; |
| | | if(g_com_map[COM_INTERVAL]<1000) |
| | | {g_com_map[COM_INTERVAL] = 1000;} |
| | | active_flag = g_com_map[ACTIVE_INDEX]; |
| | | module_power = g_com_map[POWER]; |
| | | g_com_map[IMU_ENABLE] = 0; |
| | |
| | | // g_com_map[COM_INTERVAL]=100; |
| | | if(g_com_map[COM_INTERVAL]==0) |
| | | { |
| | | g_com_map[COM_INTERVAL]=100; |
| | | g_com_map[COM_INTERVAL]=1000; |
| | | } |
| | | if(module_power>67) |
| | | {module_power=67;} |
| | |
| | | if(GPIO_Pin == GPIO_PIN_0)//加速度 |
| | | { |
| | | stationary_flag =0; |
| | | stationary_num=0; |
| | | } |
| | | } |
| | | void Uwb_Lora_Switch(uint8_t uwb, uint8_t lora) |
| | |
| | | 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); |
| | | } |
| | | uint8_t no_yingdaflag; |
| | | void Lora_Tx_Poll() |
| | | { |
| | | |
| | | 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_tx_flag=0; |
| | | 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) |
| | | {LED_TR_ON;} |
| | | else |
| | | {LED_TB_ON;} |
| | | |
| | | lora_seq_nb2++; |
| | | Lora_tx_zubao(); |
| | | // Lora_tx_mode(); |
| | | Radio.Send( usart_send, 13+Lora_tx_ancnum*4); |
| | | // if(usart_send[2]==0x99) |
| | | // {LED_TB_ON;} |
| | | Radio.Send( usart_send, 15+Lora_tx_ancnum*4); |
| | | Lora_tx_ancnum=0; |
| | | memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | | memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid)); |
| | | anjian_flag=0; |
| | | } |
| | | } |
| | | if(lora_txanchor_power_flag) |
| | | { |
| | | // SX126xReset(); |
| | | // Lora47X_change(); |
| | | // Delay_Ms(50); |
| | | Lora47X_Init(); |
| | | LED_TB_ON; |
| | | lora_seq_nb1++; |
| | | lora_txanchor_power_flag=0; |
| | | uint16_t checksum; |
| | | usart_send[2] = 0x23;//基站电量模式 |
| | | usart_send[3] = 6+Lora_tx_ancnum*3;//数据段长度 |
| | | memcpy(&usart_send[4],&dev_id,2); |
| | | usart_send[6] = lora_seq_nb1;//包序 |
| | | usart_send[7] = Lora_tx_ancnum; |
| | | memcpy(&usart_send[8],&Lora_tx_ancid,2*Lora_tx_ancnum); |
| | | 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(); |
| | | Radio.Send( usart_send, 10+Lora_tx_ancnum*3); |
| | | Lora_tx_ancnum=0; |
| | | |
| | | } |
| | | |
| | | |
| | | // Lora_Txcount=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // |
| | | // if(Lora_Txcount-Old_Lora_Txcount>=6554) |
| | | // { |
| | | // Old_Lora_Txcount=Lora_Txcount; |
| | | // LED_TB_ON; |
| | | // lora_seq_nb2++; |
| | | // Lora_tx_zubao(); |
| | | // Lora_tx_mode(); |
| | | // Radio.Send( usart_send, 12+Lora_tx_ancnum*4); |
| | | // Lora_tx_ancnum=0; |
| | | // memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | | // memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid)); |
| | | // } |
| | | |
| | | } |
| | | void MX_ADC1_Init() |
| | | { |
| | | MX_ADC_Init(); |
| | | } |
| | | extern uint16_t Lora_rece_error; |
| | | extern uint16_t Beepchixutime; |
| | | void Beep_Off() |
| | | { |
| | | __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, 0); |
| | | HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); |
| | | HAL_TIM_Base_Stop_IT(&htim2); |
| | | } |
| | | void Beep_On() |
| | | { |
| | | HAL_TIM_Base_Start_IT(&htim2); |
| | | HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); |
| | | __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, 60); |
| | | } |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | | /** |
| | |
| | | MX_USART1_UART_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | |
| | | // MX_IWDG_Init(); |
| | | MX_TIM2_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | // LED_LG_ON; |
| | | Program_Init(); |
| | |
| | | //Lora_rx_open(); |
| | | // Lora_Tx_Poll(); |
| | | Lora_Tx_Poll(); |
| | | |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | IdleTask(); |
| | | Lora_rece_error=0; |
| | | // Radio.IrqProcess( ); // Process Radio IRQ |
| | | // Anchor_App(); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM2 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | static void MX_TIM2_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM2_Init 0 */ |
| | | |
| | | /* USER CODE END TIM2_Init 0 */ |
| | | |
| | | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
| | | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
| | | TIM_OC_InitTypeDef sConfigOC = {0}; |
| | | |
| | | /* USER CODE BEGIN TIM2_Init 1 */ |
| | | |
| | | /* USER CODE END TIM2_Init 1 */ |
| | | htim2.Instance = TIM2; |
| | | htim2.Init.Prescaler = 32-1; |
| | | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
| | | htim2.Init.Period = 250-1; |
| | | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| | | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
| | | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
| | | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| | | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
| | | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
| | | sConfigOC.Pulse = 0; |
| | | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
| | | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
| | | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | /* USER CODE BEGIN TIM2_Init 2 */ |
| | | |
| | | /* USER CODE END TIM2_Init 2 */ |
| | | HAL_TIM_MspPostInit(&htim2); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief USART1 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | |
| | | HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|SDA_Pin|SCL_Pin, GPIO_PIN_SET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|GPIO_PIN_14 |
| | | |RADIO_nRESET_Pin|RADIO_NSS_Pin|GPIO_PIN_7, GPIO_PIN_RESET); |
| | | HAL_GPIO_WritePin(GPIOB, LED1_G_Pin|LED1_R_Pin|GPIO_PIN_14|RADIO_nRESET_Pin |
| | | |RADIO_NSS_Pin|GPIO_PIN_7, GPIO_PIN_RESET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|DW_CTRL_Pin|LED2_G_Pin, GPIO_PIN_RESET); |
| | |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | HAL_GPIO_Init(RADIO_BUSY_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : PB10 LED1_G_Pin LED1_R_Pin PB14 |
| | | RADIO_nRESET_Pin RADIO_NSS_Pin PB7 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|GPIO_PIN_14 |
| | | |RADIO_nRESET_Pin|RADIO_NSS_Pin|GPIO_PIN_7; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| | | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pin : INPUT_5V_Pin */ |
| | | GPIO_InitStruct.Pin = INPUT_5V_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| | | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
| | | HAL_GPIO_Init(INPUT_5V_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : LED1_G_Pin LED1_R_Pin PB14 RADIO_nRESET_Pin |
| | | RADIO_NSS_Pin PB7 */ |
| | | GPIO_InitStruct.Pin = LED1_G_Pin|LED1_R_Pin|GPIO_PIN_14|RADIO_nRESET_Pin |
| | | |RADIO_NSS_Pin|GPIO_PIN_7; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| | | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : PA8 DW_CTRL_Pin LED2_G_Pin */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_8|DW_CTRL_Pin|LED2_G_Pin; |
| | |
| | | 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++; |
| | | 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); |
| | |
| | | // } |
| | | // 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>=600) |
| | | 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>=10) |
| | | {stationary_num=0; |