Skip to content

Commit

Permalink
Add support for broadcast messages and alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
flash62au committed Mar 12, 2024
1 parent 69d7e48 commit 31402f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WiThrottleProtocol
version=1.1.11
version=1.1.12
author=David Zuhn <[email protected]>, Luca Dentella <[email protected]>, Peter Akers <[email protected]>
maintainer=Peter Akers <[email protected]>
sentence=JMRI WiThrottle Protocol implementation
Expand Down
26 changes: 26 additions & 0 deletions src/WiThrottleProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/WiThrottleProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 31402f5

Please sign in to comment.