/*******************************************************************************
|
* File Name : APL.c
|
* Description :
|
* Created on : 2018Äê5ÔÂ8ÈÕ
|
* Author : ¶Å¼ü
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Include Files *
|
*******************************************************************************/
|
#include "AppConfig.h"
|
#include "string.h"
|
#include "stm32f4xx_hal.h"
|
|
#include "Uart.h"
|
#include "Shell.h"
|
#include "DBG.h"
|
#include "Internet.h"
|
#include "HIDO_Input.h"
|
#include "HIDO_Timer.h"
|
#include "HIDO_ATLite.h"
|
#include "HIDO_Debug.h"
|
#include "HIDO_Json.h"
|
#include "Uart.h"
|
#include "Led.h"
|
#include "Reboot.h"
|
#include "Delay.h"
|
#include "GPS.h"
|
#include "qxwz_app.h"
|
#include "UDPClient.h"
|
#include "APL.h"
|
|
#include "mainex.h"
|
#include "lis3dh_driver.h"
|
#include "dw_driver.h"
|
#include "deca_device_api.h"
|
#include "global_param.h"
|
#include "TrackingDiff.h"
|
#include "dw_app.h"
|
#include "lis3dh_driver.h"
|
#include "Beep.h"
|
#include "mainex.h"
|
#include "Delay.h"
|
#include "Module.h"
|
#include "OTA.h"
|
#include "ADC.h"
|
#include "ADC_hal.h"
|
#include "OTA.h"
|
#include "Log.h"
|
#include "HTTPClient.h"
|
#include "SPIFlash.h"
|
#include "Power.h"
|
#include "TCPClient.h"
|
#include "RTKClient.h"
|
#include "NTRIPClient.h"
|
#include "NTRIPApp.h"
|
|
#include "TTS.h"
|
|
|
/*******************************************************************************
|
* Macro *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Type Definition *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Local Variable *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Local Function Declaration *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Local Function *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Global Function *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Function Name :
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
static HIDO_UINT32 l_u32TimerID = 0;
|
extern u8 bat_percent2,chargedbg_flag;
|
extern TIM_HandleTypeDef htim1;
|
extern uint16_t anchordata_id[TAG_NUM_IN_SYS],anchordata_dist[TAG_NUM_IN_SYS];
|
extern uint8_t anchordata_bat[TAG_NUM_IN_SYS];
|
extern uint8_t anchordata_num;
|
uint16_t beepontime,beep_start;
|
extern float nomove_count;
|
u8 stationary_flag;
|
void message_construct_for_4G()
|
{
|
|
|
}
|
#ifdef __APP_CODE__
|
void IMUTask(void)
|
{
|
if (nomove_count > g_com_map[STATIONARY_TIME])
|
{
|
stationary_flag = 1;
|
}
|
else
|
{
|
stationary_flag = 0;
|
}
|
// g_com_map[NOMOVESLEEP_TIME] = 5;
|
if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&g_com_map[IMU_ENABLE]==1)
|
{
|
|
// CloseRTK4G();
|
mcu_sleep();
|
}
|
}
|
u8 motor_flag;
|
void BepperTask(void)
|
{
|
if(beepontime>0)
|
{beep_start=1;}
|
if(beep_start)
|
{
|
if(beepontime>0)
|
{
|
beepontime--;
|
motor_flag = 1;
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
|
}else{
|
motor_flag = 0;
|
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_4);
|
}
|
}
|
}
|
uint16_t uwb_losttimer = 0;
|
HIDO_VOID OneSecond_TimerCallback(HIDO_VOID *_pArg)
|
{
|
BepperTask();
|
IMUTask();
|
uwb_losttimer++;
|
message_construct_for_4G();
|
}
|
#endif
|
HIDO_VOID APL_Init(void)
|
{
|
#ifdef __APP_CODE__
|
SPIFlash_Init(SPI_FLASH_ID_0);
|
parameter_init();
|
Power_Init();
|
DBG_Init();
|
Shell_Init();
|
ADC_Init();
|
Accelerometer_Init();
|
Internet_Init();
|
if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_TCP)
|
{
|
TCPClient_Init();
|
}else if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_NTRIP)
|
{
|
// qxwz_app_init();
|
NTRIPClient_Init();
|
NTRIPApp_Init();
|
}
|
#ifdef __USE_QXWZ__
|
/* ʹÓÃǧѰλÖà */
|
qxwz_app_init();
|
#endif
|
|
GPS_Init();
|
UDPClient_Init();
|
#ifdef __USE_TCP_RTCM__
|
RTKClient_Init();
|
#endif
|
#ifdef __USE_UWB__
|
uwb_app_init();
|
#endif
|
HIDO_TimerCreate(&l_u32TimerID);
|
HIDO_TimerStart(l_u32TimerID, HIDO_TIMER_TYPE_LOOP, HIDO_TIMER_TICK_MS(1000), OneSecond_TimerCallback, HIDO_NULL);
|
#endif
|
|
|
|
#ifdef __OTA_CODE__
|
SPIFlash_Init(SPI_FLASH_ID_0);
|
Power_Init();
|
DBG_Init();
|
#ifdef __USE_QXWZ__
|
HIDO_Debug("\r\nstarting ota application\r\n");
|
#endif
|
Internet_Init();
|
HTTPClient_Init();
|
OTA_Init();
|
#endif
|
}
|
|
#ifdef __APP_CODE__
|
|
void LED4Gtask(void)
|
{
|
|
|
if(Internet_IsIPReady() == HIDO_TRUE)
|
{
|
led4g = GREEN;
|
}else{
|
if(rtk_state)
|
{
|
led4g = RED;
|
}else{
|
led4g = LEDOFF;
|
}
|
|
}
|
|
}
|
#define BATTARY_DEBUG
|
u16 chongman_time;
|
u8 only_one_flag;
|
u8 power_state = 0,chargeon = 0;
|
u32 adctick = 0;
|
int LowPower_EN = 0;
|
extern HIDO_FLOAT fVoltage1;
|
void PowerLedTask(void)
|
{
|
static u8 powerled_state=0;
|
if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
|
{
|
chongman_time=0;
|
only_one_flag=0;
|
if(!power_state&&!chargedbg_flag)
|
{
|
CloseRTK4G();
|
DBG_SetMode(DBG_MODE_CHARGE);
|
power_state = 1;
|
}
|
while(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&DBG_GetMode() == DBG_MODE_CHARGE)
|
{
|
if(HIDO_TimerGetTick()-adctick>6000) //6s²ÉÑùÒ»´Î µçÁ¿
|
{
|
adctick = HIDO_TimerGetTick();
|
chongman_time=chongman_time+6;
|
#ifdef BATTARY_DEBUG
|
//printf("µçѹ: %f V,µçÁ¿ %d,±ê־λ%d,ʱ¼ä %d\r\n",fVoltage1,bat_percent2,only_one_flag,chongman_time);
|
#endif
|
if( HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10))
|
{
|
bat_percent2=Power_GetBatteryPercentage();
|
|
}else{
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET);
|
bat_percent2=Power_GetBatteryPercentage();
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
|
}
|
}
|
if(fVoltage1>=4.15&&!only_one_flag)
|
{
|
only_one_flag=1;
|
chongman_time=0;
|
}
|
if(fVoltage1>=4.15&&chongman_time>=1800)
|
{
|
powerled = GREEN;
|
}else{
|
powerled = RED;
|
}
|
delay_ms(100);
|
DBG_Poll();
|
Internet_Poll();
|
Set4LEDColor(0,0,0,powerled);
|
}
|
}
|
|
chargeon = 0;
|
if(power_state)
|
{
|
DBG_SetMode(DBG_MODE_SHELL);
|
power_state = 0;
|
OpenRTK4G();
|
if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
|
{
|
delay_ms(100);
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
delay_ms(100);
|
}
|
}
|
if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
|
{
|
chargedbg_flag = 0;
|
|
}
|
if(HIDO_TimerGetTick()%1000<10 )
|
{
|
if(powerled_state==0)
|
{
|
if(bat_percent2>15)
|
{
|
powerled = BLUE;
|
}else{
|
powerled = RED;
|
}
|
powerled_state = 1;
|
// bat_percent = Battery_GetPercentage();
|
Set4LEDColor(uwbled,rtkled,led4g,powerled);
|
}
|
}else{
|
if(powerled_state)
|
{
|
powerled_state = 0;
|
powerled = LEDOFF;
|
Set4LEDColor(uwbled,rtkled,led4g,powerled);
|
}
|
|
}
|
|
if(HIDO_TimerGetTick()-adctick>5000) //10·ÖÖÓ²ÉÑùÒ»´Î µçÁ¿
|
{
|
adctick = HIDO_TimerGetTick();
|
#ifdef BATTARY_DEBUG
|
//printf("µçѹ: %f V,µçÁ¿ %d,±ê־λ%d,ʱ¼ä %d\r\n",fVoltage1,bat_percent2,only_one_flag,chongman_time);
|
#endif
|
if( HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10))
|
{
|
bat_percent2=Power_GetBatteryPercentage();
|
|
}else{
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET);
|
bat_percent2=Power_GetBatteryPercentage();
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
|
}
|
}
|
}
|
//void PowerDownDetect(void)
|
//{
|
// static HIDO_UINT32 l_u32QXpowerTick = 0;
|
//static uint32_t powercount=0;
|
//
|
// if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12))
|
// {
|
// if((HIDO_TimerGetTick() - l_u32QXpowerTick) >=1000)
|
// {
|
// while(1)
|
// {
|
// if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12)==0)
|
// {
|
// powercount = 0;
|
// l_u32QXpowerTick = HIDO_TimerGetTick();
|
// while(1)
|
// {
|
//
|
// if((HIDO_TimerGetTick() - l_u32QXpowerTick) >=100)
|
// {
|
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
// }
|
// }
|
// }
|
// }
|
// }
|
// }else{
|
// l_u32QXpowerTick = HIDO_TimerGetTick();
|
// }
|
//}
|
|
void PowerDownDetect(void)
|
{
|
static HIDO_UINT32 l_u32QXpowerTick = 0;
|
static uint32_t powercount=0;
|
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12))
|
{
|
delay_ms(1000);
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12))
|
{
|
while(1)
|
{
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12)==0)
|
{
|
delay_ms(100);
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
}
|
}
|
}
|
}
|
}
|
extern u8 bat_percent2;
|
u16 basesystimer=0,g_Resttimer= 0;
|
u8 g_start_sync_flag;
|
void HAL_SYSTICK_Callback(void)
|
{
|
|
}
|
u32 keystarttime,keystarttime2;
|
extern u8 heartbeasend_flag,userkey_state4g;
|
u8 userkey_state;
|
void UserKeyTask(void)
|
{
|
if(!GET_USERKEY)
|
{
|
if(HIDO_TimerGetTick() - keystarttime>3000)
|
{
|
beepontime = 2;
|
userkey_state4g = 1;
|
userkey_state = 1;
|
heartbeasend_flag = 1;
|
keystarttime = HIDO_TimerGetTick();
|
}
|
if(HIDO_TimerGetTick() - keystarttime2>10000)
|
{
|
// g_com_map[CNT_RESTART] = 1;
|
}
|
}else
|
{
|
keystarttime = HIDO_TimerGetTick();
|
keystarttime2 = HIDO_TimerGetTick();
|
}
|
}
|
#endif
|
void APLPollTask(void)
|
{
|
#ifdef __APP_CODE__
|
g_Resttimer=0;
|
DBG_Poll();
|
#ifdef _RTK_MODE_
|
Internet_Poll();
|
HIDO_TimerPoll();
|
HIDO_ATLitePoll();
|
LED4Gtask();
|
GPS_Poll();
|
UDPClient_Poll();
|
#ifdef __USE_TCP_RTCM__
|
RTKClient_Poll();
|
#endif
|
#endif
|
#ifdef GAOJINGDU
|
#ifdef TCP_RTCM
|
if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_TCP)
|
TCPClient_Poll();
|
#endif
|
#endif
|
PowerLedTask();
|
PowerDownDetect();
|
//uwbpolltask();
|
UserKeyTask();
|
#endif
|
|
#ifdef __OTA_CODE__
|
Internet_Poll();
|
HIDO_TimerPoll();
|
HIDO_ATLitePoll();
|
HTTPClient_Poll();
|
OTA_Poll();
|
#endif
|
|
|
// CloseRTK4G();
|
|
|
|
}
|
uint8_t udp_uwbenable = 1,uwb_state;
|
void APL_Poll(void)
|
{
|
APLPollTask();
|
|
if(uwb_state!=udp_uwbenable)
|
{
|
uwb_state = udp_uwbenable;
|
if(uwb_state)
|
{
|
UWBSPIWakeup();
|
}else{
|
uwbled = LEDOFF;
|
dwt_entersleep();
|
}
|
}
|
// printf("UWB״̬:%d",uwb_state);
|
if(uwb_state)
|
uwb_app_poll();
|
IdleTask();
|
}
|