Library

class NullStream : public Stream

TBA.

Public Functions

inline NullStream()

TBA.

inline int available()

TBA.

inline void flush()

TBA.

inline int peek()

TBA.

inline int read()

TBA.

inline size_t write(uint8_t c)

TBA.

Parameters:

c – TBA

inline size_t write(const uint8_t *buffer, size_t size)

TBA.

Parameters:
  • buffer – TBA

  • size – TBA

class WiThrottleProtocol

This library implements the WiThrottle protocol.

WiThrottleProtocol

(as used in JMRI and other servers), allowing an device to connect to the server and act as a client (such as a dedicated fast clock device or a hardware based throttle).

Public Functions

WiThrottleProtocol(bool server = false)

Initialise the WiThrottle Protocol.

void setDelegate(WiThrottleProtocolDelegate *delegate)

Set the Delegate.

Parameters:

delegate – pointer to the delegate

void setLogStream(Stream *console)

Set the log stream.

Parameters:

console – pointer to the serial console

void setLogLevel(int level)

Set the console log level.

Parameters:

level – Log Level (0 = off 1 = basic 2 = high)

void setCommandsNeedLeadingCrLf(bool needed)

Configure the server so that outgoing commands are always preceeded with an extra CrLf. The extra CrLF is now sent by default. This can be used to disable it.

Parameters:

needed – TBA

void connect(Stream *stream)

Connect to the WiThrottle server.

Parameters:

stream – pointer to the stream

void connect(Stream *stream, int delayBetweenCommandsSent)

Connect to the WiThrottle server.

Parameters:
  • stream – pointer to the stream

  • delayBetweenCommandsSent – Delay Between Commands Sent - Minimum time allowable between outgoing commands

void disconnect()

Disconnect from the WiThrottle server.

void setDeviceName(String deviceName)

Send the name of the client device to the WiThrottle server.

Parameters:

deviceName – Abitrary name for the client device

void setDeviceID(String deviceId)

Send the ID of the client device to the WiThrottle server.

Note

WARNING! the Device ID must be unique amoungst all clients connecting to the server. Recommend a large random number on each connection (as a string).

Parameters:

deviceId – Device ID

bool check()

check to see if any inbound comms have been received from the WiThrottle server. Should be called repeatedly, and often, in the main loop of the sketch.

Returns:

True if there have been updates from the server.

void sendCommand(String cmd)

Send an arbitary command to the WiThrottle server.

Parameters:

cmd – WiThrottle command to send

double getCurrentFastTime()

Get the current Fast Time value.

Returns:

the current fast time

float getFastTimeRate()

Get the current Fast Time rate.

Returns:

The current fast time rate

void requireHeartbeat(bool needed = true)

Set if the heartbnest is required or not.

Parameters:

needed – true or false

bool addLocomotive(String address)

Add a loco to the default throttle [Deprecated. Use the multiThrottle version].

Parameters:

address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

Returns:

True if the loco was added

bool stealLocomotive(String address)

Steal a loco for the default throttle [Deprecated. Use the multiThrottle version].

Parameters:

address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

Returns:

TBA

bool releaseLocomotive(String address = "*")

Release a locomotive on he default throttle [Deprecated. Use the multiThrottle version].

Parameters:

address – DCC Address of the loco to drop (String containing the DCC address as number preceeded with “S” or “L”) or “*” to drop all locos on the throttle

Returns:

Always true

String getLeadLocomotive()

Get the lead (or only) loco on the default throttle [Deprecated. Use the multiThrottle version].

Returns:

DCC Address of the loco (String containing the DCC address as number preceeded with “S” or “L”)

String getLocomotiveAtPosition(int position)

Get the loco at a specific position within the consist/multi-unit on the default throttle [Deprecated. Use the multiThrottle version].

Parameters:

position – the postion within the consist/Multi-Unit to retrieve

Returns:

DCC Address of the loco (String containing the DCC address as number preceeded with “S” or “L”)

int getNumberOfLocomotives()

Get the number of locos that are currently assigned ot the default Throttle [Deprecated. Use the multiThrottle version].

Returns:

Number of locos (in consist/Multiple Unit) on the throttle

bool addLocomotive(char multiThrottle, String address)

Add a specfied loco to a specified throttle. Will be added to the end of the consist of one or more locos are currently assigned to that Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – Address of the loco to add.

Returns:

True if the loco was added

bool stealLocomotive(char multiThrottle, String address)

