2020-06-04 21:55:18 +02:00
|
|
|
#ifndef DCCEXParser_h
|
|
|
|
#define DCCEXParser_h
|
2020-06-12 20:56:40 +02:00
|
|
|
#include <Arduino.h>
|
2020-06-18 20:36:37 +02:00
|
|
|
|
|
|
|
typedef void (*FILTER_CALLBACK)(Print & stream, byte & opcode, byte & paramCount, int p[]);
|
|
|
|
|
2020-06-04 21:55:18 +02:00
|
|
|
struct DCCEXParser
|
2020-05-25 14:38:18 +02:00
|
|
|
{
|
2020-06-11 14:35:16 +02:00
|
|
|
DCCEXParser();
|
|
|
|
void loop(Stream & pstream);
|
2020-06-13 10:36:10 +02:00
|
|
|
void parse(Print & stream, const char * command);
|
2020-06-12 15:28:35 +02:00
|
|
|
void flush();
|
2020-06-18 20:36:37 +02:00
|
|
|
static void setFilter(FILTER_CALLBACK filter);
|
|
|
|
static const int MAX_PARAMS=10; // Must not exceed this
|
|
|
|
|
2020-05-25 14:38:18 +02:00
|
|
|
private:
|
2020-06-10 18:31:26 +02:00
|
|
|
|
|
|
|
static const int MAX_BUFFER=50; // longest command sent in
|
|
|
|
byte bufferLength=0;
|
|
|
|
bool inCommandPayload=false;
|
2020-06-11 14:35:16 +02:00
|
|
|
char buffer[MAX_BUFFER+2];
|
2020-06-13 12:17:06 +02:00
|
|
|
int splitValues( int result[MAX_PARAMS],char * command);
|
2020-06-11 14:35:16 +02:00
|
|
|
|
2020-06-12 15:28:35 +02:00
|
|
|
bool parseT(Print & stream, int params, int p[]);
|
|
|
|
bool parseZ(Print & stream, int params, int p[]);
|
|
|
|
bool parseS(Print & stream, int params, int p[]);
|
2020-06-10 18:31:26 +02:00
|
|
|
|
2020-06-07 14:48:42 +02:00
|
|
|
|
|
|
|
static bool stashBusy;
|
2020-06-12 15:28:35 +02:00
|
|
|
static Print & stashStream;
|
2020-06-10 18:31:26 +02:00
|
|
|
static int stashP[MAX_PARAMS];
|
2020-06-12 15:28:35 +02:00
|
|
|
static bool stashCallback(Print & stream, int p[MAX_PARAMS]);
|
2020-06-07 14:48:42 +02:00
|
|
|
static void callback_W(int result);
|
|
|
|
static void callback_B(int result);
|
|
|
|
static void callback_R(int result);
|
2020-06-18 20:36:37 +02:00
|
|
|
static FILTER_CALLBACK filterCallback;
|
2020-06-07 14:48:42 +02:00
|
|
|
|
2020-05-25 14:38:18 +02:00
|
|
|
};
|
2020-06-03 15:26:49 +02:00
|
|
|
|
2020-06-13 16:53:46 +02:00
|
|
|
#define BOARD_NAME F("not yet configured")
|
2020-05-27 10:40:12 +02:00
|
|
|
#endif
|