diff --git a/src/UI/UI_item.cpp b/src/UI/UI_item.cpp index a733887..1d15401 100644 --- a/src/UI/UI_item.cpp +++ b/src/UI/UI_item.cpp @@ -168,3 +168,8 @@ void UI_item::can_send(uint32_t id, uint8_t dlc, std::array payload) UNUSED(dlc); UNUSED(payload); }; + +void UI_item::can_clear() +{ + +} diff --git a/src/UI/UI_item.hpp b/src/UI/UI_item.hpp index b9a479a..000f163 100644 --- a/src/UI/UI_item.hpp +++ b/src/UI/UI_item.hpp @@ -51,6 +51,7 @@ class UI_item : public QObject virtual void set_selected(std::string selected); virtual void set_value(double value); virtual void can_send(uint32_t id, uint8_t dlc, std::array payload); + virtual void can_clear(); signals: void value_changed(); diff --git a/src/UI/custom/UI_can.cpp b/src/UI/custom/UI_can.cpp index 65c4b69..bc7913a 100644 --- a/src/UI/custom/UI_can.cpp +++ b/src/UI/custom/UI_can.cpp @@ -24,13 +24,13 @@ UI_can::UI_can(const json &j, QObject *parent) : UI_item(UI_CAN_TYPE, parent) from_json(j); } -void UI_can::add_send_message(QCanBusFrame& msg) +void UI_can::add_send_message(QCanBusFrame msg) { m_can_send_messages.push_back(msg); emit value_changed(); } -void UI_can::add_received_message(QCanBusFrame& msg) +void UI_can::add_received_message(QCanBusFrame msg) { m_can_received_messages.push_back(msg); emit value_changed(); @@ -48,6 +48,12 @@ void UI_can::clear_receive_buffer() emit value_changed(); } +void UI_can::can_clear() +{ + clear_send_buffer(); + clear_receive_buffer(); +} + void UI_can::from_json(const json &j) { UI_item::from_json(j); diff --git a/src/UI/custom/UI_can.hpp b/src/UI/custom/UI_can.hpp index 94cbeca..3593c6b 100644 --- a/src/UI/custom/UI_can.hpp +++ b/src/UI/custom/UI_can.hpp @@ -12,8 +12,8 @@ class UI_can : public UI_item UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr); UI_can(const json &j, QObject *parent = nullptr); - void add_send_message(QCanBusFrame& msg); - void add_received_message(QCanBusFrame& msg); + void add_send_message(QCanBusFrame msg); + void add_received_message(QCanBusFrame msg); void clear_send_buffer(); void clear_receive_buffer(); @@ -21,6 +21,7 @@ class UI_can : public UI_item json to_json(size_t id) const override; void can_send(uint32_t id, uint8_t dlc, std::array payload) override; + void can_clear() override; signals: void on_send(QCanBusFrame msg); private: diff --git a/tools/CAN/CAN_interface.cpp b/tools/CAN/CAN_interface.cpp index 355bbe3..7cd6916 100644 --- a/tools/CAN/CAN_interface.cpp +++ b/tools/CAN/CAN_interface.cpp @@ -36,7 +36,7 @@ CAN_Interface::~CAN_Interface() delete m_canDevice; } -void CAN_Interface::send_frame(const QCanBusFrame &frame) +void CAN_Interface::send_frame(const QCanBusFrame frame) { m_canDevice->writeFrame(frame); emit frame_send(frame); diff --git a/tools/CAN/CAN_interface.hpp b/tools/CAN/CAN_interface.hpp index 427e232..df9dc98 100644 --- a/tools/CAN/CAN_interface.hpp +++ b/tools/CAN/CAN_interface.hpp @@ -11,10 +11,10 @@ class CAN_Interface : public QObject CAN_Interface(QString dev, QObject *parent = nullptr); ~CAN_Interface(); - void send_frame(const QCanBusFrame &frame); + void send_frame(const QCanBusFrame frame); signals: - void frame_received(const QCanBusFrame frame); - void frame_send(const QCanBusFrame frame); + void frame_received(QCanBusFrame frame); + void frame_send(QCanBusFrame frame); private: void processErrors(QCanBusDevice::CanBusError error) const; diff --git a/tools/message_parser.cpp b/tools/message_parser.cpp index 11adc58..c0fb3e8 100644 --- a/tools/message_parser.cpp +++ b/tools/message_parser.cpp @@ -60,7 +60,7 @@ json Simulators::command_parser(json command) } catch (const json::exception &e) { - spdlog::error(e.what()); + spdlog::error("{} {}", __FUNCTION__, e.what()); } return j; @@ -104,6 +104,18 @@ void Simulators::event_handler(json event) ->set_selected(std::string(event.at("selected"))); break; } + case Event::can_send: { + spdlog::debug("Event {}: {}", type, (size_t)event.at("id")); + invoke_active_simulator() + ->get_UI_item(event.at("id")) + ->can_send((uint32_t)event.at("sid"), (uint8_t)event.at("dlc"), (std::array)event.at("payload")); + break; + } + case Event::can_clear: { + spdlog::debug("Event {}: {}", type, (size_t)event.at("id")); + invoke_active_simulator()->get_UI_item(event.at("id"))->can_clear(); + break; + } default: { break; } @@ -111,6 +123,6 @@ void Simulators::event_handler(json event) } catch (const json::exception &e) { - spdlog::error(e.what()); + spdlog::error("{} {}", __FUNCTION__, e.what()); } } diff --git a/tools/simulators.cpp b/tools/simulators.cpp index 541a0a3..9b7fcd8 100644 --- a/tools/simulators.cpp +++ b/tools/simulators.cpp @@ -130,7 +130,7 @@ json Simulators::changed_UI_items() json after = this->m_simulators.at(m_current_simulator)->get_UI_items(); json changed; - changed["event"]["type"] = "UI_changed"; + changed["event"]["type"] = "ui_changed"; json diff = json::diff(m_before, after); diff --git a/tools/simulators.hpp b/tools/simulators.hpp index db28588..060716c 100644 --- a/tools/simulators.hpp +++ b/tools/simulators.hpp @@ -29,6 +29,8 @@ class Simulators : public QObject value_changed, text_changed, selected, + can_send, + can_clear, ui_changed, end, begin = 0 diff --git a/tools/simulators/can_debugger.cpp b/tools/simulators/can_debugger.cpp index cb80abf..66fac87 100644 --- a/tools/simulators/can_debugger.cpp +++ b/tools/simulators/can_debugger.cpp @@ -3,13 +3,10 @@ Can_Debugger::Can_Debugger(CAN_Wrapper* can_wrapper, QObject* parent) : Simulator_base("Can_Debugger", can_wrapper, std::chrono::milliseconds(100), parent), m_wrapper(can_wrapper), - m_can_ui(Color::Black, Color::White), - m_clear_can_list("Clear list", Color::Black, Color::White) + m_can_ui(Color::Black, Color::White) { this->add_UI_item(&this->m_can_ui); - this->add_UI_item(&this->m_clear_can_list); - connect(&m_clear_can_list, &UI_button::on_click, this, [=, this]{this->m_can_ui.clear_send_buffer(); this->m_can_ui.clear_receive_buffer();}); connect(&m_can_ui, &UI_can::on_send, this, [=, this](QCanBusFrame frame){m_wrapper->send_can_message(frame);}); } diff --git a/tools/simulators/can_debugger.hpp b/tools/simulators/can_debugger.hpp index c836c0c..1d1db4a 100644 --- a/tools/simulators/can_debugger.hpp +++ b/tools/simulators/can_debugger.hpp @@ -11,5 +11,4 @@ class Can_Debugger : public Simulator_base { private: CAN_Wrapper* m_wrapper; UI_can m_can_ui; - UI_button m_clear_can_list; };