Skip to content

Commit bced0f5

Browse files
author
Carlos Rojas
committed
Merge branch 'feat/wood' of github.com:TOPLLab/WARDuino into feat/wood
2 parents fd4c18e + d97ee71 commit bced0f5

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

.github/workflows/compile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
fill-out-template:
4747
name: Fill out template files
4848
runs-on: ubuntu-latest
49+
if: github.event.pull_request.draft == false
4950
steps:
5051
- name: Checkout
5152
uses: actions/checkout@v2

documentation/OutOfPlaceDebugging.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ The supported interrupt messages:
3232
3. `interruptPOPEvent (0x72)` tells the VM to remove the event at the front of the queue and process it.
3333
4. `interruptPUSHEvent (0x73)` this messages' code is followed by a json representation of an event to be pushed on the
3434
stack.
35+
5. `interruptDUMPCallbackmapping (0x74)` requests a dump of the current callback mapping as json.
36+
6. `interruptRecvCallbackmapping (0x75)` sends a callback mapping as json to replace the current callback mapping.
37+

src/Debug/debugger.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ Debugger::Debugger(int socket) { this->socket = socket; }
2121

2222
void Debugger::addDebugMessage(size_t len, const uint8_t *buff) {
2323
uint8_t *data = this->parseDebugBuffer(len, buff);
24-
if (data != nullptr) {
24+
if (data != nullptr && *data == interruptRecvCallbackmapping) {
25+
std::string text = (char *)buff;
26+
auto *msg =
27+
(uint8_t *)acalloc(sizeof(uint8_t), len, "interrupt buffer");
28+
memcpy(msg, buff, len * sizeof(uint8_t));
29+
*msg = *data;
30+
this->debugMessages.push_back(msg);
31+
} else if (data != nullptr) {
2532
this->debugMessages.push_back(data);
2633
}
2734
}
@@ -235,13 +242,20 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
235242
dprintf(this->socket, "}\n");
236243
break;
237244
case interruptPOPEvent:
238-
CallbackHandler::resolve_event();
245+
CallbackHandler::resolve_event(true);
239246
break;
240247
#ifndef ARDUINO
241248
case interruptPUSHEvent:
242249
this->handlePushedEvent(m, reinterpret_cast<char *>(interruptData));
243250
break;
251+
case interruptRecvCallbackmapping:
252+
this->updateCallbackmapping(
253+
m, reinterpret_cast<const char *>(interruptData + 2));
254+
break;
244255
#endif
256+
case interruptDUMPCallbackmapping:
257+
this->dumpCallbackmapping();
258+
break;
245259
default:
246260
// handle later
247261
dprintf(this->socket, "COULD not parse interrupt data!\n");
@@ -458,6 +472,10 @@ void Debugger::dumpEvents(long start, long size) const {
458472
CallbackHandler::resolving_event = false;
459473
}
460474

475+
void Debugger::dumpCallbackmapping() const {
476+
dprintf(this->socket, "%s\n", CallbackHandler::dump_callbacks().c_str());
477+
}
478+
461479
/**
462480
* Read the change in bytes array.
463481
*
@@ -979,4 +997,17 @@ void Debugger::disconnect_drone() {
979997
pthread_mutex_unlock(&this->push_mutex);
980998
pthread_join(this->push_debugging_threadid, (void **)&ptr);
981999
}
1000+
1001+
void Debugger::updateCallbackmapping(Module *m, const char *data) const {
1002+
nlohmann::basic_json<> parsed = nlohmann::json::parse(data);
1003+
CallbackHandler::clear_callbacks();
1004+
nlohmann::basic_json<> callbacks = *parsed.find("callbacks");
1005+
for (auto &array : callbacks.items()) {
1006+
auto callback = array.value().begin();
1007+
for (auto &functions : callback.value().items()) {
1008+
CallbackHandler::add_callback(
1009+
Callback(m, callback.key(), functions.value()));
1010+
}
1011+
}
1012+
}
9821013
#endif

src/Debug/debugger.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ enum InterruptTypes {
4242
interruptDUMPAllEvents = 0x70,
4343
interruptDUMPEvents = 0x71,
4444
interruptPOPEvent = 0x72,
45-
interruptPUSHEvent = 0x73
45+
interruptPUSHEvent = 0x73,
46+
interruptDUMPCallbackmapping = 0x74,
47+
interruptRecvCallbackmapping = 0x75
4648
};
4749

4850
class Debugger {
@@ -92,6 +94,8 @@ class Debugger {
9294

9395
void dumpEvents(long start, long size) const;
9496

97+
void dumpCallbackmapping() const;
98+
9599
//// Handle live code update
96100

97101
static bool handleChangedFunction(Module *m, uint8_t *bytes);
@@ -108,6 +112,9 @@ class Debugger {
108112

109113
static uintptr_t readPointer(uint8_t **data);
110114

115+
#ifndef ARDUINO
116+
void updateCallbackmapping(Module *m, const char *interruptData) const;
117+
#endif
111118
public:
112119
// Public fields
113120

src/WARDuino/CallbackHandler.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void CallbackHandler::push_event(Event *event) {
7171
}
7272
}
7373

74-
bool CallbackHandler::resolve_event() {
74+
bool CallbackHandler::resolve_event(bool force) {
7575
if (CallbackHandler::resolving_event || CallbackHandler::events->empty()) {
7676
return false;
7777
}
@@ -87,8 +87,8 @@ bool CallbackHandler::resolve_event() {
8787
}
8888
#endif
8989

90-
if (CallbackHandler::manual_event_resolution ||
91-
WARDuino::instance()->program_state == WARDUINOpause) {
90+
if (!force && (CallbackHandler::manual_event_resolution ||
91+
WARDuino::instance()->program_state == WARDUINOpause)) {
9292
return true;
9393
}
9494

@@ -126,6 +126,28 @@ std::deque<Event>::const_iterator CallbackHandler::event_end() {
126126
return CallbackHandler::events->cend();
127127
}
128128

129+
void CallbackHandler::clear_callbacks() { CallbackHandler::callbacks->clear(); }
130+
131+
std::string CallbackHandler::dump_callbacks() {
132+
std::string repr = R"({"callbacks": [)";
133+
auto iterator = CallbackHandler::callbacks->begin();
134+
while (iterator != CallbackHandler::callbacks->end()) {
135+
repr += R"({")" + iterator->first + R"(": [)";
136+
for (const auto &value : *iterator->second) {
137+
auto callback = std::begin(*iterator->second);
138+
while (callback != std::end(*iterator->second)) {
139+
repr += std::to_string(callback->table_index);
140+
repr += (++callback != iterator->second->end()) ? ", " : "";
141+
}
142+
}
143+
iterator++;
144+
repr += "]}";
145+
repr += (iterator != CallbackHandler::callbacks->end()) ? ", " : "";
146+
}
147+
repr += "]}";
148+
return repr;
149+
}
150+
129151
// Callback class
130152

131153
Callback::Callback(Module *m, std::string id, uint32_t tidx) {

src/WARDuino/CallbackHandler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ class CallbackHandler {
3939

4040
static void add_callback(const Callback &c);
4141
static void remove_callback(const Callback &c);
42+
static void clear_callbacks();
43+
static std::string dump_callbacks();
4244
static size_t callback_count(const std::string &topic);
4345
static void push_event(std::string topic, const unsigned char *payload,
4446
unsigned int length);
4547
static void push_event(Event *event);
46-
static bool resolve_event();
48+
static bool resolve_event(bool force = false);
4749

4850
// WOOD needed to know when to push events
4951
static bool manual_event_resolution;

0 commit comments

Comments
 (0)