/*******************************************************************************
|
* File Name : APL.c
|
* Description :
|
* Created on : 2018Äê5ÔÂ8ÈÕ
|
* Author : ¶Å¼ü
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Include Files *
|
*******************************************************************************/
|
#include "AppConfig.h"
|
#include "string.h"
|
#include "stm32l0xx_hal.h"
|
#include "HIDO_Timer.h"
|
#include "HIDO_ATLite.h"
|
#include "HIDO_Input.h"
|
#include "Uart.h"
|
#include "Shell.h"
|
#include "Uart.h"
|
#include "Led.h"
|
#include "Reboot.h"
|
#include "Beep.h"
|
#include "Key.h"
|
#include "ADC.h"
|
#include "Lis3dhApp.h"
|
#include "Power.h"
|
#include "HIDO_Debug.h"
|
#include "GPS.h"
|
#include "Lora.h"
|
#include "main.h"
|
#include "RTC.h"
|
#include "GPIO.h"
|
#include "DBG.h"
|
#include "lis3dh_driver.h"
|
#include "WS2812.h"
|
/*******************************************************************************
|
* Macro *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Type Definition *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Local Variable *
|
*******************************************************************************/
|
uint32_t dev_id;
|
uint16_t heartbeat_timer,poll_timer,sync_timer;
|
uint8_t aRxBuffer[1],group_id;
|
uint8_t bat_percent=0,g_start_send_flag;
|
extern u8 motor_state;
|
uint16_t tyncpoll_time,lpsettime;
|
uint16_t slottime,max_slotpos;
|
uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
|
extern uint8_t module_power;
|
extern float nomove_count;
|
float motor_keeptime;
|
uint8_t imu_enable,motor_enable;
|
u16 current_slotnum;
|
extern int32_t offsettimeus;
|
//#define FIXSLOT
|
#define FIXSLOTPOS 4
|
#define CMD_NUM 12
|
u16 slotpos_intoatl;
|
uint16_t bigslot_num;
|
float motor_ontime=0;
|
uint8_t userkey_state = 0;
|
extern u8 active_flag;
|
extern uint32_t uwbled,gpsled,loraled,powerled;
|
extern uint8_t lora_recv_num;
|
HIDO_UINT32 l_u32GPSTick = 0;
|
extern uint32_t GPS_ON_TIME;
|
extern uint32_t lp_time;
|
uint32_t lora_sendfinalbag_time;
|
uint32_t lora_sendfinal_rx_time=0;
|
uint8_t lora_sendfinalbag_flag;
|
uint8_t lora_sendfinal_rx_bag_flag;
|
extern uint8_t GPS_final_data[128];
|
extern uint8_t GPS_final_changdu;
|
uint8_t fangchai_flag;
|
extern uint32_t GPSDateTime;
|
|
ST_RTCDateTime stGPSDateTime;
|
enum
|
{
|
GPS_OFF,
|
GPS_ON,
|
GPS_SUCCESS,
|
} l_eGPSState;
|
|
ST_GPIO l_stDISPIN = { GPIOA, GPIO_PIN_0};
|
ST_GPIO l_stTypeCPIN = { GPIOB, GPIO_PIN_15};
|
HIDO_BOOL l_bIsVibration = HIDO_FALSE;
|
|
/*******************************************************************************
|
* Local Function Declaration *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Local Function *
|
*******************************************************************************/
|
extern void delay_ms(uint32_t nTimer) ;
|
void PowerDownDetect(void)
|
{
|
|
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_9))
|
{
|
delay_ms(1000);
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_9))
|
{
|
while(1)
|
{
|
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_9)==0)
|
{
|
delay_ms(100);
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
|
}
|
}
|
}
|
}
|
}
|
/*******************************************************************************
|
* Function Name : GPSEventCallback
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
static void GPSEventCallback(E_GPSType _eType, HIDO_CHAR *_pcData, HIDO_UINT32 _u32Len)
|
{
|
if(GPS_TYPE_GGA == _eType)
|
{
|
// Lora_SendData((HIDO_UINT8 *)_pcData, _u32Len);
|
// loraled=BLUE;
|
}
|
|
l_eGPSState = GPS_SUCCESS;
|
}
|
|
/*******************************************************************************
|
* Function Name : IsDisassemblyAlarm
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
static HIDO_BOOL IsDisassemblyAlarm(void)
|
{
|
if(GPIO_IS_SET(&l_stDISPIN))
|
{
|
return HIDO_TRUE;
|
}
|
|
return HIDO_FALSE;
|
}
|
|
/*******************************************************************************
|
* Function Name : IsTypecCActive
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
static HIDO_BOOL IsTypecCActive(void)
|
{
|
if(GPIO_IS_SET(&l_stTypeCPIN))
|
{
|
return HIDO_TRUE;
|
}
|
|
return HIDO_FALSE;
|
}
|
|
/*******************************************************************************
|
* Function Name : HAL_GPIO_EXTI_Callback
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê7ÔÂ23ÈÕ
|
*******************************************************************************/
|
extern uint32_t nomove_time;
|
extern void MX_Init(void);
|
extern void SystemClock_Config(void);
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
{
|
if(GPIO_Pin == GPIO_PIN_5)
|
{
|
// l_bIsVibration = HIDO_TRUE;
|
nomove_time=0;
|
}
|
if(GPIO_Pin == GPIO_PIN_9)
|
{
|
HAL_ResumeTick();
|
|
SystemClock_Config();
|
MX_Init();
|
Uart_ReInit(UART_ID_DBG);
|
Uart_ReInit(UART_ID_LORA);
|
Uart_ReInit(UART_ID_GPS);
|
|
|
|
PowerDownDetect();
|
}
|
|
}
|
extern void Set4LEDColor_Off(void);
|
uint8_t lora_sendfinalbag_num;
|
void Lora_Sendfinalbag_Poll()
|
{
|
// Lora_SendData((HIDO_UINT8 *)GPS_final_data,GPS_final_changdu);
|
if(lp_time-lora_sendfinalbag_time>10&&lora_sendfinalbag_flag)
|
{
|
lora_sendfinal_rx_bag_flag=1;
|
Lora_SendData((HIDO_UINT8 *)GPS_final_data,GPS_final_changdu);
|
lora_sendfinalbag_time=lp_time;
|
lora_sendfinalbag_num=lora_sendfinalbag_num+1;
|
loraled=BLUE;
|
Set4LEDColor(powerled,loraled,gpsled,uwbled);
|
HAL_Delay(100);
|
loraled=LEDOFF;
|
Set4LEDColor(powerled,loraled,gpsled,uwbled);
|
if(lora_sendfinalbag_num>4)
|
{
|
lora_sendfinal_rx_bag_flag=0;
|
lora_sendfinalbag_flag=0;
|
lora_sendfinalbag_num=0;
|
}
|
HIDO_Debug("lora bufa\r\n");
|
}
|
}
|
|
/*******************************************************************************
|
* Function Name : IsVibration
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
static HIDO_BOOL IsVibration(void)
|
{
|
HIDO_BOOL bIsVibration = l_bIsVibration;
|
|
return bIsVibration;
|
}
|
|
/*******************************************************************************
|
* Global Function *
|
*******************************************************************************/
|
|
/*******************************************************************************
|
* Function Name :
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
extern HIDO_UINT32 Battery_GetPercentage(void);
|
HIDO_INT32 APL_Init(void)
|
{
|
//Power_GPS_LoraOn();
|
HAL_Delay(3000);
|
//Power_Init();
|
DBG_Init();
|
Shell_Init();
|
//ADC_Init();
|
//Led_Init();
|
GPS_Init();
|
lp_time=g_com_map[GPS_ONTIME];
|
GPSDateTime=0;
|
Accelerometer_Init();
|
GPS_SetEventCallback(GPSEventCallback);
|
bat_percent=Battery_GetPercentage();
|
Lora_Init();
|
|
return HIDO_OK;
|
}
|
static uint8_t Input_5V_flag=0;
|
void Input_5V_Poll (void)
|
{
|
if(IsTypecCActive() == HIDO_TRUE&&Input_5V_flag==0)
|
{ Input_5V_flag=1;
|
if(bat_percent>=90)
|
{
|
powerled=GREEN;
|
Set4LEDColor(powerled,loraled,gpsled,uwbled);
|
// HIDO_Debug("1111");
|
}
|
else
|
{
|
powerled=RED;
|
Set4LEDColor(powerled,loraled,gpsled,uwbled);
|
// HIDO_Debug("2222");
|
}
|
}
|
if(IsTypecCActive() == HIDO_FALSE)
|
{
|
Input_5V_flag=0;
|
// Set4LEDColor_Off();
|
// HIDO_Debug("3333");
|
}
|
}
|
/*******************************************************************************
|
* Function Name :
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : ¶Å¼ü
|
* Modified Date: : 2018Äê5ÔÂ8ÈÕ
|
*******************************************************************************/
|
extern uint32_t lp_time;
|
extern uint8_t GPS_ON_flag;
|
uint32_t GPSDateTime =0;
|
uint8_t uwbqiehuangps_flag;
|
extern uint8_t nomove_flag;
|
HIDO_INT32 APL_Poll(void)
|
{
|
// ST_RTCDateTime stNow;
|
|
HIDO_TimerPoll();
|
|
IdleTask();
|
GPS_Poll();//gps½ÓÊÕº¯Êý
|
Lora_Poll();//lora½ÓÊÕº¯Êý
|
if(nomove_flag==0)
|
{
|
Lora_Sendfinalbag_Poll();//loraÔÚgps³É¹¦»ñµÃλÖÃ×ø±ê»òÕß³¬¹ý1·ÖÖÓûÓлñµÃʱ·¢ËÍgps×îºóÒ»°üÊý¾ÝµÄº¯Êý£¬Ö®ºó1·ÖÖÓ(10s)·¢Ò»´Î£¬³ý·ÇloraÊÕµ½Ïû³ý±ê־λ»òÕß·¢Ëͳ¬¹ý10´Î
|
}
|
if(Lora_IsIdle() == HIDO_TRUE)
|
Input_5V_Poll();
|
#if 1
|
if(((Lora_IsIdle() == HIDO_TRUE)/*ΪÁË·ÀÖ¹lora³õʼ»¯µÄʱºò½øÈëÐÝÃß*/
|
&& (GPS_IsIdle() == HIDO_TRUE)/*·ÀÖ¹gps¹¤×÷ʱ½øÈëÐÝÃß*/
|
&&(lora_sendfinal_rx_bag_flag==0)//·ÀÖ¹loraÔÚ2sµÈ´ý½ÓÊÕµÄʱºò½øÈëÐÝÃß
|
&& (IsTypecCActive() == HIDO_FALSE)) /*5vÊäÈë¼ì²âʱ²»ÐÝÃß*/||nomove_flag==1/*¾²Ö¹1СʱÁ¢¿ÌÐÝÃß¡£*/)
|
{
|
////// if(Lora_IsIdle() == HIDO_TRUE)
|
Power_Sleep();
|
//HIDO_Debug("in sleep\r\n");
|
}
|
else
|
{
|
}
|
if(nomove_flag==0&&(Lora_IsIdle() == HIDO_TRUE))
|
{
|
if(GPS_ON_flag)
|
{
|
/* ¼ì²éGPS¶¨Ê± */
|
switch(l_eGPSState)
|
{
|
case GPS_OFF:
|
{
|
if(lp_time-GPSDateTime > g_com_map[GPS_ONTIME] /*|| IsVibration() == HIDO_TRUE*/||uwbqiehuangps_flag==1)
|
{
|
uwbqiehuangps_flag=0;
|
l_bIsVibration = HIDO_FALSE;
|
HIDO_Debug("GPS ON\r\n");
|
Power_GPS_LoraOn();
|
l_eGPSState = GPS_ON;
|
GPSDateTime=lp_time;
|
if(IsTypecCActive() == HIDO_FALSE)//Èç¹ûÓÐ5vÊäÈëµÄ»°²»¹ØµÆ¡£
|
{
|
powerled=LEDOFF;
|
Set4LEDColor(powerled,loraled,gpsled,uwbled); //¹ØÒ»ÏµçÔ´µÆ£¬·ÀÖ¹gpsͻȻ¹¤×÷²»½øÈëÐÝÃߣ¬µçÔ´µÆ³£Á¿
|
}
|
|
}
|
|
break;
|
}
|
case GPS_ON:
|
{
|
if(lp_time-GPSDateTime > 60)
|
{
|
lora_sendfinalbag_flag=1;
|
lora_sendfinal_rx_bag_flag=1;
|
HIDO_Debug("GPS OFF\r\n");
|
Power_GPS_LoraOff();
|
l_eGPSState = GPS_OFF;
|
GPSDateTime=lp_time;
|
}
|
|
break;
|
}
|
case GPS_SUCCESS:
|
{
|
lora_sendfinalbag_flag=1;
|
lora_sendfinal_rx_bag_flag=1;
|
HIDO_Debug("GPS SUCCESS\r\n");
|
Power_GPS_LoraOff();
|
l_eGPSState = GPS_OFF;
|
GPSDateTime=lp_time;
|
break;
|
}
|
default:
|
{
|
break;
|
}
|
}
|
}
|
else
|
{
|
Power_GPS_LoraOff();
|
l_eGPSState = GPS_OFF;
|
// uwbqiehuangps_flag=1;//Èç¹û·Å¿ª£¬¾ÍÊÇuwbÇе½gps»áÁ¢¿Ì¹¤×÷Ò»´Î£¬²»·Å¿ª¾ÍÊǾÍËãuwbÇл»µ½gpsÒ²ÒªÅжÏÊÇ·ñ¹ýÁËһСʱ
|
}
|
}
|
else
|
{
|
Power_GPS_LoraOff();
|
l_eGPSState = GPS_OFF;
|
uwbqiehuangps_flag=1;
|
}
|
#ifndef UWB_OFF_FANGCHAI_ON
|
#else
|
/* ²ðж¸æ¾¯ */
|
if(IsDisassemblyAlarm())
|
{
|
Beep_On();
|
fangchai_flag=1;
|
}
|
else
|
{
|
Beep_Off();
|
fangchai_flag=0;
|
}
|
#endif
|
|
#endif
|
return HIDO_OK;
|
}
|