Skip to content

Commit b6d54b4

Browse files
committed
Add connect/load/flash + setcap management
1 parent 002e616 commit b6d54b4

10 files changed

Lines changed: 695 additions & 25 deletions

File tree

tools/eeprom_editor/App.cc

Lines changed: 621 additions & 13 deletions
Large diffs are not rendered by default.

tools/eeprom_editor/App.h

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
#ifndef KICKCAT_EEPROM_EDITOR_APP_H
22
#define KICKCAT_EEPROM_EDITOR_APP_H
33

4+
#include <atomic>
5+
#include <memory>
6+
#include <mutex>
47
#include <string>
8+
#include <thread>
59
#include <vector>
610

711
#include "imgui.h"
812
#include "vendor/imgui_memory_editor.h"
913

14+
#include "kickcat/AbstractSocket.h"
1015
#include "kickcat/SIIParser.h"
1116

17+
namespace kickcat
18+
{
19+
class Bus;
20+
class Link;
21+
}
22+
1223
namespace kickcat::eeprom_editor
1324
{
1425
enum class Category
@@ -22,10 +33,13 @@ namespace kickcat::eeprom_editor
2233
RxPDO
2334
};
2435

36+
enum class SlaveAction { Load, Flash };
37+
2538
class App
2639
{
2740
public:
2841
App();
42+
~App();
2943

3044
void render();
3145

@@ -38,20 +52,61 @@ namespace kickcat::eeprom_editor
3852
void openFilePath(std::string const& path);
3953
void saveFilePath(std::string const& path);
4054

55+
// Device operations
56+
bool isConnected() const;
57+
bool isBusy() const;
58+
void connectToInterface(std::string const& name);
59+
void disconnect();
60+
void loadFromSlave(int slave_index);
61+
void flashToSlave(int slave_index);
62+
void joinWorker();
63+
void finalizeWorker();
64+
65+
// Rendering
4166
void renderMenuBar();
4267
void renderSidebar();
4368
void renderContentPanel();
4469
void renderHexPanel();
4570
void renderStatusBar();
71+
void renderConnectDialog();
72+
void renderSlaveDialog();
73+
bool renderSlaveTable(); // returns true on double-click
74+
void renderPrivilegeDialog();
4675

76+
// EEPROM state
4777
eeprom::SII sii_{};
4878
std::vector<uint8_t> serialized_;
49-
5079
std::string file_path_;
5180
bool modified_{false};
52-
5381
Category active_category_{Category::Info};
5482
MemoryEditor mem_edit_;
83+
84+
// EtherCAT connection
85+
std::shared_ptr<Link> link_;
86+
std::unique_ptr<Bus> bus_;
87+
std::string connected_interface_;
88+
89+
// Dialog state
90+
bool show_connect_dialog_{false};
91+
bool show_slave_dialog_{false};
92+
SlaveAction slave_action_{SlaveAction::Load};
93+
int selected_slave_index_{-1};
94+
std::string device_error_;
95+
std::vector<NetworkInterface> cached_interfaces_;
96+
97+
// Privilege escalation
98+
bool show_privilege_dialog_{false};
99+
bool privilege_granted_{false};
100+
std::string privilege_error_;
101+
std::atomic<bool> needs_privilege_escalation_{false};
102+
103+
// Background worker state
104+
std::thread worker_;
105+
std::atomic<float> worker_progress_{0.0f};
106+
std::atomic<bool> worker_done_{false};
107+
std::mutex worker_status_mutex_;
108+
std::string worker_status_;
109+
std::string worker_error_;
55110
};
56111
}
57112

tools/eeprom_editor/EditorUtils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace kickcat::eeprom_editor
2222

2323
if (out_of_range)
2424
{
25-
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.88f, 0.33f, 0.33f, 1.0f));
25+
ImGui::PushStyleColor(ImGuiCol_Border, COLOR_RED);
2626
}
2727

2828
ImGui::SetNextItemWidth(60.0f);

