Skip to content

Commit

Permalink
SITL: SIM IntelligentEnergy24: add error string to V2 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Nov 22, 2023
1 parent b7c6995 commit b66d81b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions libraries/SITL/SIM_IntelligentEnergy24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ const AP_Param::GroupInfo IntelligentEnergy24::var_info[] = {

// @Param: 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
AP_GROUPINFO("STATE", 2, IntelligentEnergy24, set_state, -1),

// @Param: ERROR
// @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
AP_GROUPINFO("ERROR", 3, IntelligentEnergy24, err_code, 0),

Expand All @@ -66,7 +66,6 @@ void IntelligentEnergy24::update(const struct sitl_input &input)
if (!enabled.get()) {
return;
}
// gcs().send_text(MAV_SEVERITY_INFO, "fuelcell update");
update_send();
}

Expand Down Expand Up @@ -147,7 +146,7 @@ void IntelligentEnergy24::update_send()
memset(&message, 0, sizeof(message));
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,
0.67f, // inlet pressure (bar)
battery_voltage,
Expand All @@ -157,7 +156,8 @@ void IntelligentEnergy24::update_send()
(signed)battery_pwr,
(unsigned)state,
(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
uint8_t checksum = 0;
Expand All @@ -181,3 +181,16 @@ void IntelligentEnergy24::update_send()
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 "";
}
2 changes: 2 additions & 0 deletions libraries/SITL/SIM_IntelligentEnergy24.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class IntelligentEnergy24 : public IntelligentEnergy {

void update_send();

const char * get_error_string(const uint32_t code);

AP_Int8 enabled; // enable sim
AP_Int8 set_state;
AP_Int32 err_code;
Expand Down

0 comments on commit b66d81b

Please sign in to comment.