123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #include "task_ec800_upload.h"
- /* define ------------------------------------------------------------*/
- #define ANGLE_UPDATE_TIME 50 // 角度更新时间 2s 单位100ms
- #define SPEED_Go_STRAIGHT 25 // 直行速度 25KM/H 用来判断手把扶正 初始化姿态
- /* variables ---------------------------------------------------------*/
- // 拷贝数据
- void Task_Ec800_Uplaod_CopyRs485Date(rs485RecDate *p_rs485RecDate, messageDate *p_messageDate){
- /* 尝试获取互斥量,等待无限长时间 */
- if(osMutexAcquire(mutex_rs485RecDateHandle, osWaitForever) == osOK)
- {
- /* 安全地访问s_rs485RecDate结构体 */
- memcpy(&p_messageDate->vehicleSpeed, &p_rs485RecDate->vehicleSpeed, sizeof(p_rs485RecDate->vehicleSpeed));
- memcpy(&p_messageDate->dailyDrivTime, &p_rs485RecDate->dailyDrivTime, sizeof(p_rs485RecDate->dailyDrivTime));
- memcpy(&p_messageDate->dailyDrivMileage, &p_rs485RecDate->dailyDrivMileage, sizeof(p_rs485RecDate->dailyDrivMileage));
- memcpy(&p_messageDate->accTotalDrivTime_day, &p_rs485RecDate->accTotalDrivTime_day, sizeof(p_rs485RecDate->accTotalDrivTime_day));
- memcpy(&p_messageDate->accTotalDrivTime_h_min, &p_rs485RecDate->accTotalDrivTime_h_min, sizeof(p_rs485RecDate->accTotalDrivTime_h_min));
- memcpy(&p_messageDate->accTotalMileage_h, &p_rs485RecDate->accTotalMileage_h, sizeof(p_rs485RecDate->accTotalMileage_h));
- memcpy(&p_messageDate->accTotalMileage_l, &p_rs485RecDate->accTotalMileage_l, sizeof(p_rs485RecDate->accTotalMileage_l));
- memcpy(&p_messageDate->runTime, &p_rs485RecDate->runTime, sizeof(p_rs485RecDate->runTime));
- memcpy(&p_messageDate->batCompartmentTemp, &p_rs485RecDate->batCompartmentTemp, sizeof(p_rs485RecDate->batCompartmentTemp));
- memcpy(&p_messageDate->demandCur, &p_rs485RecDate->demandCur, sizeof(p_rs485RecDate->demandCur));
- memcpy(&p_messageDate->demandVol, &p_rs485RecDate->demandVol, sizeof(p_rs485RecDate->demandVol));
- memcpy(&p_messageDate->alarmLevel, &p_rs485RecDate->alarmLevel, sizeof(p_rs485RecDate->alarmLevel));
- memcpy(&p_messageDate->alarmType, &p_rs485RecDate->alarmType, sizeof(p_rs485RecDate->alarmType));
- memcpy(&p_messageDate->batSn, &p_rs485RecDate->batSn, sizeof(p_rs485RecDate->batSn));
- memcpy(&p_messageDate->Vehicle_Num, &p_rs485RecDate->Vehicle_Num, sizeof(p_rs485RecDate->Vehicle_Num));
- memcpy(&p_messageDate->VIN, &p_rs485RecDate->VIN, sizeof(p_rs485RecDate->VIN));
-
- /* 访问完成,释放互斥量 */
- osMutexRelease(mutex_rs485RecDateHandle);
- }
- // 车辆状态判断
- if(s_comData.driveStatus == 2){
- p_messageDate->vehicleStatus = 0;
- }else if(s_comData.driveStatus == 3){
- p_messageDate->vehicleStatus = 1;
- }
- // 故障数据copy
- p_messageDate->malfunction = s_comData.Malfunction;
- // 角度数据赋值
- p_messageDate->drivDirection = previousYaw;
- }
- /**
- * @brief 上传故障信息
- * @note 如果存在故障,每秒上传一次故障报告
- * @param 无
- * @retval 无
- */
- void upload_fault_info(void) {
- static uint8_t upload_interval_counter = 0; // 上传间隔计数器
- uint32_t faultCode = 0; // 临时的故障变量存储
- nmea_utc_time time = {0}; // 临时时间存储
- char storeFaultData[30] = {0};
- uint32_t time_stamp = 0; // 临时的时间戳
- // 检查存在MQTT故障,4G模块故障,或者未完成初始化,且记录索引等于上传索引 -- 不进行故障上传
- if((s_ec800Date.ec800InitFlag == 0)
- // || (BIT_CHECK(s_comData.Malfunction, init_4G_error))
- // || (BIT_CHECK(s_comData.Malfunction, errorMqtt))
- || (s_param_boot.faultRecordIndex == s_param_boot.faultUploadIndex)){
- return;
- }
- // 更新计数器
- if (upload_interval_counter < 250) {
- upload_interval_counter++;
- } else {
- upload_interval_counter = 0;
- }
-
- // 如果计数器达到上传间隔,上传故障报告
- if (upload_interval_counter % 10 != 0) {
- return;
- }
- // 从flash中获取故障
- norflash_read((uint8_t *)storeFaultData, s_param_boot.faultUploadAddr, 27);
- // 分解故障数据
- // 使用sscanf函数将字符串解析为指定的格式
- sscanf(storeFaultData, "%4hu%2hhu%2hhu-%2hhu%2hhu%2hhu:0x%x,",
- &time.year, &time.month, &time.date, &time.hour, &time.min, &time.sec, &faultCode);
- // 计算时间戳
- time_stamp = EC800_mktime(time.year, time.month, time.date, time.hour - 8, time.min, time.sec);
-
- // 上传故障
- EC800_uploadFaultReport(time_stamp, faultCode);
- // 更新索引和获取地址
- s_param_boot.faultUploadIndex = (s_param_boot.faultUploadIndex < MAX_RECORDS) ? (s_param_boot.faultUploadIndex + 1) : 0 ;
- // 更新地址
- s_param_boot.faultUploadAddr += 27;
- if(s_param_boot.faultUploadIndex == 0){
- s_param_boot.faultUploadAddr = 0;
- }
- // 保存最新的索引和地址数据
- Write_paramArea();
- }
- /**
- * @brief 上传任务内容
- * @param None
- * @note None
- * @retval None
- */
- void task_ec800_content(void)
- {
- // unsigned long times = 0;
- // 蜂鸣器响应
- // control_beep_response();
- // 检测是否正在升级固件
- if(s_ec800Date.hardwareUpdate == 1){
- osDelay(100);
- return;
- }
- // 拷贝485接收道德数据到待发送的消息中
- Task_Ec800_Uplaod_CopyRs485Date(&s_rs485RecDate, &s_messageDate);
- // MQTT服务器数据接收处理
- handleReceive();
- // 4G模块的操作
- EC800_stateTransition_use();
- // 上传故障信息
- upload_fault_info();
- // times = getRunTimeCounterValue();
- // printf("task run time: %ld\r\n", times);
- osDelay(100);
- }
|