tools/eeprom_editor/Editors.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
namespace kickcat::eeprom_editor
1313
{
14+
constexpr ImVec4 COLOR_RED {0.88f, 0.33f, 0.33f, 1.0f};
15+
constexpr ImVec4 COLOR_GREEN {0.31f, 0.79f, 0.41f, 1.0f};
16+
constexpr ImVec4 COLOR_YELLOW {0.88f, 0.75f, 0.31f, 1.0f};
17+
constexpr ImVec4 COLOR_BLUE {0.55f, 0.75f, 0.95f, 1.0f};
18+
constexpr ImVec4 COLOR_GREY {0.65f, 0.65f, 0.65f, 1.0f};
19+
constexpr ImVec4 COLOR_DIM {0.55f, 0.55f, 0.55f, 1.0f};
20+
constexpr ImVec4 COLOR_TITLE {0.42f, 0.55f, 0.84f, 1.0f};
21+
1422
char const* resolveString(std::vector<std::string> const& strings, uint8_t index);
1523
bool stringIndexInput(char const* label, uint8_t* index,
1624
std::vector<std::string> const& strings);

tools/eeprom_editor/FMMUEditor.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <array>
2-
#include <imgui.h>
32

43
#include "Editors.h"
54

@@ -18,7 +17,7 @@ namespace kickcat::eeprom_editor::fmmu
1817
bool changed = false;
1918
auto& fmmus = sii.fmmus;
2019

21-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "FMMU -- Category 40");
20+
ImGui::TextColored(COLOR_TITLE, "FMMU -- Category 40");
2221
ImGui::Separator();
2322

2423
constexpr ImGuiTableFlags table_flags =

tools/eeprom_editor/GeneralEditor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace kickcat::eeprom_editor::general
1717
bool changed = false;
1818
auto& g = sii.general;
1919

20-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "General -- Category 30");
20+
ImGui::TextColored(COLOR_TITLE, "General -- Category 30");
2121
ImGui::Separator();
2222

2323
if (ImGui::CollapsingHeader("String References", ImGuiTreeNodeFlags_DefaultOpen))

tools/eeprom_editor/InfoEditor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace kickcat::eeprom_editor::info
77
bool changed = false;
88
auto& info = sii.info;
99

10-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "Info (Header) -- Words 0x00-0x3F");
10+
ImGui::TextColored(COLOR_TITLE, "Info (Header) -- Words 0x00-0x3F");
1111
ImGui::Separator();
1212
ImGui::Spacing();
1313

tools/eeprom_editor/PDOEditor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ namespace kickcat::eeprom_editor::pdo
1010

1111
bool const is_tx = (direction == Direction::Tx);
1212

13+
char const* title = "RxPDO (Outputs) -- Category 51";
1314
auto* mappings_ptr = &sii.RxPDO;
14-
char const* title = "RxPDO (Outputs) -- Category 51";
1515
if (is_tx)
1616
{
17-
mappings_ptr = &sii.TxPDO;
1817
title = "TxPDO (Inputs) -- Category 50";
18+
mappings_ptr = &sii.TxPDO;
1919
}
2020
auto& mappings = *mappings_ptr;
2121
auto& strings = sii.strings;
2222

23-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "%s", title);
23+
ImGui::TextColored(COLOR_TITLE, "%s", title);
2424
ImGui::Separator();
2525

2626
int delete_mapping = -1;

tools/eeprom_editor/StringsEditor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace kickcat::eeprom_editor::strings
99
bool changed = false;
1010
auto& strings = sii.strings;
1111

12-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "Strings -- Category 10");
12+
ImGui::TextColored(COLOR_TITLE, "Strings -- Category 10");
1313
ImGui::Separator();
1414

1515
if (strings.empty())

tools/eeprom_editor/SyncManagerEditor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace kickcat::eeprom_editor::syncm
1818
bool changed = false;
1919
auto& sms = sii.syncManagers;
2020

21-
ImGui::TextColored(ImVec4(0.42f, 0.55f, 0.84f, 1.0f), "Sync Managers -- Category 41");
21+
ImGui::TextColored(COLOR_TITLE, "Sync Managers -- Category 41");
2222
ImGui::Separator();
2323

2424
constexpr ImGuiTableFlags table_flags =

0 commit comments

Comments
 (0)