Steal a specified loco. Only relevant to DigiTrax systems.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – Address of the Loco to steal

Returns:

TBA

bool releaseLocomotive(char multiThrottle, String address = "*")

Release one or all locos from a specied throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to drop (String containing the DCC address as number preceeded with “S” or “L”) or “*” to drop all locos on the throttle

Returns:

Always true

String getLeadLocomotive(char multiThrottle)

Get the address of the loco in the lead positon, currently assigned to a specified Throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Returns:

DCC Address of the loco (String containing the DCC address as number preceeded with “S” or “L”)

String getLocomotiveAtPosition(char multiThrottle, int position)

Get the address of the loco at a specified positon, currently assigned to a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • position – Postion of the loco to retrieve

Returns:

DCC Address of the loco (String containing the DCC address as number preceeded with “S” or “L”)

int getNumberOfLocomotives(char multiThrottle)

Get the number of locos currently assigned to a specified Throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Returns:

Number of locos (in consist/Multiple Unit) on the throttle

void setFunction(int funcnum, bool pressed)

Set a Function on the default (first) Throttle. Assumes a button is being pressed hence Press or Release. [Deprecated. Use the multiThrottle version].

Parameters:
  • funcnum – Function Number (0-31)

  • pressed – Press or Release (True = pressed, False = released)

void setFunction(char multiThrottle, int funcnum, bool pressed)

Set a Function on the a specified Throttle. Assumes a button is being pressed hence Press or Release. [Deprecated. Use the multiThrottle version].

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • funcnum – Function Number (0-31)

  • pressed – Press or Release (True = pressed, False = released)

void setFunction(char multiThrottle, String address, int funcnum, bool pressed)

Set a Function on a specified Loco only, on a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to set (String containing the DCC address as number preceeded with “S” or “L”)

  • funcnum – Function Number (0-31)

  • pressed – Press or Release (True = pressed, False = released)

void setFunction(char multiThrottle, String address, int funcnum, bool pressed, bool force)

Set a Function on a specified Loco only, on a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to set (String containing the DCC address as number preceeded with “S” or “L”)

  • funcnum – Function Number (0-31)

  • pressed – Press or Release (True = pressed, False = released)

  • force – Force the activation of the function, overriding what the server wants to do. If true, ‘Pressed’ effectively becomes ‘Activate’ or ‘Deactivate’. (False = not forced, True = force)

bool setSpeed(int speed)

Set the speed of the default Throttle [Deprecated. Use the multiThrottle version].

Parameters:

speed – Speed (0-126)

Returns:

True if the requested speed is valid and there is a loco on the specified throttle. Otherwise False

int getSpeed()

Get the speed of the default Throttle [Deprecated. Use the multiThrottle version].

Returns:

Speed (0-126)

bool setDirection(Direction direction)

Set the direction of the default Throttle [Deprecated. Use the multiThrottle version].

Parameters:

direction – Direction. (Reverse or Forward)

Returns:

True if there is a loco on the specified throttle. Otherwise False

Direction getDirection()

Get the direction of the default Throttle [Deprecated. Use the multiThrottle version].

Returns:

Direction. (Forward or Reverse)

int getSpeedSteps()

Get the speed step of the default Throttle [Deprecated. Use the multiThrottle version].

Returns:

Speed Step setting (1 = 128step, 2 = 28step, 4 = 27step or 8 = 14step)

int getSpeedSteps(char multiThrottle)

Get the speed step of a specified Throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Returns:

Speed Step setting (1 = 128step, 2 = 28step, 4 = 27step or 8 = 14step)

bool setSpeedSteps(int steps)

Set the speed step of the default Throttle [Deprecated. Use the multiThrottle version].

Parameters:

steps – 1=128step, 2=28step, 4=27step or 8=14step

Returns:

True if the ‘steps’ is valid

bool setSpeedSteps(char multiThrottle, int steps)

Set the speed step of a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • steps – 1=128step, 2=28step, 4=27step or 8=14step

Returns:

True if the ‘steps’ is valid

bool setSpeed(char multiThrottle, int speed)

Set the speed of a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • speed – Speed 0-126

Returns:

True if the requested speed is valid and there is a loco on the specified throttle. Otherwise False

bool setSpeed(char multiThrottle, int speed, bool forceSend)

Set the speed of a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • speed – Speed 0-126

  • forceSend – Option to force the command to be sent, even if the protocol thinks it is at that speed

