| | |
| | | #include "global_param.h" |
| | | #include "TrackingDiff.h" |
| | | #include "dw_app.h" |
| | | #define DEBUG_MODE |
| | | //#define DEBUG_MODE |
| | | /* USER CODE END Includes */ |
| | | |
| | | /* Private typedef -----------------------------------------------------------*/ |
| | |
| | | |
| | | if(huart1.Instance->ISR&USART_ISR_FE) |
| | | { |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | //if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin)) |
| | | //{ |
| | |
| | | MOTOR_ON; |
| | | }else{ |
| | | MOTOR_OFF; |
| | | } |
| | | |
| | | } |
| | | break; |
| | | case 2: |
| | | MOTOR_ON; |
| | |
| | | |
| | | u16 current_slotnum; |
| | | extern int32_t offsettimeus; |
| | | //#define FIXSLOT |
| | | #define FIXSLOTPOS 8 |
| | | #define FIXSLOT |
| | | #define FIXSLOTPOS 2 |
| | | u16 slotpos_intoatl; |
| | | uint16_t bigslot_num; |
| | | uint8_t fix_slotpos =FIXSLOTPOS; |
| | | int32_t lpcount,lptime,target_time; |
| | | extern u16 tagslotpos; |
| | | void SetNextPollTime(u16 slotpos) |
| | | { |
| | | |
| | | #ifdef FIXSLOT |
| | | // fix_slotpos =FIXSLOTPOS; |
| | | fix_slotpos = g_com_map[ALARM_DISTANCE1]; |
| | | slotpos = fix_slotpos; |
| | | tagslotpos = fix_slotpos; |
| | | #endif |
| | | |
| | | if(current_slotnum>=tag_frequency) |
| | | current_slotnum-=tag_frequency; |
| | | while(current_slotnum>=tag_frequency) |
| | | { current_slotnum-=tag_frequency;} |
| | | slotpos_intoatl = current_slotnum*bigslot_num+slotpos; |
| | | |
| | | if(current_slotnum==19) |
| | | {slotpos_intoatl = current_slotnum*bigslot_num+slotpos;} |
| | | target_time=(slotpos_intoatl*SLOTTIME_MS+100)*100; |
| | | |
| | | //if(target_time<90000) |
| | | { |
| | | lptime=target_time-offsettimeus; |
| | | lptime=target_time-offsettimeus+1200; |
| | | lpcount = lptime/LPTIMER_LSB; |
| | | if(lpcount>LPTIMER_1S_COUNT) |
| | | lpcount-=LPTIMER_1S_COUNT; |
| | |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); |
| | | } |
| | | } |
| | | u8 active_flag=0; |
| | | void Program_Init(void) |
| | | { float temp; |
| | | uint16_t temp2; |
| | |
| | | Usart1ParseDataCallback = UsartParseDataHandler; |
| | | parameter_init(); |
| | | //deca_sleep(1000); |
| | | g_com_map[VERSION] = 0x0209; |
| | | g_com_map[VERSION] = 0x0210; |
| | | #ifdef DEBUG_MODE |
| | | // g_com_map[DEV_ROLE]=1; |
| | | // g_com_map[DEV_ID]=0x123; |
| | | // g_com_map[DEV_ID]=0x11; |
| | | // g_com_map[COM_INTERVAL]=100; |
| | | // g_com_map[MAX_REPORT_ANC_NUM]=1; |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | // g_com_map[IMU_ENABLE]=0; |
| | | g_com_map[IMU_ENABLE]=0; |
| | | //g_com_map[COM_INTERVAL]=50; |
| | | #endif |
| | | //g_com_map[NOMOVESLEEP_TIME]=10; |
| | | // g_com_map[IMU_ENABLE]=0; |
| | | // g_com_map[COM_INTERVAL]=50; |
| | | g_com_map[IMU_ENABLE]=0; |
| | | g_com_map[COM_INTERVAL]=1000; |
| | | active_flag = g_com_map[ACTIVE_INDEX]; |
| | | if(active_flag==0) |
| | | { g_com_map[COM_INTERVAL]=1000; |
| | | g_com_map[IMU_ENABLE]=1; |
| | | g_com_map[NOMOVESLEEP_TIME]=10; |
| | | g_com_map[MOTOR_ENABLE]=0; |
| | | } |
| | | if(g_com_map[COM_INTERVAL]==0) |
| | | { |
| | | g_com_map[COM_INTERVAL]=100; |
| | |
| | | // { |
| | | // MODBUS_Poll(); |
| | | // } |
| | | if(g_start_send_flag) |
| | | if(g_start_send_flag&&active_flag) |
| | | { static uint16_t blink_count=0; |
| | | SystemClock_Config(); |
| | | g_start_send_flag = 0; |
| | |
| | | Error_Handler(); |
| | | } |
| | | /* USER CODE BEGIN USART1_Init 2 */ |
| | | // GPIO_InitStruct.Pin = GPIO_PIN_9; |
| | | // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | // GPIO_InitStruct.Pull = GPIO_PULLUP; |
| | | // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | // GPIO_InitStruct.Alternate = GPIO_AF4_USART1; |
| | | // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | // if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 1) != HAL_OK) |
| | | // { |
| | | // Error_Handler(); |
| | | // } |
| | | GPIO_InitStruct.Pin = GPIO_PIN_9; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | GPIO_InitStruct.Alternate = GPIO_AF4_USART1; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 1) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | Usart1InitVariables(); |
| | | /* USER CODE END USART1_Init 2 */ |
| | | |
| | |
| | | current_slotnum++; |
| | | SetNextPollTime(tagslotpos); |
| | | nomove_count+=(float)g_com_map[COM_INTERVAL]/1000; |
| | | if(active_flag==0) |
| | | { |
| | | if(!GET_USERKEY) |
| | | { |
| | | LED_LG_ON; |
| | | key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000; |
| | | if(key_keeptime>3) |
| | | { |
| | | u8 i=250,keystate=1; |
| | | while(i--) |
| | | { |
| | | if(i%10==0) |
| | | { |
| | | LED_LG_BLINK; |
| | | } |
| | | if(GET_USERKEY) |
| | | {keystate = 0;} |
| | | if(keystate==0&&!GET_USERKEY) |
| | | { |
| | | parameter_init(); |
| | | g_com_map[ACTIVE_INDEX] = 1; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | delay_ms(10); |
| | | } |
| | | } |
| | | }else{ |
| | | LED_LG_OFF; |
| | | key_keeptime=0; |
| | | } |
| | | |
| | | } |
| | | if(motor_ontime>0) |
| | | { |
| | | motor_ontime-=(float)1/tag_frequency; |