/* includes ----------------------------------------------------------*/ #include "global.h" /* typedef -----------------------------------------------------------*/ /* define ------------------------------------------------------------*/ /* macro -------------------------------------------------------------*/ /* variables ---------------------------------------------------------*/ global_par s_global_par; /* function prototypes -----------------------------------------------*/ /** * @brief 中控板初始化 * @param p_param_boot : 参数区指针 * @param p_rs485RecDate:485接收数据区的指针 * @note NONE * @retval 无 */ void centralCtrSys_Init(param_boot *p_param_boot, global_par *p_global_par){ uint8_t recBack = 0; rs485RecDate *p_rs485RecDate = &s_rs485RecDate; // 1. 从flash中读出VIN Read_ParamArea(); // 读出参数区的所有数据 // 2. 与车通信获取vin数据(读取所有寄存器的值) modbus_read_holding_registers(0x01, 0x0000, 67); HAL_Delay(5000); // 延时5s // 3. vin码比对 if(s_comData.vinRecSuccess == 1){ // 成功获取到车辆数据 if(memcmp(p_param_boot->vin, p_rs485RecDate->VIN, 26) != 0){ // 比对不成功 // 备份新的VIN码 memcpy(p_param_boot->vin, p_rs485RecDate->VIN, 26); Write_paramArea(); // 置位中控板迁移事件 BIT_SET(p_global_par->ctrEvent, CtrlPanelMigration); } } // 4. 初始化4g模块 4g模块在这里不好处理 放在任务中,围栏数据也一样 // 5. 读取96位(或者说是3个32位的字)的唯一ID GetUniqueID(s_messageDate.devId); // 6. 陀螺仪的初始化 recBack = atk_ms6050_init(); if(recBack != 0){ printf("ATK-MS6050 init failed!\r\n"); BIT_SET(s_comData.Malfunction, gyroscope); // 置位陀螺仪数据异常故障 } printf("ATK-MS6050 init\r\n"); recBack = atk_ms6050_dmp_init(); if(recBack != 0){ printf("ATK-MS6050 DMP init failed!\r\n"); BIT_SET(s_comData.Malfunction, gyroscope); // 置位陀螺仪数据异常故障 } printf("ATK-MS6050 DMP init!\r\n"); } // 电池故障判断 void fault_bat(rs485RecDate *p_rs485RecDate, comData *p_comData){ uint16_t errorLevel = 0; /* 尝试获取互斥量,等待无限长时间 */ if(osMutexAcquire(mutex_rs485RecDateHandle, osWaitForever) == osOK) { errorLevel = p_rs485RecDate->alarmLevel; /* 访问完成,释放互斥量 */ osMutexRelease(mutex_rs485RecDateHandle); } // 存在电池故障 if(errorLevel != 0){ BIT_SET(s_comData.Malfunction, batError); // 置位电池故障 }else{ BIT_CLEAR(s_comData.Malfunction, batError); // 清除电池故障 } } /** * @brief 中控板故障检测 * @param p_param_boot : 参数区指针 * @param p_rs485RecDate:485接收数据区的指针 * @note NONE * @retval 无 */ void faultDetection(comData *p_comData){ uint8_t timesCnt_gps = 0; // gps记时 // 1. 超出围栏故障判断 if(p_comData->fenceStatus == 1){ BIT_SET(s_comData.Malfunction, fence); }else{ BIT_CLEAR(s_comData.Malfunction, fence); } // 2. 电池故障判断 fault_bat(&s_rs485RecDate, &s_comData); // 电池故障判断 // 3. GPS信号丢失 // 获取gps失败,但陀螺仪数据正常的情况下,一分钟之后置位gps故障 // 获取gps失败,陀螺仪数据异常,直接置位gps故障 if((p_global_par->positionErrorCnt >= 3) && (BIT_CHECK(s_comData.Malfunction, fence) == 0)){ if(timesCnt_gps < 60){ timesCnt_gps++; }else{ timesCnt_gps = 60; BIT_SET(s_comData.Malfunction, positionError); } }else if((p_global_par->positionErrorCnt >= 3) && (BIT_CHECK(s_comData.Malfunction, fence) == 1)){ timesCnt_gps = 0; BIT_SET(s_comData.Malfunction, positionError); }else{ timesCnt_gps = 0; } if(p_global_par->positionErrorCnt == 0){ // 清除gps故障 BIT_CLEAR(s_comData.Malfunction, positionError); } // 4. MQTT通信异常 if(p_global_par->mqttTimeoutCnt >= PUBLISH_TIME_MS){ BIT_SET(s_comData.Malfunction, errorMqtt); // 置位MQTT故障 } if(p_global_par->mqttTimeoutCnt == 0){ // 清除MQTT故障 BIT_CLEAR(s_comData.Malfunction, errorMqtt); } // 5. 4G模块初始化故障 if(p_global_par->InitFaultFlag_4G == 1){ BIT_SET(s_comData.Malfunction, init_4G_error); // 置位4g模块初始化故障 }else{ BIT_CLEAR(s_comData.Malfunction, init_4G_error); // 清除4g模块初始化故障 } // 6. 485通信故障 if(p_global_par->timeoutCnt_485 >= TIMEOUT_485){ BIT_SET(s_comData.Malfunction, com485); // 置位485通信故障 } if(p_global_par->timeoutCnt_48 == 0){ BIT_CLEAR(s_comData.Malfunction, com485); // 置位485通信故障 } }