1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00
CommandStation-EX/DCCEXParser.h

75 lines
2.7 KiB
C
Raw Normal View History

2020-07-03 18:35:02 +02:00
/*
* © 2020, Chris Harlow. All rights reserved.
*
* This file is part of Asbelos DCC API
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
2020-06-04 21:55:18 +02:00
#ifndef DCCEXParser_h
#define DCCEXParser_h
#include <Arduino.h>
#include "FSH.h"
2020-06-18 20:36:37 +02:00
typedef void (*FILTER_CALLBACK)(Print * stream, byte & opcode, byte & paramCount, int p[]);
typedef void (*AT_COMMAND_CALLBACK)(const byte * command);
2020-06-18 20:36:37 +02:00
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 & stream);
void parse(Print * stream, byte * command, bool blocking);
void parse(const FSH * cmd);
void flush();
2020-06-18 20:36:37 +02:00
static void setFilter(FILTER_CALLBACK filter);
static void setRMFTFilter(FILTER_CALLBACK filter);
static void setAtCommandCallback(AT_COMMAND_CALLBACK filter);
2021-02-09 14:43:40 +01:00
static const int MAX_COMMAND_PARAMS=10; // Must not exceed this
2020-06-18 20:36:37 +02:00
2020-05-25 14:38:18 +02:00
private:
static const int MAX_BUFFER=50; // longest command sent in
byte bufferLength=0;
bool inCommandPayload=false;
byte buffer[MAX_BUFFER+2];
2021-02-09 14:43:40 +01:00
int splitValues( int result[MAX_COMMAND_PARAMS], const byte * command);
int splitHexValues( int result[MAX_COMMAND_PARAMS], const byte * command);
2020-06-11 14:35:16 +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[]);
bool parsef(Print * stream, int params, int p[]);
bool parseD(Print * stream, int params, int p[]);
static bool stashBusy;
2020-07-01 17:58:48 +02:00
static Print * stashStream;
2021-02-09 14:43:40 +01:00
static int stashP[MAX_COMMAND_PARAMS];
bool stashCallback(Print * stream, int p[MAX_COMMAND_PARAMS]);
static void callback_W(int result);
static void callback_B(int result);
static void callback_R(int result);
2020-09-20 01:59:07 +02:00
static void callback_Rloco(int result);
static void callback_Wloco(int result);
2020-09-18 01:04:42 +02:00
static void callback_Vbit(int result);
static void callback_Vbyte(int result);
2020-06-18 20:36:37 +02:00
static FILTER_CALLBACK filterCallback;
static FILTER_CALLBACK filterRMFTCallback;
static AT_COMMAND_CALLBACK atCommandCallback;
static void funcmap(int cab, byte value, byte fstart, byte fstop);
2020-05-25 14:38:18 +02:00
};
2020-05-27 10:40:12 +02:00
#endif