Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#include <helpers/nrf52/EthernetCLI.h>
#endif

// On Linux, Serial is output-only, so the interactive CLI reads from a control
// socket / stdin console instead. Other platforms keep using hardware Serial.
#ifdef ARDULINUX_PLATFORM
#include <LinuxConsole.h>
#define MC_CLI Console
#else
#define MC_CLI Serial
#endif

StdRNG fast_rng;
SimpleMeshTables tables;

Expand Down Expand Up @@ -59,6 +68,10 @@ void setup() {
Serial.begin(115200);
delay(1000);

#ifdef ARDULINUX_PLATFORM
Console.begin(); // open the control socket / prepare stdin for the CLI
#endif

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
Expand Down Expand Up @@ -151,12 +164,12 @@ void setup() {
void loop() {
// Handle Serial CLI
int len = strlen(command);
while (Serial.available() && len < sizeof(command)-1) {
char c = Serial.read();
while (MC_CLI.available() && len < sizeof(command)-1) {
char c = MC_CLI.read();
if (c != '\n') {
command[len++] = c;
command[len] = 0;
Serial.print(c);
MC_CLI.print(c);
}
if (c == '\r') break;
}
Expand All @@ -165,7 +178,7 @@ void loop() {
}

if (len > 0 && command[len - 1] == '\r') { // received complete line
Serial.print('\n');
MC_CLI.print('\n');
command[len - 1] = 0; // replace newline with C string null terminator
char reply[160];
reply[0] = 0;
Expand All @@ -177,7 +190,7 @@ void loop() {
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
#endif
if (reply[0]) {
Serial.print(" -> "); Serial.println(reply);
MC_CLI.print(" -> "); MC_CLI.println(reply);
}

command[0] = 0; // reset command buffer
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ build_src_filter =
+<../src/Packet.cpp>
+<../src/helpers/ConfigSerializer.cpp>
+<../src/helpers/DynamicConfigSerializer.cpp>
+<../variants/linux/LinuxConsole.cpp>
+<../variants/linux/LinuxEventLoop.cpp>
+<../variants/linux/LinuxRadioWait.cpp>
lib_deps =
Expand Down
Loading
Loading