完成MCU的错误消息上报
This commit is contained in:
parent
1b7fbcb028
commit
ba6717c923
@ -56,6 +56,12 @@ public:
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// 获取所有当前错误码
|
||||
const std::set<int> &getAllErrorCodes() const
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
|
||||
// 判断某个错误码是否存在
|
||||
bool hasError(int code) const
|
||||
{
|
||||
@ -68,6 +74,7 @@ private:
|
||||
|
||||
// 故障字典声明(在 .cpp 实现里定义)
|
||||
extern std::unordered_map<int, FaultInfo> faultMap;
|
||||
extern const uint8_t mcuErrorCode[25];
|
||||
extern ErrorCodeSet vehicle_error_code;
|
||||
|
||||
std::string generateFaultJson(int code, const std::string &vin, int64_t timestamp);
|
||||
|
||||
@ -37,6 +37,8 @@ bool updateFaultLevel(int code, int newLevel)
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint8_t mcuErrorCode[25] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 30, 31, 32, 33, 34};
|
||||
|
||||
std::unordered_map<int, FaultInfo> faultMap = {
|
||||
{1001, {"BMS", "BMS_TEMP_HIGH_ERR", "温度过高", 0}},
|
||||
{1002, {"BMS", "BMS_TEMP_LOW_ERR", "温度过低", 0}},
|
||||
|
||||
@ -54,7 +54,7 @@ void Msg_Handler(const mc::msg::CanFrame::SharedPtr msg)
|
||||
|
||||
case 0x1825E5F1:
|
||||
{
|
||||
for (int i = 0; i < 28; i++)
|
||||
for (int i = 0; i < 28; ++i)
|
||||
{
|
||||
int byte_index = 1 + (i / 4); // 从 data[1] 开始,所以 +1
|
||||
int bit_offset = (3 - (i % 4)) * 2; // 每 2bit 表示一个错误
|
||||
@ -74,6 +74,30 @@ void Msg_Handler(const mc::msg::CanFrame::SharedPtr msg)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x1A4:
|
||||
{
|
||||
// 清空所有 MCU 错误码
|
||||
for (int code = 1101; code <= 1125; ++code)
|
||||
{
|
||||
vehicle_error_code.removeErrorCode(code);
|
||||
}
|
||||
|
||||
// 添加当前报文中的错误码(最多6个)
|
||||
for (uint8_t i = 0; i < 6; ++i)
|
||||
{
|
||||
for (uint8_t j = 0; j < 25; ++j)
|
||||
{
|
||||
if (msg->data[i] == mcuErrorCode[j])
|
||||
{
|
||||
int error_code = 1101 + j;
|
||||
vehicle_error_code.addErrorCode(error_code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,13 +157,10 @@ private:
|
||||
|
||||
void fault_timer_callback()
|
||||
{
|
||||
for (int code = 1001; code <= 1028; ++code)
|
||||
for (int code : vehicle_error_code.getAllErrorCodes())
|
||||
{
|
||||
if (vehicle_error_code.hasError(code))
|
||||
{
|
||||
std::string bms_fault_json = generateFaultJson(code, config.vid, getCurrentTimestampMs());
|
||||
mqtt_client_.publish(fault_topic_, bms_fault_json);
|
||||
}
|
||||
std::string fault_json = generateFaultJson(code, config.vid, getCurrentTimestampMs());
|
||||
mqtt_client_.publish(fault_topic_, fault_json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ void UartHandler::read_loop()
|
||||
|
||||
void UartHandler::print_hex(uint8_t *buf, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
printf("%02X ", buf[i]);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user