Returns:

True if the requested speed is valid and there is a loco on the specified throttle. Otherwise False

int getSpeed(char multiThrottle)

Get the speed of a specified Throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Returns:

Speed (0-126)

bool setDirection(char multiThrottle, Direction direction)

Set the direction of a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • direction – Direction. (Reverse or Forward)

Returns:

True if there is a loco on the specified throttle. Otherwise False

bool setDirection(char multiThrottle, Direction direction, bool forceSend)

Set the direction of a specified Throttle, with the option to force the send.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • direction – Direction. (Reverse or Forward)

  • forceSend – Option to force the command to be sent, even if the protocol thinks it is in that Direction

Returns:

True if there is a loco on the specified throttle. Otherwise False

bool setDirection(char multiThrottle, String address, Direction direction)

Set the direction of a specific locomotive on a specified Throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to set (String containing the DCC address as number preceeded with “S” or “L”)

  • direction – Direction. (Reverse or Forward)

Returns:

True if there is a loco on the specified throttle. Otherwise False

bool setDirection(char multiThrottle, String address, Direction direction, bool ForceSend)

et the direction of a specific locomotive on a specified Throttle, with the option to force the send

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to set (String containing the DCC address as number preceeded with “S” or “L”)

  • direction – Direction. (Forward or Reverse)

  • ForceSend – Option to force the command to be sent, even if the protocol thinks it is in that Direction

Returns:

True if there is a loco on the specified throttle. Otherwise False

Direction getDirection(char multiThrottle)

Get the direction of a specific throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Returns:

Direction (Forward or Reverse)

Direction getDirection(char multiThrottle, String address)

Get the direction of a specific locomotives on a specific throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to get (String containing the DCC address as number preceeded with “S” or “L”)

Returns:

Direction (Forward or Reverse)

void emergencyStop(char multiThrottle)

Emergency Stop all locomotives on a specific throttle.

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

void emergencyStop(char multiThrottle, String address)

Emergency Stop a specific locomotives on a specific throttle.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address of the loco to stop (String containing the DCC address as number preceeded with “S” or “L”)

void setTrackPower(TrackPower state)

Set the state of a Track Power.

Parameters:

state – State required. One of - PowerOff = 0, PowerOn = 1

void emergencyStop()

Emergency Stop all locomotives on the default (first) throttle.

bool setTurnout(String address, TurnoutAction action)

Set the state of a Turnout/Point.

Parameters:
  • address – Identifier of the Turnout/Point

  • action – Action to perform on the Turnout/Point. (TurnoutClose, TurnoutThrow or TurnoutToggle)

Returns:

always True

bool setRoute(String address)

Set (activate) a Route.

Parameters:

address – Identifier of the Route to activate

Returns:

always True

int getMultiThrottleIndex(char multiThrottle)

Get the Throttle index number from a char Throttle Id. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

Parameters:

multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only.

long getLastServerResponseTime()

Get the last time that the server sent a resonse to the client.

Public Members

bool clockChanged

TBA.

String currentDeviceName

The name of the client device.

bool heartbeatChanged

If the server heatbeat value has changed.

std::vector<String> locomotives[6]

Used to record the locos in a consist (on each Throttle)

std::vector<Direction> locomotivesFacing[6]

Used to record the direction the locos in a consist (on each Throttle) are facing.

Private Functions

bool processCommand(char *c, int len)

Process an incoming command from the Command Station.

bool processLocomotiveAction(char multiThrottle, char *c, int len)

Process an incoming command from the Command Station - specific to locomotives.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • c – Command to process

  • len – length of the command

bool processFastTime(char *c, int len)

Process an incoming fast time command from the Command Station.

Parameters:
  • c – Command/information to process

  • len – length of the command/information

bool processHeartbeat(char *c, int len)

Process an incoming Heartbeat command from the Command Station.

Parameters:
  • c – Information to process

  • len – length of the command/information

bool processRosterFunctionList(char multiThrottle, char *c, int len)

Process an incoming Roster command from the Command Station.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • c – Command to process

  • len – length of the command

void processProtocolVersion(char *c, int len)

Process an incoming Protocol information from the Command Station.

Parameters:
  • c – Protocol information to process

  • len – length of the command/information

void processServerType(char *c, int len)

Process an incoming Server Type information from the Command Station.

Parameters:
  • c – Information to process

  • len – length of the information

void processServerDescription(char *c, int len)

