-
Notifications
You must be signed in to change notification settings - Fork 2
/
WiThrottle.h
77 lines (58 loc) · 2.22 KB
/
WiThrottle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// WiThrottle.h
//Implements the JRMI WiThrottle protocol over a TCP socket
//https://www.jmri.org/help/en/package/jmri/jmrit/withrottle/Protocol.shtml
#ifndef _WITHROTTLE_h
#define _WITHROTTLE_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <ESPAsyncTCP.h> //Github me-no-dev/ESPAsyncTCP
#include <string> //required if you wish to compile in arduino IDE, this is the std::string library
namespace nsWiThrottle {
#define WITHROTTLE_TIMEOUT 3 //3 sec timeout
struct CLIENT_T {
AsyncClient *client;
std::string HU; //HU identifier from client
uint8_t timeout;
};
struct THROTTLE
{
AsyncClient* toClient; //associated client
//int8_t MT; //multi throttle designator on the client 0-9. -1 signifies ALL
char MT; //typically identifiers are M0 through M9 or MT for solo throttles
char address[8]; //L10293 is the longest poss addr
int8_t locoSlot;
uint8_t MTaction;
bool orientation;
// uint8_t timeout; //now done at client level
};
struct CLIENTMESSAGE
{
std::string msg; //safer inside a vector, will avoid memory leaks
AsyncClient* toClient; //pointer to specific client, nullptr=all clients
};
/*function prototypes*/
void startThrottle(void);
void seedLoco(void);
void dumpLoco(void);
void broadcastChanges(bool clearFlags);
void broadcastPower(void);
void broadcastLocoRoster(AsyncClient *client);
void broadcastTurnoutRoster(AsyncClient *client);
void sendWiMinimal(AsyncClient* client); //do i need this?
void processTimeout();
uint8_t clientCount(void);
/*local scope, hence declared static*/
static int8_t doThrottleCommand(void *data, AsyncClient *client);
static void sendToClient(char *data, AsyncClient *client);
static void sendToClient(std::string s, AsyncClient *client);
static void queueMessage(std::string s, AsyncClient *client);
static void setPower(bool powerOn);
static int8_t addReleaseThrottle(AsyncClient *client, char MT, char *address, bool doAdd);
static bool checkDoSteal(char *address, bool checkOnly, bool &isConsist);
static void setConsistID(THROTTLE *t);
static void checkClientID(AsyncClient *client);
}
#endif