Skip to content

Commit f2b938f

Browse files
committed
Add dronify instruction
1 parent a59000d commit f2b938f

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/Debug/debugger.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111

1212
#include "../Memory/mem.h"
13+
#include "../RFC/SocketServer.h"
1314
#include "../RFC/proxy_server.h"
1415
#include "../RFC/rfc.h"
1516
#include "../Utils//util.h"
@@ -232,9 +233,23 @@ bool Debugger::checkDebugMessages(Module *m, RunningState *program_state) {
232233
free(interruptData);
233234
} break;
234235
#endif
236+
#ifdef ARDUINO
235237
case interruptDronify:
236-
// TODO Dronify
238+
// 0x65 the wifi ssid \0 wifipass \0
239+
// 1 |____len_____| 1
240+
char *ssid = (char *)(interruptData + 1);
241+
size_t ssid_len = strlen(ssid);
242+
char *pass = (char *)(interruptData + 1 + ssid_len + 1);
243+
ServerCredentials serverCredentials = {ssid, pass};
244+
SocketServer::createServer(
245+
8080, 8081, [m](size_t len, uint8_t *buff) {
246+
m->warduino->handleInterrupt(len, buff);
247+
});
248+
auto server = SocketServer::getServer();
249+
server->connect2Wifi(&serverCredentials);
250+
*program_state = WARDUINOdrone;
237251
break;
252+
#endif
238253
case interruptDUMPAllEvents:
239254
printf("InterruptDUMPEvents\n");
240255
size = (long)CallbackHandler::event_count();

src/Debug/debugger.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ enum RunningState {
1717
WARDUINOrun,
1818
WARDUINOpause,
1919
WARDUINOstep,
20-
WARDuinoProxyRun
20+
WARDuinoProxyRun, // Running state used when executing a proxy call. During
21+
// this state the call is set up and executed by the main
22+
// loop. After execution, the state is restored to
23+
// WARDUINODrone
24+
WARDUINODrone // Do not run the program (program runs on computer, which
25+
// sends messages for primitives, do forward interupts)
2126
};
2227

2328
enum InterruptTypes {
@@ -40,7 +45,7 @@ enum InterruptTypes {
4045
interruptRecvState = 0x62,
4146
interruptMonitorProxies = 0x63,
4247
interruptProxyCall = 0x64,
43-
interruptDronify = 0x65,
48+
interruptDronify = 0x65, // wifi SSID \0 wifi PASS \0
4449

4550
// Push Debugging
4651
interruptDUMPAllEvents = 0x70,

src/Interpreter/instructions.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,10 +1536,13 @@ bool interpret(Module *m) {
15361536
// check if call completes
15371537
if (callee->callCompleted(m)) {
15381538
callee->returnResult(m);
1539+
1540+
// TODO: this is likley no longer needed
15391541
callee->restoreExecutionState(m,
15401542
&m->warduino->program_state);
15411543
RFC::removeRFCallee();
15421544
callee = nullptr;
1545+
m->warduino->program_state = WARDUINODrone;
15431546
}
15441547
}
15451548
}
@@ -1549,7 +1552,9 @@ bool interpret(Module *m) {
15491552
// no event currently resolving
15501553
CallbackHandler::resolve_event();
15511554

1552-
if (m->warduino->program_state == WARDUINOpause) {
1555+
// Skip the main loop if paused or drone
1556+
if (m->warduino->program_state == WARDUINOpause ||
1557+
m->warduino->program_state == WARDUINODrone) {
15531558
continue;
15541559
}
15551560

0 commit comments

Comments
 (0)