From 31402f584aba67fffcff186aa5de6f1e136b1eec Mon Sep 17 00:00:00 2001 From: Peter Akers Date: Tue, 12 Mar 2024 11:29:58 +1000 Subject: [PATCH] Add support for broadcast messages and alerts --- library.properties | 2 +- src/WiThrottleProtocol.cpp | 26 ++++++++++++++++++++++++++ src/WiThrottleProtocol.h | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index cb53da9..6b1421b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiThrottleProtocol -version=1.1.11 +version=1.1.12 author=David Zuhn , Luca Dentella , Peter Akers maintainer=Peter Akers sentence=JMRI WiThrottle Protocol implementation diff --git a/src/WiThrottleProtocol.cpp b/src/WiThrottleProtocol.cpp index 2e4ab33..a9006ac 100644 --- a/src/WiThrottleProtocol.cpp +++ b/src/WiThrottleProtocol.cpp @@ -435,6 +435,14 @@ bool WiThrottleProtocol::processCommand(char *c, int len) { processServerDescription(c+2, len-2); return true; } + else if (len > 2 && c[0]=='H' && c[1]=='M') { + processAlert(c+2, len-2); + return true; + } + else if (len > 2 && c[0]=='H' && c[1]=='m') { + processMessage(c+2, len-2); + return true; + } else if (len > 2 && c[0]=='P' && c[1]=='W') { processWebPort(c+2, len-2); return true; @@ -567,6 +575,24 @@ void WiThrottleProtocol::processServerDescription(char *c, int len) { } } +void WiThrottleProtocol::processMessage(char *c, int len) { + console->println("processMessage()"); + + if (delegate && len > 0) { + String message = String(c); + delegate->receivedMessage(message); + } +} + +void WiThrottleProtocol::processAlert(char *c, int len) { + console->println("processAlert()"); + + if (delegate && len > 0) { + String alert = String(c); + delegate->receivedAlert(alert); + } +} + void WiThrottleProtocol::processWebPort(char *c, int len) { if (delegate && len > 0) { String port_string = String(c); diff --git a/src/WiThrottleProtocol.h b/src/WiThrottleProtocol.h index 7cdb6c0..0dd8f6b 100644 --- a/src/WiThrottleProtocol.h +++ b/src/WiThrottleProtocol.h @@ -29,6 +29,7 @@ /* Version information: +1.1.12 - Add support for broadcast messages and alerts 1.1.11 - Change to the fix for the _wifiTrax WFD-30, so that leading CR+LF is always sent - Removal of setSpeedCommandShouldBeSenttwice(bool twice) 1.1.10 - discarded @@ -112,6 +113,8 @@ class WiThrottleProtocolDelegate virtual void receivedVersion(String version) {} virtual void receivedServerType(String type) {} virtual void receivedServerDescription(String description) {} + virtual void receivedMessage(String message) {} + virtual void receivedAlert(String alert) {} virtual void receivedRosterEntries(int rosterSize) {} virtual void receivedRosterEntry(int index, String name, int address, char length) {} @@ -262,6 +265,8 @@ class WiThrottleProtocol void processProtocolVersion(char *c, int len); void processServerType(char *c, int len); void processServerDescription(char *c, int len); + void processMessage(char *c, int len); + void processAlert(char *c, int len); void processWebPort(char *c, int len); void processRosterList(char *c, int len); void processTurnoutList(char *c, int len);