|
|
@ -37,9 +37,26 @@ static osThreadId PacketRxThreadId; |
|
|
|
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|
|
|
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|
|
|
|
|
|
|
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
|
|
|
|
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
|
|
|
|
static bool motorErrorFlagCache[10]; // 电机异常状态上报标志位
|
|
|
|
static zmutex motorErrorFlagCacheLock; |
|
|
|
static uint8_t m_dflag; |
|
|
|
|
|
|
|
static bool motorErrorFlag_get(int subindex) { |
|
|
|
bool ret; |
|
|
|
{ |
|
|
|
zlock_guard guard(motorErrorFlagCacheLock); |
|
|
|
ret = motorErrorFlagCache[subindex]; |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
static uint8_t m_dflag; |
|
|
|
static void motorErrorFlag_set(int subindex, bool val) { |
|
|
|
{ |
|
|
|
zlock_guard guard(motorErrorFlagCacheLock); |
|
|
|
motorErrorFlagCache[subindex] = val; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
* FUNCTION_IMPL * |
|
|
@ -126,7 +143,9 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
|
Hardware::ins().motor(subindex)->enableIC(false); |
|
|
|
Hardware::ins().motor(subindex)->enableIC(true); |
|
|
|
Hardware::ins().motor(subindex)->rotate(velocity); |
|
|
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
motorErrorFlag_set(subindex, false); |
|
|
|
} |
|
|
|
|
|
|
|
// 泵机停止
|
|
|
@ -365,26 +384,26 @@ static void onPressureSensorDataReportTimer(void const* argument) { |
|
|
|
|
|
|
|
static void onMotorMonitorTimer(void const* argument) { |
|
|
|
// 电机异常检查
|
|
|
|
static bool motorErrorFlagCache[10]; |
|
|
|
|
|
|
|
report_exeception_data_t data; |
|
|
|
for (size_t i = 0; i < Hardware::ins().motorNum(); i++) { |
|
|
|
bool estate = motorErrorFlag_get(i); |
|
|
|
|
|
|
|
if (!Hardware::ins().motor(i)->ping()) { |
|
|
|
data.subid = i; |
|
|
|
data.ecode = kerr_motor_subdevice_offline; |
|
|
|
|
|
|
|
if (!motorErrorFlagCache[i]) { |
|
|
|
motorErrorFlagCache[i] = true; |
|
|
|
if (!estate) { |
|
|
|
motorErrorFlag_set(i, true); |
|
|
|
ZLOGE(TAG, "motor %d offline error", i); |
|
|
|
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|
|
|
} |
|
|
|
} else { |
|
|
|
auto gstate = Hardware::ins().motor(i)->getGState(); |
|
|
|
bool flag = gstate.reset || gstate.drv_err || gstate.uv_cp; |
|
|
|
// flag = true;
|
|
|
|
if (!flag && motorErrorFlagCache[i]) { |
|
|
|
motorErrorFlagCache[i] = false; |
|
|
|
} else if (flag && !motorErrorFlagCache[i]) { |
|
|
|
if (!flag && estate) { |
|
|
|
motorErrorFlag_set(i, false); |
|
|
|
} else if (flag && !estate) { |
|
|
|
ZLOGE(TAG, "motor %d error, reset %d, drv_err %d, uv_cp %d", i, gstate.reset, gstate.drv_err, gstate.uv_cp); |
|
|
|
if (gstate.reset) { |
|
|
|
data.ecode = kerr_motor_reset_error; |
|
|
@ -396,7 +415,7 @@ static void onMotorMonitorTimer(void const* argument) { |
|
|
|
data.ecode = kerr_motor_unkown_error; |
|
|
|
} |
|
|
|
data.subid = i; |
|
|
|
motorErrorFlagCache[i] = true; |
|
|
|
motorErrorFlag_set(i, true); |
|
|
|
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|
|
|
} |
|
|
|
} |
|
|
@ -410,6 +429,7 @@ static void onMotorMonitorTimer(void const* argument) { |
|
|
|
void protocol_impl_service_init() { //
|
|
|
|
Hardware::ins().init(); |
|
|
|
ForceReportFlagMgr::ins()->init(); |
|
|
|
motorErrorFlagCacheLock.init(); |
|
|
|
m_dflag = 0x00; |
|
|
|
SET_BIT(m_dflag, 0); |
|
|
|
|
|
|
|