123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /*Includes ----------------------------------------------*/
- #include "system.h"
- #include "exception.h"
- #include "ble_comm.h"
- #include "app_charge.h"
- #include "app_self_checking.h"
- #include "hal_monitor.h"
- #include "hal_ble_uart0.h"
- #include "hal_ble_client.h"
- #include "hal_mode_manage.h"
- /*Private macro ------------------------------------------------*/
- #define SELF_CHECK_WHEEL_EMPTY_TIMES_MAX 20 //允许最大轮空次数
- #define SELF_CHECK_ITEMS 4 //自检项数
- #define SELF_CHECK_ITEM_SUCCESS 0 //自检项目成功
- #define SELF_CHECK_ITEM_FAIL 1 //自检项目失败
- #define SELF_CHECK_ITEM_FRONT_SENSOR_INDEX 0 //自检项目 - 前脚传感器
- #define SELF_CHECK_ITEM_BACK_SENSOR_INDEX 1 //自检项目 - 后脚传感器
- #define SELF_CHECK_ITEM_BATTERY_INDEX 2 //自检项目 - 电量
- #define SELF_CHECK_ITEM_CHARGE_INDEX 3 //自检项目 - 充电电压
- /*STRUCTION ----------------------------------------------------*/
- typedef enum {
- SELF_CHECK_STAGE_READY, //准备阶段
- SELF_CHECK_STAGE_CHECK, //自检阶段
-
- } SELF_CHECK_STAGE_e;
- typedef struct self_check
- {
- /*private member*/
- SELF_CHECK_STAGE_e stage; //阶段字段
-
- int wheel_empty_times; //轮空次数
-
- uint8_t result[SELF_CHECK_ITEMS]; //自检结果
-
-
-
- } Self_Check_t;
- /*Local Variable -----------------------------------------------*/
- static Self_Check_t ob_self_check;
- /*Local Functions ----------------------------------------------*/
- static void app_self_checking_Process(void)
- {
- static char adv_name[TARFET_LEN_MAX];
- int adv_name_len;
- uint32_t txd,rxd;
-
- switch(app_charge_Getstate())
- {
- case BLE_Client_T_CHARGE_PULLOUT: //没充电
- ob_self_check.stage = SELF_CHECK_STAGE_READY; //设置阶段为准备阶段
- ob_self_check.wheel_empty_times = 0; //清空轮空次数
- break;
-
- case BLE_Client_T_CHARGE_INSERT: //充电
- case BLE_Client_T_CHARGE_DONE:
- switch(ob_self_check.stage)
- {
- case SELF_CHECK_STAGE_READY: //准备阶段
- slave_get_advname_len(&adv_name_len);
- if(adv_name_len != 0){
- slave_get_advname(adv_name, adv_name_len);
- UART0_GetPinConfig(&txd, &rxd);
- UART0_Initialize(PIN_TXD_BLE,UART0_INVALID_PIN,UART_HZ);
- UART0_Tx_Send(0,UART0_T_SELF_CHECK_RDY,(uint8_t*)adv_name,adv_name_len); //将广播名发送给触发设备
- UART0_Initialize(txd,rxd,UART_HZ);
- }
- break;
-
- case SELF_CHECK_STAGE_CHECK: //自检阶段
- ob_self_check.wheel_empty_times++;
-
- if(ob_self_check.wheel_empty_times >= SELF_CHECK_WHEEL_EMPTY_TIMES_MAX){
-
- if(hal_mode_get() != HAL_MODE_SELF_CHECK){
- Except_SaveExceptype(EXCEPT_DATA_FRONT_ACC);
- Except_SaveExceptype(EXCEPT_DATA_FRONT_GRY);
- Except_SaveExceptype(EXCEPT_DATA_FRONT_MAG);
- }
-
- memset(ob_self_check.result, SELF_CHECK_ITEM_SUCCESS, SELF_CHECK_ITEMS);
-
- //前脚传感器
- if(Except_IsError(EXCEPT_DATA_FRONT_ACC)){ob_self_check.result[SELF_CHECK_ITEM_FRONT_SENSOR_INDEX] = SELF_CHECK_ITEM_FAIL;}
- if(Except_IsError(EXCEPT_DATA_FRONT_GRY)){ob_self_check.result[SELF_CHECK_ITEM_FRONT_SENSOR_INDEX] = SELF_CHECK_ITEM_FAIL;}
- if(Except_IsError(EXCEPT_DATA_FRONT_MAG)){ob_self_check.result[SELF_CHECK_ITEM_FRONT_SENSOR_INDEX] = SELF_CHECK_ITEM_FAIL;}
- //后脚传感器
- if(Except_IsError(EXCEPT_DATA_BACK_MAG)){ob_self_check.result[SELF_CHECK_ITEM_BACK_SENSOR_INDEX] = SELF_CHECK_ITEM_FAIL;}
- //电量
- if(Except_IsError(EXCEPT_DATA_BATTERY)){ob_self_check.result[SELF_CHECK_ITEM_BATTERY_INDEX] = SELF_CHECK_ITEM_FAIL;}
- //充电电压
- if(Except_IsError(EXCEPT_DATA_CHARGE)){ob_self_check.result[SELF_CHECK_ITEM_CHARGE_INDEX] = SELF_CHECK_ITEM_FAIL;}
-
-
- //灯显示结果,逻辑应该是先显示完灯后在去重新检测
-
- ob_self_check.wheel_empty_times = SELF_CHECK_WHEEL_EMPTY_TIMES_MAX;
- }
- break;
- }
- break;
- }
- }
- static void cb_UART0_R_SELF_CHECK_ASK(void* handle)
- {
- if(ob_self_check.stage == SELF_CHECK_STAGE_READY)
- {
- hal_mode_set(HAL_MODE_SELF_CHECK); //串口接收自检指令,开启自检模式
- ob_self_check.stage = SELF_CHECK_STAGE_CHECK; //进入自检阶段
- }
- }
- /*API ----------------------------------------------------------*/
- void app_self_checking_Init(void)
- {
- ob_self_check.stage = SELF_CHECK_STAGE_READY;
- ob_self_check.wheel_empty_times = 0;
-
- UART0_Rx_Regist(UART0_R_SELF_CHECK_ASK,cb_UART0_R_SELF_CHECK_ASK);
- Process_Start(10,"app_self_checking_Process",app_self_checking_Process);
- }
|