Skip to content

Commit 330695e

Browse files
committed
Split messages in proxy supervisor
Not really ideal, still doesn't collect messages in chunks like the debugger, but it's a bit better at least.
1 parent f157d08 commit 330695e

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/Oop/proxy_supervisor.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,32 @@ void ProxySupervisor::listenToSocket() {
8484
exit(-1);
8585
}
8686
if (readAmount > 0) {
87-
try {
88-
nlohmann::basic_json<> parsed = nlohmann::json::parse(message);
89-
printf("parseJSON: %s\n", parsed.dump().c_str());
90-
91-
if (isEvent(parsed)) {
92-
CallbackHandler::push_event(new Event(
93-
*parsed.find("topic"), *parsed.find("payload")));
94-
WARDuino::instance()->debugger->notifyPushedEvent();
87+
std::string msg_str = std::string(reinterpret_cast<char *>(message));
88+
printf("msg_str = \"%s\"\n", (char*) message);
89+
while (!msg_str.empty()) {
90+
auto first_msg = msg_str.substr(0, msg_str.find('\n'));
91+
msg_str = msg_str.substr(msg_str.find('\n') + 1);
92+
printf("first_msg = \"%s\"\n", first_msg.c_str());
93+
94+
try {
95+
nlohmann::basic_json<> parsed = nlohmann::json::parse(first_msg);
96+
printf("parseJSON: %s\n", parsed.dump().c_str());
97+
98+
if (isEvent(parsed)) {
99+
CallbackHandler::push_event(new Event(
100+
*parsed.find("topic"), *parsed.find("payload")));
101+
WARDuino::instance()->debugger->notifyPushedEvent();
102+
}
103+
104+
if (isReply(parsed)) {
105+
this->hasReplied = true;
106+
this->proxyResult = parsed;
107+
}
108+
} catch (const nlohmann::detail::parse_error &e) {
109+
//printf("Non RFC call: %s\n", first_msg.c_str());
110+
//printf("error: %s\n", e.what());
111+
WARDuino::instance()->handleInterrupt(readAmount, (uint8_t*) first_msg.c_str());
95112
}
96-
97-
if (isReply(parsed)) {
98-
this->hasReplied = true;
99-
this->proxyResult = parsed;
100-
}
101-
} catch (const nlohmann::detail::parse_error &e) {
102-
printf("Non RFC call: %s", message);
103-
printf("error: %s", e.what());
104-
WARDuino::instance()->handleInterrupt(readAmount, message);
105113
}
106114
}
107115
}

0 commit comments

Comments
 (0)