mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
did some testing with custom hardware
This commit is contained in:
@@ -168,3 +168,8 @@ void UI_item::can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload)
|
|||||||
UNUSED(dlc);
|
UNUSED(dlc);
|
||||||
UNUSED(payload);
|
UNUSED(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void UI_item::can_clear()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class UI_item : public QObject
|
|||||||
virtual void set_selected(std::string selected);
|
virtual void set_selected(std::string selected);
|
||||||
virtual void set_value(double value);
|
virtual void set_value(double value);
|
||||||
virtual void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload);
|
virtual void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload);
|
||||||
|
virtual void can_clear();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void value_changed();
|
void value_changed();
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ UI_can::UI_can(const json &j, QObject *parent) : UI_item(UI_CAN_TYPE, parent)
|
|||||||
from_json(j);
|
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);
|
m_can_send_messages.push_back(msg);
|
||||||
emit value_changed();
|
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);
|
m_can_received_messages.push_back(msg);
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
@@ -48,6 +48,12 @@ void UI_can::clear_receive_buffer()
|
|||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UI_can::can_clear()
|
||||||
|
{
|
||||||
|
clear_send_buffer();
|
||||||
|
clear_receive_buffer();
|
||||||
|
}
|
||||||
|
|
||||||
void UI_can::from_json(const json &j)
|
void UI_can::from_json(const json &j)
|
||||||
{
|
{
|
||||||
UI_item::from_json(j);
|
UI_item::from_json(j);
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class UI_can : public UI_item
|
|||||||
UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr);
|
UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
UI_can(const json &j, QObject *parent = nullptr);
|
UI_can(const json &j, QObject *parent = nullptr);
|
||||||
|
|
||||||
void add_send_message(QCanBusFrame& msg);
|
void add_send_message(QCanBusFrame msg);
|
||||||
void add_received_message(QCanBusFrame& msg);
|
void add_received_message(QCanBusFrame msg);
|
||||||
void clear_send_buffer();
|
void clear_send_buffer();
|
||||||
void clear_receive_buffer();
|
void clear_receive_buffer();
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ class UI_can : public UI_item
|
|||||||
json to_json(size_t id) const override;
|
json to_json(size_t id) const override;
|
||||||
|
|
||||||
void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload) override;
|
void can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload) override;
|
||||||
|
void can_clear() override;
|
||||||
signals:
|
signals:
|
||||||
void on_send(QCanBusFrame msg);
|
void on_send(QCanBusFrame msg);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ CAN_Interface::~CAN_Interface()
|
|||||||
delete m_canDevice;
|
delete m_canDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAN_Interface::send_frame(const QCanBusFrame &frame)
|
void CAN_Interface::send_frame(const QCanBusFrame frame)
|
||||||
{
|
{
|
||||||
m_canDevice->writeFrame(frame);
|
m_canDevice->writeFrame(frame);
|
||||||
emit frame_send(frame);
|
emit frame_send(frame);
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ class CAN_Interface : public QObject
|
|||||||
CAN_Interface(QString dev, QObject *parent = nullptr);
|
CAN_Interface(QString dev, QObject *parent = nullptr);
|
||||||
~CAN_Interface();
|
~CAN_Interface();
|
||||||
|
|
||||||
void send_frame(const QCanBusFrame &frame);
|
void send_frame(const QCanBusFrame frame);
|
||||||
signals:
|
signals:
|
||||||
void frame_received(const QCanBusFrame frame);
|
void frame_received(QCanBusFrame frame);
|
||||||
void frame_send(const QCanBusFrame frame);
|
void frame_send(QCanBusFrame frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processErrors(QCanBusDevice::CanBusError error) const;
|
void processErrors(QCanBusDevice::CanBusError error) const;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ json Simulators::command_parser(json command)
|
|||||||
}
|
}
|
||||||
catch (const json::exception &e)
|
catch (const json::exception &e)
|
||||||
{
|
{
|
||||||
spdlog::error(e.what());
|
spdlog::error("{} {}", __FUNCTION__, e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return j;
|
return j;
|
||||||
@@ -104,6 +104,18 @@ void Simulators::event_handler(json event)
|
|||||||
->set_selected(std::string(event.at("selected")));
|
->set_selected(std::string(event.at("selected")));
|
||||||
break;
|
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<uint8_t, 8>)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: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -111,6 +123,6 @@ void Simulators::event_handler(json event)
|
|||||||
}
|
}
|
||||||
catch (const json::exception &e)
|
catch (const json::exception &e)
|
||||||
{
|
{
|
||||||
spdlog::error(e.what());
|
spdlog::error("{} {}", __FUNCTION__, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ json Simulators::changed_UI_items()
|
|||||||
|
|
||||||
json after = this->m_simulators.at(m_current_simulator)->get_UI_items();
|
json after = this->m_simulators.at(m_current_simulator)->get_UI_items();
|
||||||
json changed;
|
json changed;
|
||||||
changed["event"]["type"] = "UI_changed";
|
changed["event"]["type"] = "ui_changed";
|
||||||
|
|
||||||
json diff = json::diff(m_before, after);
|
json diff = json::diff(m_before, after);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ class Simulators : public QObject
|
|||||||
value_changed,
|
value_changed,
|
||||||
text_changed,
|
text_changed,
|
||||||
selected,
|
selected,
|
||||||
|
can_send,
|
||||||
|
can_clear,
|
||||||
ui_changed,
|
ui_changed,
|
||||||
end,
|
end,
|
||||||
begin = 0
|
begin = 0
|
||||||
|
|||||||
@@ -3,13 +3,10 @@
|
|||||||
Can_Debugger::Can_Debugger(CAN_Wrapper* can_wrapper, QObject* parent) :
|
Can_Debugger::Can_Debugger(CAN_Wrapper* can_wrapper, QObject* parent) :
|
||||||
Simulator_base("Can_Debugger", can_wrapper, std::chrono::milliseconds(100), parent),
|
Simulator_base("Can_Debugger", can_wrapper, std::chrono::milliseconds(100), parent),
|
||||||
m_wrapper(can_wrapper),
|
m_wrapper(can_wrapper),
|
||||||
m_can_ui(Color::Black, Color::White),
|
m_can_ui(Color::Black, Color::White)
|
||||||
m_clear_can_list("Clear list", Color::Black, Color::White)
|
|
||||||
{
|
{
|
||||||
this->add_UI_item(&this->m_can_ui);
|
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);});
|
connect(&m_can_ui, &UI_can::on_send, this, [=, this](QCanBusFrame frame){m_wrapper->send_can_message(frame);});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,5 +11,4 @@ class Can_Debugger : public Simulator_base {
|
|||||||
private:
|
private:
|
||||||
CAN_Wrapper* m_wrapper;
|
CAN_Wrapper* m_wrapper;
|
||||||
UI_can m_can_ui;
|
UI_can m_can_ui;
|
||||||
UI_button m_clear_can_list;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user