Process an incoming Server Description information from the Command Station.

Parameters:
  • c – Information to process

  • len – length of the information

void processMessage(char *c, int len)

Process an incoming Broadcast Message from the Command Station.

Parameters:
  • c – Message to process

  • len – length of the message

void processAlert(char *c, int len)

Process an incoming Broadcast Alert from the Command Station.

Parameters:
  • c – Alert message to process

  • len – length of the Alert message

void processWebPort(char *c, int len)

Process an incoming Web Port information from the Command Station. The port that serves HTTP. This can be used to retrieve loco images.

Parameters:
  • c – Message to process

  • len – length of the message

void processRosterList(char *c, int len)

Process an incoming Roster List from the Command Station. This is the complete list of all the locos in the Roster.

Parameters:
  • c – Roster list to process

  • len – length of the list

void processTurnoutList(char *c, int len)

Process an incoming Turnout/Points List from the Command Station. This is the complete list of all the locos in the Roster.

Parameters:
  • c – Turnout/Points list to process

  • len – length of the list

void processRouteList(char *c, int len)

Process an incoming Routes List from the Command Station. This is the complete list of all the locos in the Roster.

Parameters:
  • c – Routes list to process

  • len – length of the list

void processTrackPower(char *c, int len)

Process an incoming Track Power information from the Command Station.

Parameters:
  • c – Information to process

  • len – length of the information

void processFunctionState(char multiThrottle, const String &functionData)

TBA.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • functionData – TBA

void processRosterFunctionListEntries(char multiThrottle, const String &s)

TBA.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • s – TBA

void processSpeedSteps(char multiThrottle, const String &speedStepData)

TBA.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • speedStepData – TBA

void processDirection(char multiThrottle, const String &directionStr)

Process an incoming Direction command from the Command Station for a specific multiThrottle.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • directionStr – TBA

void processDirection(char multiThrottle, String &loco, const String &directionStr)

Process an incoming Direction command from the Command Station for a specific multiThrottle.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • loco – TBA

  • directionStr – TBA

void processSpeed(char multiThrottle, const String &speedData)

Process an incoming Speed command from the Command Station for a specific multiThrottle.

Parameters:

speedData – TBA

void processAddRemove(char multiThrottle, char *c, int len)

Process an incoming command from the Command Station to add or remove on or more locomotives from a specified multiThrottle.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • c – Command to process

  • len – length of the command

void processStealNeeded(char multiThrottle, char *c, int len)

Process an incoming command from the Command Station to to advice that a steal command is required to aquire a locomotive. Specific the DigiTrack Command Stations only.

Parameters:
  • multithrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • c – Command to process

  • len – length of the command

void processTurnoutAction(char *c, int len)

TBA.

Parameters:
  • c – Command to process

  • len – length of the command

void processRouteAction(char *c, int len)

TBA.

Parameters:
  • c – Command to process

  • len – length of the command

void processUnknownCommand(char *c, int len)
bool checkFastTime()

TBA.

Outbound Commands ^^^^^^^^^^^^^^^^^

bool checkHeartbeat()

TBA

void sendDelayedCommand(String cmd)

TBA.

Parameters:

cmd – TBA

void setCurrentFastTime(const String &s)

TBA.

Parameters:

s – TBA

void resetChangeFlags()
void init()

Private Members

bool server
Stream *stream
int logLevel = 1
Stream *console
NullStream nullStream
String outboundBuffer
double outboundCmdsTimeLastSent
int outboundCmdsMininumDelay
bool commandsNeedLeadingCrLf = false
WiThrottleProtocolDelegate *delegate = NULL
char inputbuffer[32767]
ssize_t nextChar
unsigned long heartbeatTimer
int heartbeatPeriod
bool heartbeatEnabled = false
unsigned long timeLastLocoAcquired
unsigned long fastTimeTimer
double currentFastTime
float currentFastTimeRate
bool locomotiveSelected[MAX_WIT_THROTTLES] = {false, false, false, false, false, false}
String currentAddress[MAX_WIT_THROTTLES]
int currentSpeed[MAX_WIT_THROTTLES]
int speedSteps[MAX_WIT_THROTTLES]
Direction currentDirection[MAX_WIT_THROTTLES]
String mostRecentTurnout
TurnoutState mostRecentTurnoutState
long lastServerResponseTime
class WiThrottleProtocolDelegate

Class for the Delegate methods.

Public Functions

