SITL: SIM IntelligentEnergy24: add error string to V2 protocol

This commit is contained in:
Iampete1 2023-10-25 12:46:49 +01:00 committed by Andrew Tridgell
parent a00b6b6f86
commit d626928e0c
2 changed files with 20 additions and 5 deletions

View File

@ -43,13 +43,13 @@ const AP_Param::GroupInfo IntelligentEnergy24::var_info[] = {
// @Param: STATE // @Param: STATE
// @DisplayName: Explicitly set state // @DisplayName: Explicitly set state
// @Description: Explicity specify a state for the generator to be in // @Description: Explicitly specify a state for the generator to be in
// @User: Advanced // @User: Advanced
AP_GROUPINFO("STATE", 2, IntelligentEnergy24, set_state, -1), AP_GROUPINFO("STATE", 2, IntelligentEnergy24, set_state, -1),
// @Param: ERROR // @Param: ERROR
// @DisplayName: Explicitly set error code // @DisplayName: Explicitly set error code
// @Description: Explicity specify an error code to send to the generator // @Description: Explicitly specify an error code to send to the generator
// @User: Advanced // @User: Advanced
AP_GROUPINFO("ERROR", 3, IntelligentEnergy24, err_code, 0), AP_GROUPINFO("ERROR", 3, IntelligentEnergy24, err_code, 0),
@ -66,7 +66,6 @@ void IntelligentEnergy24::update(const struct sitl_input &input)
if (!enabled.get()) { if (!enabled.get()) {
return; return;
} }
// gcs().send_text(MAV_SEVERITY_INFO, "fuelcell update");
update_send(); update_send();
} }
@ -147,7 +146,7 @@ void IntelligentEnergy24::update_send()
memset(&message, 0, sizeof(message)); memset(&message, 0, sizeof(message));
int8_t tank_remaining_pct = (float)tank_bar / MAX_TANK_PRESSURE * 100.0; int8_t tank_remaining_pct = (float)tank_bar / MAX_TANK_PRESSURE * 100.0;
hal.util->snprintf(message, ARRAY_SIZE(message), "<%i,%.2f,%.1f,%i,%u,%i,%i,%u,%u,%i,,", // last blank , is for fuel cell to send info string up to 32 char ASCII hal.util->snprintf(message, ARRAY_SIZE(message), "<%i,%.2f,%.1f,%i,%u,%i,%i,%u,%u,%i,%s,", // last blank , is for fuel cell to send info string up to 32 char ASCII
tank_remaining_pct, tank_remaining_pct,
0.67f, // inlet pressure (bar) 0.67f, // inlet pressure (bar)
battery_voltage, battery_voltage,
@ -157,7 +156,8 @@ void IntelligentEnergy24::update_send()
(signed)battery_pwr, (signed)battery_pwr,
(unsigned)state, (unsigned)state,
(unsigned)err_code, (unsigned)err_code,
0); // fault state 2 (0 = no fault) 0, // fault state 2 (0 = no fault)
get_error_string(err_code));
// calculate the checksum // calculate the checksum
uint8_t checksum = 0; uint8_t checksum = 0;
@ -181,3 +181,16 @@ void IntelligentEnergy24::update_send()
AP_HAL::panic("Failed to write to autopilot: %s", strerror(errno)); AP_HAL::panic("Failed to write to autopilot: %s", strerror(errno));
} }
} }
const char * IntelligentEnergy24::get_error_string(const uint32_t code)
{
switch (code) {
case 20:
return "THERMAL MNGMT";
default:
break;
}
return "";
}

View File

@ -60,6 +60,8 @@ private:
void update_send(); void update_send();
const char * get_error_string(const uint32_t code);
AP_Int8 enabled; // enable sim AP_Int8 enabled; // enable sim
AP_Int8 set_state; AP_Int8 set_state;
AP_Int32 err_code; AP_Int32 err_code;