diff --git a/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.cpp b/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.cpp index 4be6f1ec89..d00f9f8747 100644 --- a/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.cpp +++ b/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.cpp @@ -10,15 +10,14 @@ void ev_board_support_extendedImpl::init() { mod->serial.signal_keep_alive.connect([this](KeepAlive k) { types::ev_board_support_extended::KeepAliveData data; - data.timestamp = k.time_stamp; // will get converted to signed unfortunatly + data.timestamp = k.time_stamp; // will get converted to signed unfortunatly data.hw_revision_minor = k.hw_revision_minor; // will get converted to signed unfortunatly data.sw_version = k.sw_version_string; - switch (k.hw_revision_major) - { + switch (k.hw_revision_major) { case ConfigHardwareRevisionMajor_HW_MAJOR_REV_A: data.hw_revision_major = types::ev_board_support_extended::Hw_revision_major::Rev_A; break; - + default: data.hw_revision_major = types::ev_board_support_extended::Hw_revision_major::UNKNOWN; break; @@ -27,11 +26,11 @@ void ev_board_support_extendedImpl::init() { }); mod->serial.signal_ac_meas_instant.connect([this](ACMeasInstant d) { - types::ev_board_support_extended::ACVoltageData data; - data.Ua = d.Ua; - data.Ub = d.Ub; - data.Uc = d.Uc; - publish_ac_voltage_event(data); + types::ev_board_support_extended::ACVoltageData data; + data.Ua = d.Ua; + data.Ub = d.Ub; + data.Uc = d.Uc; + publish_ac_voltage_event(data); }); mod->serial.signal_ac_stats.connect([this](ACMeasStats d) { @@ -47,7 +46,7 @@ void ev_board_support_extendedImpl::init() { data.Uc.min = d.Uc.min; data.Uc.max = d.Uc.max; data.Uc.average = d.Uc.avg; - + publish_ac_statistics_event(data); }); } @@ -61,11 +60,10 @@ bool ev_board_support_extendedImpl::handle_set_status_led(bool& state) { return true; } -void ev_board_support_extendedImpl::handle_reset(bool& soft_reset) -{ - //EVLOG_info << "Resetting " << (soft_reset ? "SOFT" : "HARD"); - if(soft_reset) { - if(!mod->serial.soft_reset()) +void ev_board_support_extendedImpl::handle_reset(bool& soft_reset) { + // EVLOG_info << "Resetting " << (soft_reset ? "SOFT" : "HARD"); + if (soft_reset) { + if (!mod->serial.soft_reset()) EVLOG_error << "Could not soft reset"; else EVLOG_info << "Sent soft resetting packet to MCU."; @@ -74,22 +72,19 @@ void ev_board_support_extendedImpl::handle_reset(bool& soft_reset) } } -void ev_board_support_extendedImpl::handle_get_ac_data_instant() -{ - if(!mod->serial.get_ac_data_instant()) +void ev_board_support_extendedImpl::handle_get_ac_data_instant() { + if (!mod->serial.get_ac_data_instant()) EVLOG_error << "Could not send measurement request packet."; else EVLOG_info << "Sent AC instant measurement request packet."; } -void ev_board_support_extendedImpl::handle_get_ac_statistics() -{ - if(!mod->serial.get_ac_statistic()) +void ev_board_support_extendedImpl::handle_get_ac_statistics() { + if (!mod->serial.get_ac_statistic()) EVLOG_error << "Could not send measurement request packet."; else EVLOG_info << "Sent AC statistics measurement request packet."; } - -} // namespace board_support +} // namespace board_support_extended } // namespace module diff --git a/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.hpp b/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.hpp index b234649a10..ec6d0c06f6 100644 --- a/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.hpp +++ b/modules/mMWcarBSP/board_support_extended/ev_board_support_extendedImpl.hpp @@ -59,7 +59,7 @@ class ev_board_support_extendedImpl : public ev_board_support_extendedImplBase { // insert other definitions here // ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 -} // namespace board_support +} // namespace board_support_extended } // namespace module #endif // BOARD_SUPPORT_EV_BOARD_SUPPORT_EXTENDED_IMPL_HPP diff --git a/modules/mMWcarBSP/mMWcar_mcu_comms/evSerial.cpp b/modules/mMWcarBSP/mMWcar_mcu_comms/evSerial.cpp index 5cf55e71c8..3dbf6338a0 100644 --- a/modules/mMWcarBSP/mMWcar_mcu_comms/evSerial.cpp +++ b/modules/mMWcarBSP/mMWcar_mcu_comms/evSerial.cpp @@ -135,7 +135,6 @@ void evSerial::handle_packet(uint8_t* buf, int len) { McuToEverest msg_in; pb_istream_t istream = pb_istream_from_buffer(buf, len); - if (pb_decode(&istream, McuToEverest_fields, &msg_in)) { switch (msg_in.which_payload) { @@ -158,50 +157,49 @@ void evSerial::handle_packet(uint8_t* buf, int len) { case McuToEverest_response_calibration_tag: signal_calibration_response(msg_in.payload.response_calibration); break; -/* - case McuToEverest_cp_state_tag: - signal_cp_state(msg_in.connector, msg_in.payload.cp_state); - break; - - case McuToEverest_set_coil_state_response_tag: - signal_set_coil_state_response(msg_in.connector, msg_in.payload.set_coil_state_response); - break; - - case McuToEverest_error_flags_tag: - signal_error_flags(msg_in.connector, msg_in.payload.error_flags); - break; - - case McuToEverest_telemetry_tag: - signal_telemetry(msg_in.connector, msg_in.payload.telemetry); - break; - - case McuToEverest_reset_tag: - reset_done_flag = true; - if (!forced_reset) - signal_spurious_reset(msg_in.payload.reset); - break; - - case McuToEverest_pp_state_tag: - signal_pp_state(msg_in.connector, msg_in.payload.pp_state); - break; - - case McuToEverest_fan_state_tag: - signal_fan_state(msg_in.payload.fan_state); - break; - - case McuToEverest_lock_state_tag: - signal_lock_state(msg_in.connector, msg_in.payload.lock_state); - break; - - case McuToEverest_config_request_tag: - signal_config_request(); - break; -*/ + /* + case McuToEverest_cp_state_tag: + signal_cp_state(msg_in.connector, msg_in.payload.cp_state); + break; + + case McuToEverest_set_coil_state_response_tag: + signal_set_coil_state_response(msg_in.connector, msg_in.payload.set_coil_state_response); + break; + + case McuToEverest_error_flags_tag: + signal_error_flags(msg_in.connector, msg_in.payload.error_flags); + break; + + case McuToEverest_telemetry_tag: + signal_telemetry(msg_in.connector, msg_in.payload.telemetry); + break; + + case McuToEverest_reset_tag: + reset_done_flag = true; + if (!forced_reset) + signal_spurious_reset(msg_in.payload.reset); + break; + + case McuToEverest_pp_state_tag: + signal_pp_state(msg_in.connector, msg_in.payload.pp_state); + break; + + case McuToEverest_fan_state_tag: + signal_fan_state(msg_in.payload.fan_state); + break; + + case McuToEverest_lock_state_tag: + signal_lock_state(msg_in.connector, msg_in.payload.lock_state); + break; + + case McuToEverest_config_request_tag: + signal_config_request(); + break; + */ default: break; } } - } void evSerial::cobs_decode(uint8_t* buf, int len) { @@ -270,7 +268,7 @@ void evSerial::read_thread() { if (read_thread_handle.shouldExit()) break; n = read(fd, buf, sizeof buf); - //printf ("read %u bytes.\n", n); + // printf ("read %u bytes.\n", n); cobs_decode(buf, n); } } @@ -335,41 +333,36 @@ bool evSerial::serial_timed_out() { return false; } -bool evSerial::soft_reset() -{ +bool evSerial::soft_reset() { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_reset_tag; msg_out.payload.reset = true; - + return link_write(&msg_out); } -bool evSerial::get_ac_data_instant() -{ +bool evSerial::get_ac_data_instant() { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_request_measurement_tag; - msg_out.payload.request_measurement = MeasRequest_AC_INSTANT; + msg_out.payload.request_measurement = MeasRequest_AC_INSTANT; return link_write(&msg_out); } -bool evSerial::get_ac_statistic() -{ +bool evSerial::get_ac_statistic() { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_request_measurement_tag; - msg_out.payload.request_measurement = MeasRequest_AC_STATISTICS; + msg_out.payload.request_measurement = MeasRequest_AC_STATISTICS; return link_write(&msg_out); } -bool evSerial::get_calibration_values() -{ +bool evSerial::get_calibration_values() { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_get_calibration_tag; msg_out.payload.get_calibration = true; return link_write(&msg_out); } -bool evSerial::set_calibration_values(CalibrationValues& vals) -{ +bool evSerial::set_calibration_values(CalibrationValues& vals) { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_set_calibration_tag; @@ -378,8 +371,7 @@ bool evSerial::set_calibration_values(CalibrationValues& vals) return link_write(&msg_out); } -bool evSerial::request_ac_calibration(CalibrationRequest& req) -{ +bool evSerial::request_ac_calibration(CalibrationRequest& req) { EverestToMcu msg_out; msg_out.which_payload = EverestToMcu_request_calibration_tag; diff --git a/modules/mMWcarBSP/mMWcar_setup/main.cpp b/modules/mMWcarBSP/mMWcar_setup/main.cpp index 7497c5a079..fc65cd57ea 100644 --- a/modules/mMWcarBSP/mMWcar_setup/main.cpp +++ b/modules/mMWcarBSP/mMWcar_setup/main.cpp @@ -25,9 +25,9 @@ #include "ftxui/screen/color_info.hpp" // for ColorInfo #include "ftxui/screen/terminal.hpp" // for Size, Dimensions -#include -#include #include +#include +#include #include #include @@ -36,13 +36,14 @@ using namespace ftxui; std::mutex data_mutex; std::vector> calibration_table_content = {{"Data", "foo"}}; -std::string Ua_gain{"0"}, Ub_gain{"0"}, Uc_gain{"0"}, Ua_offset{"0"}, Ub_offset{"0"}, Uc_offset{"0"}, reference_voltage{"0.0"}; +std::string Ua_gain{"0"}, Ub_gain{"0"}, Uc_gain{"0"}, Ua_offset{"0"}, Ub_offset{"0"}, Uc_offset{"0"}, + reference_voltage{"0.0"}; std::vector phase_entries = {"Ua", "Ub", "Uc"}; std::vector ac_cal_types = {"Gain", "Offset"}; int phase_selected = 0; int ac_cal_type_selected = 0; -struct CalibrationData{ +struct CalibrationData { // HW-specific calibration values uint16_t atm90_ua_gain{0}; uint16_t atm90_ub_gain{0}; @@ -52,8 +53,7 @@ struct CalibrationData{ uint16_t atm90_uc_offset{0}; } cal_data; -void calibration_table_data(struct CalibrationData& data) -{ +void calibration_table_data(struct CalibrationData& data) { calibration_table_content = {{"Ua", "gain", fmt::format("{}", data.atm90_ua_gain)}}; calibration_table_content.push_back({"Ua", "offset", fmt::format("{}", data.atm90_ua_offset)}); calibration_table_content.push_back({"Ub", "gain", fmt::format("{}", data.atm90_ub_gain)}); @@ -62,8 +62,7 @@ void calibration_table_data(struct CalibrationData& data) calibration_table_content.push_back({"Uc", "offset", fmt::format("{}", data.atm90_uc_offset)}); } -void send_new_calibration_values(evSerial& p) -{ +void send_new_calibration_values(evSerial& p) { CalibrationValues data; data.atm90_ua_gain = std::stoi(Ua_gain); data.atm90_ub_gain = std::stoi(Ub_gain); @@ -74,12 +73,11 @@ void send_new_calibration_values(evSerial& p) p.set_calibration_values(data); } -void start_calibration(evSerial& p) -{ +void start_calibration(evSerial& p) { CalibrationRequest req; req.which_calibration_type = CalibrationRequest_ac_tag; req.calibration_type.ac.phase = static_cast(phase_selected); - if(ac_cal_type_selected == 0) { + if (ac_cal_type_selected == 0) { req.calibration_type.ac.which_type = AC_Calibration_gain_tag; // TODO: read reference voltage from input double _reference_voltage = 0; @@ -101,8 +99,7 @@ void help() { printf("Usage: ./mMWcar_setup /dev/ttyXXX\n\n"); } -void start_ui(evSerial& p) -{ +void start_ui(evSerial& p) { // build UI auto screen = ScreenInteractive::Fullscreen(); calibration_table_data(cal_data); @@ -132,8 +129,8 @@ void start_ui(evSerial& p) ACPhase phase = v.calibration_type.ac.phase; uint32_t value = v.value; - if(v.calibration_type.ac.which_type == AC_Calibration_gain_tag) { - switch(phase) { + if (v.calibration_type.ac.which_type == AC_Calibration_gain_tag) { + switch (phase) { case ACPhase::ACPhase_Ua: Ua_gain = fmt::format("{}", value); break; @@ -145,7 +142,7 @@ void start_ui(evSerial& p) break; } } else { - switch(phase) { + switch (phase) { case ACPhase::ACPhase_Ua: Ua_offset = fmt::format("{}", value); break; @@ -155,7 +152,7 @@ void start_ui(evSerial& p) case ACPhase::ACPhase_Uc: Uc_offset = fmt::format("{}", value); break; - } + } } screen.Post(Event::Custom); @@ -169,7 +166,7 @@ void start_ui(evSerial& p) Component get_calibration_button = Button( "Get calibration values in EEPROM", [&] { p.get_calibration_values(); }, ButtonOption::Animated(Color::Red, Color::White, Color::RedLight, Color::White)); - + auto cal_ctrl_component = Container::Horizontal({ Container::Vertical({ get_calibration_button, @@ -184,38 +181,32 @@ void start_ui(evSerial& p) }) | flex_grow, }) | flex_grow; - }); + }); /* Inputs for manual setting of gain/offset or calibration */ Component input_Ua_gain = Input(&Ua_gain, "0"); - input_Ua_gain |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Ua_gain |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_Ub_gain = Input(&Ub_gain, "0"); - input_Ub_gain |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Ub_gain |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_Uc_gain = Input(&Uc_gain, "0"); - input_Uc_gain |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Uc_gain |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_Ua_offset = Input(&Ua_offset, "0"); - input_Ua_offset |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Ua_offset |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_Ub_offset = Input(&Ub_offset, "0"); - input_Ub_offset |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Ub_offset |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_Uc_offset = Input(&Uc_offset, "0"); - input_Uc_offset |= CatchEvent([&](Event event) { - return event.is_character() && !std::isdigit(event.character()[0]); - }); + input_Uc_offset |= + CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); Component input_reference_voltage_offset = Input(&reference_voltage, "0.0"); @@ -248,27 +239,26 @@ void start_ui(evSerial& p) // Tweak how the component tree is rendered: auto calibration_input_renderer = Renderer(calibration_input_component, [&] { - return vbox({ - text("Values to commit to MCU"), - separator(), - hbox(text(" Ua gain : "), input_Ua_gain->Render()), - hbox(text(" Ua offset : "), input_Ua_offset->Render()), - hbox(text(" Ub gain : "), input_Ub_gain->Render()), - hbox(text(" Ub offset : "), input_Ub_offset->Render()), - hbox(text(" Uc gain : "), input_Uc_gain->Render()), - hbox(text(" Uc offset : "), input_Uc_offset->Render()), - separator(), - hbox({ - vbox(text("Phase"), dropdown_phase->Render()) | flex_grow, - vbox(text("AC cal. type"), dropdown_ac_type->Render()) | flex_grow, - } - ), - hbox(text(" Reference voltage : "), input_reference_voltage_offset->Render()), - do_calibration_button->Render(), - separator(), - set_calibration_button->Render(), - }) | - border; + return vbox({ + text("Values to commit to MCU"), + separator(), + hbox(text(" Ua gain : "), input_Ua_gain->Render()), + hbox(text(" Ua offset : "), input_Ua_offset->Render()), + hbox(text(" Ub gain : "), input_Ub_gain->Render()), + hbox(text(" Ub offset : "), input_Ub_offset->Render()), + hbox(text(" Uc gain : "), input_Uc_gain->Render()), + hbox(text(" Uc offset : "), input_Uc_offset->Render()), + separator(), + hbox({ + vbox(text("Phase"), dropdown_phase->Render()) | flex_grow, + vbox(text("AC cal. type"), dropdown_ac_type->Render()) | flex_grow, + }), + hbox(text(" Reference voltage : "), input_reference_voltage_offset->Render()), + do_calibration_button->Render(), + separator(), + set_calibration_button->Render(), + }) | + border; }); /* Display of MCU values*/ @@ -277,7 +267,7 @@ void start_ui(evSerial& p) std::scoped_lock lock(data_mutex); calibration_table_data(cal_data); } - + auto cal_table = Table(calibration_table_content); // add borders cal_table.SelectColumn(1).Border(LIGHT); @@ -285,17 +275,12 @@ void start_ui(evSerial& p) cal_table.SelectRow(i).Border(LIGHT); } - return window( - text("Calibration data MCU"), - hbox({cal_table.Render()}) | flex_grow ); + return window(text("Calibration data MCU"), hbox({cal_table.Render()}) | flex_grow); }); /* Main container*/ - auto main_container = Container::Horizontal({ - calibration_controls_renderer, - calibration_input_renderer, - calibration_display_renderer - }); + auto main_container = Container::Horizontal( + {calibration_controls_renderer, calibration_input_renderer, calibration_display_renderer}); auto main_renderer = Renderer(main_container, [&] { return vbox({ @@ -307,15 +292,13 @@ void start_ui(evSerial& p) screen.Loop(main_renderer); } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { if (argc != 2) { help(); exit(0); } const char* device = argv[1]; - evSerial p; if (!p.open_device(device, 115200)) { @@ -325,5 +308,4 @@ int main(int argc, char* argv[]) start_ui(p); } - } \ No newline at end of file diff --git a/modules/mMWcarBSP/simple_board_support/ev_board_supportImpl.cpp b/modules/mMWcarBSP/simple_board_support/ev_board_supportImpl.cpp index 131417b18c..d572f4b16e 100644 --- a/modules/mMWcarBSP/simple_board_support/ev_board_supportImpl.cpp +++ b/modules/mMWcarBSP/simple_board_support/ev_board_supportImpl.cpp @@ -18,16 +18,25 @@ void ev_board_supportImpl::handle_enable(bool& value) { void ev_board_supportImpl::handle_set_cp_state(types::ev_board_support::EvCpState& cp_state) { CpState state; - switch(cp_state) { - case types::ev_board_support::EvCpState::A : {state = CpState_STATE_A;} break; - case types::ev_board_support::EvCpState::B : {state = CpState_STATE_B;} break; - case types::ev_board_support::EvCpState::C : {state = CpState_STATE_C;} break; - case types::ev_board_support::EvCpState::D : {state = CpState_STATE_D;} break; - case types::ev_board_support::EvCpState::E : {state = CpState_STATE_E;} break; + switch (cp_state) { + case types::ev_board_support::EvCpState::A: { + state = CpState_STATE_A; + } break; + case types::ev_board_support::EvCpState::B: { + state = CpState_STATE_B; + } break; + case types::ev_board_support::EvCpState::C: { + state = CpState_STATE_C; + } break; + case types::ev_board_support::EvCpState::D: { + state = CpState_STATE_D; + } break; + case types::ev_board_support::EvCpState::E: { + state = CpState_STATE_E; + } break; } - - if(!mod->serial.set_cp_state(state)) + if (!mod->serial.set_cp_state(state)) EVLOG_error << "Could not send set_cp_state packet"; else EVLOG_info << "Sent set_cp_state packet";