inline virtual void receivedVersion(String version)

Delegate method to receive the WiThrottle version.

Parameters:

version – Version Number

inline virtual void receivedServerType(String type)

Delegate method to receive the Server Type.

Parameters:

type – Server Type

inline virtual void receivedServerDescription(String description)

Delegate method to receive the Server Decription.

Parameters:

description – Server Description

inline virtual void receivedMessage(String message)

Delegate method to receive a message from the Withrottle Server.

Parameters:

message – Message Content

inline virtual void receivedAlert(String alert)

Delegate method to receive a broadcast Alert from the Withrottle Server.

Parameters:

alert – Broadcast Alert content

inline virtual void receivedRosterEntries(int rosterSize)

Delegate method to receive the total number of Roster Entries from the Withrottle Server.

Parameters:

rosterSize – total number of Roster Entries from the Withrottle Server

inline virtual void receivedRosterEntry(int index, String name, int address, char length)

Delegate method to receive the a single Roster Entry from the Withrottle Server.

Parameters:
  • index – sequence number

  • name – Roster entry name

  • address – DCC Address (number containing the DCC address)

  • length – ‘S’|’L’ Short or Long address

inline virtual void receivedTurnoutEntries(int turnoutListSize)

Delegate method to receive the total number of Turnouts/Points Entries from the Withrottle Server.

Parameters:

turnoutListSize – total number of Turnout/Point Entries in the Withrottle Server

inline virtual void receivedTurnoutEntry(int index, String sysName, String userName, int state)

Delegate method to receive the a single Turnout/Point Entry from the Withrottle Server.

Parameters:
  • index – sequence number

  • sysName – Turnout/Point system name

  • userName – Turnout/Point entry name

  • state – current state of the Turnout/Point

inline virtual void receivedRouteEntries(int routeListSize)

Delegate method to receive the total number of Routes Entries from the Withrottle Server.

Parameters:

routeListSize – total number of Route Entries in the Withrottle Server

inline virtual void receivedRouteEntry(int index, String sysName, String userName, int state)

Delegate method to receive a single Route Entry from the Withrottle Server.

Parameters:
  • index – sequence number

  • sysName – Route system name

  • userName – Route entry name

  • state – current state of the Route

inline virtual void fastTimeChanged(uint32_t time)

Delegate method to receive.

Parameters:

time – TBA

inline virtual void fastTimeRateChanged(double rate)

Delegate method to receive.

Parameters:

rate – Rate of the fast time cloce

inline virtual void heartbeatConfig(int seconds)

Delegate method to receive the the Server heartbeat configurtio from the Withrottle Server.

Parameters:

seconds – Number of seconds betwean heartbeats

inline virtual void receivedFunctionState(uint8_t func, bool state)

Delegate method to received from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:
  • func – Function number (0-31)

  • state – Function State (Boolean True= active/pressed, False = inactive/not pressed)

inline virtual void receivedRosterFunctionList(String functions[MAX_FUNCTIONS])

Delegate method to received from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:

functions – TBA

inline virtual void receivedFunctionStateMultiThrottle(char multiThrottle, uint8_t func, bool state)

Delegate method to received from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • func – Function number (0-31)

  • state – Function State (Boolean True= active/pressed, False = inactive/not pressed)

inline virtual void receivedRosterFunctionListMultiThrottle(char multiThrottle, String functions[MAX_FUNCTIONS])

Delegate method to receive from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • functions – TBA

inline virtual void receivedSpeed(int speed)

Delegate method to receive the speed for the default (first) throttle from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:

speed – TBA

inline virtual void receivedDirection(Direction dir)

Delegate method to receive the direction for the default (first) throttle from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:

dir – TBA

inline virtual void receivedDirection(String address, Direction dir)

Delegate method to receive the direction for the default (first) throttle for an individual loco from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:
  • dir – TBA

  • loco – TBA

inline virtual void receivedSpeedSteps(int steps)

Delegate method to receive the number of speed steps for the default (first) throttle from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:

steps – 1=128step, 2=28step, 4=27step or 8=14step

inline virtual void receivedSpeedMultiThrottle(char multiThrottle, int speed)

Delegate method to receive the speed for a specific throttle from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • speed – TBA

inline virtual void receivedDirectionMultiThrottle(char multiThrottle, Direction dir)

Delegate method to receive the direction for a specific throttle from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • dir – Direction (Forward or Reverse)

inline virtual void receivedDirectionMultiThrottle(char multiThrottle, String address, Direction dir)

Delegate method to receive the direction for a specific throttle for an individual loco from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only.

  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • dir – (Forward or Reverse)

inline virtual void receivedSpeedStepsMultiThrottle(char multiThrottle, int steps)

Delegate method to receive the speed steps for a specific throttle from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • steps – 1=128step, 2=28step, 4=27step or 8=14step

inline virtual void receivedWebPort(int port)

Delegate method to receive the web port number from the Withrottle Server.

Parameters:

port – Port number

inline virtual void receivedTrackPower(TrackPower state)

Delegate method to receive a message that the track power has changed, from the Withrottle Server.

Parameters:

state – TBA

inline virtual void addressAdded(String address, String entry)

Delegate method to receive a message that a loco has been added, from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:
  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • entry – TBA

inline virtual void addressRemoved(String address, String command)

Delegate method to receive a message that the loco has been dropped from the throttle, from the Withrottle Server [Deprecated. Use the multiThrottle version].

Parameters:
  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • command – TBA

inline virtual void addressStealNeeded(String address, String entry)

Delegate method to receive a message for the need to steal the loco, from the Withrottle Server. Only relevant to DigiTrax systems [Deprecated. Use the multiThrottle version].

Parameters:
  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • entry – TBA

inline virtual void addressAddedMultiThrottle(char multiThrottle, String address, String entry)

Delegate method to receive a message that a loco has been added to a specific throttle, from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only.

  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • entry – TBA

inline virtual void addressRemovedMultiThrottle(char multiThrottle, String address, String command)

Delegate method to receive a message that a loco has been dropped from a specific throttle, from the Withrottle Server.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • command – TBA

inline virtual void addressStealNeededMultiThrottle(char multiThrottle, String address, String entry)

Delegate method to receive a message for the need to steal the loco for a specific throttle, from the Withrottle Server. Only relevant to DigiTrax systems.

Parameters:
  • multiThrottle – Which Throttle. Supported multiThrottle codes are ‘T’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ only. (‘T’ is include for compatibiilty with the non multiThrottle methods.)

  • address – DCC Address (String containing the DCC address as number preceeded with “S” or “L”)

  • entry – TBA

inline virtual void receivedTurnoutAction(String systemName, TurnoutState state)

Delegate method to receive a turnout/point action, from the Withrottle Server.

Parameters:
  • systemName – System name of the Turnout/Point

  • state – Turnout State (TurnoutClosed, TurnoutThrown, TurnoutUnknown, TurnoutInconsistent)

inline virtual void receivedRouteAction(String systemName, RouteState state)

Delegate method to receive a route action, from the Withrottle Server.

Parameters:
  • systemName – System name of the Route

  • state – Route State (RouteActive, RouteInactive)

inline virtual void receivedUnknownCommand(String unknownCommand)

Delegate method to receive an unknown command from the Withrottle Server.

Parameters:

unknownCommand – command received

file WiThrottleProtocol.cpp
#include <vector>
#include “WiThrottleProtocol.h

Variables

static const int MIN_SPEED = 0
static const int MAX_SPEED = 126
static const char *rosterSegmentDesc[] = {"Name", "Address", "Length"}
file WiThrottleProtocol.h
#include “Arduino.h”
#include <vector>

Defines

PROPERTY_SEPARATOR
ENTRY_SEPARATOR
SEGMENT_SEPARATOR
NEWLINE
CR
DEFAULT_MULTITHROTTLE
ALL_LOCOS_ON_THROTTLE
MAX_WIT_THROTTLES
MAX_FUNCTIONS

Enums

enum Direction

Loco/Throttle Direction options.

Values:

enumerator Reverse
enumerator Forward
enum TrackPower

Track Power options.

Values:

enumerator PowerOff
enumerator PowerOn
enumerator PowerUnknown
enum TurnoutState

Turnout/Point state options.

Values:

enumerator TurnoutClosed
enumerator TurnoutThrown
enumerator TurnoutUnknown
enumerator TurnoutInconsistent
enum TurnoutAction

Turnout/Point action options.

Values:

enumerator TurnoutClose
enumerator TurnoutThrow
enumerator TurnoutToggle
enum RouteState

Route states.

Values:

enumerator RouteActive
enumerator RouteInactive
enumerator RouteInconsistent
dir /home/runner/work/WiThrottleProtocol/WiThrottleProtocol/src