mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-28 18:03:45 +02:00
Compare commits
84 Commits
v5.4.14-Pr
...
zzparser
Author | SHA1 | Date | |
---|---|---|---|
|
9bda665ad4 | ||
|
1bcc2678c2 | ||
|
502ba7a653 | ||
|
16a1ddc6e9 | ||
|
8d52cd8542 | ||
|
6087486b91 | ||
|
91e8f89fe2 | ||
|
18dcbeff31 | ||
|
83a5c52a0d | ||
|
45af57ebf2 | ||
|
3f8ecf2a52 | ||
|
764639ed79 | ||
|
e56e4826ec | ||
|
3aa5cbcdfc | ||
|
16f13d9aee | ||
|
2b82e65978 | ||
|
b840aee21e | ||
|
1cce32bb2a | ||
|
570fd75b15 | ||
|
83e62c7479 | ||
|
6d8ca67a2b | ||
|
5d18c910fa | ||
|
a4c71889c6 | ||
|
cb24a4dec7 | ||
|
cda3b3ca1c | ||
|
ed21284930 | ||
|
6d9951c871 | ||
|
56add464ac | ||
|
3d794c59d8 | ||
|
84918cbf36 | ||
|
0294409214 | ||
|
2a007f99dd | ||
|
3095de4672 | ||
|
dcfb3f061d | ||
|
7f488de06e | ||
|
c99eac6ada | ||
|
ed69a51e97 | ||
|
f2a7577313 | ||
|
56a339a598 | ||
|
a3bd5ac86f | ||
|
da66469faa | ||
|
5d1b3a7a03 | ||
|
f3b87877ef | ||
|
07691e3985 | ||
|
d14aa46d51 | ||
|
2b50e31e50 | ||
|
ee8f6eea1f | ||
|
fb6070784e | ||
|
2f1d5b993c | ||
|
58b180603a | ||
|
95d90aa337 | ||
|
137008ceb3 | ||
|
4ec9a62ab6 | ||
|
08076443cb | ||
|
748ddcde8c | ||
|
dc84f560e6 | ||
|
680f765775 | ||
|
7e8841611d | ||
|
2503158e32 | ||
|
f031add7a0 | ||
|
32066a3bfa | ||
|
e20935848f | ||
|
6f0ff49945 | ||
|
c93dd75323 | ||
|
519cabffb6 | ||
|
aa4306123d | ||
|
ccbff56355 | ||
|
e0aa16ff2c | ||
|
6b0dc272ea | ||
|
9602c32ea7 | ||
|
1235c288dc | ||
|
001c4664c1 | ||
|
9786ea9b3a | ||
|
6a35daab6b | ||
|
afff10df28 | ||
|
b9ce166028 | ||
|
0a96320fd0 | ||
|
9a6e1707e7 | ||
|
64a34b3a32 | ||
|
19f4869401 | ||
|
bcdf9cb1c5 | ||
|
701f4e852f | ||
|
657fb7009c | ||
|
e131a9cce8 |
36
.github/workflows/docs.yml
vendored
Normal file
36
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Docs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- devel
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Install Requirements
|
||||
run: |
|
||||
cd docs
|
||||
python -m pip install --upgrade pip
|
||||
pip3 install -r requirements.txt
|
||||
sudo apt-get install doxygen
|
||||
|
||||
- name: Build Prod docs
|
||||
run: |
|
||||
cd docs
|
||||
make html
|
||||
touch _build/html/.nojekyll
|
||||
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: gh-pages # The branch the action should deploy to.
|
||||
folder: docs/_build/html # The folder the action should deploy.
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,3 +15,6 @@ my*.h
|
||||
compile_commands.json
|
||||
newcode.txt.old
|
||||
UserAddin.txt
|
||||
_build
|
||||
venv
|
||||
.DS_Store
|
||||
|
111
CamCommands.h
Normal file
111
CamCommands.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* © 2023-2025, Barry Daniel
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
//sensorCAM parser.cpp version 3.06 Jan 2025
|
||||
#include "DCCEXParser.h"
|
||||
#include "CamParser.h"
|
||||
#include "FSH.h"
|
||||
|
||||
void camsend(byte camop,int16_t param1,int16_t param3) {
|
||||
DIAG(F("CamParser: %d %c %d %d"),CAMBaseVpin,camop,param1,param3);
|
||||
IODevice::writeAnalogue(CAMBaseVpin,param1,camop,param3);
|
||||
}
|
||||
|
||||
|
||||
// The CAMVPINS array will be filled by IO_EXSensorCam HAL drivers calling
|
||||
// the CamParser::addVpin() function.
|
||||
// The CAMBaseVpin is the one to be used when commands are given without a vpin.
|
||||
VPIN CamParser::CAMBaseVpin = 0; // no vpins yet known
|
||||
VPIN CamParser::CAMVPINS[] = {0,0,0,0}; // determines max # CAM's
|
||||
int CamParser::vpcount=sizeof(CAMVPINS)/sizeof(CAMVPINS[0]);
|
||||
|
||||
|
||||
ZZ(N) // lists current base vpin and others available
|
||||
DIAG(F("Cam base vpin:%d"),CAMBaseVpin);
|
||||
for (auto i=0;i<vpcount;i++){
|
||||
if (CAMVPINS[i]==0) break;
|
||||
DIAG(F("EXSensorCam #%d vpin %d"),i+1,CAMVPINS[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ZZ(N,V) // show version
|
||||
camsend('^',0,999);
|
||||
ZZ(N,F) //
|
||||
camsend(']',0,999);
|
||||
ZZ(N,Q) //
|
||||
camsend('Q',0,10);
|
||||
ZZ(N,camop) //
|
||||
CHECK(STRCHR_P((const char *)F("EGMRW"),camop))
|
||||
camsend(camop,0,999);
|
||||
|
||||
ZZ(N,C,pin) // change CAM base vpin or cam number from list
|
||||
CHECK(pin>=100 || (pin<vpcount && pin>=0))
|
||||
CAMBaseVpin=(pin>=100? pin:CAMVPINS[pin];
|
||||
DIAG(F("CAM base Vpin:%d "),pin,CAMBaseVpin);
|
||||
|
||||
ZZ(N,camop,p1) //send camop p1
|
||||
CHECK(STRCHR_P((const char *)F("ABFHILMNOPQRSTUV"),camop))
|
||||
camsend(camop,p1,999);
|
||||
|
||||
ZZ(N,I,p1,p2) //send camop p1 p2
|
||||
camsend('I',p1,p2);
|
||||
ZZ(N,J,p1,p2) //send camop p1 p2
|
||||
camsend('J',p1,p2);
|
||||
ZZ(N,M,p1,p2) //send camop p1 p2
|
||||
camsend('M',p1,p2);
|
||||
ZZ(N,N,p1,p2) //send camop p1 p2
|
||||
camsend('N',p1,p2);
|
||||
ZZ(N,T,p1,p2) //send camop p1 p2
|
||||
camsend('T',p1,p2);
|
||||
ZZ(N,vpin,rowY,colX) //send 0x80 row col
|
||||
auto hold=CAMBaseVpin;
|
||||
CAMBaseVpin=vpin;
|
||||
camsend(0x80,rowY,colX);
|
||||
CAMBaseVpin=hold;
|
||||
|
||||
ZZ(N,A,id,row,col)
|
||||
CHECK(col<=316 && col>=0)
|
||||
CHECK(row<=236 && row>=0)
|
||||
CHECK(id<=97 && id >=0)
|
||||
auto hold=CAMBaseVpin;
|
||||
CAMBaseVpin=CAMBaseVpin + (id/10)*8 + id%10; //translate from pseudo octal
|
||||
camsend(0x80,row,col)
|
||||
CAMBaseVpin=hold;
|
||||
|
||||
void CamParser::addVpin(VPIN pin) {
|
||||
// called by IO_EXSensorCam starting up a camera on a vpin
|
||||
byte slot=255;
|
||||
for (auto i=0;i<vpcount && slot==255;i++) {
|
||||
if (CAMVPINS[i]==0) {
|
||||
slot=i;
|
||||
CAMVPINS[slot]=pin;
|
||||
}
|
||||
}
|
||||
if (slot==255) {
|
||||
DIAG(F("No more than %d cameras supported"),vpcount);
|
||||
return;
|
||||
}
|
||||
if (slot==0) CAMBaseVpin=pin;
|
||||
DIAG(F("CamParser Registered cam #%dvpin %d"),slot+1,pin);
|
||||
// tell the DCCEXParser that we wish to filter commands
|
||||
DCCEXParser::setCamParserFilter(&parse);
|
||||
}
|
104
CamParser.cpp
104
CamParser.cpp
@@ -1,31 +1,57 @@
|
||||
/*
|
||||
* © 2023-2025, Barry Daniel
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
//sensorCAM parser.cpp version 3.03 Sep 2024
|
||||
//sensorCAM parser.cpp version 3.06 Jan 2025
|
||||
#include "DCCEXParser.h"
|
||||
#include "CamParser.h"
|
||||
#include "FSH.h"
|
||||
#include "IO_EXSensorCAM.h"
|
||||
|
||||
#ifndef SENSORCAM_VPIN //define CAM vpin (700?) in config.h
|
||||
#define SENSORCAM_VPIN 0
|
||||
#endif
|
||||
#define CAM_VPIN SENSORCAM_VPIN
|
||||
#ifndef SENSORCAM2_VPIN
|
||||
#define SENSORCAM2_VPIN CAM_VPIN
|
||||
#endif
|
||||
#ifndef SENSORCAM3_VPIN
|
||||
#define SENSORCAM3_VPIN 0
|
||||
#endif
|
||||
const int CAMVPINS[] = {CAM_VPIN,SENSORCAM_VPIN,SENSORCAM2_VPIN,SENSORCAM3_VPIN};
|
||||
const int16_t ver=30177;
|
||||
const int16_t ve =2899;
|
||||
|
||||
VPIN EXSensorCAM::CAMBaseVpin = CAM_VPIN;
|
||||
|
||||
// The CAMVPINS array will be filled by IO_EXSensorCam HAL drivers calling
|
||||
// the CamParser::addVpin() function.
|
||||
// The CAMBaseVpin is the one to be used when commands are given without a vpin.
|
||||
VPIN CamParser::CAMBaseVpin = 0; // no vpins yet known
|
||||
VPIN CamParser::CAMVPINS[] = {0,0,0,0}; // determines max # CAM's
|
||||
int CamParser::vpcount=sizeof(CAMVPINS)/sizeof(CAMVPINS[0]);
|
||||
|
||||
void CamParser::parse(Print * stream, byte & opcode, byte & paramCount, int16_t p[]) {
|
||||
if (opcode!='N') return; // this is not for us.
|
||||
if (parseN(stream,paramCount,p)) opcode=0; // we have consumed this
|
||||
// If we fail, the caller will <X> the <N command.
|
||||
}
|
||||
|
||||
bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
|
||||
(void)stream; // probably unused parameter
|
||||
VPIN vpin=EXSensorCAM::CAMBaseVpin; //use current CAM selection
|
||||
(void)stream; // probably unused parameter
|
||||
if (CAMBaseVpin==0) CAMBaseVpin=CAMVPINS[0]; // default to CAM 1.
|
||||
VPIN vpin=CAMBaseVpin; //use current CAM selection
|
||||
|
||||
if (paramCount==0) {
|
||||
DIAG(F("vpin:%d EXSensorCAMs defined at Vpins #1@ %d #2@ %d #3@ %d"),vpin,CAMVPINS[1],CAMVPINS[2],CAMVPINS[3]);
|
||||
DIAG(F("Cam base vpin:%d"),CAMBaseVpin);
|
||||
for (auto i=0;i<vpcount;i++){
|
||||
if (CAMVPINS[i]==0) break;
|
||||
DIAG(F("EXSensorCam #%d vpin %d"),i+1,CAMVPINS[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
uint8_t camop=p[0]; // cam oprerator
|
||||
@@ -33,44 +59,45 @@ bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
|
||||
int16_t param3=9999; // =0 could invoke parameter changes. & -1 gives later errors
|
||||
|
||||
if(camop=='C'){
|
||||
if(p[1]>=100) EXSensorCAM::CAMBaseVpin=p[1];
|
||||
if(p[1]<4) EXSensorCAM::CAMBaseVpin=CAMVPINS[p[1]];
|
||||
DIAG(F("CAM base Vpin: %c %d "),p[0],EXSensorCAM::CAMBaseVpin);
|
||||
if(p[1]>=100) CAMBaseVpin=p[1];
|
||||
if(p[1]<=vpcount && p[1]>0) CAMBaseVpin=CAMVPINS[p[1]-1];
|
||||
DIAG(F("CAM base Vpin: %c %d "),p[0],CAMBaseVpin);
|
||||
return true;
|
||||
}
|
||||
if (camop<100) { //switch CAM# if p[1] dictates
|
||||
if(p[1]>=100 && p[1]<400) { //limits to CAM# 1 to 3 for now
|
||||
vpin=CAMVPINS[p[1]/100];
|
||||
EXSensorCAM::CAMBaseVpin=vpin;
|
||||
if(p[1]>=100 && p[1]<=(vpcount*100+99)) { //limits to CAM# 1 to 4 for now
|
||||
vpin=CAMVPINS[p[1]/100-1];
|
||||
CAMBaseVpin=vpin;
|
||||
DIAG(F("switching to CAM %d baseVpin:%d"),p[1]/100,vpin);
|
||||
p[1]=p[1]%100; //strip off CAM #
|
||||
}
|
||||
}
|
||||
if (EXSensorCAM::CAMBaseVpin==0) return false; // no cam defined
|
||||
|
||||
|
||||
if (CAMBaseVpin==0) {DIAG(F("<n Error: Invalid CAM selected, default to CAM1>"));
|
||||
return false; // cam not defined
|
||||
}
|
||||
|
||||
// send UPPER case to sensorCAM to flag binary data from a DCCEX-CS parser
|
||||
switch(paramCount) {
|
||||
case 1: //<N ver> produces '^'
|
||||
if((p[0] == ve) || (p[0] == ver) || (p[0] == 'V')) camop='^';
|
||||
if((camop == 'V') || (p[0] == ve) || (p[0] == ver) ) camop='^';
|
||||
if (STRCHR_P((const char *)F("EFGMQRVW^"),camop) == nullptr) return false;
|
||||
if (camop=='Q') param3=10; //<NQ> for activation state of all 10 banks of sensors
|
||||
if (camop=='F') camop=']'; //<NF> for Reset/Finish webCAM.
|
||||
break; // F Coded as ']' else conflicts with <Nf %%>
|
||||
|
||||
case 2: //<N camop p1>
|
||||
if (STRCHR_P((const char *)F("ABFILMNOPQRSTUV"),camop)==nullptr) return false;
|
||||
if (STRCHR_P((const char *)F("ABFHILMNOPQRSTUV"),camop)==nullptr) return false;
|
||||
param1=p[1];
|
||||
break;
|
||||
|
||||
case 3: //<N vpin rowY colx > or <N cmd p1 p2>
|
||||
camop=p[0];
|
||||
if (p[0]>=100) { //vpin - i.e. NOT 'A' through 'Z'
|
||||
if (p[1]>236 || p[1]<0) return false; //row
|
||||
if (p[2]>316 || p[2]<0) return false; //column
|
||||
camop=0x80; // special 'a' case for IO_SensorCAM
|
||||
vpin = p[0];
|
||||
}else if (STRCHR_P((const char *)F("IJMNT"),camop) == nullptr) return false;
|
||||
camop=p[0];
|
||||
param1 = p[1];
|
||||
param3 = p[2];
|
||||
break;
|
||||
@@ -92,4 +119,23 @@ bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
|
||||
DIAG(F("CamParser: %d %c %d %d"),vpin,camop,param1,param3);
|
||||
IODevice::writeAnalogue(vpin,param1,camop,param3);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CamParser::addVpin(VPIN pin) {
|
||||
// called by IO_EXSensorCam starting up a camera on a vpin
|
||||
byte slot=255;
|
||||
for (auto i=0;i<vpcount && slot==255;i++) {
|
||||
if (CAMVPINS[i]==0) {
|
||||
slot=i;
|
||||
CAMVPINS[slot]=pin;
|
||||
}
|
||||
}
|
||||
if (slot==255) {
|
||||
DIAG(F("No more than %d cameras supported"),vpcount);
|
||||
return;
|
||||
}
|
||||
if (slot==0) CAMBaseVpin=pin;
|
||||
DIAG(F("CamParser Registered cam #%dvpin %d"),slot+1,pin);
|
||||
// tell the DCCEXParser that we wish to filter commands
|
||||
DCCEXParser::setCamParserFilter(&parse);
|
||||
}
|
30
CamParser.h
30
CamParser.h
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* © 2023-2025, Barry Daniel
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CamParser_H
|
||||
#define CamParser_H
|
||||
#include <Arduino.h>
|
||||
@@ -5,7 +27,13 @@
|
||||
|
||||
class CamParser {
|
||||
public:
|
||||
static bool parseN(Print * stream, byte paramCount, int16_t p[]);
|
||||
static void parse(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
||||
static void addVpin(VPIN pin);
|
||||
private:
|
||||
static bool parseN(Print * stream, byte paramCount, int16_t p[]);
|
||||
static VPIN CAMBaseVpin;
|
||||
static VPIN CAMVPINS[];
|
||||
static int vpcount;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2022 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2020 Gregor Baues
|
||||
* © 2022 Colin Murdoch
|
||||
* All rights reserved.
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "DCC.h"
|
||||
#include "TrackManager.h"
|
||||
#include "StringFormatter.h"
|
||||
#include "Websockets.h"
|
||||
|
||||
// variables to hold clock time
|
||||
int16_t lastclocktime;
|
||||
@@ -44,6 +45,7 @@ template<typename... Targs> void CommandDistributor::broadcastReply(clientType t
|
||||
broadcastBufferWriter->flush();
|
||||
StringFormatter::send(broadcastBufferWriter, msg...);
|
||||
broadcastToClients(type);
|
||||
if (type==COMMAND_TYPE) broadcastToClients(WEBSOCKET_TYPE);
|
||||
}
|
||||
#else
|
||||
// on a single USB connection config, write direct to Serial and ignore flush/shove
|
||||
@@ -56,14 +58,17 @@ template<typename... Targs> void CommandDistributor::broadcastReply(clientType t
|
||||
#ifdef CD_HANDLE_RING
|
||||
// wifi or ethernet ring streams with multiple client types
|
||||
RingStream * CommandDistributor::ring=0;
|
||||
CommandDistributor::clientType CommandDistributor::clients[8]={
|
||||
NONE_TYPE,NONE_TYPE,NONE_TYPE,NONE_TYPE,NONE_TYPE,NONE_TYPE,NONE_TYPE,NONE_TYPE};
|
||||
CommandDistributor::clientType CommandDistributor::clients[MAX_NUM_TCP_CLIENTS]={ NONE_TYPE }; // 0 is and must be NONE_TYPE
|
||||
|
||||
// Parse is called by Withrottle or Ethernet interface to determine which
|
||||
// protocol the client is using and call the appropriate part of dcc++Ex
|
||||
void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream) {
|
||||
if (Diag::WIFI && Diag::CMD)
|
||||
DIAG(F("Parse C=%d T=%d B=%s"),clientId, clients[clientId], buffer);
|
||||
if (clientId>=sizeof (clients)) {
|
||||
// Caution, diag dump of buffer could corrupt ringstream
|
||||
// if headed by websocket bytes.
|
||||
DIAG(F("::parse invalid client=%d"),clientId);
|
||||
return;
|
||||
}
|
||||
ring=stream;
|
||||
|
||||
// First check if the client is not known
|
||||
@@ -72,22 +77,40 @@ void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream
|
||||
// client is using the DCC++ protocol where all commands start
|
||||
// with '<'
|
||||
if (clients[clientId] == NONE_TYPE) {
|
||||
auto websock=Websockets::checkConnectionString(clientId,buffer,stream);
|
||||
if (websock) {
|
||||
clients[clientId]=WEBSOCK_CONNECTING_TYPE;
|
||||
// websockets will have replied already
|
||||
return;
|
||||
}
|
||||
if (buffer[0] == '<')
|
||||
clients[clientId]=COMMAND_TYPE;
|
||||
else
|
||||
clients[clientId]=WITHROTTLE_TYPE;
|
||||
}
|
||||
|
||||
// after first inbound transmission the websocket is connected
|
||||
if (clients[clientId]==WEBSOCK_CONNECTING_TYPE)
|
||||
clients[clientId]=WEBSOCKET_TYPE;
|
||||
|
||||
|
||||
// mark buffer that is sent to parser
|
||||
ring->mark(clientId);
|
||||
|
||||
// When type is known, send the string
|
||||
// to the right parser
|
||||
if (clients[clientId] == COMMAND_TYPE) {
|
||||
ring->mark(clientId);
|
||||
DCCEXParser::parse(stream, buffer, ring);
|
||||
} else if (clients[clientId] == WITHROTTLE_TYPE) {
|
||||
ring->mark(clientId);
|
||||
WiThrottle::getThrottle(clientId)->parse(ring, buffer);
|
||||
}
|
||||
else if (clients[clientId] == WEBSOCKET_TYPE) {
|
||||
buffer=Websockets::unmask(clientId,ring, buffer);
|
||||
if (!buffer) return; // unmask may have handled it alrerday (ping/pong)
|
||||
// mark ring with client flagged as websocket for transmission later
|
||||
ring->mark(clientId | Websockets::WEBSOCK_CLIENT_MARKER);
|
||||
DCCEXParser::parse(stream, buffer, ring);
|
||||
}
|
||||
|
||||
if (ring->peekTargetMark()!=RingStream::NO_CLIENT) {
|
||||
// The commit call will either write the length bytes
|
||||
@@ -131,7 +154,7 @@ void CommandDistributor::broadcastToClients(clientType type) {
|
||||
for (byte clientId=0; clientId<sizeof(clients); clientId++) {
|
||||
if (clients[clientId]==type) {
|
||||
//DIAG(F("CD mark client %d"), clientId);
|
||||
ring->mark(clientId);
|
||||
ring->mark(clientId | (type==WEBSOCKET_TYPE? Websockets::WEBSOCK_CLIENT_MARKER : 0));
|
||||
ring->print(broadcastBufferWriter->getString());
|
||||
//DIAG(F("CD commit client %d"), clientId);
|
||||
ring->commit();
|
||||
@@ -185,10 +208,15 @@ void CommandDistributor::setClockTime(int16_t clocktime, int8_t clockrate, byte
|
||||
{
|
||||
case 1:
|
||||
if (clocktime != lastclocktime){
|
||||
auto difference = clocktime - lastclocktime;
|
||||
if (difference<0) difference+=1440;
|
||||
DCC::setTime(clocktime,clockrate,difference>2);
|
||||
// CAH. DIAG removed because LCD does it anyway.
|
||||
LCD(6,F("Clk Time:%d Sp %d"), clocktime, clockrate);
|
||||
// look for an event for this time
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
RMFT2::clockEvent(clocktime,1);
|
||||
#endif
|
||||
// Now tell everyone else what the time is.
|
||||
CommandDistributor::broadcastClockTime(clocktime, clockrate);
|
||||
lastclocktime = clocktime;
|
||||
@@ -207,9 +235,13 @@ int16_t CommandDistributor::retClockTime() {
|
||||
return lastclocktime;
|
||||
}
|
||||
|
||||
void CommandDistributor::broadcastLoco(byte slot) {
|
||||
DCC::LOCO * sp=&DCC::speedTable[slot];
|
||||
broadcastReply(COMMAND_TYPE, F("<l %d %d %d %l>\n"), sp->loco,slot,sp->speedCode,sp->functions);
|
||||
void CommandDistributor::broadcastLoco(DCC::LOCO* sp) {
|
||||
if (!sp) {
|
||||
broadcastReply(COMMAND_TYPE,F("<l 0 -1 128 0>\n"));
|
||||
return;
|
||||
}
|
||||
broadcastReply(COMMAND_TYPE, F("<l %d 0 %d %l>\n"),
|
||||
sp->loco,sp->targetSpeed,sp->functions);
|
||||
#ifdef SABERTOOTH
|
||||
if (Serial2 && sp->loco == SABERTOOTH) {
|
||||
static uint8_t rampingmode = 0;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2022 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2020 Gregor Baues
|
||||
* © 2022 Colin Murdoch
|
||||
*
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "StringBuffer.h"
|
||||
#include "defines.h"
|
||||
#include "EXRAIL2.h"
|
||||
#include "DCC.h"
|
||||
|
||||
#if WIFI_ON | ETHERNET_ON
|
||||
// Command Distributor must handle a RingStream of clients
|
||||
@@ -36,17 +37,17 @@
|
||||
|
||||
class CommandDistributor {
|
||||
public:
|
||||
enum clientType: byte {NONE_TYPE,COMMAND_TYPE,WITHROTTLE_TYPE};
|
||||
enum clientType: byte {NONE_TYPE = 0,COMMAND_TYPE,WITHROTTLE_TYPE,WEBSOCK_CONNECTING_TYPE,WEBSOCKET_TYPE}; // independent of other types, NONE_TYPE must be 0
|
||||
private:
|
||||
static void broadcastToClients(clientType type);
|
||||
static StringBuffer * broadcastBufferWriter;
|
||||
#ifdef CD_HANDLE_RING
|
||||
static RingStream * ring;
|
||||
static clientType clients[8];
|
||||
static clientType clients[MAX_NUM_TCP_CLIENTS];
|
||||
#endif
|
||||
public :
|
||||
static void parse(byte clientId,byte* buffer, RingStream * ring);
|
||||
static void broadcastLoco(byte slot);
|
||||
static void broadcastLoco(DCC::LOCO * slot);
|
||||
static void broadcastForgetLoco(int16_t loco);
|
||||
static void broadcastSensor(int16_t id, bool value);
|
||||
static void broadcastTurnout(int16_t id, bool isClosed);
|
||||
|
457
DCC.cpp
457
DCC.cpp
@@ -5,7 +5,7 @@
|
||||
* © 2021 Herb Morton
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2021 M Steve Todd
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "CommandDistributor.h"
|
||||
#include "TrackManager.h"
|
||||
#include "DCCTimer.h"
|
||||
#include "Railcom.h"
|
||||
#include "DCCQueue.h"
|
||||
|
||||
// This module is responsible for converting API calls into
|
||||
// messages to be sent to the waveform generator.
|
||||
@@ -60,6 +62,8 @@ const byte FN_GROUP_5=0x10;
|
||||
FSH* DCC::shieldName=NULL;
|
||||
byte DCC::globalSpeedsteps=128;
|
||||
|
||||
#define SLOTLOOP for (auto slot=&speedTable[0];slot!=&speedTable[MAX_LOCOS];slot++)
|
||||
|
||||
void DCC::begin() {
|
||||
StringFormatter::send(&USB_SERIAL,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
|
||||
#ifndef DISABLE_EEPROM
|
||||
@@ -72,13 +76,49 @@ void DCC::begin() {
|
||||
#endif
|
||||
}
|
||||
|
||||
byte DCC::defaultMomentumA=0;
|
||||
byte DCC::defaultMomentumD=0;
|
||||
bool DCC::linearAcceleration=false;
|
||||
|
||||
byte DCC::getMomentum(LOCO * slot) {
|
||||
auto target=slot->targetSpeed & 0x7f;
|
||||
auto current=slot->speedCode & 0x7f;
|
||||
if (target > current) {
|
||||
// accelerating
|
||||
auto momentum=slot->momentumA==MOMENTUM_USE_DEFAULT ? defaultMomentumA : slot->momentumA;
|
||||
// if nonlinear acceleration, momentum is reduced according to
|
||||
// gap between throttle and speed.
|
||||
// ie. Loco takes accelerates faster if high throttle
|
||||
if (momentum==0 || linearAcceleration) return momentum;
|
||||
auto powerDifference= (target-current)/8;
|
||||
if (momentum-powerDifference <0) return 0;
|
||||
return momentum-powerDifference;
|
||||
}
|
||||
return slot->momentumD==MOMENTUM_USE_DEFAULT ? defaultMomentumD : slot->momentumD;
|
||||
}
|
||||
|
||||
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
|
||||
if (tSpeed==1) {
|
||||
if (cab==0) {
|
||||
estopAll(); // ESTOP broadcast fix
|
||||
return;
|
||||
}
|
||||
}
|
||||
byte speedCode = (tSpeed & 0x7F) + tDirection * 128;
|
||||
setThrottle2(cab, speedCode);
|
||||
TrackManager::setDCSignal(cab,speedCode); // in case this is a dcc track on this addr
|
||||
// retain speed for loco reminders
|
||||
updateLocoReminder(cab, speedCode );
|
||||
LOCO * slot=lookupSpeedTable(cab);
|
||||
if (slot->targetSpeed==speedCode) return;
|
||||
slot->targetSpeed=speedCode;
|
||||
byte momentum=getMomentum(slot);
|
||||
if (momentum && tSpeed!=1) { // not ESTOP
|
||||
// we dont throttle speed, we just let the reminders take it to target
|
||||
slot->momentum_base=millis();
|
||||
}
|
||||
else { // Momentum not involved, throttle now.
|
||||
slot->speedCode = speedCode;
|
||||
setThrottle2(cab, speedCode);
|
||||
TrackManager::setDCSignal(cab,speedCode); // in case this is a dcc track on this addr
|
||||
}
|
||||
CommandDistributor::broadcastLoco(slot);
|
||||
}
|
||||
|
||||
void DCC::setThrottle2( uint16_t cab, byte speedCode) {
|
||||
@@ -118,8 +158,8 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) {
|
||||
b[nB++] = speedCode; // for encoding see setThrottle
|
||||
|
||||
}
|
||||
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 0);
|
||||
if ((speedCode & 0x7F) == 1) DCCQueue::scheduleEstopPacket(b, nB, 4, cab); // highest priority
|
||||
else DCCQueue::scheduleDCCSpeedPacket( b, nB, 4, cab);
|
||||
}
|
||||
|
||||
void DCC::setFunctionInternal(int cab, byte byte1, byte byte2, byte count) {
|
||||
@@ -133,24 +173,28 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2, byte count) {
|
||||
if (byte1!=0) b[nB++] = byte1;
|
||||
b[nB++] = byte2;
|
||||
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, count);
|
||||
DCCQueue::scheduleDCCPacket(b, nB, count);
|
||||
}
|
||||
|
||||
// returns speed steps 0 to 127 (1 == emergency stop)
|
||||
// or -1 on "loco not found"
|
||||
int8_t DCC::getThrottleSpeed(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0) return -1;
|
||||
return speedTable[reg].speedCode & 0x7F;
|
||||
return getThrottleSpeedByte(cab) & 0x7F;
|
||||
}
|
||||
|
||||
// returns speed code byte
|
||||
// or 128 (speed 0, dir forward) on "loco not found".
|
||||
// This is the throttle set speed
|
||||
uint8_t DCC::getThrottleSpeedByte(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0)
|
||||
return 128;
|
||||
return speedTable[reg].speedCode;
|
||||
LOCO * slot=lookupSpeedTable(cab,false);
|
||||
return slot?slot->targetSpeed:128;
|
||||
}
|
||||
// returns speed code byte for loco.
|
||||
// This is the most recently send DCC speed packet byte
|
||||
// or 128 (speed 0, dir forward) on "loco not found".
|
||||
uint8_t DCC::getLocoSpeedByte(int cab) {
|
||||
LOCO* slot=lookupSpeedTable(cab,false);
|
||||
return slot?slot->speedCode:128;
|
||||
}
|
||||
|
||||
// returns 0 to 7 for frequency
|
||||
@@ -159,12 +203,11 @@ uint8_t DCC::getThrottleFrequency(int cab) {
|
||||
(void)cab;
|
||||
return 0;
|
||||
#else
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0)
|
||||
return 0; // use default frequency
|
||||
LOCO* slot=lookupSpeedTable(cab);
|
||||
if (!slot) return 0; // use default frequency
|
||||
// shift out first 29 bits so we have the 3 "frequency bits" left
|
||||
uint8_t res = (uint8_t)(speedTable[reg].functions >>29);
|
||||
//DIAG(F("Speed table %d functions %l shifted %d"), reg, speedTable[reg].functions, res);
|
||||
uint8_t res = (uint8_t)(slot->functions >>29);
|
||||
//DIAG(F("Speed table %d functions %l shifted %d"), reg, slot->functions, res);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
@@ -172,9 +215,7 @@ uint8_t DCC::getThrottleFrequency(int cab) {
|
||||
// returns direction on loco
|
||||
// or true/forward on "loco not found"
|
||||
bool DCC::getThrottleDirection(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0) return true;
|
||||
return (speedTable[reg].speedCode & 0x80) !=0;
|
||||
return getThrottleSpeedByte(cab) & 0x80;
|
||||
}
|
||||
|
||||
// Set function to value on or off
|
||||
@@ -198,7 +239,7 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
b[nB++] = (functionNumber & 0x7F) | (on ? 0x80 : 0); // low order bits and state flag
|
||||
b[nB++] = functionNumber >>7 ; // high order bits
|
||||
}
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
||||
DCCQueue::scheduleDCCPacket(b, nB, 4);
|
||||
}
|
||||
// We use the reminder table up to 28 for normal functions.
|
||||
// We use 29 to 31 for DC frequency as well so up to 28
|
||||
@@ -207,22 +248,21 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
if (functionNumber > 31)
|
||||
return true;
|
||||
|
||||
int reg = lookupSpeedTable(cab);
|
||||
if (reg<0) return false;
|
||||
|
||||
LOCO * slot = lookupSpeedTable(cab);
|
||||
|
||||
// Take care of functions:
|
||||
// Set state of function
|
||||
uint32_t previous=speedTable[reg].functions;
|
||||
uint32_t previous=slot->functions;
|
||||
uint32_t funcmask = (1UL<<functionNumber);
|
||||
if (on) {
|
||||
speedTable[reg].functions |= funcmask;
|
||||
slot->functions |= funcmask;
|
||||
} else {
|
||||
speedTable[reg].functions &= ~funcmask;
|
||||
slot->functions &= ~funcmask;
|
||||
}
|
||||
if (speedTable[reg].functions != previous) {
|
||||
if (slot->functions != previous) {
|
||||
if (functionNumber <= 28)
|
||||
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
updateGroupflags(slot->groupFlags, functionNumber);
|
||||
CommandDistributor::broadcastLoco(slot);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -239,12 +279,10 @@ void DCC::changeFn( int cab, int16_t functionNumber) {
|
||||
int8_t DCC::getFn( int cab, int16_t functionNumber) {
|
||||
if (cab<=0 || functionNumber>31)
|
||||
return -1; // unknown
|
||||
int reg = lookupSpeedTable(cab);
|
||||
if (reg<0)
|
||||
return -1;
|
||||
|
||||
auto slot = lookupSpeedTable(cab);
|
||||
|
||||
unsigned long funcmask = (1UL<<functionNumber);
|
||||
return (speedTable[reg].functions & funcmask)? 1 : 0;
|
||||
return (slot->functions & funcmask)? 1 : 0;
|
||||
}
|
||||
|
||||
// Set the group flag to say we have touched the particular group.
|
||||
@@ -261,22 +299,22 @@ void DCC::updateGroupflags(byte & flags, int16_t functionNumber) {
|
||||
|
||||
uint32_t DCC::getFunctionMap(int cab) {
|
||||
if (cab<=0) return 0; // unknown pretend all functions off
|
||||
int reg = lookupSpeedTable(cab);
|
||||
return (reg<0)?0:speedTable[reg].functions;
|
||||
auto slot = lookupSpeedTable(cab,false);
|
||||
return slot?slot->functions:0;
|
||||
}
|
||||
|
||||
// saves DC frequency (0..3) in spare functions 29,30,31
|
||||
void DCC::setDCFreq(int cab,byte freq) {
|
||||
if (cab==0 || freq>3) return;
|
||||
auto reg=lookupSpeedTable(cab,true);
|
||||
auto slot=lookupSpeedTable(cab,true);
|
||||
// drop and replace F29,30,31 (top 3 bits)
|
||||
auto newFunctions=speedTable[reg].functions & 0x1FFFFFFFUL;
|
||||
auto newFunctions=slot->functions & 0x1FFFFFFFUL;
|
||||
if (freq==1) newFunctions |= (1UL<<29); // F29
|
||||
else if (freq==2) newFunctions |= (1UL<<30); // F30
|
||||
else if (freq==3) newFunctions |= (1UL<<31); // F31
|
||||
if (newFunctions==speedTable[reg].functions) return; // no change
|
||||
speedTable[reg].functions=newFunctions;
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
if (newFunctions==slot->functions) return; // no change
|
||||
slot->functions=newFunctions;
|
||||
CommandDistributor::broadcastLoco(slot);
|
||||
}
|
||||
|
||||
void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) {
|
||||
@@ -302,16 +340,17 @@ void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) {
|
||||
// second byte is of the form 1AAACPPG, where C is 1 for on, PP the ports 0 to 3 and G the gate (coil).
|
||||
b[0] = address % 64 + 128;
|
||||
b[1] = ((((address / 64) % 8) << 4) + (port % 4 << 1) + gate % 2) ^ 0xF8;
|
||||
if (onoff != 0) {
|
||||
DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat on packet three times
|
||||
#if defined(EXRAIL_ACTIVE)
|
||||
RMFT2::activateEvent(address<<2|port,gate);
|
||||
#endif
|
||||
}
|
||||
if (onoff != 1) {
|
||||
if (onoff==0) { // off packet only
|
||||
b[1] &= ~0x08; // set C to 0
|
||||
DCCWaveform::mainTrack.schedulePacket(b, 2, 3); // Repeat off packet three times
|
||||
}
|
||||
DCCQueue::scheduleDCCPacket(b, 2, 3);
|
||||
} else if (onoff==1) { // on packet only
|
||||
DCCQueue::scheduleDCCPacket(b, 2, 3);
|
||||
} else { // auto timed on then off
|
||||
DCCQueue::scheduleAccOnOffPacket(b, 2, 3, 100); // On then off after 100mS
|
||||
}
|
||||
#if defined(EXRAIL_ACTIVE)
|
||||
if (onoff !=0) RMFT2::activateEvent(address<<2|port,gate);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DCC::setExtendedAccessory(int16_t address, int16_t value, byte repeats) {
|
||||
@@ -361,7 +400,7 @@ whole range of the 11 bits sent to track.
|
||||
| (((~(address>>8)) & 0x07)<<4) // shift out 8, invert, mask 3 bits, shift up 4
|
||||
| ((address & 0x03)<<1); // mask 2 bits, shift up 1
|
||||
b[2]=value;
|
||||
DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), repeats);
|
||||
DCCQueue::scheduleDCCPacket(b, sizeof(b), repeats);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -380,7 +419,26 @@ void DCC::writeCVByteMain(int cab, int cv, byte bValue) {
|
||||
b[nB++] = cv2(cv);
|
||||
b[nB++] = bValue;
|
||||
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
||||
DCCQueue::scheduleDCCPacket(b, nB, 4);
|
||||
}
|
||||
|
||||
//
|
||||
// readCVByteMain: Read a byte with PoM on main.
|
||||
// This requires Railcom active
|
||||
//
|
||||
void DCC::readCVByteMain(int cab, int cv, ACK_CALLBACK callback) {
|
||||
byte b[5];
|
||||
byte nB = 0;
|
||||
if (cab > HIGHEST_SHORT_ADDR)
|
||||
b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address
|
||||
|
||||
b[nB++] = lowByte(cab);
|
||||
b[nB++] = cv1(READ_BYTE_MAIN, cv); // any CV>1023 will become modulus(1024) due to bit-mask of 0x03
|
||||
b[nB++] = cv2(cv);
|
||||
b[nB++] = 0;
|
||||
|
||||
DCCQueue::scheduleDCCPacket(b, nB, 4);
|
||||
Railcom::anticipate(cab,cv,callback);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -401,7 +459,45 @@ void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) {
|
||||
b[nB++] = cv2(cv);
|
||||
b[nB++] = WRITE_BIT | (bValue ? BIT_ON : BIT_OFF) | bNum;
|
||||
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
||||
DCCQueue::scheduleDCCPacket(b, nB, 4);
|
||||
}
|
||||
|
||||
bool DCC::setTime(uint16_t minutes,uint8_t speed, bool suddenChange) {
|
||||
/* see rcn-122
|
||||
5 Global commands
|
||||
These commands are sent and begin exclusively with a broadcast address 0
|
||||
always with {synchronous bits} 0 0000-0000 … and end with the checksum
|
||||
... PPPPPPPP 1. Therefore, only the bytes of the commands and not that of
|
||||
shown below whole package shown. The commands can be used by vehicle and
|
||||
accessory decoders alike.
|
||||
|
||||
5.1 Time command
|
||||
This command is four bytes long and has the format:
|
||||
1100-0001 CCxx-xxxx xxxx-xxxxx xxxx-xxxx
|
||||
CC indicates what data is transmitted in the packet:
|
||||
CC = 00 Model Time
|
||||
1100-0001 00MM-MMMM WWWH-HHHH U0BB-BBBB with:
|
||||
MMMMMM = Minutes, Value range: 0..59
|
||||
WWW = Day of the Week, Value range: 0 = Monday, 1 = Tuesday, 2 = Wednesday,
|
||||
3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday, 7 = Weekday
|
||||
is not supported.
|
||||
HHHHH = Hours, value range: 0..23
|
||||
U =
|
||||
Update, i.e. the time has changed suddenly, e.g. by a new one timetable to start.
|
||||
Up to 4 can occur per sudden change commands can be marked like this.
|
||||
BBBBBB = Acceleration factor, value range 0..63. An acceleration factor of 0 means the
|
||||
model clock has been stopped, a factor of 1 corresponds to real time, at 2 the
|
||||
clock runs twice as fast, at three times as fast as real time, etc.
|
||||
*/
|
||||
if (minutes>=1440 || speed>63 ) return false;
|
||||
byte b[5];
|
||||
b[0]=0; // broadcast address
|
||||
b[1]=0b11000001; // 1100-0001 (model time)
|
||||
b[2]=minutes % 60 ; // MM
|
||||
b[3]= 0b11100000 | (minutes/60); // 111H-HHHH weekday not supported
|
||||
b[4]= (suddenChange ? 0b10000000 : 0) | speed;
|
||||
DCCQueue::scheduleDCCPacket(b, sizeof(b), 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
FSH* DCC::getMotorShieldName() {
|
||||
@@ -732,10 +828,9 @@ void DCC::setConsistId(int id,bool reverse,ACK_CALLBACK callback) {
|
||||
|
||||
void DCC::forgetLoco(int cab) { // removes any speed reminders for this loco
|
||||
setThrottle2(cab,1); // ESTOP this loco if still on track
|
||||
int reg=lookupSpeedTable(cab, false);
|
||||
if (reg>=0) {
|
||||
speedTable[reg].loco=0;
|
||||
setThrottle2(cab,1); // ESTOP if this loco still on track
|
||||
auto slot=lookupSpeedTable(cab, false);
|
||||
if (slot) {
|
||||
slot->loco=-1; // no longer used but not end of world
|
||||
CommandDistributor::broadcastForgetLoco(cab);
|
||||
}
|
||||
}
|
||||
@@ -743,7 +838,7 @@ void DCC::forgetAllLocos() { // removes all speed reminders
|
||||
setThrottle2(0,1); // ESTOP all locos still on track
|
||||
for (int i=0;i<MAX_LOCOS;i++) {
|
||||
if (speedTable[i].loco) CommandDistributor::broadcastForgetLoco(speedTable[i].loco);
|
||||
speedTable[i].loco=0;
|
||||
speedTable[i].loco=0; // no longer used and looks like end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,33 +846,79 @@ byte DCC::loopStatus=0;
|
||||
|
||||
void DCC::loop() {
|
||||
TrackManager::loop(); // power overload checks
|
||||
issueReminders();
|
||||
if (DCCWaveform::mainTrack.isReminderWindowOpen()) {
|
||||
// Now is a good time to choose a packet to be sent
|
||||
// Either highest priority from the queues or a reminder
|
||||
if (!DCCQueue::scheduleNext()) {
|
||||
issueReminders();
|
||||
DCCQueue::scheduleNext(); // push through any just created reminder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DCC::issueReminders() {
|
||||
// if the main track transmitter still has a pending packet, skip this time around.
|
||||
if (!DCCWaveform::mainTrack.isReminderWindowOpen()) return;
|
||||
// Move to next loco slot. If occupied, send a reminder.
|
||||
int reg = lastLocoReminder+1;
|
||||
if (reg > highestUsedReg) reg = 0; // Go to start of table
|
||||
if (speedTable[reg].loco > 0) {
|
||||
// have found loco to remind
|
||||
if (issueReminder(reg))
|
||||
lastLocoReminder = reg;
|
||||
} else
|
||||
lastLocoReminder = reg;
|
||||
auto slot = nextLocoReminder;
|
||||
if (slot >= &speedTable[MAX_LOCOS]) slot=&speedTable[0]; // Go to start of table
|
||||
if (slot->loco > 0)
|
||||
if (!issueReminder(slot))
|
||||
return;
|
||||
// a loco=0 is at the end of the list, a loco <0 is deleted
|
||||
if (slot->loco==0) nextLocoReminder = &speedTable[0];
|
||||
else nextLocoReminder=slot+1;
|
||||
}
|
||||
|
||||
bool DCC::issueReminder(int reg) {
|
||||
unsigned long functions=speedTable[reg].functions;
|
||||
int loco=speedTable[reg].loco;
|
||||
byte flags=speedTable[reg].groupFlags;
|
||||
int16_t normalize(byte speed) {
|
||||
if (speed & 0x80) return speed & 0x7F;
|
||||
return 0-1-speed;
|
||||
}
|
||||
byte dccalize(int16_t speed) {
|
||||
if (speed>127) return 0xFF; // 127 forward
|
||||
if (speed<-127) return 0x7F; // 127 reverse
|
||||
if (speed >=0) return speed | 0x80;
|
||||
// negative speeds... -1==dcc 0, -2==dcc 1
|
||||
return (int16_t)-1 - speed;
|
||||
}
|
||||
|
||||
bool DCC::issueReminder(LOCO * slot) {
|
||||
unsigned long functions=slot->functions;
|
||||
int loco=slot->loco;
|
||||
byte flags=slot->groupFlags;
|
||||
|
||||
switch (loopStatus) {
|
||||
case 0:
|
||||
// DIAG(F("Reminder %d speed %d"),loco,speedTable[reg].speedCode);
|
||||
setThrottle2(loco, speedTable[reg].speedCode);
|
||||
break;
|
||||
case 0: {
|
||||
// calculate any momentum change going on
|
||||
auto sc=slot->speedCode;
|
||||
if (slot->targetSpeed!=sc) {
|
||||
// calculate new speed code
|
||||
auto now=millis();
|
||||
int16_t delay=now-slot->momentum_base;
|
||||
auto millisPerNotch=MOMENTUM_FACTOR * (int16_t)getMomentum(slot);
|
||||
// allow for momentum change to 0 while accelerating/slowing
|
||||
auto ticks=(millisPerNotch>0)?(delay/millisPerNotch):500;
|
||||
if (ticks>0) {
|
||||
auto current=normalize(sc); // -128..+127
|
||||
auto target=normalize(slot->targetSpeed);
|
||||
// DIAG(F("Momentum l=%d ti=%d sc=%d c=%d t=%d"),loco,ticks,sc,current,target);
|
||||
if (current<target) { // accelerate
|
||||
current+=ticks;
|
||||
if (current>target) current=target;
|
||||
}
|
||||
else { // slow
|
||||
current-=ticks;
|
||||
if (current<target) current=target;
|
||||
}
|
||||
sc=dccalize(current);
|
||||
//DIAG(F("c=%d newsc=%d"),current,sc);
|
||||
slot->speedCode=sc;
|
||||
TrackManager::setDCSignal(loco,sc); // in case this is a dcc track on this addr
|
||||
slot->momentum_base=now;
|
||||
}
|
||||
}
|
||||
// DIAG(F("Reminder %d speed %d"),loco,slot->speedCode);
|
||||
setThrottle2(loco, sc);
|
||||
}
|
||||
break;
|
||||
case 1: // remind function group 1 (F0-F4)
|
||||
if (flags & FN_GROUP_1)
|
||||
#ifndef DISABLE_FUNCTION_REMINDERS
|
||||
@@ -838,70 +979,128 @@ byte DCC::cv2(int cv) {
|
||||
return lowByte(cv);
|
||||
}
|
||||
|
||||
int DCC::lookupSpeedTable(int locoId, bool autoCreate) {
|
||||
DCC::LOCO * DCC::lookupSpeedTable(int locoId, bool autoCreate) {
|
||||
// determine speed reg for this loco
|
||||
int firstEmpty = MAX_LOCOS;
|
||||
int reg;
|
||||
for (reg = 0; reg < MAX_LOCOS; reg++) {
|
||||
if (speedTable[reg].loco == locoId) break;
|
||||
if (speedTable[reg].loco == 0 && firstEmpty == MAX_LOCOS) firstEmpty = reg;
|
||||
LOCO * firstEmpty=nullptr;
|
||||
SLOTLOOP {
|
||||
if (firstEmpty==nullptr && slot->loco<=0) firstEmpty=slot;
|
||||
if (slot->loco == locoId) return slot;
|
||||
if (slot->loco==0) break;
|
||||
}
|
||||
|
||||
// return -1 if not found and not auto creating
|
||||
if (reg== MAX_LOCOS && !autoCreate) return -1;
|
||||
if (reg == MAX_LOCOS) reg = firstEmpty;
|
||||
if (reg >= MAX_LOCOS) {
|
||||
DIAG(F("Too many locos"));
|
||||
return -1;
|
||||
if (!autoCreate) return nullptr;
|
||||
if (firstEmpty==nullptr) {
|
||||
// return last slot if full
|
||||
DIAG(F("Too many locos, reusing last slot"));
|
||||
firstEmpty=&speedTable[MAX_LOCOS-1];
|
||||
}
|
||||
if (reg==firstEmpty){
|
||||
speedTable[reg].loco = locoId;
|
||||
speedTable[reg].speedCode=128; // default direction forward
|
||||
speedTable[reg].groupFlags=0;
|
||||
speedTable[reg].functions=0;
|
||||
}
|
||||
if (reg > highestUsedReg) highestUsedReg = reg;
|
||||
return reg;
|
||||
// fill first empty slot with new entry
|
||||
firstEmpty->loco = locoId;
|
||||
firstEmpty->speedCode=128; // default direction forward
|
||||
firstEmpty->targetSpeed=128; // default direction forward
|
||||
firstEmpty->groupFlags=0;
|
||||
firstEmpty->functions=0;
|
||||
firstEmpty->momentumA=MOMENTUM_USE_DEFAULT;
|
||||
firstEmpty->momentumD=MOMENTUM_USE_DEFAULT;
|
||||
return firstEmpty;
|
||||
}
|
||||
|
||||
void DCC::updateLocoReminder(int loco, byte speedCode) {
|
||||
|
||||
if (loco==0) {
|
||||
// broadcast stop/estop but dont change direction
|
||||
for (int reg = 0; reg <= highestUsedReg; reg++) {
|
||||
if (speedTable[reg].loco==0) continue;
|
||||
byte newspeed=(speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f);
|
||||
if (speedTable[reg].speedCode != newspeed) {
|
||||
speedTable[reg].speedCode = newspeed;
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
}
|
||||
}
|
||||
return;
|
||||
bool DCC::setMomentum(int locoId,int16_t accelerating, int16_t decelerating) {
|
||||
if (locoId<0) return false;
|
||||
if (locoId==0) {
|
||||
if (accelerating<0 || decelerating<0) return false;
|
||||
defaultMomentumA=accelerating/MOMENTUM_FACTOR;
|
||||
defaultMomentumD=decelerating/MOMENTUM_FACTOR;
|
||||
return true;
|
||||
}
|
||||
// -1 is ok and means this loco should use the default.
|
||||
if (accelerating<-1 || decelerating<-1) return false;
|
||||
if (accelerating/MOMENTUM_FACTOR >= MOMENTUM_USE_DEFAULT ||
|
||||
decelerating/MOMENTUM_FACTOR >= MOMENTUM_USE_DEFAULT) return false;
|
||||
|
||||
// Values stored are 255=MOMENTUM_USE_DEFAULT, or millis/MOMENTUM_FACTOR.
|
||||
// This is to keep the values in a byte rather than int16
|
||||
// thus saving 2 bytes RAM per loco slot.
|
||||
LOCO* slot=lookupSpeedTable(locoId,true);
|
||||
slot->momentumA=(accelerating<0)? MOMENTUM_USE_DEFAULT: (accelerating/MOMENTUM_FACTOR);
|
||||
slot->momentumD=(decelerating<0)? MOMENTUM_USE_DEFAULT: (decelerating/MOMENTUM_FACTOR);
|
||||
return true;
|
||||
}
|
||||
|
||||
// determine speed reg for this loco
|
||||
int reg=lookupSpeedTable(loco);
|
||||
if (reg>=0 && speedTable[reg].speedCode!=speedCode) {
|
||||
speedTable[reg].speedCode = speedCode;
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
|
||||
void DCC::estopAll() {
|
||||
setThrottle2(0,1); // estop all locos
|
||||
TrackManager::setDCSignal(0,1);
|
||||
|
||||
// remind stop/estop but dont change direction
|
||||
SLOTLOOP {
|
||||
if (slot->loco<=0) continue;
|
||||
byte newspeed=(slot->targetSpeed & 0x80) | 0x01;
|
||||
slot->speedCode = newspeed;
|
||||
slot->targetSpeed = newspeed;
|
||||
CommandDistributor::broadcastLoco(slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DCC::LOCO DCC::speedTable[MAX_LOCOS];
|
||||
int DCC::lastLocoReminder = 0;
|
||||
int DCC::highestUsedReg = 0;
|
||||
DCC::LOCO * DCC::nextLocoReminder = &DCC::speedTable[0];
|
||||
|
||||
|
||||
void DCC::displayCabList(Print * stream) {
|
||||
|
||||
StringFormatter::send(stream,F("<*\n"));
|
||||
int used=0;
|
||||
for (int reg = 0; reg <= highestUsedReg; reg++) {
|
||||
if (speedTable[reg].loco>0) {
|
||||
SLOTLOOP {
|
||||
if (slot->loco==0) break; // no more locos
|
||||
if (slot->loco>0) {
|
||||
used ++;
|
||||
StringFormatter::send(stream,F("cab=%d, speed=%d, dir=%c \n"),
|
||||
speedTable[reg].loco, speedTable[reg].speedCode & 0x7f,(speedTable[reg].speedCode & 0x80) ? 'F':'R');
|
||||
StringFormatter::send(stream,F("cab=%d, speed=%d, target=%d, momentum=%d/%d, block=%d\n"),
|
||||
slot->loco, slot->speedCode, slot->targetSpeed,
|
||||
slot->momentumA, slot->momentumD, slot->blockOccupied);
|
||||
}
|
||||
}
|
||||
StringFormatter::send(stream,F("Used=%d, max=%d\n"),used,MAX_LOCOS);
|
||||
|
||||
StringFormatter::send(stream,F("Used=%d, max=%d, momentum=%d/%d *>\n"),
|
||||
used,MAX_LOCOS, DCC::defaultMomentumA,DCC::defaultMomentumD);
|
||||
}
|
||||
|
||||
void DCC::setLocoInBlock(int loco, uint16_t blockid, bool exclusive) {
|
||||
// update block loco is in, tell exrail leaving old block, and entering new.
|
||||
|
||||
// NOTE: The loco table scanning is really inefficient and needs rewriting
|
||||
// This was done once in the momentum poc.
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
auto slot=lookupSpeedTable(loco,true);
|
||||
if (!slot) return;
|
||||
auto oldBlock=slot->blockOccupied;
|
||||
if (oldBlock==blockid) return;
|
||||
if (oldBlock) RMFT2::blockEvent(oldBlock,loco,false);
|
||||
slot->blockOccupied=blockid;
|
||||
if (blockid) RMFT2::blockEvent(blockid,loco,true);
|
||||
|
||||
if (exclusive) {
|
||||
SLOTLOOP {
|
||||
if (slot->loco==0) break; // no more locos
|
||||
if (slot->loco>0) {
|
||||
if (slot->loco!=loco && slot->blockOccupied==blockid) {
|
||||
RMFT2::blockEvent(blockid,slot->loco,false);
|
||||
slot->blockOccupied=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DCC::clearBlock(uint16_t blockid) {
|
||||
// Railcom reports block empty... tell Exrail about all leavers
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
SLOTLOOP {
|
||||
if (slot->loco==0) break; // no more locos
|
||||
if (slot->loco>0) {
|
||||
if (slot->blockOccupied==blockid) {
|
||||
RMFT2::blockEvent(blockid,slot->loco,false);
|
||||
slot->blockOccupied=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
32
DCC.h
32
DCC.h
@@ -3,7 +3,7 @@
|
||||
* © 2021 Fred Decker
|
||||
* © 2021 Herb Morton
|
||||
* © 2020-2021 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of Asbelos DCC API
|
||||
@@ -59,11 +59,15 @@ public:
|
||||
|
||||
// Public DCC API functions
|
||||
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||
static void estopAll();
|
||||
static int8_t getThrottleSpeed(int cab);
|
||||
static uint8_t getThrottleSpeedByte(int cab);
|
||||
static uint8_t getLocoSpeedByte(int cab); // may lag throttle
|
||||
static uint8_t getThrottleFrequency(int cab);
|
||||
static bool getThrottleDirection(int cab);
|
||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||
static void readCVByteMain(int cab, int cv, ACK_CALLBACK callback);
|
||||
|
||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
||||
static void setFunction(int cab, byte fByte, byte eByte);
|
||||
static bool setFn(int cab, int16_t functionNumber, bool on);
|
||||
@@ -83,7 +87,9 @@ public:
|
||||
static void writeCVBit(int16_t cv, byte bitNum, bool bitValue, ACK_CALLBACK callback);
|
||||
static void verifyCVByte(int16_t cv, byte byteValue, ACK_CALLBACK callback);
|
||||
static void verifyCVBit(int16_t cv, byte bitNum, bool bitValue, ACK_CALLBACK callback);
|
||||
|
||||
static bool setTime(uint16_t minutes,uint8_t speed, bool suddenChange);
|
||||
static void setLocoInBlock(int loco, uint16_t blockid, bool exclusive);
|
||||
static void clearBlock(uint16_t blockid);
|
||||
static void getLocoId(ACK_CALLBACK callback);
|
||||
static void setLocoId(int id,ACK_CALLBACK callback);
|
||||
static void setConsistId(int id,bool reverse,ACK_CALLBACK callback);
|
||||
@@ -102,20 +108,31 @@ public:
|
||||
byte speedCode;
|
||||
byte groupFlags;
|
||||
uint32_t functions;
|
||||
// Momentum management variables
|
||||
uint32_t momentum_base; // millis() when speed modified under momentum
|
||||
byte momentumA, momentumD;
|
||||
byte targetSpeed; // speed set by throttle
|
||||
uint16_t blockOccupied; // railcom detected block
|
||||
};
|
||||
static const int16_t MOMENTUM_FACTOR=7;
|
||||
static const byte MOMENTUM_USE_DEFAULT=255;
|
||||
static bool linearAcceleration;
|
||||
static byte getMomentum(LOCO * slot);
|
||||
|
||||
static LOCO speedTable[MAX_LOCOS];
|
||||
static int lookupSpeedTable(int locoId, bool autoCreate=true);
|
||||
static LOCO * lookupSpeedTable(int locoId, bool autoCreate=true);
|
||||
static byte cv1(byte opcode, int cv);
|
||||
static byte cv2(int cv);
|
||||
static bool setMomentum(int locoId,int16_t accelerating, int16_t decelerating);
|
||||
|
||||
private:
|
||||
static byte loopStatus;
|
||||
static byte defaultMomentumA; // Accelerating
|
||||
static byte defaultMomentumD; // Accelerating
|
||||
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
||||
static void updateLocoReminder(int loco, byte speedCode);
|
||||
static void setFunctionInternal(int cab, byte fByte, byte eByte, byte count);
|
||||
static bool issueReminder(int reg);
|
||||
static int lastLocoReminder;
|
||||
static int highestUsedReg;
|
||||
static bool issueReminder(LOCO * slot);
|
||||
static LOCO* nextLocoReminder;
|
||||
static FSH *shieldName;
|
||||
static byte globalSpeedsteps;
|
||||
|
||||
@@ -126,6 +143,7 @@ private:
|
||||
// NMRA codes #
|
||||
static const byte SET_SPEED = 0x3f;
|
||||
static const byte WRITE_BYTE_MAIN = 0xEC;
|
||||
static const byte READ_BYTE_MAIN = 0xE4;
|
||||
static const byte WRITE_BIT_MAIN = 0xE8;
|
||||
static const byte WRITE_BYTE = 0x7C;
|
||||
static const byte VERIFY_BYTE = 0x74;
|
||||
|
634
DCCEXCommands.h
Normal file
634
DCCEXCommands.h
Normal file
@@ -0,0 +1,634 @@
|
||||
/*
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021-2025 Herb Morton
|
||||
* © 2020-2023 Harald Barth
|
||||
* © 2020-2021 M Steve Todd
|
||||
* © 2020-2021 Fred Decker
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2022 Colin Murdoch
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
List of single character OPCODEs in use for reference.
|
||||
|
||||
When determining a new OPCODE for a new feature, refer to this list as the source of truth.
|
||||
|
||||
Once a new OPCODE is decided upon, update this list.
|
||||
|
||||
Character, Usage
|
||||
/, |EX-R| interactive commands
|
||||
-, Remove from reminder table
|
||||
=, |TM| configuration
|
||||
!, Emergency stop
|
||||
@, Reserved for future use - LCD messages to JMRI
|
||||
#, Request number of supported cabs/locos; heartbeat
|
||||
+, WiFi AT commands
|
||||
?, Reserved for future use
|
||||
0, Track power off
|
||||
1, Track power on
|
||||
a, DCC accessory control
|
||||
A, DCC extended accessory control
|
||||
b, Write CV bit on main
|
||||
B, Write CV bit
|
||||
c, Request current command
|
||||
C, configure the CS
|
||||
d,
|
||||
D, Diagnostic commands
|
||||
e, Erase EEPROM
|
||||
E, Store configuration in EEPROM
|
||||
f, Loco decoder function control (deprecated)
|
||||
F, Loco decoder function control
|
||||
g,
|
||||
G,
|
||||
h,
|
||||
H, Turnout state broadcast
|
||||
i, Server details string
|
||||
I, Turntable object command, control, and broadcast
|
||||
j, Throttle responses
|
||||
J, Throttle queries
|
||||
k, Block exit (Railcom)
|
||||
K, Block enter (Railcom)
|
||||
l, Loco speedbyte/function map broadcast
|
||||
L, Reserved for LCC interface (implemented in EXRAIL)
|
||||
m, message to throttles (broadcast output)
|
||||
m, set momentum
|
||||
M, Write DCC packet
|
||||
n, Reserved for SensorCam
|
||||
N, Reserved for Sensorcam
|
||||
o, Neopixel driver (see also IO_NeoPixel.h)
|
||||
O, Output broadcast
|
||||
p, Broadcast power state
|
||||
P, Write DCC packet
|
||||
q, Sensor deactivated
|
||||
Q, Sensor activated
|
||||
r, Broadcast address read on programming track
|
||||
R, Read CVs
|
||||
s, Display status
|
||||
S, Sensor configuration
|
||||
t, Cab/loco update command
|
||||
T, Turnout configuration/control
|
||||
u, Reserved for user commands
|
||||
U, Reserved for user commands
|
||||
v,
|
||||
V, Verify CVs
|
||||
w, Write CV on main
|
||||
W, Write CV
|
||||
x,
|
||||
X, Invalid command response
|
||||
y,
|
||||
Y, Output broadcast
|
||||
z, Direct output
|
||||
Z, Output configuration/control
|
||||
*/
|
||||
/*
|
||||
Each ZZ macro matches a command opcode and its parameters.
|
||||
Paramters in UPPER case are matched as keywords, parameters in lower case are values provided by the user.
|
||||
Its important to recognise that if the same opcode has more than one match with the same length, you must match the
|
||||
keywprds before picking up user values.
|
||||
e.g.
|
||||
ZZ(X,value1,value2)
|
||||
ZZ(X,SET,value1) This will never be matched.
|
||||
|
||||
|
||||
Use of the CHECK() macro validates a condition to be true.
|
||||
If the condition is false an error is genarated, resulting in an <X> reply.
|
||||
Commonly known parameters such as loco, cv bitvalue etc are range checked automatically.
|
||||
The REPLY( format, ...) macro sends a formatted string to the stream.
|
||||
|
||||
These macros are included into the DCCEXParser::execute function so
|
||||
stream, ringStream and other DCCEXParser variables are available in context. */
|
||||
|
||||
|
||||
|
||||
ZZBEGIN
|
||||
ZZ(#) // Request number of simultaneously supported locos
|
||||
REPLY( "<# %d>\n", MAX_LOCOS)
|
||||
ZZ(!) // Emergency stop all locos
|
||||
DCC::estopAll();
|
||||
ZZ(t,loco) // Request loco status
|
||||
CommandDistributor::broadcastLoco(DCC::lookupSpeedTable(loco,false));
|
||||
ZZ(t,loco,tspeed,direction) // Set throttle speed(0..127) and direction (0=reverse, 1=fwd)
|
||||
CHECK(setThrottle(loco,tspeed,direction))
|
||||
ZZ(t,ignore,loco,tspeed,direction) // (Deprecated) Set throttle speed and direction
|
||||
CHECK(setThrottle(loco,tspeed,direction))
|
||||
ZZ(f,loco,byte1) // (Deprecated use F) Set loco function group
|
||||
switch ( byte1 & 0b11110000) { // 1111 0000
|
||||
case 0b11100000: // 111x xxxx Function group 1 F0..F4
|
||||
case 0b11110000:
|
||||
// Shuffle bits from order F0 F4 F3 F2 F1 to F4 F3 F2 F1 F0
|
||||
return (funcmap(loco, (byte1 << 1 & 0x1e) | (byte1 >> 4 & 0x01), 0, 4));
|
||||
case 0b10110000: // 1011 xxxx Function group 2 F5..F8
|
||||
return (funcmap(loco, byte1, 5, 8));
|
||||
case 0b10100000: // 1010 xxxx Function group 3 F9..F12
|
||||
return (funcmap(loco, byte1, 9, 12));
|
||||
default:
|
||||
CHECK(false,Invalid function group)
|
||||
}
|
||||
ZZ(f,loco,group,byte2) // (Deprecated use F) Set loco function group
|
||||
if (group == 222) return (funcmap(loco, byte2, 13, 20));
|
||||
if (group == 223) return (funcmap(loco, byte2, 21, 28));
|
||||
CHECK(false,Invalid function group)
|
||||
ZZ(T) // List all turnouts
|
||||
Turnout::printAll(stream); // will <X> if none found
|
||||
ZZ(T,id) // Delete turnout
|
||||
CHECK(Turnout::remove(id))
|
||||
ZZ(T,id,X) // List turnout details
|
||||
auto tt=Turnout::get(id); CHECK(tt) tt->print(stream);
|
||||
ZZ(T,id,T) // Throw Turnout
|
||||
Turnout::setClosed(id, false);
|
||||
ZZ(T,id,C) // Close turnout#
|
||||
Turnout::setClosed(id, true);
|
||||
ZZ(T,id,value) // Close (value=0) ot Throw turnout
|
||||
Turnout::setClosed(id, value==0);
|
||||
ZZ(T,id,SERVO,vpin,closedValue,thrownValue) // Create Servo turnout
|
||||
CHECK(ServoTurnout::create(id, (VPIN)vpin, (uint16_t)closedValue, (uint16_t)thrownValue, 1))
|
||||
ZZ(T,id,VPIN,vpin) // Create pin turnout
|
||||
CHECK(VpinTurnout::create(id, vpin))
|
||||
ZZ(T,id,DCC,addr,subadd) // Create DCC turnout
|
||||
CHECK(DCCTurnout::create(id, addr, subadd))
|
||||
ZZ(T,id,DCC,linearAddr) // Create DCC turnout
|
||||
CHECK(DCCTurnout::create(id, (linearAddr-1)/4+1, (linearAddr-1)%4))
|
||||
ZZ(T,id,addr,subadd) // Create DCC turnout
|
||||
CHECK(DCCTurnout::create(id, addr, subadd))
|
||||
ZZ(T,id,vpin,closedValue,thrownValue) // Create SERVO turnout
|
||||
CHECK(ServoTurnout::create(id, (VPIN)vpin, (uint16_t)closedValue, (uint16_t)thrownValue, 1))
|
||||
ZZ(S,id,vpin,pullup) // Create Sensor
|
||||
CHECK(Sensor::create(id,vpin,pullup))
|
||||
ZZ(S,id) // Delete sensor
|
||||
CHECK(Sensor::remove(id))
|
||||
ZZ(S) // List sensors
|
||||
for (auto *tt = Sensor::firstSensor; tt; tt = tt->nextSensor) {
|
||||
REPLY("<Q %d %d %d>\n", tt->data.snum, tt->data.pin, tt->data.pullUp)
|
||||
}
|
||||
ZZ(J,M) // List stash values
|
||||
Stash::list(stream);
|
||||
ZZ(J,M,stash_id) // get stash value
|
||||
Stash::list(stream, stash_id);
|
||||
ZZ(J,M,CLEAR,ALL) // Clear all stash values
|
||||
Stash::clearAll();
|
||||
ZZ(J,M,CLEAR,stash_id) // Clear given stash
|
||||
Stash::clear(stash_id);
|
||||
ZZ(J,M,stashId,locoId) // Set stash value
|
||||
Stash::set(stashId,locoId);
|
||||
ZZ(J,M,CLEAR,ANY,locoId) // Clear all stash entries that contain locoId
|
||||
Stash::clearAny(locoId);
|
||||
ZZ(J,C) // get fastclock time
|
||||
REPLY("<jC %d>\n", CommandDistributor::retClockTime())
|
||||
ZZ(J,C,mmmm,nn) // Set fastclock time
|
||||
CommandDistributor::setClockTime(mmmm, nn, 1);
|
||||
ZZ(J,G) // FReport gauge limits
|
||||
TrackManager::reportGauges(stream);
|
||||
ZZ(J,I) // Report currents
|
||||
TrackManager::reportCurrent(stream);
|
||||
// TODO... Ask @Ash zz(J,L,display,row) // Direct current displays to LCS/OLED
|
||||
// TrackManager::reportCurrentLCD(display,row); // Track power status
|
||||
ZZ(J,A) // List Routes
|
||||
REPLY( "<jA>\n")
|
||||
ZZ(J,R) // List Roster
|
||||
REPLY("<jR")
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
SENDFLASHLIST(stream,RMFT2::rosterIdList)
|
||||
#endif
|
||||
REPLY(">\n");
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
ZZ(J,R,id) // Get roster for loco
|
||||
auto rosterName= RMFT2::getRosterName(id);
|
||||
if (!rosterName) rosterName=F("");
|
||||
auto functionNames= RMFT2::getRosterFunctions(id);
|
||||
if (!functionNames) functionNames=RMFT2::getRosterFunctions(0);
|
||||
if (!functionNames) functionNames=F("");
|
||||
REPLY("<jR %d \"%S\" \"%S\">\n",id, rosterName, functionNames)
|
||||
#endif
|
||||
ZZ(J,T) // Get turnout list
|
||||
REPLY("<jT")
|
||||
for ( auto t=Turnout::first(); t; t=t->next()) if (!t->isHidden()) REPLY(" %d",t->getId())
|
||||
REPLY(">\n");
|
||||
ZZ(J,T,id) // Get turnout state and description
|
||||
auto t=Turnout::get(id);
|
||||
if (!t || t->isHidden()) { REPLY("<jT %d X>\n",id) return true; }
|
||||
const FSH *tdesc=nullptr;
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
tdesc = RMFT2::getTurnoutDescription(id);
|
||||
#endif
|
||||
if (!tdesc) tdesc = F("");
|
||||
REPLY("<jT %d %c \"%S\">\n",id,t->isThrown()?'T':'C',tdesc)
|
||||
ZZ(z,vpin) // Set pin. HIGH iv vpin positive, LOW if vpin negative
|
||||
IODevice::write(vpin,(vpin>0)?HIGH:LOW);
|
||||
ZZ(z,vpin,analog,profile,duration) // Change analog value over duration (Fade or servo move)
|
||||
IODevice::writeAnalogue(vpin,analog,profile,duration);
|
||||
ZZ(z,vpin,analog,profile) // Write analog device using profile number (Fade or servo movement)
|
||||
IODevice::writeAnalogue(vpin,analog,profile,0);
|
||||
ZZ(z,vpin,analog) // Write analog device value
|
||||
IODevice::writeAnalogue(vpin,analog,0,0);
|
||||
|
||||
// ==========================
|
||||
// Turntable - no support if no HAL
|
||||
// <I> - list all
|
||||
// <I id> - broadcast type and current position
|
||||
// <I id DCC> - create DCC - This is TBA
|
||||
// <I id steps> - operate (DCC)
|
||||
// <I id steps activity> - operate (EXTT)
|
||||
// <I id ADD position value> - add position
|
||||
// <I id EXTT i2caddress vpin home> - create EXTT
|
||||
|
||||
ZZ(I) // List all turntables
|
||||
return Turntable::printAll(stream);
|
||||
ZZ(I,id) // Broadcast turntable type and current position
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(tto,Turntable not found)
|
||||
REPLY("<I %d %d>\n", tto->isEXTT(), tto->getPosition())
|
||||
ZZ(I,id,position) // Rotate a DCC turntable
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(tto,Turntable not found)
|
||||
CHECK(!tto->isEXTT(),Turntable type incorrect)
|
||||
CHECK(tto->setPosition(id,position))
|
||||
|
||||
ZZ(I,id,DCC,home) // Create DCC turntable
|
||||
CHECK(home >=0 && home <= 3600)
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(!tto,Turntable already exists)
|
||||
CHECK(DCCTurntable::create(id))
|
||||
tto = Turntable::get(id);
|
||||
CHECK(tto)
|
||||
tto->addPosition(0, 0, home);
|
||||
REPLY("<I>\n")
|
||||
|
||||
ZZ(I,id,position,activity) // Rotate an EXTT turntable
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(tto,Turntable not found)
|
||||
CHECK(tto->isEXTT(), Turntable wrong type)
|
||||
CHECK(tto->setPosition(id, position,activity))
|
||||
|
||||
ZZ(I,id,EXTT,vpin,home) // Create an EXTT turntable
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(!tto,Turntable already exists)
|
||||
CHECK(home >= 0 && home <= 3600)
|
||||
CHECK(EXTTTurntable::create(id, (VPIN)vpin))
|
||||
tto = Turntable::get(id);
|
||||
tto->addPosition(0, 0, home);
|
||||
REPLY("<I>\n")
|
||||
|
||||
ZZ(I,id,ADD,position,value,angle) // Add turntable position
|
||||
auto tto = Turntable::get(id);
|
||||
CHECK(tto,Turntable not found)
|
||||
CHECK(position <= 48 && angle >=0 && angle <= 3600)
|
||||
tto->addPosition(id,value,angle);
|
||||
REPLY("<I>\n")
|
||||
|
||||
ZZ(Q) // List all sensors
|
||||
Sensor::printAll(stream);
|
||||
|
||||
ZZ(s) // Command station status
|
||||
REPLY("<iDCC-EX V-" VERSION " / " ARDUINO_TYPE " / %S G-" GITHUB_SHA ">\n", DCC::getMotorShieldName())
|
||||
CommandDistributor::broadcastPower(); // <s> is the only "get power status" command we have
|
||||
Turnout::printAll(stream); //send all Turnout states
|
||||
Sensor::printAll(stream); //send all Sensor states
|
||||
|
||||
|
||||
#ifndef DISABLE_EEPROM
|
||||
ZZ(E) // STORE EPROM
|
||||
EEStore::store();
|
||||
REPLY("<e %d %d %d>\n", EEStore::eeStore->data.nTurnouts, EEStore::eeStore->data.nSensors, EEStore::eeStore->data.nOutputs)
|
||||
ZZ(e) // CLEAR EPROM
|
||||
EEStore::clear();
|
||||
REPLY("<O>\n")
|
||||
#endif
|
||||
|
||||
ZZ(Z) // List Output definitions
|
||||
bool gotone = false;
|
||||
for (auto *tt = Output::firstOutput; tt ; tt = tt->nextOutput) {
|
||||
gotone = true;
|
||||
REPLY("<Y %d %d %d %d>\n",tt->data.id, tt->data.pin, tt->data.flags, tt->data.active)
|
||||
}
|
||||
CHECK(gotone,No Outputs found)
|
||||
|
||||
ZZ(Z,id,pin,iflag) // Create Output
|
||||
CHECK(id > 0 && iflag >= 0 && iflag <= 7 )
|
||||
CHECK(Output::create(id,pin,iflag, 1))
|
||||
REPLY("<O>\n")
|
||||
ZZ(Z,id,active) // Set output
|
||||
auto o = Output::get(id);
|
||||
CHECK(o,Output not found)
|
||||
o->activate(active);
|
||||
REPLY("<Y %d %d>\n", id,active)
|
||||
ZZ(Z,id) // Delete output
|
||||
CHECK(Output::remove(id))
|
||||
REPLY("<O>\n")
|
||||
|
||||
ZZ(D,ACK,ON) // Enable PROG track diagnostics
|
||||
Diag::ACK = true;
|
||||
ZZ(D,ACK,OFF) // Disable PROG track diagnostics
|
||||
Diag::ACK = false;
|
||||
ZZ(D,CABS) // Diagnostic display loco state table
|
||||
DCC::displayCabList(stream);
|
||||
ZZ(D,RAM) // Diagnostic display free RAM
|
||||
DIAG(F("Free memory=%d"), DCCTimer::getMinimumFreeMemory());
|
||||
ZZ(D,CMD,ON) // Enable command input diagnostics
|
||||
Diag::CMD = true;
|
||||
ZZ(D,CMD,OFF) // Disable command input diagnostics
|
||||
Diag::CMD = false;
|
||||
ZZ(D,RAILCOM,ON) // Enable Railcom diagnostics
|
||||
Diag::RAILCOM = true;
|
||||
ZZ(D,RAILCOM,OFF) // DIsable Railcom diagnostics
|
||||
Diag::RAILCOM = false;
|
||||
ZZ(D,WIFI,ON) // Enable Wifi diagnostics
|
||||
Diag::WIFI = true;
|
||||
ZZ(D,WIFI,OFF) // Disable Wifi diagnostics
|
||||
Diag::WIFI = false;
|
||||
ZZ(D,ETHERNET,ON) // Enable Ethernet diagnostics
|
||||
Diag::ETHERNET = true;
|
||||
ZZ(D,ETHERNET,OFF) // Disabel Ethernet diagnostics
|
||||
Diag::ETHERNET = false;
|
||||
ZZ(D,WIT,ON) // Enable Withrottle diagnostics
|
||||
Diag::WITHROTTLE = true;
|
||||
ZZ(D,WIT,OFF) // Disable Withrottle diagnostics
|
||||
Diag::WITHROTTLE = false;
|
||||
ZZ(D,LCN,ON) // Enable LCN Diagnostics
|
||||
Diag::LCN = true;
|
||||
ZZ(D,LCN,OFF) // Disabel LCN diagnostics
|
||||
Diag::LCN = false;
|
||||
ZZ(D,WEBSOCKET,ON) // Enable Websocket diagnostics
|
||||
Diag::WEBSOCKET = true;
|
||||
ZZ(D,WEBSOCKET,OFF) // Disable wensocket diagnostics
|
||||
Diag::WEBSOCKET = false;
|
||||
|
||||
#ifndef DISABLE_EEPROM
|
||||
ZZ(D,EEPROM,numentries) // Dump EEPROM contents
|
||||
EEStore::dump(numentries);
|
||||
#endif
|
||||
|
||||
|
||||
ZZ(D,ANOUT,vpin,position) // see <z vpin position>
|
||||
IODevice::writeAnalogue(vpin,position,0);
|
||||
ZZ(D,ANOUT,vpin,position,profile) // see <z vpin position profile>
|
||||
IODevice::writeAnalogue(vpin,position,profile);
|
||||
ZZ(D,SERVO,vpin,position) // Test servo
|
||||
IODevice::writeAnalogue(vpin,position,0);
|
||||
ZZ(D,SERVO,vpin,position,profile) // Test servo
|
||||
IODevice::writeAnalogue(vpin,position,profile);
|
||||
|
||||
ZZ(D,ANIN,vpin) // Display analogue input value
|
||||
DIAG(F("VPIN=%u value=%d"), vpin, IODevice::readAnalogue(vpin));
|
||||
|
||||
ZZ(D,HAL,SHOW) // Show HAL devices table
|
||||
IODevice::DumpAll();
|
||||
ZZ(D,HAL,RESET) // Reset all HAL devices
|
||||
IODevice::reset();
|
||||
ZZ(D,TT,vpin,steps) // Test turntable
|
||||
IODevice::writeAnalogue(vpin,steps,0);
|
||||
ZZ(D,TT,vpin,steps,activity) // Test turntable
|
||||
IODevice::writeAnalogue(vpin,steps,activity);
|
||||
|
||||
ZZ(C,PROGBOOST) // Configute PROG track boost
|
||||
TrackManager::progTrackBoosted=true;
|
||||
ZZ(C,RESET) // Reset and restart command station
|
||||
DCCTimer::reset();
|
||||
ZZ(C,SPEED28) // Set all DCC speed commands as 28 step to old decoders
|
||||
DCC::setGlobalSpeedsteps(28); DIAG(F("28 Speedsteps"));
|
||||
ZZ(C,SPEED128) // Set all DCC speed commands to 128 step (default)
|
||||
DCC::setGlobalSpeedsteps(128); DIAG(F("128 Speedsteps"));
|
||||
ZZ(C,RAILCOM,ON) // Enable Railcom cutout
|
||||
DIAG(F("Railcom %S"),DCCWaveform::setRailcom(true,false)?F("ON"):F("OFF"));
|
||||
ZZ(C,RAILCOM,OFF) // Disable Railcom cutout
|
||||
DIAG(F("Railcom OFF")); DCCWaveform::setRailcom(false,false);
|
||||
ZZ(C,RAILCOM,DEBUG) // Enable Railcom cutout for easy scope reading test
|
||||
DIAG(F("Railcom %S"), DCCWaveform::setRailcom(true,true)?F("ON"):F("OFF"));
|
||||
|
||||
#ifndef DISABLE_PROG
|
||||
ZZ(D,ACK,LIMIT,value) // Set ACK detection limit mA
|
||||
DCCACK::setAckLimit(value); LCD(1, F("Ack Limit=%dmA"), value);
|
||||
ZZ(D,ACK,MIN,value,MS) // Set ACK minimum duration mS
|
||||
DCCACK::setMinAckPulseDuration(value*1000L); LCD(1, F("Ack Min=%dmS"), value);
|
||||
ZZ(D,ACK,MIN,value) // Set ACK minimum duration uS
|
||||
DCCACK::setMinAckPulseDuration(value); LCD(1, F("Ack Min=%duS"), value);
|
||||
ZZ(D,ACK,MAX,value,MS) // Set ACK maximum duration mS
|
||||
DCCACK::setMaxAckPulseDuration(value*1000L); LCD(1, F("Ack Max=%dmS"), value);
|
||||
ZZ(D,ACK,MAX,value) // Set ACK maximum duration uS
|
||||
DCCACK::setMaxAckPulseDuration(value); LCD(1, F("Ack Max=%duS"), value);
|
||||
ZZ(D,ACK,RETRY,value) // Set ACK retry count
|
||||
DCCACK::setAckRetry(value); LCD(1, F("Ack Retry=%d"), value);
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// Dirty definition tricks because the executed check needs quote separation markers
|
||||
// that should be invisible to the doc extractor.
|
||||
// The equivalent documentation will be extracted from the commented line below
|
||||
// and the matchedFormat is hand modified to the correct format which includes quotes.
|
||||
|
||||
// (documented version) ZZ(C,WIFI,"ssid","password") // reconfigure stored wifi credentials
|
||||
ZZ_nodoc(C,WIFI,ssid,password)
|
||||
CHECK(false, ssid and password must be in "quotes")
|
||||
ZZ_nodoc(C,WIFI,marker1,ssid,marker2,password)
|
||||
DCCEXParser::matchedCommandFormat=F("C,WIFI,\"ssid\",\"password\""); // for error reporting
|
||||
CHECK(marker1==0x7777 && marker2==0x7777, ssid and password must be in "quotes")
|
||||
WifiESP::setup((const char*)(com + ssid), (const char*)(com + password), WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP);
|
||||
#endif
|
||||
|
||||
ZZ(o,vpin) // Set neopixel on(vpin>0) or off(vpin<0)
|
||||
IODevice::write(abs(vpin),vpin>0);
|
||||
ZZ(o,vpin,count) // Set multiple neopixels on(vpin>0) or off(vpin<0)
|
||||
IODevice::writeRange(abs(vpin),vpin>0,count);
|
||||
ZZ(o,vpin,r,g,b) // Set neopixel colour
|
||||
CHECK(r>=0 && r<=0xff && g>=0 && g<=0xff && b>=0 && b<=0xff, r,g,b values range 0..255)
|
||||
IODevice::writeAnalogueRange(abs(vpin),vpin>0,r<<8 | g,b,1);
|
||||
ZZ(o,vpin,r,g,b,count) // Set multiple neopixels colour
|
||||
CHECK(r>=0 && r<=0xff && g>=0 && g<=0xff && b>=0 && b<=0xff, r,g,b values range 0..255)
|
||||
IODevice::writeAnalogueRange(abs(vpin),vpin>0,r<<8 | g,b,count);
|
||||
|
||||
ZZ(1) // Power ON all tracks
|
||||
TrackManager::setTrackPower(TRACK_ALL, POWERMODE::ON);
|
||||
ZZ(1,MAIN) // Power on MAIN track
|
||||
TrackManager::setTrackPower(TRACK_MODE_MAIN, POWERMODE::ON);
|
||||
#ifndef DISABLE_PROG
|
||||
ZZ(1,PROG) // Power on PROG track
|
||||
TrackManager::setJoin(false); TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::ON);
|
||||
ZZ(1,JOIN) // JOIN prog track to MAIN and power
|
||||
TrackManager::setJoin(true); TrackManager::setTrackPower(TRACK_MODE_MAIN|TRACK_MODE_PROG, POWERMODE::ON);
|
||||
#endif
|
||||
ZZ(1,track) // Power on given track
|
||||
TrackManager::setTrackPower(POWERMODE::ON, (byte)track-'A');
|
||||
ZZ(0) // Power off all tracks
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::setTrackPower(TRACK_ALL, POWERMODE::OFF);
|
||||
ZZ(0,MAIN) // Power off MAIN track
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::setTrackPower(TRACK_MODE_MAIN, POWERMODE::OFF);
|
||||
ZZ(0,PROG) // Power off PROG track
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::progTrackBoosted=false;
|
||||
// todo move to TrackManager Prog track boost mode will not outlive prog track off
|
||||
TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::OFF);
|
||||
ZZ(0,track) // Power off given track
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::setTrackPower(POWERMODE::OFF, (byte)track-'a');
|
||||
|
||||
ZZ(c) // Report main track currect (Deprecated)
|
||||
TrackManager::reportObsoleteCurrent(stream);
|
||||
|
||||
ZZ(a,address,subaddress,activate) // Send DCC accessory command
|
||||
CHECK(activate==0 || activate ==1, invalid activate 0..1 )
|
||||
DCC::setAccessory(address, subaddress,activate ^ accessoryCommandReverse);
|
||||
ZZ(a,address,subaddress,activate,onoff) // Send DCC accessory command with onoff control (TODO.. numbers)
|
||||
CHECK(activate==0 || activate ==1, invalid activate 0..1 )
|
||||
CHECK(onoff>=0 && onoff<=2,invalid onoff 0..2 )
|
||||
DCC::setAccessory(address, subaddress,activate ^ accessoryCommandReverse ,onoff);
|
||||
ZZ(a,linearaddress,activate) // send dcc accessory command
|
||||
CHECK(activate==0 || activate ==1, invalid activate 0..1 )
|
||||
DCC::setAccessory((linearaddress - 1) / 4 + 1,(linearaddress - 1) % 4 ,activate ^ accessoryCommandReverse);
|
||||
ZZ(A,address,value) // Send DCC extended accessory (Aspect) command
|
||||
DCC::setExtendedAccessory(address,value);
|
||||
|
||||
ZZ(w,loco,cv,value) // POM write cv on main track
|
||||
DCC::writeCVByteMain(loco,cv,value);
|
||||
ZZ(r,loco,cv) // POM read cv on main track
|
||||
CHECK(DCCWaveform::isRailcom(),Railcom not active)
|
||||
EXPECT_CALLBACK
|
||||
DCC::readCVByteMain(loco,cv,callback_r);
|
||||
ZZ(b,loco,cv,bit,bitvalue) // POM write cv bit on main track
|
||||
DCC::writeCVBitMain(loco,cv,bit,bitvalue);
|
||||
|
||||
ZZ(m,LINEAR) // Set Momentum algorithm to linear acceleration
|
||||
DCC::linearAcceleration=true;
|
||||
ZZ(m,POWER) // Set momentum algortithm to very based on difference between current speed and throttle seting
|
||||
DCC::linearAcceleration=false;
|
||||
ZZ(m,loco,momentum) // set momentum for loco (accel and braking)
|
||||
CHECK(DCC::setMomentum(loco,momentum,momentum))
|
||||
ZZ(m,loco,accelerating,braking) // set momentum for loco
|
||||
CHECK(DCC::setMomentum(loco,accelerating,braking))
|
||||
|
||||
// todo reorder for more sensible doco.
|
||||
ZZ(W,cv,value,ignore1,ignore2) // (Deprecated) Write cv value on PROG track
|
||||
EXPECT_CALLBACK DCC::writeCVByte(cv,value, callback_W);
|
||||
ZZ(W,loco) // Write loco address on PROG track
|
||||
EXPECT_CALLBACK DCC::setLocoId(loco,callback_Wloco);
|
||||
ZZ(W,CONSIST,loco,REVERSE) // Write consist address and reverse flag on PROG track
|
||||
EXPECT_CALLBACK DCC::setConsistId(loco,true,callback_Wconsist);
|
||||
ZZ(W,CONSIST,loco) // write consist address on PROG track
|
||||
EXPECT_CALLBACK DCC::setConsistId(loco,false,callback_Wconsist);
|
||||
ZZ(W,cv,value) // Write cv value on PROG track
|
||||
EXPECT_CALLBACK DCC::writeCVByte(cv,value, callback_W);
|
||||
ZZ(W,cv,bitvalue,bit) // Write cv bit on prog track
|
||||
EXPECT_CALLBACK DCC::writeCVBit(cv,bitvalue,bit,callback_W);
|
||||
ZZ(V,cv,value) // Fast read cv with expected value
|
||||
EXPECT_CALLBACK DCC::verifyCVByte(cv,value, callback_Vbyte);
|
||||
ZZ(V,cv,bit,bitvalue) // Fast read bit with expected value
|
||||
EXPECT_CALLBACK DCC::verifyCVBit(cv,bit,bitvalue,callback_Vbit);
|
||||
ZZ(B,cv,bit,bitvalue) // Write cv bit
|
||||
EXPECT_CALLBACK DCC::writeCVBit(cv,bit,bitvalue,callback_B);
|
||||
ZZ(R,cv,ignore1,ignore2) // (Deprecated) read cv value on PROG track
|
||||
EXPECT_CALLBACK DCC::readCV(cv,callback_R);
|
||||
ZZ(R,cv) // Read cv
|
||||
EXPECT_CALLBACK DCC::verifyCVByte(cv, 0, callback_Vbyte);
|
||||
ZZ(R) // Read driveable loco id (may be long, short or consist)
|
||||
EXPECT_CALLBACK DCC::getLocoId(callback_Rloco);
|
||||
|
||||
#ifndef DISABLE_VDPY
|
||||
ZZ_nodoc(@) CommandDistributor::setVirtualLCDSerial(stream);
|
||||
REPLY( "<@ 0 0 \"DCC-EX v" VERSION "\">\n<@ 0 1 \"Lic GPLv3\">\n")
|
||||
#endif
|
||||
|
||||
ZZ(-) // Clear loco state and reminder table
|
||||
DCC::forgetAllLocos();
|
||||
ZZ(-,loco) // remove loco state amnd reminders
|
||||
DCC::forgetLoco(loco);
|
||||
ZZ(F,loco,DCCFREQ,freqvalue) // Set DC frequencey for loco
|
||||
CHECK(freqvalue>=0 && freqvalue<=3) DCC::setDCFreq(loco,freqvalue);
|
||||
ZZ(F,loco,function,onoff) // Set loco function ON/OFF
|
||||
CHECK(onoff==0 || onoff==1) DCC::setFn(loco,function,onoff);
|
||||
|
||||
// ZZ(M,ignore,d0,d1,d2,d3,d4,d5) // Send up to 5 byte DCC packet on MAIN track (all d values in hex)
|
||||
ZZ_nodoc(M,ignore,d0,d1,d2,d3,d4,d5) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3,(byte)d4,(byte)d5}; DCCWaveform::mainTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(M,ignore,d0,d1,d2,d3,d4) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3,(byte)d4}; DCCWaveform::mainTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(M,ignore,d0,d1,d2,d3) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3}; DCCWaveform::mainTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(M,ignore,d0,d1,d2) byte packet[]={(byte)d0,(byte)d1,(byte)d2}; DCCWaveform::mainTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(M,ignore,d0,d1) byte packet[]={(byte)d0,(byte)d1}; DCCWaveform::mainTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
// ZZ(P,ignore,d0,d1,d2,d3,d4,d5) // Send up to 5 byte DCC packet on PROG track (all d values in hex)
|
||||
ZZ_nodoc(P,ignore,d0,d1,d2,d3,d4,d5) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3,(byte)d4,(byte)d5}; DCCWaveform::progTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(P,ignore,d0,d1,d2,d3,d4) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3,(byte)d4}; DCCWaveform::progTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(P,ignore,d0,d1,d2,d3) byte packet[]={(byte)d0,(byte)d1,(byte)d2,(byte)d3}; DCCWaveform::progTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(P,ignore,d0,d1,d2) byte packet[]={(byte)d0,(byte)d1,(byte)d2}; DCCWaveform::progTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
ZZ_nodoc(P,ignore,d0,d1) byte packet[]={(byte)d0,(byte)d1}; DCCWaveform::progTrack.schedulePacket(packet,sizeof(packet),3);
|
||||
|
||||
ZZ(J,O) // List turntable IDs
|
||||
REPLY("<jO")
|
||||
for (auto tto=Turntable::first(); tto; tto=tto->next()) if (!tto->isHidden()) REPLY(" %d",tto->getId())
|
||||
REPLY(">\n")
|
||||
ZZ(J,O,id) // List turntable state
|
||||
auto tto=Turntable::get(id);
|
||||
if (!tto || tto->isHidden()) {REPLY("<jO %d X>\n", id) return true;}
|
||||
const FSH *todesc = nullptr;
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
todesc = RMFT2::getTurntableDescription(id);
|
||||
#endif
|
||||
if (todesc == nullptr) todesc = F("");
|
||||
REPLY("<jO %d %d %d %d \"%S\">\n", id, tto->isEXTT(), tto->getPosition(), tto->getPositionCount(), todesc)
|
||||
|
||||
ZZ(J,P,id) // list turntable positions
|
||||
auto tto=Turntable::get(id);
|
||||
if (!tto || tto->isHidden()) {REPLY("<jP %d X>\n", id) return true;}
|
||||
auto posCount = tto->getPositionCount();
|
||||
if (posCount==0) {REPLY("<jP X>\n") return true;}
|
||||
|
||||
for (auto p = 0; p < posCount; p++) {
|
||||
const FSH *tpdesc = nullptr;
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
tpdesc = RMFT2::getTurntablePositionDescription(id, p);
|
||||
#endif
|
||||
if (tpdesc == NULL) tpdesc = F("");
|
||||
REPLY("<jP %d %d %d \"%S\">\n", id, p, tto->getPositionAngle(p), tpdesc)
|
||||
}
|
||||
|
||||
// Track manager
|
||||
|
||||
ZZ(=) // list track manager states
|
||||
TrackManager::list(stream);
|
||||
ZZ(=,track,MAIN) // Set track to MAIN
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_MAIN))
|
||||
ZZ(=,track,MAIN_INV) // Set track to MAIN inverted polatity
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_MAIN_INV))
|
||||
ZZ(=,track,MAIN_AUTO) // Set track to MAIN with auto reversing
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_MAIN_AUTO))
|
||||
ZZ(=,track,PROG) // Set track to PROG
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_PROG))
|
||||
ZZ(=,track,OFF) // Set track power OFF
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_NONE))
|
||||
ZZ(=,track,NONE) // Set track no output
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_NONE))
|
||||
ZZ(=,track,EXT) // Set track to use external sync
|
||||
CHECK(TrackManager::setTrackMode(track,TRACK_MODE_EXT))
|
||||
|
||||
#ifdef BOOSTER_INPUT
|
||||
ZZ_nodoc(=,track,BOOST) CHECK(TrackManager::setTrackMode(track,TRACK_MODE_BOOST))
|
||||
ZZ_nodoc(=,track,BOOST_INV) CHECK(TrackManager::setTrackMode(track,TRACK_MODE_BOOST_INV))
|
||||
ZZ_nodoc(=,track,BOOST_AUTO) CHECK(TrackManager::setTrackMode(track,TRACK_MODE_BOOST_AUTO))
|
||||
#endif
|
||||
ZZ(=,track,AUTO) // Update track to auto reverse
|
||||
CHECK(TrackManager::orTrackMode(track, TRACK_MODIFIER_AUTO))
|
||||
ZZ(=,track,INV) // Update track to inverse polarity
|
||||
CHECK(TrackManager::orTrackMode(track, TRACK_MODIFIER_INV))
|
||||
ZZ(=,track,DC,loco) // Set track to DC
|
||||
CHECK(TrackManager::setTrackMode(track, TRACK_MODE_DC, loco))
|
||||
ZZ(=,track,DC_INV,loco) // Set track to DC with inverted polarity
|
||||
CHECK(TrackManager::setTrackMode(track, TRACK_MODE_DC_INV, loco))
|
||||
ZZ(=,track,DCX,loco) // Set track to DC with inverted polarity
|
||||
CHECK(TrackManager::setTrackMode(track, TRACK_MODE_DC_INV, loco))
|
||||
|
||||
ZZEND
|
1129
DCCEXParser.cpp
1129
DCCEXParser.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of Asbelos DCC API
|
||||
@@ -37,23 +37,21 @@ struct DCCEXParser
|
||||
static void parseOne(Print * stream, byte * command, RingStream * ringStream);
|
||||
static void setFilter(FILTER_CALLBACK filter);
|
||||
static void setRMFTFilter(FILTER_CALLBACK filter);
|
||||
static void setCamParserFilter(FILTER_CALLBACK filter);
|
||||
static void setAtCommandCallback(AT_COMMAND_CALLBACK filter);
|
||||
static const int MAX_COMMAND_PARAMS=10; // Must not exceed this
|
||||
|
||||
static const FSH * matchedCommandFormat;
|
||||
static const FSH * checkFailedFormat;
|
||||
|
||||
private:
|
||||
|
||||
#ifdef DCC_ACCESSORY_COMMAND_REVERSE
|
||||
static const bool accessoryCommandReverse = true;
|
||||
#else
|
||||
static const bool accessoryCommandReverse = false;
|
||||
#endif
|
||||
static const int16_t MAX_BUFFER=50; // longest command sent in
|
||||
static int16_t splitValues( int16_t result[MAX_COMMAND_PARAMS], byte * command, bool usehex);
|
||||
|
||||
static bool parseT(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parseZ(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parseS(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parsef(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parseC(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parseD(Print * stream, int16_t params, int16_t p[]);
|
||||
#ifndef IO_NO_HAL
|
||||
static bool parseI(Print * stream, int16_t params, int16_t p[]);
|
||||
#endif
|
||||
static bool execute(byte * command, Print * stream, byte opcode, byte params, int16_t p[], RingStream * ringStream);
|
||||
|
||||
static Print * getAsyncReplyStream();
|
||||
static void commitAsyncReplyStream();
|
||||
@@ -68,7 +66,8 @@ struct DCCEXParser
|
||||
static void callback_W(int16_t result);
|
||||
static void callback_W4(int16_t result);
|
||||
static void callback_B(int16_t result);
|
||||
static void callback_R(int16_t result);
|
||||
static void callback_R(int16_t result); // prog
|
||||
static void callback_r(int16_t result); // main
|
||||
static void callback_Rloco(int16_t result);
|
||||
static void callback_Wloco(int16_t result);
|
||||
static void callback_Wconsist(int16_t result);
|
||||
@@ -76,9 +75,11 @@ struct DCCEXParser
|
||||
static void callback_Vbyte(int16_t result);
|
||||
static FILTER_CALLBACK filterCallback;
|
||||
static FILTER_CALLBACK filterRMFTCallback;
|
||||
static FILTER_CALLBACK filterCamParserCallback;
|
||||
static AT_COMMAND_CALLBACK atCommandCallback;
|
||||
static bool funcmap(int16_t cab, byte value, byte fstart, byte fstop);
|
||||
static void sendFlashList(Print * stream,const int16_t flashList[]);
|
||||
static bool setThrottle(int16_t cab,int16_t tspeed,int16_t direction);
|
||||
|
||||
};
|
||||
|
||||
|
90
DCCEXParserMacros.h
Normal file
90
DCCEXParserMacros.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// Count the number of arguments
|
||||
#define FOR_EACH_NARG(...) FOR_EACH_NARG_HELPER(__VA_ARGS__,8,7, 6,5,4, 3, 2, 1, 0)
|
||||
#define FOR_EACH_NARG_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
|
||||
|
||||
// Step 2: Force proper expansion (extra indirection to resolve `##`)
|
||||
#define EXPAND(x) x
|
||||
#define CONCAT(a, b) a##b
|
||||
|
||||
|
||||
#define ZZZ(_i,_arg) \
|
||||
if ( #_arg[0]<='Z' && p[_i]!=CONCAT(#_arg,_hk)) break; \
|
||||
auto _arg=p[_i]; (void) _arg;
|
||||
|
||||
// Each ZZ terminates the previous one
|
||||
#define ZPREP(op,count) return true; } if (opcode==#op[0] && params==count) for (;;) {
|
||||
#define Z1(op) ZPREP(op,0)
|
||||
#define Z2(op,_1) ZPREP(op,1) ZZZ(0,_1)
|
||||
#define Z3(op,_1,_2) ZPREP(op,2) ZZZ(0,_1) ZZZ(1,_2)
|
||||
#define Z4(op,_1,_2,_3) ZPREP(op,3) ZZZ(0,_1) ZZZ(1,_2) ZZZ(2,_3)
|
||||
#define Z5(op,_1,_2,_3,_4) ZPREP(op,4) ZZZ(0,_1) ZZZ(1,_2) ZZZ(2,_3) ZZZ(3,_4)
|
||||
#define Z6(op,_1,_2,_3,_4,_5) ZPREP(op,5) ZZZ(0,_1) ZZZ(1,_2) ZZZ(2,_3) ZZZ(3,_4) ZZZ(4,_5)
|
||||
#define Z7(op,_1,_2,_3,_4,_5,_6) ZPREP(op,6) ZZZ(0,_1) ZZZ(1,_2) ZZZ(2,_3) ZZZ(3,_4) ZZZ(4,_5) ZZZ(5,_6)
|
||||
#define Z8(op,_1,_2,_3,_4,_5,_6,_7) ZPREP(op,7) ZZZ(0,_1) ZZZ(1,_2) ZZZ(2,_3) ZZZ(3,_4) ZZZ(4,_5) ZZZ(5,_6) ZZZ(6,_7)
|
||||
|
||||
#define ZRIP(count) CONCAT(Z,count)
|
||||
|
||||
#define ZC1(op)
|
||||
#define ZC2(op,_1) ZZCHK(0,_1)
|
||||
#define ZC3(op,_1,_2) ZZCHK(0,_1) ZZCHK(1,_2)
|
||||
#define ZC4(op,_1,_2,_3) ZZCHK(0,_1) ZZCHK(1,_2) ZZCHK(2,_3)
|
||||
#define ZC5(op,_1,_2,_3,_4) ZZCHK(0,_1) ZZCHK(1,_2) ZZCHK(2,_3) ZZCHK(3,_4)
|
||||
#define ZC6(op,_1,_2,_3,_4,_5) ZZCHK(0,_1) ZZCHK(1,_2) ZZCHK(2,_3) ZZCHK(3,_4) ZZCHK(4,_5)
|
||||
#define ZC7(op,_1,_2,_3,_4,_5,_6) ZZCHK(0,_1) ZZCHK(1,_2) ZZCHK(2,_3) ZZCHK(3,_4) ZZCHK(4,_5) ZZCHK(5,_6)
|
||||
#define ZC8(op,_1,_2,_3,_4,_5,_6,_7) ZZCHK(0,_1) ZZCHK(1,_2) ZZCHK(2,_3) ZZCHK(3,_4) ZZCHK(4,_5) ZZCHK(5,_6) ZZCHK(6,_7)
|
||||
#define ZCRIP(count) CONCAT(ZC,count)
|
||||
|
||||
#define ZZ(...) \
|
||||
ZRIP(FOR_EACH_NARG(__VA_ARGS__))(__VA_ARGS__) \
|
||||
DCCEXParser::matchedCommandFormat = F( #__VA_ARGS__); \
|
||||
ZCRIP(FOR_EACH_NARG(__VA_ARGS__))(__VA_ARGS__)
|
||||
|
||||
|
||||
|
||||
#define ZZBEGIN if (false) {
|
||||
#define ZZEND return true; } return false;
|
||||
#define CHECK(x,...) if (!(x)) { DCCEXParser::checkFailedFormat=#__VA_ARGS__[0]?F(#__VA_ARGS__):F(#x); return false;}
|
||||
#define REPLY(format,...) StringFormatter::send(stream,F(format), ##__VA_ARGS__);
|
||||
#define EXPECT_CALLBACK CHECK(stashCallback(stream, p, ringStream))
|
||||
// helper macro to hide command from documentation extractor
|
||||
#define ZZ_nodoc ZZ
|
||||
|
||||
#define ZCHECK(_checkname,_index,_pname,_min,_max) \
|
||||
if (CONCAT(#_pname,_hk) == CONCAT(#_checkname,_hk) \
|
||||
&& (p[_index]<_min || p[_index]>_max)) CHECK(false,_checkname _min .. _max)
|
||||
|
||||
// Automatic range checks based on name of inserted parameter
|
||||
#define ZZCHK(_index,_pname)\
|
||||
ZCHECK(loco,_index,_pname,0,10239) \
|
||||
ZCHECK(track,_index,_pname,'A','H') \
|
||||
ZCHECK(cv,_index,_pname,1,255) \
|
||||
ZCHECK(value,_index,_pname,0,255) \
|
||||
ZCHECK(bit,_index,_pname,0,7) \
|
||||
ZCHECK(bitvalue,_index,_pname,0,1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
185
DCCQueue.cpp
Normal file
185
DCCQueue.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "defines.h"
|
||||
#include "DCCQueue.h"
|
||||
#include "DCCWaveform.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
// create statics
|
||||
DCCQueue* DCCQueue::lowPriorityQueue=new DCCQueue();
|
||||
DCCQueue* DCCQueue::highPriorityQueue=new DCCQueue();
|
||||
PendingSlot* DCCQueue::recycleList=nullptr;
|
||||
|
||||
DCCQueue::DCCQueue() {
|
||||
head=nullptr;
|
||||
tail=nullptr;
|
||||
}
|
||||
|
||||
void DCCQueue::addQueue(PendingSlot* p) {
|
||||
if (tail) tail->next=p;
|
||||
else head=p;
|
||||
tail=p;
|
||||
p->next=nullptr;
|
||||
}
|
||||
|
||||
void DCCQueue::jumpQueue(PendingSlot* p) {
|
||||
p->next=head;
|
||||
head=p;
|
||||
if (!tail) tail=p;
|
||||
}
|
||||
|
||||
|
||||
void DCCQueue::recycle(PendingSlot* p) {
|
||||
p->next=recycleList;
|
||||
recycleList=p;
|
||||
}
|
||||
|
||||
// Packet joins end of low priority queue.
|
||||
void DCCQueue::scheduleDCCPacket(byte* packet, byte length, byte repeats) {
|
||||
lowPriorityQueue->addQueue(getSlot(NORMAL_PACKET,packet,length,repeats,0));
|
||||
}
|
||||
|
||||
// Packet replaces existing loco speed packet or joins end of high priority queue.
|
||||
|
||||
void DCCQueue::scheduleDCCSpeedPacket(byte* packet, byte length, byte repeats, uint16_t loco) {
|
||||
for (auto p=highPriorityQueue->head;p;p=p->next) {
|
||||
if (p->locoId==loco) {
|
||||
// replace existing packet
|
||||
memcpy(p->packet,packet,length);
|
||||
p->packetLength=length;
|
||||
p->packetRepeat=repeats;
|
||||
return;
|
||||
}
|
||||
}
|
||||
highPriorityQueue->addQueue(getSlot(NORMAL_PACKET,packet,length,repeats,loco));
|
||||
}
|
||||
|
||||
|
||||
// ESTOP -
|
||||
// any outstanding throttle packet for this loco (all if loco=0) discarded
|
||||
// Packet joins start of queue,
|
||||
|
||||
|
||||
void DCCQueue::scheduleEstopPacket(byte* packet, byte length, byte repeats,uint16_t loco) {
|
||||
|
||||
// DIAG(F("DCC ESTOP loco=%d"),loco);
|
||||
|
||||
// kill any existing throttle packets for this loco
|
||||
PendingSlot * previous=nullptr;
|
||||
auto p=highPriorityQueue->head;
|
||||
while(p) {
|
||||
if (loco==0 || p->locoId==loco) {
|
||||
// drop this packet from the highPriority queue
|
||||
if (previous) previous->next=p->next;
|
||||
else highPriorityQueue->head=p->next;
|
||||
|
||||
recycle(p); // recycle this slot
|
||||
|
||||
// address next packet
|
||||
p=previous?previous->next : highPriorityQueue->head;
|
||||
}
|
||||
else {
|
||||
previous=p;
|
||||
p=p->next;
|
||||
}
|
||||
}
|
||||
// add the estop packet to the start of the queue
|
||||
highPriorityQueue->jumpQueue(getSlot(NORMAL_PACKET,packet,length,repeats,0));
|
||||
}
|
||||
|
||||
// Accessory gate-On Packet joins end of queue as normal.
|
||||
// When dequeued, packet is retained at start of queue
|
||||
// but modified to gate-off and given the delayed start.
|
||||
// getNext will ignore this packet until the requested start time.
|
||||
void DCCQueue::scheduleAccOnOffPacket(byte* packet, byte length, byte repeats,int16_t delayms) {
|
||||
auto p=getSlot(ACC_ON_PACKET,packet,length,repeats,0);
|
||||
p->delayOff=delayms;
|
||||
lowPriorityQueue->addQueue(p);
|
||||
};
|
||||
|
||||
|
||||
// Obtain packet (fills packet, length and repeats)
|
||||
// returns 0 length if nothing in queue.
|
||||
|
||||
bool DCCQueue::scheduleNext() {
|
||||
// check high priority queue first
|
||||
if (!DCCWaveform::mainTrack.isReminderWindowOpen()) return false;
|
||||
PendingSlot* previous=nullptr;
|
||||
for (auto p=highPriorityQueue->head;p;p=p->next) {
|
||||
// skip over pending ACC_OFF packets which are still delayed
|
||||
if (p->type == ACC_OFF_PACKET && millis()<p->startTime) continue;
|
||||
// use this slot
|
||||
DCCWaveform::mainTrack.schedulePacket(p->packet,p->packetLength,p->packetRepeat);
|
||||
// remove this slot from the queue
|
||||
if (previous) previous->next=p->next;
|
||||
else highPriorityQueue->head=p->next;
|
||||
if (!highPriorityQueue->head) highPriorityQueue->tail=nullptr;
|
||||
|
||||
// and recycle it.
|
||||
recycle(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
// No high priopity packets found, check low priority queue
|
||||
auto p=lowPriorityQueue->head;
|
||||
if (!p) return false; // nothing in queues
|
||||
|
||||
// schedule first packet in queue
|
||||
DCCWaveform::mainTrack.schedulePacket(p->packet,p->packetLength,p->packetRepeat);
|
||||
|
||||
// remove from queue
|
||||
lowPriorityQueue->head=p->next;
|
||||
if (!lowPriorityQueue->head) lowPriorityQueue->tail=nullptr;
|
||||
|
||||
if (p->type == ACC_ON_PACKET) {
|
||||
// convert to a delayed off packet and jump the high priority queue
|
||||
p->type= ACC_OFF_PACKET;
|
||||
p->packet[1] &= ~0x08; // set C to 0 (gate off)
|
||||
p->startTime=millis()+p->delayOff;
|
||||
highPriorityQueue->jumpQueue(p);
|
||||
}
|
||||
else recycle(p); // recycle this slot
|
||||
return true;
|
||||
}
|
||||
|
||||
// obtain and initialise slot for a PendingSlot.
|
||||
PendingSlot* DCCQueue::getSlot(PendingType type, byte* packet, byte length, byte repeats,uint16_t loco) {
|
||||
PendingSlot * p;
|
||||
if (recycleList) {
|
||||
p=recycleList;
|
||||
recycleList=p->next;
|
||||
}
|
||||
else {
|
||||
DIAG(F("New DCC queue slot"));
|
||||
p=new PendingSlot; // need a queue entry
|
||||
}
|
||||
p->next=nullptr;
|
||||
p->type=type;
|
||||
p->packetLength=length;
|
||||
p->packetRepeat=repeats;
|
||||
memcpy((void*)p->packet,packet,length);
|
||||
p->locoId=loco;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
84
DCCQueue.h
Normal file
84
DCCQueue.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef DCCQueue_h
|
||||
#define DCCQueue_h
|
||||
#include "Arduino.h"
|
||||
#include "DCCWaveform.h"
|
||||
|
||||
enum PendingType:byte {NORMAL_PACKET,ACC_ON_PACKET,ACC_OFF_PACKET,DEAD_PACKET};
|
||||
struct PendingSlot {
|
||||
PendingSlot* next;
|
||||
PendingType type;
|
||||
byte packetLength;
|
||||
byte packetRepeat;
|
||||
byte packet[MAX_PACKET_SIZE];
|
||||
|
||||
union { // use depends on packet type
|
||||
uint16_t locoId; // NORMAL_PACKET .. only set >0 for speed change packets
|
||||
// so they can be easily discarded if an estop jumps the queue.
|
||||
uint16_t delayOff; // ACC_ON_PACKET delay to apply between on/off
|
||||
uint32_t startTime; // ACC_OFF_PACKET time (mS) to transmit
|
||||
};
|
||||
};
|
||||
|
||||
class DCCQueue {
|
||||
public:
|
||||
|
||||
|
||||
// Non-speed packets are queued in the main queue
|
||||
static void scheduleDCCPacket(byte* packet, byte length, byte repeats);
|
||||
|
||||
// Speed packets are queued in the high priority queue
|
||||
static void scheduleDCCSpeedPacket(byte* packet, byte length, byte repeats, uint16_t loco);
|
||||
|
||||
// ESTOP packets jump the high priority queue and discard any outstanding throttle packets for this loco
|
||||
static void scheduleEstopPacket(byte* packet, byte length, byte repeats,uint16_t loco);
|
||||
|
||||
// Accessory gate-On Packet joins end of main queue as normal.
|
||||
// When dequeued, packet is modified to gate-off and given the delayed start in the high priority queue.
|
||||
// getNext will ignore this packet until the requested start time.
|
||||
static void scheduleAccOnOffPacket(byte* packet, byte length, byte repeats,int16_t delayms);
|
||||
|
||||
|
||||
// Schedules a main track packet from the queues if none pending.
|
||||
// returns true if a packet was scheduled.
|
||||
static bool scheduleNext();
|
||||
|
||||
private:
|
||||
|
||||
// statics to manage high and low priority queues and recycleing of PENDINGs
|
||||
static PendingSlot* recycleList;
|
||||
static DCCQueue* highPriorityQueue;
|
||||
static DCCQueue* lowPriorityQueue;
|
||||
|
||||
DCCQueue();
|
||||
|
||||
PendingSlot* head;
|
||||
PendingSlot * tail;
|
||||
|
||||
// obtain and initialise slot for a PendingSlot.
|
||||
static PendingSlot* getSlot(PendingType type, byte* packet, byte length, byte repeats, uint16_t loco);
|
||||
static void recycle(PendingSlot* p);
|
||||
void addQueue(PendingSlot * p);
|
||||
void jumpQueue(PendingSlot * p);
|
||||
|
||||
};
|
||||
#endif
|
@@ -2,7 +2,7 @@
|
||||
* © 2021 Mike S
|
||||
* © 2021-2023 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
* © 2021 Chris Harlow
|
||||
* © 2021-2025 Chris Harlow
|
||||
* © 2021 David Cutting
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -57,66 +57,59 @@ void DCCTimer::begin(INTERRUPT_CALLBACK callback) {
|
||||
TCCR1B = _BV(WGM13) | _BV(CS10); // Mode 8, clock select 1
|
||||
TIMSK1 = _BV(TOIE1); // Enable Software interrupt
|
||||
interrupts();
|
||||
//diagnostic pinMode(4,OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void DCCTimer::startRailcomTimer(byte brakePin) {
|
||||
(void) brakePin; // Ignored... works on pin 9 only
|
||||
// diagnostic digitalWrite(4,HIGH);
|
||||
|
||||
/* The Railcom timer is started in such a way that it
|
||||
- First triggers 28uS after the last TIMER1 tick.
|
||||
- First triggers 58+29 uS after the previous TIMER1 tick.
|
||||
This provides an accurate offset (in High Accuracy mode)
|
||||
for the start of the Railcom cutout.
|
||||
- Sets the Railcom pin high at first tick,
|
||||
because its been setup with 100% PWM duty cycle.
|
||||
- Sets the Railcom pin high at first tick and subsequent ticks
|
||||
until its reset to setting pin 9 low at next tick.
|
||||
|
||||
- Cycles at 436uS so the second tick is the
|
||||
correct distance from the cutout.
|
||||
|
||||
- Waveform code is responsible for altering the PWM
|
||||
duty cycle to 0% any time between the first and last tick.
|
||||
- Waveform code is responsible for resetting
|
||||
any time between the first and second tick.
|
||||
(there will be 7 DCC timer1 ticks in which to do this.)
|
||||
|
||||
*/
|
||||
(void) brakePin; // Ignored... works on pin 9 only
|
||||
const int cutoutDuration = 430; // Desired interval in microseconds
|
||||
|
||||
// Set up Timer2 for CTC mode (Clear Timer on Compare Match)
|
||||
TCCR2A = 0; // Clear Timer2 control register A
|
||||
TCCR2B = 0; // Clear Timer2 control register B
|
||||
TCNT2 = 0; // Initialize Timer2 counter value to 0
|
||||
// Configure Phase and Frequency Correct PWM mode
|
||||
TCCR2A = (1 << COM2B1); // enable pwm on pin 9
|
||||
TCCR2A |= (1 << WGM20);
|
||||
|
||||
const int cycle=cutoutDuration/2;
|
||||
|
||||
// Set Timer 2 prescaler to 32
|
||||
TCCR2B = (1 << CS21) | (1 << CS20); // 32 prescaler
|
||||
|
||||
// Set the compare match value for desired interval
|
||||
OCR2A = (F_CPU / 1000000) * cutoutDuration / 64 - 1;
|
||||
|
||||
// Calculate the compare match value for desired duty cycle
|
||||
OCR2B = OCR2A+1; // set duty cycle to 100%= OCR2A)
|
||||
|
||||
const byte RailcomFudge0=58+58+29;
|
||||
|
||||
// Set Timer2 to CTC mode with set on compare match
|
||||
TCCR2A = (1 << WGM21) | (1 << COM2B0) | (1 << COM2B1);
|
||||
// Prescaler of 32
|
||||
TCCR2B = (1 << CS21) | (1 << CS20);
|
||||
OCR2A = cycle-1; // Compare match value for 430 uS
|
||||
// Enable Timer2 output on pin 9 (OC2B)
|
||||
DDRB |= (1 << DDB1);
|
||||
// TODO Fudge TCNT2 to sync with last tcnt1 tick + 28uS
|
||||
|
||||
// RailcomFudge2 is the expected time from idealised
|
||||
// setup call (at previous DCC timer interrupt) to the cutout.
|
||||
// This value should be reduced to reflect the Timer1 value
|
||||
// measuring the time since the previous hardware interrupt
|
||||
byte tcfudge=TCNT1/16;
|
||||
TCNT2=cycle-RailcomFudge0/2+tcfudge/2;
|
||||
|
||||
|
||||
// Previous TIMER1 Tick was at rising end-of-packet bit
|
||||
// Cutout starts half way through first preamble
|
||||
// that is 2.5 * 58uS later.
|
||||
// TCNT1 ticks 8 times / microsecond
|
||||
// auto microsendsToFirstRailcomTick=(58+58+29)-(TCNT1/8);
|
||||
// set the railcom timer counter allowing for phase-correct
|
||||
|
||||
// CHris's NOTE:
|
||||
// I dont kniow quite how this calculation works out but
|
||||
// it does seems to get a good answer.
|
||||
|
||||
TCNT2=193 + (ICR1 - TCNT1)/8;
|
||||
}
|
||||
}
|
||||
|
||||
void DCCTimer::ackRailcomTimer() {
|
||||
OCR2B= 0x00; // brake pin pwm duty cycle 0 at next tick
|
||||
// Change Timer2 to CTC mode with RESET pin 9 on next compare match
|
||||
TCCR2A = (1 << WGM21) | (1 << COM2B1);
|
||||
// diagnostic digitalWrite(4,LOW);
|
||||
}
|
||||
|
||||
|
||||
|
152
DCCWaveform.cpp
152
DCCWaveform.cpp
@@ -24,14 +24,13 @@
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
// This code is replaced entirely on an ESP32
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "DCCWaveform.h"
|
||||
#include "TrackManager.h"
|
||||
#include "DCCTimer.h"
|
||||
#include "DCCACK.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
|
||||
bool DCCWaveform::cutoutNextTime=false;
|
||||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
||||
|
||||
@@ -71,9 +70,18 @@ void DCCWaveform::loop() {
|
||||
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize ("-O3")
|
||||
|
||||
void DCCWaveform::interruptHandler() {
|
||||
// call the timer edge sensitive actions for progtrack and maintrack
|
||||
// member functions would be cleaner but have more overhead
|
||||
#if defined(HAS_ENOUGH_MEMORY)
|
||||
if (cutoutNextTime) {
|
||||
cutoutNextTime=false;
|
||||
railcomSampleWindow=false; // about to cutout, stop reading railcom data.
|
||||
railcomCutoutCounter++;
|
||||
DCCTimer::startRailcomTimer(9);
|
||||
}
|
||||
#endif
|
||||
byte sigMain=signalTransform[mainTrack.state];
|
||||
byte sigProg=TrackManager::progTrackSyncMain? sigMain : signalTransform[progTrack.state];
|
||||
|
||||
@@ -115,19 +123,24 @@ DCCWaveform::DCCWaveform( byte preambleBits, bool isMain) {
|
||||
bytes_sent = 0;
|
||||
bits_sent = 0;
|
||||
}
|
||||
|
||||
|
||||
bool DCCWaveform::railcomPossible=false; // High accuracy only
|
||||
volatile bool DCCWaveform::railcomActive=false; // switched on by user
|
||||
volatile bool DCCWaveform::railcomDebug=false; // switched on by user
|
||||
volatile bool DCCWaveform::railcomSampleWindow=false; // true during packet transmit
|
||||
volatile byte DCCWaveform::railcomCutoutCounter=0; // cyclic cutout
|
||||
volatile byte DCCWaveform::railcomLastAddressHigh=0;
|
||||
volatile byte DCCWaveform::railcomLastAddressLow=0;
|
||||
|
||||
bool DCCWaveform::setRailcom(bool on, bool debug) {
|
||||
if (on) {
|
||||
// TODO check possible
|
||||
if (on && railcomPossible) {
|
||||
railcomActive=true;
|
||||
railcomDebug=debug;
|
||||
}
|
||||
else {
|
||||
railcomActive=false;
|
||||
railcomDebug=false;
|
||||
railcomSampleWindow=false;
|
||||
}
|
||||
return railcomActive;
|
||||
}
|
||||
@@ -140,14 +153,37 @@ void DCCWaveform::interrupt2() {
|
||||
// or WAVE_HIGH_0 for a 0 bit.
|
||||
if (remainingPreambles > 0 ) {
|
||||
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
||||
|
||||
remainingPreambles--;
|
||||
|
||||
// As we get to the end of the preambles, open the reminder window.
|
||||
// This delays any reminder insertion until the last moment so
|
||||
// that the reminder doesn't block a more urgent packet.
|
||||
reminderWindowOpen=transmitRepeats==0 && remainingPreambles<4 && remainingPreambles>1;
|
||||
if (remainingPreambles==1) promotePendingPacket();
|
||||
else if (remainingPreambles==10 && isMainTrack && railcomActive) DCCTimer::ackRailcomTimer();
|
||||
reminderWindowOpen=transmitRepeats==0 && remainingPreambles<10 && remainingPreambles>1;
|
||||
if (remainingPreambles==1)
|
||||
promotePendingPacket();
|
||||
|
||||
#if defined(HAS_ENOUGH_MEMORY)
|
||||
else if (isMainTrack && railcomActive) {
|
||||
if (remainingPreambles==(requiredPreambles-1)) {
|
||||
// First look if we need to start a railcom cutout on next interrupt
|
||||
cutoutNextTime= true;
|
||||
} else if (remainingPreambles==(requiredPreambles-12)) {
|
||||
// cutout has ended so its now possible to poll the railcom detectors
|
||||
// requiredPreambles is one higher that preamble length so
|
||||
// if preamble length is 16 then this evaluates to 5
|
||||
// Remember address bytes of last sent packet so that Railcom can
|
||||
// work out where the channel2 data came from.
|
||||
railcomLastAddressHigh=transmitPacket[0];
|
||||
railcomLastAddressLow =transmitPacket[1];
|
||||
railcomSampleWindow=true;
|
||||
} else if (remainingPreambles==(requiredPreambles-3)) {
|
||||
// cutout can be ended when read
|
||||
// see above for requiredPreambles
|
||||
DCCTimer::ackRailcomTimer();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Update free memory diagnostic as we don't have anything else to do this time.
|
||||
// Allow for checkAck and its called functions using 22 bytes more.
|
||||
else DCCTimer::updateMinimumFreeMemoryISR(22);
|
||||
@@ -171,13 +207,7 @@ void DCCWaveform::interrupt2() {
|
||||
bytes_sent = 0;
|
||||
// preamble for next packet will start...
|
||||
remainingPreambles = requiredPreambles;
|
||||
|
||||
// set the railcom coundown to trigger half way
|
||||
// through the first preamble bit.
|
||||
// Note.. we are still sending the last packet bit
|
||||
// and we then have to allow for the packet end bit
|
||||
if (isMainTrack && railcomActive) DCCTimer::startRailcomTimer(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma GCC pop_options
|
||||
@@ -212,7 +242,7 @@ void DCCWaveform::promotePendingPacket() {
|
||||
transmitRepeats--;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (packetPending) {
|
||||
// Copy pending packet to transmit packet
|
||||
// a fixed length memcpy is faster than a variable length loop for these small lengths
|
||||
@@ -230,7 +260,7 @@ void DCCWaveform::promotePendingPacket() {
|
||||
// Fortunately reset and idle packets are the same length
|
||||
// Note: If railcomDebug is on, then we send resets to the main
|
||||
// track instead of idles. This means that all data will be zeros
|
||||
// and only the porersets will be ones, making it much
|
||||
// and only the presets will be ones, making it much
|
||||
// easier to read on a logic analyser.
|
||||
memcpy( transmitPacket, (isMainTrack && (!railcomDebug)) ? idlePacket : resetPacket, sizeof(idlePacket));
|
||||
transmitLength = sizeof(idlePacket);
|
||||
@@ -238,91 +268,3 @@ void DCCWaveform::promotePendingPacket() {
|
||||
if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "DCCWaveform.h"
|
||||
#include "DCCACK.h"
|
||||
|
||||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
||||
RMTChannel *DCCWaveform::rmtMainChannel = NULL;
|
||||
RMTChannel *DCCWaveform::rmtProgChannel = NULL;
|
||||
|
||||
DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) {
|
||||
isMainTrack = isMain;
|
||||
requiredPreambles = preambleBits;
|
||||
}
|
||||
void DCCWaveform::begin() {
|
||||
for(const auto& md: TrackManager::getMainDrivers()) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if(rmtMainChannel) {
|
||||
//DIAG(F("added pins %d %d to MAIN channel"), p.pin, p.invpin);
|
||||
rmtMainChannel->addPin(p); // add pin to existing main channel
|
||||
} else {
|
||||
//DIAG(F("new MAIN channel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtMainChannel = new RMTChannel(p, true); /* create new main channel */
|
||||
}
|
||||
}
|
||||
MotorDriver *md = TrackManager::getProgDriver();
|
||||
if (md) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if (rmtProgChannel) {
|
||||
//DIAG(F("added pins %d %d to PROG channel"), p.pin, p.invpin);
|
||||
rmtProgChannel->addPin(p); // add pin to existing prog channel
|
||||
} else {
|
||||
//DIAG(F("new PROGchannel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtProgChannel = new RMTChannel(p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
|
||||
if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum
|
||||
RMTChannel *rmtchannel = (isMainTrack ? rmtMainChannel : rmtProgChannel);
|
||||
if (rmtchannel == NULL)
|
||||
return; // no idea to prepare packet if we can not send it anyway
|
||||
|
||||
rmtchannel->waitForDataCopy(); // blocking wait so we can write into buffer
|
||||
byte checksum = 0;
|
||||
for (byte b = 0; b < byteCount; b++) {
|
||||
checksum ^= buffer[b];
|
||||
pendingPacket[b] = buffer[b];
|
||||
}
|
||||
// buffer is MAX_PACKET_SIZE but pendingPacket is one bigger
|
||||
pendingPacket[byteCount] = checksum;
|
||||
pendingLength = byteCount + 1;
|
||||
pendingRepeats = repeats;
|
||||
// DIAG repeated commands (accesories)
|
||||
// if (pendingRepeats > 0)
|
||||
// DIAG(F("Repeats=%d on %s track"), pendingRepeats, isMainTrack ? "MAIN" : "PROG");
|
||||
// The resets will be zero not only now but as well repeats packets into the future
|
||||
clearResets(repeats+1);
|
||||
{
|
||||
int ret = 0;
|
||||
do {
|
||||
ret = rmtchannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
|
||||
} while(ret > 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool DCCWaveform::isReminderWindowOpen() {
|
||||
if(isMainTrack) {
|
||||
if (rmtMainChannel == NULL)
|
||||
return false;
|
||||
return !rmtMainChannel->busy();
|
||||
} else {
|
||||
if (rmtProgChannel == NULL)
|
||||
return false;
|
||||
return !rmtProgChannel->busy();
|
||||
}
|
||||
}
|
||||
void IRAM_ATTR DCCWaveform::loop() {
|
||||
DCCACK::checkAck(progTrack.getResets());
|
||||
}
|
||||
|
||||
bool DCCWaveform::setRailcom(bool on, bool debug) {
|
||||
// TODO... ESP32 railcom waveform
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2024 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
@@ -23,11 +23,8 @@
|
||||
*/
|
||||
#ifndef DCCWaveform_h
|
||||
#define DCCWaveform_h
|
||||
|
||||
#include "MotorDriver.h"
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "DCCRMT.h"
|
||||
#include "TrackManager.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -86,8 +83,30 @@ class DCCWaveform {
|
||||
bool isReminderWindowOpen();
|
||||
void promotePendingPacket();
|
||||
static bool setRailcom(bool on, bool debug);
|
||||
static bool isRailcom() {return railcomActive;}
|
||||
|
||||
inline static bool isRailcom() {
|
||||
return railcomActive;
|
||||
};
|
||||
inline static byte getRailcomCutoutCounter() {
|
||||
return railcomCutoutCounter;
|
||||
};
|
||||
inline static bool isRailcomSampleWindow() {
|
||||
return railcomSampleWindow;
|
||||
};
|
||||
inline static bool isRailcomPossible() {
|
||||
return railcomPossible;
|
||||
};
|
||||
inline static void setRailcomPossible(bool yes) {
|
||||
railcomPossible=yes;
|
||||
if (!yes) setRailcom(false,false);
|
||||
};
|
||||
inline static uint16_t getRailcomLastLocoAddress() {
|
||||
// first 2 bits 00=short loco, 11=long loco , 01/10 = accessory
|
||||
byte addressType=railcomLastAddressHigh & 0xC0;
|
||||
if (addressType==0xC0) return ((railcomLastAddressHigh & 0x3f)<<8) | railcomLastAddressLow;
|
||||
if (addressType==0x00) return railcomLastAddressHigh & 0x3F;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
volatile bool packetPending;
|
||||
@@ -112,9 +131,13 @@ class DCCWaveform {
|
||||
byte pendingPacket[MAX_PACKET_SIZE+1]; // +1 for checksum
|
||||
byte pendingLength;
|
||||
byte pendingRepeats;
|
||||
static bool railcomPossible; // High accuracy mode only
|
||||
static volatile bool railcomActive; // switched on by user
|
||||
static volatile bool railcomDebug; // switched on by user
|
||||
|
||||
static volatile bool railcomSampleWindow; // when safe to sample
|
||||
static volatile byte railcomCutoutCounter; // incremented for each cutout
|
||||
static volatile byte railcomLastAddressHigh,railcomLastAddressLow;
|
||||
static bool cutoutNextTime; // railcom
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
static RMTChannel *rmtMainChannel;
|
||||
static RMTChannel *rmtProgChannel;
|
||||
|
120
DCCWaveformRMT.cpp
Normal file
120
DCCWaveformRMT.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
// This code is ESP32 ONLY.
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "DCCWaveform.h"
|
||||
#include "DCCACK.h"
|
||||
#include "TrackManager.h"
|
||||
|
||||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
|
||||
RMTChannel *DCCWaveform::rmtMainChannel = NULL;
|
||||
RMTChannel *DCCWaveform::rmtProgChannel = NULL;
|
||||
|
||||
bool DCCWaveform::railcomPossible=false; // High accuracy only
|
||||
volatile bool DCCWaveform::railcomActive=false; // switched on by user
|
||||
volatile bool DCCWaveform::railcomDebug=false; // switched on by user
|
||||
volatile bool DCCWaveform::railcomSampleWindow=false; // true during packet transmit
|
||||
volatile byte DCCWaveform::railcomCutoutCounter=0; // cyclic cutout
|
||||
volatile byte DCCWaveform::railcomLastAddressHigh=0;
|
||||
volatile byte DCCWaveform::railcomLastAddressLow=0;
|
||||
|
||||
DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) {
|
||||
isMainTrack = isMain;
|
||||
requiredPreambles = preambleBits;
|
||||
}
|
||||
void DCCWaveform::begin() {
|
||||
for(const auto& md: TrackManager::getMainDrivers()) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if(rmtMainChannel) {
|
||||
//DIAG(F("added pins %d %d to MAIN channel"), p.pin, p.invpin);
|
||||
rmtMainChannel->addPin(p); // add pin to existing main channel
|
||||
} else {
|
||||
//DIAG(F("new MAIN channel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtMainChannel = new RMTChannel(p, true); /* create new main channel */
|
||||
}
|
||||
}
|
||||
MotorDriver *md = TrackManager::getProgDriver();
|
||||
if (md) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if (rmtProgChannel) {
|
||||
//DIAG(F("added pins %d %d to PROG channel"), p.pin, p.invpin);
|
||||
rmtProgChannel->addPin(p); // add pin to existing prog channel
|
||||
} else {
|
||||
//DIAG(F("new PROGchannel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtProgChannel = new RMTChannel(p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
|
||||
if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum
|
||||
RMTChannel *rmtchannel = (isMainTrack ? rmtMainChannel : rmtProgChannel);
|
||||
if (rmtchannel == NULL)
|
||||
return; // no idea to prepare packet if we can not send it anyway
|
||||
|
||||
rmtchannel->waitForDataCopy(); // blocking wait so we can write into buffer
|
||||
byte checksum = 0;
|
||||
for (byte b = 0; b < byteCount; b++) {
|
||||
checksum ^= buffer[b];
|
||||
pendingPacket[b] = buffer[b];
|
||||
}
|
||||
// buffer is MAX_PACKET_SIZE but pendingPacket is one bigger
|
||||
pendingPacket[byteCount] = checksum;
|
||||
pendingLength = byteCount + 1;
|
||||
pendingRepeats = repeats;
|
||||
// DIAG repeated commands (accesories)
|
||||
// if (pendingRepeats > 0)
|
||||
// DIAG(F("Repeats=%d on %s track"), pendingRepeats, isMainTrack ? "MAIN" : "PROG");
|
||||
// The resets will be zero not only now but as well repeats packets into the future
|
||||
clearResets(repeats+1);
|
||||
{
|
||||
int ret = 0;
|
||||
do {
|
||||
ret = rmtchannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
|
||||
} while(ret > 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool DCCWaveform::isReminderWindowOpen() {
|
||||
if(isMainTrack) {
|
||||
if (rmtMainChannel == NULL)
|
||||
return false;
|
||||
return !rmtMainChannel->busy();
|
||||
} else {
|
||||
if (rmtProgChannel == NULL)
|
||||
return false;
|
||||
return !rmtProgChannel->busy();
|
||||
}
|
||||
}
|
||||
void IRAM_ATTR DCCWaveform::loop() {
|
||||
DCCACK::checkAck(progTrack.getResets());
|
||||
}
|
||||
|
||||
bool DCCWaveform::setRailcom(bool on, bool debug) {
|
||||
// TODO... ESP32 railcom waveform
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
167
EXRAIL2.cpp
167
EXRAIL2.cpp
@@ -2,7 +2,7 @@
|
||||
* © 2024 Paul M. Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021-2023 Harald Barth
|
||||
* © 2020-2023 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2025 Morten Nielsen
|
||||
* All rights reserved.
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "Turntables.h"
|
||||
#include "IODevice.h"
|
||||
#include "EXRAILSensor.h"
|
||||
#include "Stash.h"
|
||||
|
||||
|
||||
// One instance of RMFT clas is used for each "thread" in the automation.
|
||||
@@ -88,10 +89,11 @@ LookList * RMFT2::onClockLookup=NULL;
|
||||
LookList * RMFT2::onRotateLookup=NULL;
|
||||
#endif
|
||||
LookList * RMFT2::onOverloadLookup=NULL;
|
||||
LookList * RMFT2::onBlockEnterLookup=NULL;
|
||||
LookList * RMFT2::onBlockExitLookup=NULL;
|
||||
byte * RMFT2::routeStateArray=nullptr;
|
||||
const FSH * * RMFT2::routeCaptionArray=nullptr;
|
||||
int16_t * RMFT2::stashArray=nullptr;
|
||||
int16_t RMFT2::maxStashId=0;
|
||||
|
||||
|
||||
// getOperand instance version, uses progCounter from instance.
|
||||
uint16_t RMFT2::getOperand(byte n) {
|
||||
@@ -132,11 +134,11 @@ int16_t LookList::find(int16_t value) {
|
||||
void LookList::chain(LookList * chain) {
|
||||
m_chain=chain;
|
||||
}
|
||||
void LookList::handleEvent(const FSH* reason,int16_t id) {
|
||||
void LookList::handleEvent(const FSH* reason,int16_t id, int16_t loco) {
|
||||
// New feature... create multiple ONhandlers
|
||||
for (int i=0;i<m_size;i++)
|
||||
if (m_lookupArray[i]==id)
|
||||
RMFT2::startNonRecursiveTask(reason,id,m_resultArray[i]);
|
||||
RMFT2::startNonRecursiveTask(reason,id,m_resultArray[i],loco);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,6 +206,12 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
||||
onRotateLookup=LookListLoader(OPCODE_ONROTATE);
|
||||
#endif
|
||||
onOverloadLookup=LookListLoader(OPCODE_ONOVERLOAD);
|
||||
|
||||
if (compileFeatures & FEATURE_BLOCK) {
|
||||
onBlockEnterLookup=LookListLoader(OPCODE_ONBLOCKENTER);
|
||||
onBlockExitLookup=LookListLoader(OPCODE_ONBLOCKEXIT);
|
||||
}
|
||||
|
||||
// onLCCLookup is not the same so not loaded here.
|
||||
|
||||
// Second pass startup, define any turnouts or servos, set signals red
|
||||
@@ -250,13 +258,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
||||
IODevice::configureInput((VPIN)pin,true);
|
||||
break;
|
||||
}
|
||||
case OPCODE_STASH:
|
||||
case OPCODE_CLEAR_STASH:
|
||||
case OPCODE_PICKUP_STASH: {
|
||||
maxStashId=max(maxStashId,((int16_t)operand));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case OPCODE_ATGTE:
|
||||
case OPCODE_ATLT:
|
||||
case OPCODE_IFGTE:
|
||||
@@ -344,13 +346,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
||||
}
|
||||
SKIPOP; // include ENDROUTES opcode
|
||||
|
||||
if (compileFeatures & FEATURE_STASH) {
|
||||
// create the stash array from the highest id found
|
||||
if (maxStashId>0) stashArray=(int16_t*)calloc(maxStashId+1, sizeof(int16_t));
|
||||
//TODO check EEPROM and fetch stashArray
|
||||
}
|
||||
|
||||
DIAG(F("EXRAIL %db, fl=%d, stash=%d"),progCounter,MAX_FLAGS, maxStashId);
|
||||
DIAG(F("EXRAIL %db, fl=%d"),progCounter,MAX_FLAGS);
|
||||
|
||||
// Removed for 4.2.31 new RMFT2(0); // add the startup route
|
||||
diag=saved_diag;
|
||||
@@ -380,7 +376,7 @@ char RMFT2::getRouteType(int16_t id) {
|
||||
}
|
||||
|
||||
|
||||
RMFT2::RMFT2(int progCtr) {
|
||||
RMFT2::RMFT2(int progCtr, int16_t _loco) {
|
||||
progCounter=progCtr;
|
||||
|
||||
// get an unused task id from the flags table
|
||||
@@ -393,9 +389,7 @@ RMFT2::RMFT2(int progCtr) {
|
||||
}
|
||||
}
|
||||
delayTime=0;
|
||||
loco=0;
|
||||
speedo=0;
|
||||
forward=true;
|
||||
loco=_loco;
|
||||
invert=false;
|
||||
blinkState=not_blink_task;
|
||||
stackDepth=0;
|
||||
@@ -413,7 +407,10 @@ RMFT2::RMFT2(int progCtr) {
|
||||
|
||||
|
||||
RMFT2::~RMFT2() {
|
||||
driveLoco(1); // ESTOP my loco if any
|
||||
// estop my loco if this is not an ONevent
|
||||
// (prevents DONE stopping loco at the end of an
|
||||
// ONBLOCKENTER or ONBLOCKEXIT )
|
||||
if (loco>0 && this->onEventStartPosition==-1) DCC::setThrottle(loco,1,DCC::getThrottleDirection(loco));
|
||||
setFlag(taskId,0,TASK_FLAG); // we are no longer using this id
|
||||
if (next==this)
|
||||
loopTask=NULL;
|
||||
@@ -429,23 +426,9 @@ RMFT2::~RMFT2() {
|
||||
void RMFT2::createNewTask(int route, uint16_t cab) {
|
||||
int pc=routeLookup->find(route);
|
||||
if (pc<0) return;
|
||||
RMFT2* task=new RMFT2(pc);
|
||||
task->loco=cab;
|
||||
new RMFT2(pc,cab);
|
||||
}
|
||||
|
||||
void RMFT2::driveLoco(byte speed) {
|
||||
if (loco<=0) return; // Prevent broadcast!
|
||||
//if (diag) DIAG(F("EXRAIL drive %d %d %d"),loco,speed,forward^invert);
|
||||
/* TODO.....
|
||||
power on appropriate track if DC or main if dcc
|
||||
if (TrackManager::getMainPowerMode()==POWERMODE::OFF) {
|
||||
TrackManager::setMainPower(POWERMODE::ON);
|
||||
}
|
||||
**********/
|
||||
|
||||
DCC::setThrottle(loco,speed, forward^invert);
|
||||
speedo=speed;
|
||||
}
|
||||
|
||||
bool RMFT2::readSensor(uint16_t sensorId) {
|
||||
// Exrail operands are unsigned but we need the signed version as inserted by the macros.
|
||||
@@ -500,7 +483,7 @@ bool RMFT2::skipIfBlock() {
|
||||
if (cv & LONG_ADDR_MARKER) { // maker bit indicates long addr
|
||||
progtrackLocoId = cv ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr
|
||||
if (progtrackLocoId <= HIGHEST_SHORT_ADDR ) { // out of range for long addr
|
||||
DIAG(F("Long addr %d <= %d unsupported"), progtrackLocoId, HIGHEST_SHORT_ADDR);
|
||||
DIAG(F("Long addr %d <= %d unsupported\n"), progtrackLocoId, HIGHEST_SHORT_ADDR);
|
||||
progtrackLocoId = -1;
|
||||
}
|
||||
} else {
|
||||
@@ -508,6 +491,15 @@ bool RMFT2::skipIfBlock() {
|
||||
}
|
||||
}
|
||||
|
||||
void RMFT2::pause() {
|
||||
if (loco)
|
||||
pauseSpeed=DCC::getThrottleSpeedByte(loco);
|
||||
}
|
||||
void RMFT2::resume() {
|
||||
if (loco)
|
||||
DCC::setThrottle(loco,pauseSpeed & 0x7f, pauseSpeed & 0x80);
|
||||
}
|
||||
|
||||
void RMFT2::loop() {
|
||||
if (compileFeatures & FEATURE_SENSOR)
|
||||
EXRAILSensor::checkAll();
|
||||
@@ -572,18 +564,23 @@ void RMFT2::loop2() {
|
||||
#endif
|
||||
|
||||
case OPCODE_REV:
|
||||
forward = false;
|
||||
driveLoco(operand);
|
||||
if (loco) DCC::setThrottle(loco,operand,invert);
|
||||
break;
|
||||
|
||||
case OPCODE_FWD:
|
||||
forward = true;
|
||||
driveLoco(operand);
|
||||
break;
|
||||
if (loco) DCC::setThrottle(loco,operand,!invert);
|
||||
break;
|
||||
|
||||
case OPCODE_SPEED:
|
||||
forward=DCC::getThrottleDirection(loco)^invert;
|
||||
driveLoco(operand);
|
||||
if (loco) DCC::setThrottle(loco,operand,DCC::getThrottleDirection(loco));
|
||||
break;
|
||||
|
||||
case OPCODE_MOMENTUM:
|
||||
DCC::setMomentum(loco,operand,getOperand(1));
|
||||
break;
|
||||
|
||||
case OPCODE_ESTOPALL:
|
||||
DCC::setThrottle(0,1,1); // all locos speed=1
|
||||
break;
|
||||
|
||||
case OPCODE_FORGET:
|
||||
@@ -595,12 +592,11 @@ void RMFT2::loop2() {
|
||||
|
||||
case OPCODE_INVERT_DIRECTION:
|
||||
invert= !invert;
|
||||
driveLoco(speedo);
|
||||
break;
|
||||
|
||||
case OPCODE_RESERVE:
|
||||
if (getFlag(operand,SECTION_FLAG)) {
|
||||
driveLoco(0);
|
||||
if (loco) DCC::setThrottle(loco,1,DCC::getThrottleDirection(loco));
|
||||
delayMe(500);
|
||||
return;
|
||||
}
|
||||
@@ -699,7 +695,7 @@ void RMFT2::loop2() {
|
||||
break;
|
||||
|
||||
case OPCODE_PAUSE:
|
||||
DCC::setThrottle(0,1,true); // pause all locos on the track
|
||||
DCC::estopAll(); // pause all locos on the track
|
||||
pausingTask=this;
|
||||
break;
|
||||
|
||||
@@ -707,6 +703,10 @@ void RMFT2::loop2() {
|
||||
if (loco) DCC::writeCVByteMain(loco, operand, getOperand(1));
|
||||
break;
|
||||
|
||||
case OPCODE_XPOM:
|
||||
DCC::writeCVByteMain(operand, getOperand(1), getOperand(2));
|
||||
break;
|
||||
|
||||
case OPCODE_POWEROFF:
|
||||
TrackManager::setPower(POWERMODE::OFF);
|
||||
TrackManager::setJoin(false);
|
||||
@@ -743,8 +743,8 @@ void RMFT2::loop2() {
|
||||
|
||||
case OPCODE_RESUME:
|
||||
pausingTask=NULL;
|
||||
driveLoco(speedo);
|
||||
for (RMFT2 * t=next; t!=this;t=t->next) if (t->loco >0) t->driveLoco(t->speedo);
|
||||
resume();
|
||||
for (RMFT2 * t=next; t!=this;t=t->next) t->resume();
|
||||
break;
|
||||
|
||||
case OPCODE_IF: // do next operand if sensor set
|
||||
@@ -803,6 +803,10 @@ void RMFT2::loop2() {
|
||||
case OPCODE_IFCLOSED:
|
||||
skipIf=Turnout::isThrown(operand);
|
||||
break;
|
||||
|
||||
case OPCODE_IFSTASH:
|
||||
skipIf=Stash::get(operand)==0;
|
||||
break;
|
||||
|
||||
#ifndef IO_NO_HAL
|
||||
case OPCODE_IFTTPOSITION: // do block if turntable at this position
|
||||
@@ -855,8 +859,7 @@ void RMFT2::loop2() {
|
||||
|
||||
case OPCODE_DRIVE:
|
||||
{
|
||||
byte analogSpeed=IODevice::readAnalogue(operand) *127 / 1024;
|
||||
if (speedo!=analogSpeed) driveLoco(analogSpeed);
|
||||
// Non functional but reserved
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -954,8 +957,6 @@ void RMFT2::loop2() {
|
||||
// which is intended so it can be checked
|
||||
// from within EXRAIL
|
||||
loco=progtrackLocoId;
|
||||
speedo=0;
|
||||
forward=true;
|
||||
invert=false;
|
||||
break;
|
||||
#endif
|
||||
@@ -977,16 +978,13 @@ void RMFT2::loop2() {
|
||||
{
|
||||
int newPc=routeLookup->find(getOperand(1));
|
||||
if (newPc<0) break;
|
||||
RMFT2* newtask=new RMFT2(newPc); // create new task
|
||||
newtask->loco=operand;
|
||||
new RMFT2(newPc,operand); // create new task
|
||||
}
|
||||
break;
|
||||
|
||||
case OPCODE_SETLOCO:
|
||||
{
|
||||
loco=operand;
|
||||
speedo=0;
|
||||
forward=true;
|
||||
invert=false;
|
||||
}
|
||||
break;
|
||||
@@ -1061,30 +1059,32 @@ void RMFT2::loop2() {
|
||||
break;
|
||||
|
||||
case OPCODE_STASH:
|
||||
if (compileFeatures & FEATURE_STASH)
|
||||
stashArray[operand] = invert? -loco : loco;
|
||||
Stash::set(operand,invert? -loco : loco);
|
||||
break;
|
||||
|
||||
case OPCODE_CLEAR_STASH:
|
||||
if (compileFeatures & FEATURE_STASH)
|
||||
stashArray[operand] = 0;
|
||||
Stash::clear(operand);
|
||||
break;
|
||||
|
||||
case OPCODE_CLEAR_ALL_STASH:
|
||||
if (compileFeatures & FEATURE_STASH)
|
||||
for (int i=0;i<=maxStashId;i++) stashArray[operand]=0;
|
||||
Stash::clearAll();
|
||||
break;
|
||||
|
||||
case OPCODE_CLEAR_ANY_STASH:
|
||||
if (loco) Stash::clearAny(loco);
|
||||
break;
|
||||
|
||||
case OPCODE_PICKUP_STASH:
|
||||
if (compileFeatures & FEATURE_STASH) {
|
||||
int16_t x=stashArray[operand];
|
||||
if (x>=0) {
|
||||
loco=x;
|
||||
invert=false;
|
||||
break;
|
||||
}
|
||||
loco=-x;
|
||||
invert=true;
|
||||
{
|
||||
auto x=Stash::get(operand);
|
||||
if (x>=0) {
|
||||
loco=x;
|
||||
invert=false;
|
||||
}
|
||||
else {
|
||||
loco=-x;
|
||||
invert=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1120,7 +1120,8 @@ void RMFT2::loop2() {
|
||||
case OPCODE_ONROTATE:
|
||||
#endif
|
||||
case OPCODE_ONOVERLOAD:
|
||||
|
||||
case OPCODE_ONBLOCKENTER:
|
||||
case OPCODE_ONBLOCKEXIT:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1312,6 +1313,14 @@ void RMFT2::activateEvent(int16_t addr, bool activate) {
|
||||
else onDeactivateLookup->handleEvent(F("DEACTIVATE"),addr);
|
||||
}
|
||||
|
||||
void RMFT2::blockEvent(int16_t block, int16_t loco, bool entering) {
|
||||
if (compileFeatures & FEATURE_BLOCK) {
|
||||
// Hunt for an ONBLOCKENTER/ONBLOCKEXIT for this accessory
|
||||
if (entering) onBlockEnterLookup->handleEvent(F("BLOCKENTER"),block,loco);
|
||||
else onBlockExitLookup->handleEvent(F("BLOCKEXIT"),block,loco);
|
||||
}
|
||||
}
|
||||
|
||||
void RMFT2::changeEvent(int16_t vpin, bool change) {
|
||||
// Hunt for an ONCHANGE for this sensor
|
||||
if (change) onChangeLookup->handleEvent(F("CHANGE"),vpin);
|
||||
@@ -1367,11 +1376,11 @@ void RMFT2::killBlinkOnVpin(VPIN pin, uint16_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) {
|
||||
void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc, uint16_t loco) {
|
||||
// Check we dont already have a task running this handler
|
||||
RMFT2 * task=loopTask;
|
||||
while(task) {
|
||||
if (task->onEventStartPosition==pc) {
|
||||
if (task->onEventStartPosition==pc && task->loco==loco) {
|
||||
DIAG(F("Recursive ON%S(%d)"),reason, id);
|
||||
return;
|
||||
}
|
||||
@@ -1379,7 +1388,7 @@ void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) {
|
||||
if (task==loopTask) break;
|
||||
}
|
||||
|
||||
task=new RMFT2(pc); // new task starts at this instruction
|
||||
task=new RMFT2(pc,loco); // new task starts at this instruction
|
||||
task->onEventStartPosition=pc; // flag for recursion detector
|
||||
}
|
||||
|
||||
|
36
EXRAIL2.h
36
EXRAIL2.h
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2020-2022 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2023 Harald Barth
|
||||
* © 2025 Morten Nielsen
|
||||
@@ -36,6 +36,7 @@
|
||||
//
|
||||
enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||
OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION,
|
||||
OPCODE_MOMENTUM,
|
||||
OPCODE_RESERVE,OPCODE_FREE,
|
||||
OPCODE_AT,OPCODE_AFTER,
|
||||
OPCODE_AFTEROVERLOAD,OPCODE_AUTOSTART,
|
||||
@@ -76,8 +77,11 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
|
||||
OPCODE_ROUTE_DISABLED,
|
||||
OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH,
|
||||
OPCODE_ONBUTTON,OPCODE_ONSENSOR,
|
||||
OPCODE_CLEAR_ANY_STASH,
|
||||
OPCODE_ONBUTTON,OPCODE_ONSENSOR,
|
||||
OPCODE_NEOPIXEL,
|
||||
OPCODE_ONBLOCKENTER,OPCODE_ONBLOCKEXIT,
|
||||
OPCODE_ESTOPALL,OPCODE_XPOM,
|
||||
// OPcodes below this point are skip-nesting IF operations
|
||||
// placed here so that they may be skipped as a group
|
||||
// see skipIfBlock()
|
||||
@@ -90,7 +94,8 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||
OPCODE_IFCLOSED,OPCODE_IFTHROWN,
|
||||
OPCODE_IFRE,
|
||||
OPCODE_IFLOCO,
|
||||
OPCODE_IFTTPOSITION
|
||||
OPCODE_IFTTPOSITION,
|
||||
OPCODE_IFSTASH,
|
||||
};
|
||||
|
||||
// Ensure thrunge_lcd is put last as there may be more than one display,
|
||||
@@ -134,9 +139,10 @@ enum SignalType {
|
||||
static const byte FEATURE_LCC = 0x40;
|
||||
static const byte FEATURE_ROSTER= 0x20;
|
||||
static const byte FEATURE_ROUTESTATE= 0x10;
|
||||
static const byte FEATURE_STASH = 0x08;
|
||||
// spare = 0x08;
|
||||
static const byte FEATURE_BLINK = 0x04;
|
||||
static const byte FEATURE_SENSOR = 0x02;
|
||||
static const byte FEATURE_BLOCK = 0x01;
|
||||
|
||||
|
||||
// Flag bits for status of hardware and TPL
|
||||
@@ -163,7 +169,7 @@ class LookList {
|
||||
int16_t findPosition(int16_t value); // finds index
|
||||
int16_t size();
|
||||
void stream(Print * _stream);
|
||||
void handleEvent(const FSH* reason,int16_t id);
|
||||
void handleEvent(const FSH* reason,int16_t id, int16_t loco=0);
|
||||
|
||||
private:
|
||||
int16_t m_size;
|
||||
@@ -177,8 +183,7 @@ class LookList {
|
||||
public:
|
||||
static void begin();
|
||||
static void loop();
|
||||
RMFT2(int progCounter);
|
||||
RMFT2(int route, uint16_t cab);
|
||||
RMFT2(int progCounter, int16_t cab=0);
|
||||
~RMFT2();
|
||||
static void readLocoCallback(int16_t cv);
|
||||
static void createNewTask(int route, uint16_t cab);
|
||||
@@ -188,6 +193,7 @@ class LookList {
|
||||
static void clockEvent(int16_t clocktime, bool change);
|
||||
static void rotateEvent(int16_t id, bool change);
|
||||
static void powerEvent(int16_t track, bool overload);
|
||||
static void blockEvent(int16_t block, int16_t loco, bool entering);
|
||||
static bool signalAspectEvent(int16_t address, byte aspect );
|
||||
// Throttle Info Access functions built by exrail macros
|
||||
static const byte rosterNameCount;
|
||||
@@ -201,15 +207,20 @@ class LookList {
|
||||
static const FSH * getRosterFunctions(int16_t id);
|
||||
static const FSH * getTurntableDescription(int16_t id);
|
||||
static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId);
|
||||
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
|
||||
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc, uint16_t loco=0);
|
||||
static bool readSensor(uint16_t sensorId);
|
||||
static bool isSignal(int16_t id,char rag);
|
||||
static SIGNAL_DEFINITION getSignalSlot(int16_t slotno);
|
||||
|
||||
private:
|
||||
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
||||
static bool parseCommands(Print * stream, byte opcode, byte params, int16_t p[]);
|
||||
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
|
||||
static void streamFlags(Print* stream);
|
||||
static void streamStatus(Print * stream);
|
||||
|
||||
|
||||
static bool streamLCC(Print * stream);
|
||||
static bool setFlag(VPIN id,byte onMask, byte OffMask=0);
|
||||
static bool getFlag(VPIN id,byte mask);
|
||||
static int16_t progtrackLocoId;
|
||||
@@ -225,7 +236,6 @@ private:
|
||||
static RMFT2 * loopTask;
|
||||
static RMFT2 * pausingTask;
|
||||
void delayMe(long millisecs);
|
||||
void driveLoco(byte speedo);
|
||||
bool skipIfBlock();
|
||||
bool readLoco();
|
||||
void loop2();
|
||||
@@ -234,6 +244,8 @@ private:
|
||||
void printMessage2(const FSH * msg);
|
||||
void thrungeString(uint32_t strfar, thrunger mode, byte id=0);
|
||||
uint16_t getOperand(byte n);
|
||||
void pause();
|
||||
void resume();
|
||||
|
||||
static bool diag;
|
||||
static const HIGHFLASH3 byte RouteCode[];
|
||||
@@ -255,6 +267,9 @@ private:
|
||||
static LookList * onRotateLookup;
|
||||
#endif
|
||||
static LookList * onOverloadLookup;
|
||||
static LookList * onBlockEnterLookup;
|
||||
static LookList * onBlockExitLookup;
|
||||
|
||||
|
||||
static const int countLCCLookup;
|
||||
static int onLCCLookup[];
|
||||
@@ -279,9 +294,8 @@ private:
|
||||
byte taskId;
|
||||
BlinkState blinkState; // includes AT_TIMEOUT flag.
|
||||
uint16_t loco;
|
||||
bool forward;
|
||||
bool invert;
|
||||
byte speedo;
|
||||
byte pauseSpeed;
|
||||
int onEventStartPosition;
|
||||
byte stackDepth;
|
||||
int callStack[MAX_STACK_DEPTH];
|
||||
|
1152
EXRAIL2MacroReset.h
1152
EXRAIL2MacroReset.h
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021-2023 Harald Barth
|
||||
* © 2020-2023 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -29,211 +29,27 @@
|
||||
#include "EXRAIL2.h"
|
||||
#include "DCC.h"
|
||||
#include "KeywordHasher.h"
|
||||
#include "DCCEXParser.h"
|
||||
#include "DCCEXParserMacros.h"
|
||||
|
||||
// This filter intercepts <> commands to do the following:
|
||||
// - Implement RMFT specific commands/diagnostics
|
||||
// - Reject/modify JMRI commands that would interfere with RMFT processing
|
||||
|
||||
void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]) {
|
||||
(void)stream; // avoid compiler warning if we don't access this parameter
|
||||
|
||||
switch(opcode) {
|
||||
|
||||
case 'D':
|
||||
if (p[0]=="EXRAIL"_hk) { // <D EXRAIL ON/OFF>
|
||||
diag = paramCount==2 && (p[1]=="ON"_hk || p[1]==1);
|
||||
opcode=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case '/': // New EXRAIL command
|
||||
if (parseSlash(stream,paramCount,p)) opcode=0;
|
||||
break;
|
||||
|
||||
case 'A': // <A address aspect>
|
||||
if (paramCount!=2) break;
|
||||
// Ask exrail if this is just changing the aspect on a
|
||||
// predefined DCCX_SIGNAL. Because this will handle all
|
||||
// the IFRED and ONRED type issues at the same time.
|
||||
if (signalAspectEvent(p[0],p[1])) opcode=0; // all done
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
// This entire code block is compiled out if LLC macros not used
|
||||
if (!(compileFeatures & FEATURE_LCC)) return;
|
||||
static int lccProgCounter=0;
|
||||
static int lccEventIndex=0;
|
||||
|
||||
if (paramCount==0) { //<L> LCC adapter introducing self
|
||||
LCCSerial=stream; // now we know where to send events we raise
|
||||
opcode=0; // flag command as intercepted
|
||||
|
||||
// loop through all possible sent/waited events
|
||||
for (int progCounter=lccProgCounter;; SKIPOP) {
|
||||
byte exrailOpcode=GET_OPCODE;
|
||||
switch (exrailOpcode) {
|
||||
case OPCODE_ENDEXRAIL:
|
||||
stream->print(F("<LR>\n")); // ready to roll
|
||||
lccProgCounter=0; // allow a second pass
|
||||
lccEventIndex=0;
|
||||
return;
|
||||
|
||||
case OPCODE_LCC:
|
||||
StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0));
|
||||
SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_LCCX: // long form LCC
|
||||
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"),
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_ACON: // CBUS ACON
|
||||
case OPCODE_ACOF: // CBUS ACOF
|
||||
StringFormatter::send(stream,F("<LS x%c%h%h>\n"),
|
||||
exrailOpcode==OPCODE_ACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1));
|
||||
SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
// we stream the hex events we wish to listen to
|
||||
// and at the same time build the event index looku.
|
||||
|
||||
case OPCODE_ONLCC:
|
||||
StringFormatter::send(stream,F("<LL %d x%h%h%h:%h>\n"),
|
||||
lccEventIndex,
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_ONACON:
|
||||
case OPCODE_ONACOF:
|
||||
StringFormatter::send(stream,F("<LL %d x%c%h%h>\n"),
|
||||
lccEventIndex,
|
||||
exrailOpcode==OPCODE_ONACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1)
|
||||
);
|
||||
SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (paramCount==1) { // <L eventid> LCC event arrived from adapter
|
||||
int16_t eventid=p[0];
|
||||
bool reject = eventid<0 || eventid>=countLCCLookup;
|
||||
if (!reject) {
|
||||
startNonRecursiveTask(F("LCC"),eventid,onLCCLookup[eventid]);
|
||||
opcode=0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'J': // throttle info commands
|
||||
if (paramCount<1) return;
|
||||
switch(p[0]) {
|
||||
case "A"_hk: // <JA> returns automations/routes
|
||||
if (paramCount==1) {// <JA>
|
||||
StringFormatter::send(stream, F("<jA"));
|
||||
routeLookup->stream(stream);
|
||||
StringFormatter::send(stream, F(">\n"));
|
||||
opcode=0;
|
||||
return;
|
||||
}
|
||||
if (paramCount==2) { // <JA id>
|
||||
int16_t id=p[1];
|
||||
StringFormatter::send(stream,F("<jA %d %c \"%S\">\n"),
|
||||
id, getRouteType(id), getRouteDescription(id));
|
||||
|
||||
if (compileFeatures & FEATURE_ROUTESTATE) {
|
||||
// Send any non-default button states or captions
|
||||
int16_t statePos=routeLookup->findPosition(id);
|
||||
if (statePos>=0) {
|
||||
if (routeStateArray[statePos])
|
||||
StringFormatter::send(stream,F("<jB %d %d>\n"), id, routeStateArray[statePos]);
|
||||
if (routeCaptionArray[statePos])
|
||||
StringFormatter::send(stream,F("<jB %d \"%S\">\n"), id,routeCaptionArray[statePos]);
|
||||
}
|
||||
}
|
||||
opcode=0;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "M"_hk:
|
||||
// NOTE: we only need to handle valid calls here because
|
||||
// DCCEXParser has to have code to handle the <J<> cases where
|
||||
// exrail isnt involved anyway.
|
||||
// This entire code block is compiled out if STASH macros not used
|
||||
if (!(compileFeatures & FEATURE_STASH)) return;
|
||||
if (paramCount==1) { // <JM>
|
||||
StringFormatter::send(stream,F("<jM %d>\n"),maxStashId);
|
||||
opcode=0;
|
||||
break;
|
||||
}
|
||||
if (paramCount==2) { // <JM id>
|
||||
if (p[1]<=0 || p[1]>maxStashId) break;
|
||||
StringFormatter::send(stream,F("<jM %d %d>\n"),
|
||||
p[1],stashArray[p[1]]);
|
||||
opcode=0;
|
||||
break;
|
||||
}
|
||||
if (paramCount==3) { // <JM id cab>
|
||||
if (p[1]<=0 || p[1]>maxStashId) break;
|
||||
stashArray[p[1]]=p[2];
|
||||
opcode=0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default: // other commands pass through
|
||||
break;
|
||||
}
|
||||
if (parseCommands(stream,opcode,paramCount,p)) opcode='\0'; // command was handled by parseCommands()
|
||||
}
|
||||
|
||||
bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
|
||||
if (paramCount==0) { // STATUS
|
||||
StringFormatter::send(stream, F("<* EXRAIL STATUS"));
|
||||
RMFT2 * task=loopTask;
|
||||
void RMFT2::streamStatus(Print * stream) {
|
||||
REPLY("<* EXRAIL STATUS")
|
||||
auto task=loopTask;
|
||||
while(task) {
|
||||
if ((compileFeatures & FEATURE_BLINK)
|
||||
&& (task->blinkState==blink_high || task->blinkState==blink_low)) {
|
||||
StringFormatter::send(stream,F("\nID=%d,PC=%d,BLINK=%d"),
|
||||
(int)(task->taskId),task->progCounter,task->blinkPin
|
||||
);
|
||||
REPLY("\nID=%d,PC=%d,BLINK=%d",(int)(task->taskId),task->progCounter,task->blinkPin)
|
||||
}
|
||||
else {
|
||||
StringFormatter::send(stream,F("\nID=%d,PC=%d,LOCO=%d%c,SPEED=%d%c"),
|
||||
(int)(task->taskId),task->progCounter,task->loco,
|
||||
task->invert?'I':' ',
|
||||
task->speedo,
|
||||
task->forward?'F':'R'
|
||||
);
|
||||
REPLY("\nID=%d,PC=%d,LOCO=%d %c",(int)(task->taskId),task->progCounter,task->loco,task->invert?'I':' ')
|
||||
}
|
||||
task=task->next;
|
||||
if (task==loopTask) break;
|
||||
@@ -242,9 +58,9 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
for (int id=0;id<MAX_FLAGS; id++) {
|
||||
byte flag=flags[id];
|
||||
if (flag & ~TASK_FLAG & ~SIGNAL_MASK) { // not interested in TASK_FLAG only. Already shown above
|
||||
StringFormatter::send(stream,F("\nflags[%d] "),id);
|
||||
if (flag & SECTION_FLAG) StringFormatter::send(stream,F(" RESERVED"));
|
||||
if (flag & LATCH_FLAG) StringFormatter::send(stream,F(" LATCHED"));
|
||||
REPLY("\nflags[%d] ",id);
|
||||
if (flag & SECTION_FLAG) REPLY(" RESERVED");
|
||||
if (flag & LATCH_FLAG) REPLY(" LATCHED");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,110 +72,189 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
if (slot.type==sigtypeNoMoreSignals) break; // end of signal list
|
||||
if (slot.type==sigtypeContinuation) continue; // continueation of previous line
|
||||
byte flag=flags[sigslot] & SIGNAL_MASK; // obtain signal flags for this ids
|
||||
StringFormatter::send(stream,F("\n%S[%d]"),
|
||||
REPLY("\n%S[%d]",
|
||||
(flag == SIGNAL_RED)? F("RED") : (flag==SIGNAL_GREEN) ? F("GREEN") : F("AMBER"),
|
||||
slot.id);
|
||||
slot.id)
|
||||
}
|
||||
}
|
||||
REPLY(" *>\n")
|
||||
}
|
||||
//
|
||||
bool RMFT2::streamLCC(Print * stream) {
|
||||
if (!(compileFeatures & FEATURE_LCC)) return false;
|
||||
// This function is called to stream the LCC commands to the LCC adapter.
|
||||
LCCSerial=stream; // now we know where to send events we raise
|
||||
|
||||
static int lccProgCounter=0;
|
||||
static int lccEventIndex=0;
|
||||
for (int progCounter=lccProgCounter;; SKIPOP) {
|
||||
byte exrailOpcode=GET_OPCODE;
|
||||
switch (exrailOpcode) {
|
||||
case OPCODE_ENDEXRAIL:
|
||||
stream->print(F("<LR>\n")); // ready to roll
|
||||
lccProgCounter=0; // allow a second pass
|
||||
lccEventIndex=0;
|
||||
return true;
|
||||
|
||||
if (compileFeatures & FEATURE_STASH) {
|
||||
for (int i=1;i<=maxStashId;i++) {
|
||||
if (stashArray[i])
|
||||
StringFormatter::send(stream,F("\nSTASH[%d] Loco=%d"),
|
||||
i, stashArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
StringFormatter::send(stream,F(" *>\n"));
|
||||
return true;
|
||||
}
|
||||
switch (p[0]) {
|
||||
case "PAUSE"_hk: // </ PAUSE>
|
||||
if (paramCount!=1) return false;
|
||||
DCC::setThrottle(0,1,true); // pause all locos on the track
|
||||
pausingTask=(RMFT2 *)1; // Impossible task address
|
||||
return true;
|
||||
|
||||
case "RESUME"_hk: // </ RESUME>
|
||||
if (paramCount!=1) return false;
|
||||
pausingTask=NULL;
|
||||
{
|
||||
RMFT2 * task=loopTask;
|
||||
while(task) {
|
||||
if (task->loco) task->driveLoco(task->speedo);
|
||||
task=task->next;
|
||||
if (task==loopTask) break;
|
||||
case OPCODE_LCC:
|
||||
StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0));
|
||||
SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return true;
|
||||
|
||||
case OPCODE_LCCX: // long form LCC
|
||||
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"),
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return true;
|
||||
|
||||
case OPCODE_ACON: // CBUS ACON
|
||||
case OPCODE_ACOF: // CBUS ACOF
|
||||
StringFormatter::send(stream,F("<LS x%c%h%h>\n"),
|
||||
exrailOpcode==OPCODE_ACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1));
|
||||
SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return true;
|
||||
|
||||
// we stream the hex events we wish to listen to
|
||||
// and at the same time build the event index looku.
|
||||
|
||||
case OPCODE_ONLCC:
|
||||
StringFormatter::send(stream,F("<LL %d x%h%h%h:%h>\n"),
|
||||
lccEventIndex,
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return true;
|
||||
|
||||
case OPCODE_ONACON:
|
||||
case OPCODE_ONACOF:
|
||||
StringFormatter::send(stream,F("<LL %d x%c%h%h>\n"),
|
||||
lccEventIndex,
|
||||
exrailOpcode==OPCODE_ONACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1)
|
||||
);
|
||||
SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RMFT2::parseCommands(Print * stream, byte opcode, byte params, int16_t p[]) {
|
||||
|
||||
ZZBEGIN
|
||||
ZZ(D,EXRAIL,ON) // EXRAIL diagnostics on
|
||||
diag=1;
|
||||
ZZ(D,EXRAIL,OFF) // EXRAIL doagnostics off
|
||||
diag=0; // <D EXRAIL OFF> - turn off diagnostics
|
||||
|
||||
// This is not documented here because its an override of the one in DCCEXParserCommands.h
|
||||
ZZ_nodoc(A,address,aspect) // Send DCC extended accessory (aspect) and syncronize any signal on this address
|
||||
return signalAspectEvent(address,aspect);
|
||||
ZZ(L) // LCC/CBUS adapter introducing self
|
||||
CHECK(streamLCC(stream),no LCC/CBUS events)
|
||||
ZZ(L,eventid) // LCC incoming event
|
||||
CHECK(eventid>=0 && eventid<countLCCLookup)
|
||||
startNonRecursiveTask(F("LCC"),eventid,onLCCLookup[eventid]);
|
||||
|
||||
ZZ(J,A) // List automation ids
|
||||
REPLY("<jA") routeLookup->stream(stream); REPLY(">\n")
|
||||
ZZ(J,A,id) // list automation details
|
||||
REPLY("<jA %d %c \"%S\">\n",id, getRouteType(id), getRouteDescription(id));
|
||||
if (compileFeatures & FEATURE_ROUTESTATE) {
|
||||
// Send any non-default button states or captions
|
||||
int16_t statePos=routeLookup->findPosition(id);
|
||||
if (statePos>=0) {
|
||||
if (routeStateArray[statePos]) REPLY("<jB %d %d>\n", id, routeStateArray[statePos]);
|
||||
if (routeCaptionArray[statePos]) REPLY("<jB %d \"%S\">\n", id,routeCaptionArray[statePos]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
case "START"_hk: // </ START [cab] route >
|
||||
if (paramCount<2 || paramCount>3) return false;
|
||||
{
|
||||
int route=(paramCount==2) ? p[1] : p[2];
|
||||
uint16_t cab=(paramCount==2)? 0 : p[1];
|
||||
int pc=routeLookup->find(route);
|
||||
if (pc<0) return false;
|
||||
RMFT2* task=new RMFT2(pc);
|
||||
task->loco=cab;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ZZ(K,blockid,loco) // Loco entering Block
|
||||
blockEvent(blockid,loco,true);
|
||||
ZZ(k,blockid,loco) // Loco exiting block
|
||||
blockEvent(blockid,loco,false);
|
||||
|
||||
// check KILL ALL here, otherwise the next validation confuses ALL with a flag
|
||||
if (p[0]=="KILL"_hk && p[1]=="ALL"_hk) {
|
||||
while (loopTask) loopTask->kill(F("KILL ALL")); // destructor changes loopTask
|
||||
return true;
|
||||
}
|
||||
|
||||
// all other / commands take 1 parameter
|
||||
if (paramCount!=2 ) return false;
|
||||
|
||||
switch (p[0]) {
|
||||
case "KILL"_hk: // Kill taskid|ALL
|
||||
{
|
||||
if ( p[1]<0 || p[1]>=MAX_FLAGS) return false;
|
||||
RMFT2 * task=loopTask;
|
||||
ZZ(/) // Stream EXRAIL status
|
||||
streamStatus(stream);
|
||||
ZZ(/,PAUSE) // pause all tasks
|
||||
RMFT2 * task=loopTask;
|
||||
while(task) {
|
||||
if (task->taskId==p[1]) {
|
||||
task->pause();
|
||||
task=task->next;
|
||||
if (task==loopTask) break;
|
||||
}
|
||||
DCC::estopAll(); // pause all locos on the track
|
||||
pausingTask=(RMFT2 *)1; // Impossible task address
|
||||
|
||||
ZZ(/,RESUME) // Resume all tasks
|
||||
pausingTask=NULL;
|
||||
RMFT2 * task=loopTask;
|
||||
while(task) {
|
||||
task->resume();
|
||||
task=task->next;
|
||||
if (task==loopTask) break;
|
||||
}
|
||||
|
||||
ZZ(/,START,route) // Start a route or sequence
|
||||
auto pc=routeLookup->find(route);
|
||||
CHECK(pc>=0,route not found)
|
||||
new RMFT2(pc,0); // no cab for route start
|
||||
|
||||
ZZ(/,START,loco,route) // Start an AUTOMATION or sequence with a loco
|
||||
auto pc=routeLookup->find(route);
|
||||
CHECK(pc>=0, route not found)
|
||||
new RMFT2(pc,loco);
|
||||
|
||||
ZZ(/,KILL,ALL) // Kill all exrail tasks
|
||||
while (loopTask) loopTask->kill(F("KILL ALL")); // destructor changes loopTask
|
||||
ZZ(/,KILL,taskid) // Kill specific exrail tasks
|
||||
CHECK(taskid>=0 && taskid<MAX_FLAGS)
|
||||
auto task=loopTask;
|
||||
bool found=false;
|
||||
while(task) {
|
||||
if (task->taskId==taskid) {
|
||||
found=true;
|
||||
task->kill(F("KILL"));
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
task=task->next;
|
||||
if (task==loopTask) break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
case "RESERVE"_hk: // force reserve a section
|
||||
return setFlag(p[1],SECTION_FLAG);
|
||||
|
||||
case "FREE"_hk: // force free a section
|
||||
return setFlag(p[1],0,SECTION_FLAG);
|
||||
|
||||
case "LATCH"_hk:
|
||||
return setFlag(p[1], LATCH_FLAG);
|
||||
|
||||
case "UNLATCH"_hk:
|
||||
return setFlag(p[1], 0, LATCH_FLAG);
|
||||
|
||||
case "RED"_hk:
|
||||
doSignal(p[1],SIGNAL_RED);
|
||||
return true;
|
||||
|
||||
case "AMBER"_hk:
|
||||
doSignal(p[1],SIGNAL_AMBER);
|
||||
return true;
|
||||
|
||||
case "GREEN"_hk:
|
||||
doSignal(p[1],SIGNAL_GREEN);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
CHECK(found, task not found)
|
||||
ZZ(/,RESERVE,section) // Flag section as reserved
|
||||
CHECK(setFlag(section,SECTION_FLAG),invalid section)
|
||||
ZZ(/,FREE,section) // Free reserve on section
|
||||
CHECK(setFlag(section,0,SECTION_FLAG),invalid section)
|
||||
ZZ(/,LATCH,latch) // Set pin latch
|
||||
CHECK(setFlag(latch,LATCH_FLAG),invalid section)
|
||||
ZZ(/,UNLATCH,latch) // Removeve pin latch
|
||||
CHECK(setFlag(latch,0,LATCH_FLAG),invalid section)
|
||||
ZZ(/,RED,signal) // Set signal to Red
|
||||
doSignal(signal,SIGNAL_RED);
|
||||
ZZ(/,AMBER,signal) // set Signal to Amber
|
||||
doSignal(signal,SIGNAL_AMBER);
|
||||
ZZ(/,GREEN,signal) // Set signal to Green
|
||||
doSignal(signal,SIGNAL_GREEN);
|
||||
ZZEND
|
||||
}
|
||||
|
165
EXRAILAsserts.h
Normal file
165
EXRAILAsserts.h
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* © 2020-2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// This file checks the myAutomation for errors by generating a list of compile time asserts.
|
||||
|
||||
// Assert Pass 1 Collect sequence numbers.
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef AUTOMATION
|
||||
#define AUTOMATION(id, description) id,
|
||||
#undef ROUTE
|
||||
#define ROUTE(id, description) id,
|
||||
#undef SEQUENCE
|
||||
#define SEQUENCE(id) id,
|
||||
constexpr int16_t compileTimeSequenceList[]={
|
||||
#include "myAutomation.h"
|
||||
0
|
||||
};
|
||||
constexpr int16_t stuffSize=sizeof(compileTimeSequenceList)/sizeof(int16_t) - 1;
|
||||
|
||||
|
||||
// Compile time function to check for sequence number duplication
|
||||
constexpr int16_t seqCount(const int16_t value, const int16_t pos=0, const int16_t count=0 ) {
|
||||
return pos>=stuffSize? count :
|
||||
seqCount(value,pos+1,count+((compileTimeSequenceList[pos]==value)?1:0));
|
||||
}
|
||||
|
||||
|
||||
// Build a compile time blacklist of pin numbers.
|
||||
// Includes those defined in defaults.h for the cpu (PIN_BLACKLIST)
|
||||
// and cheats in the motor shield pins from config.h (MOTOR_SHIELD_TYPE)
|
||||
// for reference the MotorDriver constructor is:
|
||||
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, int8_t brake_pin, byte current_pin,
|
||||
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||
|
||||
// create capture macros to reinterpret MOTOR_SHIELD_TYPE from configuration
|
||||
#define new
|
||||
#define MotorDriver(power_pin,signal_pin,signal_pin2, \
|
||||
brake_pin,current_pin,senseFactor,tripMilliamps,faultPin) \
|
||||
abs(power_pin),abs(signal_pin),abs(signal_pin2),abs(brake_pin),abs(current_pin),abs(faultPin)
|
||||
#ifndef PIN_BLACKLIST
|
||||
#define PIN_BLACKLIST UNUSED_PIN
|
||||
#endif
|
||||
#define MDFURKLE(stuff) MDFURKLE2(stuff)
|
||||
#define MDFURKLE2(description,...) REMOVE_TRAILING_COMMA(__VA_ARGS__)
|
||||
#define REMOVE_TRAILING_COMMA(...) __VA_ARGS__
|
||||
|
||||
|
||||
constexpr int16_t compileTimePinBlackList[]={
|
||||
PIN_BLACKLIST, MDFURKLE(MOTOR_SHIELD_TYPE)
|
||||
};
|
||||
constexpr int16_t pbSize=sizeof(compileTimePinBlackList)/sizeof(int16_t) - 1;
|
||||
|
||||
|
||||
// remove capture macros
|
||||
#undef new
|
||||
#undef MotorDriver
|
||||
|
||||
// Compile time function to check for dangerous pins.
|
||||
constexpr bool unsafePin(const int16_t value, const uint16_t pos=0 ) {
|
||||
return pos>=pbSize? false :
|
||||
compileTimePinBlackList[pos]==value
|
||||
|| unsafePin(value,pos+1);
|
||||
}
|
||||
|
||||
|
||||
//pass 2 apply static asserts:
|
||||
// check call and follows etc for existing sequence numbers
|
||||
// check sequence numbers for duplicates
|
||||
// check range on LATCH/UNLATCH
|
||||
// check range on RESERVE/FREE
|
||||
// check range on SPEED/FWD/REV
|
||||
// check range on SET/RESET (pins that are not safe to use in EXRAIL)
|
||||
//
|
||||
// This pass generates no runtime data or code
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef ASPECT
|
||||
#define ASPECT(address,value) static_assert(address <=2044, "invalid Address"); \
|
||||
static_assert(address>=-3, "Invalid value");
|
||||
|
||||
// check references to sequences/routes/automations
|
||||
#undef CALL
|
||||
#define CALL(id) static_assert(seqCount(id)>0,"Sequence not found");
|
||||
#undef FOLLOW
|
||||
#define FOLLOW(id) static_assert(seqCount(id)>0,"Sequence not found");
|
||||
#undef START
|
||||
#define START(id) static_assert(seqCount(id)>0,"Sequence not found");
|
||||
#undef SENDLOCO
|
||||
#define SENDLOCO(cab,id) static_assert(seqCount(id)>0,"Sequence not found");
|
||||
#undef ROUTE_ACTIVE
|
||||
#define ROUTE_ACTIVE(id) static_assert(seqCount(id)>0,"Route not found");
|
||||
#undef ROUTE_INACTIVE
|
||||
#define ROUTE_INACTIVE(id) static_assert(seqCount(id)>0,"Route not found");
|
||||
#undef ROUTE_HIDDEN
|
||||
#define ROUTE_HIDDEN(id) static_assert(seqCount(id)>0,"Route not found");
|
||||
#undef ROUTE_DISABLED
|
||||
#define ROUTE_DISABLED(id) static_assert(seqCount(id)>0,"Route not found");
|
||||
#undef ROUTE_CAPTION
|
||||
#define ROUTE_CAPTION(id,caption) static_assert(seqCount(id)>0,"Route not found");
|
||||
|
||||
|
||||
#undef LATCH
|
||||
#define LATCH(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef UNLATCH
|
||||
#define UNLATCH(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef RESERVE
|
||||
#define RESERVE(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef FREE
|
||||
#define FREE(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef IFRESERVE
|
||||
#define IFRESERVE(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
|
||||
//check speeds
|
||||
#undef SPEED
|
||||
#define SPEED(speed) static_assert(speed>=0 && speed<128,"\n\nUSER ERROR: Speed out of valid range 0-127\n");
|
||||
#undef FWD
|
||||
#define FWD(speed) static_assert(speed>=0 && speed<128,"\n\nUSER ERROR: Speed out of valid range 0-127\n");
|
||||
#undef REV
|
||||
#define REV(speed) static_assert(speed>=0 && speed<128,"\n\nUSER ERROR: Speed out of valid range 0-127\n");
|
||||
|
||||
// check duplicate sequences
|
||||
#undef SEQUENCE
|
||||
#define SEQUENCE(id) static_assert(seqCount(id)==1,"\n\nUSER ERROR: Duplicate ROUTE/AUTOMATION/SEQUENCE(" #id ")\n");
|
||||
#undef AUTOMATION
|
||||
#define AUTOMATION(id,description) static_assert(seqCount(id)==1,"\n\nUSER ERROR: Duplicate ROUTE/AUTOMATION/SEQUENCE(" #id ")\n");
|
||||
#undef ROUTE
|
||||
#define ROUTE(id,description) static_assert(seqCount(id)==1,"\n\nUSER ERROR: Duplicate ROUTE/AUTOMATION/SEQUENCE(" #id ")\n");
|
||||
|
||||
// check dangerous pins
|
||||
#define _PIN_RESERVED_ "\n\nUSER ERROR: Pin is used by Motor Shield or other critical function.\n"
|
||||
#undef SET
|
||||
#define SET(vpin, ...) static_assert(!unsafePin(vpin),"SET(" #vpin ")" _PIN_RESERVED_);
|
||||
#undef RESET
|
||||
#define RESET(vpin,...) static_assert(!unsafePin(vpin),"RESET(" #vpin ")" _PIN_RESERVED_);
|
||||
#undef BLINK
|
||||
#define BLINK(vpin,onDuty,offDuty) static_assert(!unsafePin(vpin),"BLINK(" #vpin ")" _PIN_RESERVED_);
|
||||
#undef SIGNAL
|
||||
#define SIGNAL(redpin,amberpin,greenpin) \
|
||||
static_assert(!unsafePin(redpin),"Red pin " #redpin _PIN_RESERVED_); \
|
||||
static_assert(amberpin==0 ||!unsafePin(amberpin),"Amber pin " #amberpin _PIN_RESERVED_); \
|
||||
static_assert(!unsafePin(greenpin),"Green pin " #greenpin _PIN_RESERVED_);
|
||||
#undef SIGNALH
|
||||
#define SIGNALH(redpin,amberpin,greenpin) \
|
||||
static_assert(!unsafePin(redpin),"Red pin " #redpin _PIN_RESERVED_); \
|
||||
static_assert(amberpin==0 ||!unsafePin(amberpin),"Amber pin " #amberpin _PIN_RESERVED_); \
|
||||
static_assert(!unsafePin(greenpin),"Green pin " #greenpin _PIN_RESERVED_);
|
||||
|
||||
// and run the assert pass.
|
||||
#include "myAutomation.h"
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2020-2022 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2023 Harald Barth
|
||||
* © 2025 Morten Nielsen
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#ifndef EXRAILMacros_H
|
||||
#define EXRAILMacros_H
|
||||
#include "IODeviceList.h"
|
||||
|
||||
// remove normal code LCD & SERIAL macros (will be restored later)
|
||||
#undef LCD
|
||||
@@ -85,72 +86,8 @@
|
||||
#define ALIAS(name,value...) const int name= #value[0] ? value+0: -__COUNTER__ ;
|
||||
#include "myAutomation.h"
|
||||
|
||||
// Pass 1d Detect sequence duplicates.
|
||||
// This pass generates no runtime data or code
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef AUTOMATION
|
||||
#define AUTOMATION(id, description) id,
|
||||
#undef ROUTE
|
||||
#define ROUTE(id, description) id,
|
||||
#undef SEQUENCE
|
||||
#define SEQUENCE(id) id,
|
||||
constexpr int16_t compileTimeSequenceList[]={
|
||||
#include "myAutomation.h"
|
||||
0
|
||||
};
|
||||
constexpr int16_t stuffSize=sizeof(compileTimeSequenceList)/sizeof(int16_t) - 1;
|
||||
|
||||
|
||||
// Compile time function to check for sequence nos.
|
||||
constexpr bool hasseq(const int16_t value, const int16_t pos=0 ) {
|
||||
return pos>=stuffSize? false :
|
||||
compileTimeSequenceList[pos]==value
|
||||
|| hasseq(value,pos+1);
|
||||
}
|
||||
|
||||
// Compile time function to check for duplicate sequence nos.
|
||||
constexpr bool hasdup(const int16_t value, const int16_t pos ) {
|
||||
return pos>=stuffSize? false :
|
||||
compileTimeSequenceList[pos]==value
|
||||
|| hasseq(value,pos+1)
|
||||
|| hasdup(compileTimeSequenceList[pos],pos+1);
|
||||
}
|
||||
|
||||
|
||||
static_assert(!hasdup(compileTimeSequenceList[0],1),"Duplicate SEQUENCE/ROUTE/AUTOMATION detected");
|
||||
|
||||
//pass 1s static asserts to
|
||||
// - check call and follows etc for existing sequence numbers
|
||||
// - check range on LATCH/UNLATCH
|
||||
// This pass generates no runtime data or code
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef ASPECT
|
||||
#define ASPECT(address,value) static_assert(address <=2044, "invalid Address"); \
|
||||
static_assert(address>=-3, "Invalid value");
|
||||
#undef CALL
|
||||
#define CALL(id) static_assert(hasseq(id),"Sequence not found");
|
||||
#undef FOLLOW
|
||||
#define FOLLOW(id) static_assert(hasseq(id),"Sequence not found");
|
||||
#undef START
|
||||
#define START(id) static_assert(hasseq(id),"Sequence not found");
|
||||
#undef SENDLOCO
|
||||
#define SENDLOCO(cab,id) static_assert(hasseq(id),"Sequence not found");
|
||||
#undef LATCH
|
||||
#define LATCH(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef UNLATCH
|
||||
#define UNLATCH(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef RESERVE
|
||||
#define RESERVE(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef FREE
|
||||
#define FREE(id) static_assert(id>=0 && id<MAX_FLAGS,"Id out of valid range 0-255" );
|
||||
#undef SPEED
|
||||
#define SPEED(speed) static_assert(speed>=0 && speed<128,"Speed out of valid range 0-127");
|
||||
#undef FWD
|
||||
#define FWD(speed) static_assert(speed>=0 && speed<128,"Speed out of valid range 0-127");
|
||||
#undef REV
|
||||
#define REV(speed) static_assert(speed>=0 && speed<128,"Speed out of valid range 0-127");
|
||||
|
||||
#include "myAutomation.h"
|
||||
// Perform compile time asserts to check the script for errors
|
||||
#include "EXRAILAsserts.h"
|
||||
|
||||
// Pass 1g Implants STEALTH_GLOBAL in correct place
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
@@ -217,20 +154,16 @@ bool exrailHalSetup() {
|
||||
#undef ROUTE_CAPTION
|
||||
#define ROUTE_CAPTION(id,caption) | FEATURE_ROUTESTATE
|
||||
|
||||
#undef CLEAR_STASH
|
||||
#define CLEAR_STASH(id) | FEATURE_STASH
|
||||
#undef CLEAR_ALL_STASH
|
||||
#define CLEAR_ALL_STASH | FEATURE_STASH
|
||||
#undef PICKUP_STASH
|
||||
#define PICKUP_STASH(id) | FEATURE_STASH
|
||||
#undef STASH
|
||||
#define STASH(id) | FEATURE_STASH
|
||||
#undef BLINK
|
||||
#define BLINK(vpin,onDuty,offDuty) | FEATURE_BLINK
|
||||
#undef ONBUTTON
|
||||
#define ONBUTTON(vpin) | FEATURE_SENSOR
|
||||
#undef ONSENSOR
|
||||
#define ONSENSOR(vpin) | FEATURE_SENSOR
|
||||
#undef ONBLOCKENTER
|
||||
#define ONBLOCKENTER(blockid) | FEATURE_BLOCK
|
||||
#undef ONBLOCKEXIT
|
||||
#define ONBLOCKEXIT(blockid) | FEATURE_BLOCK
|
||||
|
||||
const byte RMFT2::compileFeatures = 0
|
||||
#include "myAutomation.h"
|
||||
@@ -494,6 +427,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define CALL(route) OPCODE_CALL,V(route),
|
||||
#define CLEAR_STASH(id) OPCODE_CLEAR_STASH,V(id),
|
||||
#define CLEAR_ALL_STASH OPCODE_CLEAR_ALL_STASH,V(0),
|
||||
#define CLEAR_ANY_STASH OPCODE_CLEAR_ANY_STASH,V(0),
|
||||
#define CLOSE(id) OPCODE_CLOSE,V(id),
|
||||
#define CONFIGURE_SERVO(vpin,pos1,pos2,profile)
|
||||
#ifndef IO_NO_HAL
|
||||
@@ -513,6 +447,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define ENDIF OPCODE_ENDIF,0,0,
|
||||
#define ENDTASK OPCODE_ENDTASK,0,0,
|
||||
#define ESTOP OPCODE_SPEED,V(1),
|
||||
#define ESTOPALL OPCODE_ESTOPALL,0,0,
|
||||
#define EXRAIL
|
||||
#ifndef IO_NO_HAL
|
||||
#define EXTT_TURNTABLE(id,vpin,home,description...) OPCODE_EXTTTURNTABLE,V(id),OPCODE_PAD,V(vpin),OPCODE_PAD,V(home),
|
||||
@@ -539,6 +474,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define IFRANDOM(percent) OPCODE_IFRANDOM,V(percent),
|
||||
#define IFRED(signal_id) OPCODE_IFRED,V(signal_id),
|
||||
#define IFRESERVE(block) OPCODE_IFRESERVE,V(block),
|
||||
#define IFSTASH(stash_id) OPCODE_IFSTASH,V(stash_id),
|
||||
#define IFTHROWN(turnout_id) OPCODE_IFTHROWN,V(turnout_id),
|
||||
#define IFTIMEOUT OPCODE_IFTIMEOUT,0,0,
|
||||
#ifndef IO_NO_HAL
|
||||
@@ -565,6 +501,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define STEALTH_GLOBAL(code...)
|
||||
#define LCN(msg) PRINT(msg)
|
||||
#define MESSAGE(msg) PRINT(msg)
|
||||
#define MOMENTUM(accel,decel...) OPCODE_MOMENTUM,V(accel),OPCODE_PAD,V(#decel[0]?decel+0:accel),
|
||||
#define MOVETT(id,steps,activity) OPCODE_SERVO,V(id),OPCODE_PAD,V(steps),OPCODE_PAD,V(EXTurntable::activity),OPCODE_PAD,V(0),
|
||||
#define NEOPIXEL(id,r,g,b,count...) OPCODE_NEOPIXEL,V(id),\
|
||||
OPCODE_PAD,V(((r & 0xff)<<8) | (g & 0xff)),\
|
||||
@@ -575,6 +512,8 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define ONACTIVATE(addr,subaddr) OPCODE_ONACTIVATE,V(addr<<2|subaddr),
|
||||
#define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3),
|
||||
#define ONAMBER(signal_id) OPCODE_ONAMBER,V(signal_id),
|
||||
#define ONBLOCKENTER(block_id) OPCODE_ONBLOCKENTER,V(block_id),
|
||||
#define ONBLOCKEXIT(block_id) OPCODE_ONBLOCKEXIT,V(block_id),
|
||||
#define ONCLOSE(turnout_id) OPCODE_ONCLOSE,V(turnout_id),
|
||||
#define ONLCC(sender,event) OPCODE_ONLCC,V(event),\
|
||||
OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\
|
||||
@@ -598,9 +537,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define PAUSE OPCODE_PAUSE,0,0,
|
||||
#define PICKUP_STASH(id) OPCODE_PICKUP_STASH,V(id),
|
||||
#define PIN_TURNOUT(id,pin,description...) OPCODE_PINTURNOUT,V(id),OPCODE_PAD,V(pin),
|
||||
#ifndef DISABLE_PROG
|
||||
#define POM(cv,value) OPCODE_POM,V(cv),OPCODE_PAD,V(value),
|
||||
#endif
|
||||
#define POWEROFF OPCODE_POWEROFF,0,0,
|
||||
#define POWERON OPCODE_POWERON,0,0,
|
||||
#define PRINT(msg) OPCODE_PRINT,V(__COUNTER__ - StringMacroTracker2),
|
||||
@@ -668,6 +605,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define XFTOGGLE(cab,func) OPCODE_XFTOGGLE,V(cab),OPCODE_PAD,V(func),
|
||||
#define XFWD(cab,speed) OPCODE_XFWD,V(cab),OPCODE_PAD,V(speed),
|
||||
#define XREV(cab,speed) OPCODE_XREV,V(cab),OPCODE_PAD,V(speed),
|
||||
#define XPOM(cab,cv,value) OPCODE_XPOM,V(cab),OPCODE_PAD,V(cv),OPCODE_PAD,V(value),
|
||||
|
||||
// Build RouteCode
|
||||
const int StringMacroTracker2=__COUNTER__;
|
||||
|
200
EXmDNS.cpp
Normal file
200
EXmDNS.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* © 2024 Harald Barth
|
||||
* © 2024 Paul M. Antoine
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "EthernetInterface.h"
|
||||
#ifdef DO_MDNS
|
||||
#include "EXmDNS.h"
|
||||
|
||||
// fixed values for mDNS
|
||||
static IPAddress mdnsMulticastIPAddr = IPAddress(224, 0, 0, 251);
|
||||
#define MDNS_SERVER_PORT 5353
|
||||
|
||||
// dotToLen()
|
||||
// converts stings of form ".foo.barbar.x" to a string with the
|
||||
// dots replaced with lenght. So string above would result in
|
||||
// "\x03foo\x06barbar\x01x" in C notation. If not NULL, *substr
|
||||
// will point to the beginning of the last component, in this
|
||||
// example that would be "\x01x".
|
||||
//
|
||||
static void dotToLen(char *str, char **substr) {
|
||||
char *dotplace = NULL;
|
||||
char *s;
|
||||
byte charcount = 0;
|
||||
for (s = str;/*see break*/ ; s++) {
|
||||
if (*s == '.' || *s == '\0') {
|
||||
// take care of accumulated
|
||||
if (dotplace != NULL && charcount != 0) {
|
||||
*dotplace = charcount;
|
||||
}
|
||||
if (*s == '\0')
|
||||
break;
|
||||
if (substr && *s == '.')
|
||||
*substr = s;
|
||||
// set new values
|
||||
dotplace = s;
|
||||
charcount = 0;
|
||||
} else {
|
||||
charcount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MDNS::MDNS(EthernetUDP& udp) {
|
||||
_udp = &udp;
|
||||
}
|
||||
MDNS::~MDNS() {
|
||||
_udp->stop();
|
||||
if (_name) free(_name);
|
||||
if (_serviceName) free(_serviceName);
|
||||
if (_serviceProto) free(_serviceProto);
|
||||
}
|
||||
int MDNS::begin(const IPAddress& ip, char* name) {
|
||||
// if we were called very soon after the board was booted, we need to give the
|
||||
// EthernetShield (WIZnet) some time to come up. Hence, we delay until millis() is at
|
||||
// least 3000. This is necessary, so that if we need to add a service record directly
|
||||
// after begin, the announce packet does not get lost in the bowels of the WIZnet chip.
|
||||
//while (millis() < 3000)
|
||||
// delay(100);
|
||||
|
||||
_ipAddress = ip;
|
||||
_name = (char *)malloc(strlen(name)+2);
|
||||
byte n;
|
||||
for(n = 0; n<strlen(name); n++)
|
||||
_name[n+1] = name[n];
|
||||
_name[n+1] = '\0';
|
||||
_name[0] = '.';
|
||||
dotToLen(_name, NULL);
|
||||
return _udp->beginMulticast(mdnsMulticastIPAddr, MDNS_SERVER_PORT);
|
||||
}
|
||||
|
||||
int MDNS::addServiceRecord(const char* name, uint16_t port, MDNSServiceProtocol_t proto) {
|
||||
// we ignore proto, assume TCP
|
||||
(void)proto;
|
||||
_serviceName = (char *)malloc(strlen(name) + 2);
|
||||
byte n;
|
||||
for(n = 0; n<strlen(name); n++)
|
||||
_serviceName[n+1] = name[n];
|
||||
_serviceName[n+1] = '\0';
|
||||
_serviceName[0] = '.';
|
||||
_serviceProto = NULL; //to be filled in
|
||||
dotToLen(_serviceName, &_serviceProto);
|
||||
_servicePort = port;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char dns_rr_services[] = "\x09_services\x07_dns-sd\x04_udp\x05local";
|
||||
static char dns_rr_tcplocal[] = "\x04_tcp\x05local";
|
||||
static char *dns_rr_local = dns_rr_tcplocal + dns_rr_tcplocal[0] + 1;
|
||||
|
||||
typedef struct _DNSHeader_t
|
||||
{
|
||||
uint16_t xid;
|
||||
uint16_t flags; // flags condensed
|
||||
uint16_t queryCount;
|
||||
uint16_t answerCount;
|
||||
uint16_t authorityCount;
|
||||
uint16_t additionalCount;
|
||||
} __attribute__((__packed__)) DNSHeader_t;
|
||||
|
||||
//
|
||||
// MDNS::run()
|
||||
// This broadcasts whatever we got evey BROADCASTTIME seconds.
|
||||
// Why? Too much brokenness i all mDNS implementations available
|
||||
//
|
||||
void MDNS::run() {
|
||||
static long int lastrun = BROADCASTTIME * 1000UL;
|
||||
unsigned long int now = millis();
|
||||
if (!(now - lastrun > BROADCASTTIME * 1000UL)) {
|
||||
return;
|
||||
}
|
||||
lastrun = now;
|
||||
DNSHeader_t dnsHeader = {0, 0, 0, 0, 0, 0};
|
||||
// DNSHeader_t dnsHeader = { 0 };
|
||||
|
||||
_udp->beginPacket(mdnsMulticastIPAddr, MDNS_SERVER_PORT);
|
||||
|
||||
// dns header
|
||||
dnsHeader.flags = HTONS((uint16_t)0x8400); // Response, authorative
|
||||
dnsHeader.answerCount = HTONS(4 /*5 if TXT but we do not do that */);
|
||||
_udp->write((uint8_t*)&dnsHeader, sizeof(DNSHeader_t));
|
||||
|
||||
// rr #1, the PTR record from generic _services.x.local to service.x.local
|
||||
_udp->write((uint8_t*)dns_rr_services, sizeof(dns_rr_services));
|
||||
|
||||
byte buf[10];
|
||||
buf[0] = 0x00;
|
||||
buf[1] = 0x0c; //PTR
|
||||
buf[2] = 0x00;
|
||||
buf[3] = 0x01; //IN
|
||||
*((uint32_t*)(buf+4)) = HTONL(120); //TTL in sec
|
||||
*((uint16_t*)(buf+8)) = HTONS( _serviceProto[0] + 1 + strlen(dns_rr_tcplocal) + 1);
|
||||
_udp->write(buf, 10);
|
||||
|
||||
_udp->write(_serviceProto,_serviceProto[0]+1);
|
||||
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
||||
|
||||
// rr #2, the PTR record from proto.x to name.proto.x
|
||||
_udp->write(_serviceProto,_serviceProto[0]+1);
|
||||
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
||||
*((uint16_t*)(buf+8)) = HTONS(strlen(_serviceName) + strlen(dns_rr_tcplocal) + 1); // recycle most of buf
|
||||
_udp->write(buf, 10);
|
||||
|
||||
_udp->write(_serviceName, strlen(_serviceName));
|
||||
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
||||
// rr #3, the SRV record for the service that points to local name
|
||||
_udp->write(_serviceName, strlen(_serviceName));
|
||||
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
||||
|
||||
buf[1] = 0x21; // recycle most of buf but here SRV
|
||||
buf[2] = 0x80; // cache flush
|
||||
*((uint16_t*)(buf+8)) = HTONS(strlen(_name) + strlen(dns_rr_local) + 1 + 6);
|
||||
_udp->write(buf, 10);
|
||||
|
||||
byte srv[6];
|
||||
// priority and weight
|
||||
srv[0] = srv[1] = srv[2] = srv[3] = 0;
|
||||
// port
|
||||
*((uint16_t*)(srv+4)) = HTONS(_servicePort);
|
||||
_udp->write(srv, 6);
|
||||
// target
|
||||
_udp->write(_name, _name[0]+1);
|
||||
_udp->write(dns_rr_local, strlen(dns_rr_local)+1);
|
||||
|
||||
// rr #4, the A record for the name.local
|
||||
_udp->write(_name, _name[0]+1);
|
||||
_udp->write(dns_rr_local, strlen(dns_rr_local)+1);
|
||||
|
||||
buf[1] = 0x01; // recycle most of buf but here A
|
||||
*((uint16_t*)(buf+8)) = HTONS(4);
|
||||
_udp->write(buf, 10);
|
||||
byte ip[4];
|
||||
ip[0] = _ipAddress[0];
|
||||
ip[1] = _ipAddress[1];
|
||||
ip[2] = _ipAddress[2];
|
||||
ip[3] = _ipAddress[3];
|
||||
_udp->write(ip, 4);
|
||||
|
||||
_udp->endPacket();
|
||||
_udp->flush();
|
||||
//
|
||||
}
|
||||
#endif //DO_MDNS
|
50
EXmDNS.h
Normal file
50
EXmDNS.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* © 2024 Harald Barth
|
||||
* © 2024 Paul M. Antoine
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifdef DO_MDNS
|
||||
#define BROADCASTTIME 15 //seconds
|
||||
|
||||
// We do this ourselves because every library is different and/or broken...
|
||||
#define HTONS(x) ((uint16_t)(((x) << 8) | (((x) >> 8) & 0xFF)))
|
||||
#define HTONL(x) ( ((uint32_t)(x) << 24) | (((uint32_t)(x) << 8) & 0xFF0000) | \
|
||||
(((uint32_t)(x) >> 8) & 0xFF00) | ((uint32_t)(x) >> 24) )
|
||||
|
||||
typedef enum _MDNSServiceProtocol_t
|
||||
{
|
||||
MDNSServiceTCP,
|
||||
MDNSServiceUDP
|
||||
} MDNSServiceProtocol_t;
|
||||
|
||||
class MDNS {
|
||||
public:
|
||||
MDNS(EthernetUDP& udp);
|
||||
~MDNS();
|
||||
int begin(const IPAddress& ip, char* name);
|
||||
int addServiceRecord(const char* name, uint16_t port, MDNSServiceProtocol_t proto);
|
||||
void run();
|
||||
private:
|
||||
EthernetUDP *_udp;
|
||||
IPAddress _ipAddress;
|
||||
char* _name;
|
||||
char* _serviceName;
|
||||
char* _serviceProto;
|
||||
int _servicePort;
|
||||
};
|
||||
#endif //DO_MDNS
|
@@ -31,13 +31,12 @@
|
||||
#include "CommandDistributor.h"
|
||||
#include "WiThrottle.h"
|
||||
#include "DCCTimer.h"
|
||||
#if __has_include ( "MDNS_Generic.h")
|
||||
#include "MDNS_Generic.h"
|
||||
#define DO_MDNS
|
||||
EthernetUDP udp;
|
||||
MDNS mdns(udp);
|
||||
#endif
|
||||
|
||||
#ifdef DO_MDNS
|
||||
#include "EXmDNS.h"
|
||||
EthernetUDP udp;
|
||||
MDNS mdns(udp);
|
||||
#endif
|
||||
|
||||
//extern void looptimer(unsigned long timeout, const FSH* message);
|
||||
#define looptimer(a,b)
|
||||
@@ -116,10 +115,10 @@ void EthernetInterface::setup()
|
||||
|
||||
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
|
||||
#ifdef DO_MDNS
|
||||
mdns.begin(Ethernet.localIP(), WIFI_HOSTNAME); // hostname
|
||||
if (!mdns.begin(Ethernet.localIP(), (char *)WIFI_HOSTNAME))
|
||||
DIAG(F("mdns.begin fail")); // hostname
|
||||
mdns.addServiceRecord(WIFI_HOSTNAME "._withrottle", IP_PORT, MDNSServiceTCP);
|
||||
// Not sure if we need to run it once, but just in case!
|
||||
mdns.run();
|
||||
mdns.run(); // run it right away to get out info ASAP
|
||||
#endif
|
||||
connected=true;
|
||||
}
|
||||
@@ -144,7 +143,9 @@ void EthernetInterface::acceptClient() { // STM32 version
|
||||
return;
|
||||
}
|
||||
}
|
||||
DIAG(F("Ethernet OVERFLOW"));
|
||||
// reached here only if more than MAX_SOCK_NUM clients want to connect
|
||||
DIAG(F("Ethernet more than %d clients, not accepting new connection"), MAX_SOCK_NUM);
|
||||
client.stop();
|
||||
}
|
||||
#else
|
||||
void EthernetInterface::acceptClient() { // non-STM32 version
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2024 Harald Barth
|
||||
* © 2020-2024 Chris Harlow
|
||||
* © 2020 Gregor Baues
|
||||
* All rights reserved.
|
||||
@@ -31,24 +31,32 @@
|
||||
#define EthernetInterface_h
|
||||
|
||||
#include "defines.h"
|
||||
#if ETHERNET_ON == true
|
||||
#include "DCCEXParser.h"
|
||||
#include <Arduino.h>
|
||||
//#include <avr/pgmspace.h>
|
||||
#if defined (ARDUINO_TEENSY41)
|
||||
#include <NativeEthernet.h> //TEENSY Ethernet Treiber
|
||||
#include <NativeEthernetUdp.h>
|
||||
#ifndef MAX_SOCK_NUM
|
||||
#define MAX_SOCK_NUM 4
|
||||
#endif
|
||||
// can't use our MDNS because of a namespace clash with Teensy's NativeEthernet library!
|
||||
// #define DO_MDNS
|
||||
#elif defined (ARDUINO_NUCLEO_F429ZI) || defined (ARDUINO_NUCLEO_F439ZI) || defined (ARDUINO_NUCLEO_F4X9ZI)
|
||||
#include <LwIP.h>
|
||||
// #include "STM32lwipopts.h"
|
||||
#include <STM32Ethernet.h>
|
||||
#include <lwip/netif.h>
|
||||
extern "C" struct netif gnetif;
|
||||
#define STM32_ETHERNET
|
||||
#define MAX_SOCK_NUM 8
|
||||
#define MAX_SOCK_NUM MAX_NUM_TCP_CLIENTS
|
||||
#define DO_MDNS
|
||||
#else
|
||||
#include "Ethernet.h"
|
||||
#define DO_MDNS
|
||||
#endif
|
||||
|
||||
|
||||
#include "RingStream.h"
|
||||
|
||||
/**
|
||||
@@ -77,5 +85,5 @@ class EthernetInterface {
|
||||
static void dropClient(byte socketnum);
|
||||
|
||||
};
|
||||
|
||||
#endif // ETHERNET_ON
|
||||
#endif
|
||||
|
@@ -1 +1 @@
|
||||
#define GITHUB_SHA "c389fe9"
|
||||
#define GITHUB_SHA "devel-202503250850Z"
|
||||
|
14
IODevice.h
14
IODevice.h
@@ -560,18 +560,6 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
#include "IO_MCP23008.h"
|
||||
#include "IO_MCP23017.h"
|
||||
#include "IO_PCF8574.h"
|
||||
#include "IO_PCF8575.h"
|
||||
#include "IO_PCA9555.h"
|
||||
#include "IO_duinoNodes.h"
|
||||
#include "IO_EXIOExpander.h"
|
||||
#include "IO_trainbrains.h"
|
||||
#include "IO_EncoderThrottle.h"
|
||||
#include "IO_TCA8418.h"
|
||||
#include "IO_NeoPixel.h"
|
||||
#include "IO_TM1638.h"
|
||||
#include "IO_EXSensorCAM.h"
|
||||
//#include "IODeviceList.h"
|
||||
|
||||
#endif // iodevice_h
|
||||
|
38
IODeviceList.h
Normal file
38
IODeviceList.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
/*
|
||||
This is the list of HAL drivers automatically included by IODevice.h
|
||||
It has been moved here to be easier to maintain than editing IODevice.h
|
||||
*/
|
||||
#include "IO_MCP23008.h"
|
||||
#include "IO_MCP23017.h"
|
||||
#include "IO_PCF8574.h"
|
||||
#include "IO_PCF8575.h"
|
||||
#include "IO_PCA9555.h"
|
||||
#include "IO_duinoNodes.h"
|
||||
#include "IO_EXIOExpander.h"
|
||||
#include "IO_trainbrains.h"
|
||||
#include "IO_EncoderThrottle.h"
|
||||
#include "IO_TCA8418.h"
|
||||
#include "IO_NeoPixel.h"
|
||||
#include "IO_TM1638.h"
|
||||
#include "IO_EXSensorCAM.h"
|
||||
#include "IO_DS1307.h"
|
||||
#include "IO_I2CRailcom.h"
|
||||
|
143
IO_DS1307.cpp
Normal file
143
IO_DS1307.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The IO_DS1307 device driver is used to interface a standalone realtime clock.
|
||||
* The clock will announce every minute (which will trigger EXRAIL ONTIME events).
|
||||
* Seconds, and Day/date info is ignored, except that the announced hhmm time
|
||||
* will attempt to synchronize with the 0 seconds of the clock.
|
||||
* An analog read in EXRAIL (IFGTE(vpin, value) etc will check against the hh*60+mm time.
|
||||
* The clock can be easily set by an analog write to the vpin using 24 hr clock time
|
||||
* with the command <z vpin hh mm ss>
|
||||
*/
|
||||
|
||||
#include "IO_DS1307.h"
|
||||
#include "I2CManager.h"
|
||||
#include "DIAG.h"
|
||||
#include "CommandDistributor.h"
|
||||
|
||||
uint8_t d2b(uint8_t d) {
|
||||
return (d >> 4)*10 + (d & 0x0F);
|
||||
}
|
||||
|
||||
void DS1307::create(VPIN vpin, I2CAddress i2cAddress) {
|
||||
if (checkNoOverlap(vpin, 1, i2cAddress)) new DS1307(vpin, i2cAddress);
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
DS1307::DS1307(VPIN vpin,I2CAddress i2cAddress){
|
||||
_firstVpin = vpin;
|
||||
_nPins = 1;
|
||||
_I2CAddress = i2cAddress;
|
||||
addDevice(this);
|
||||
}
|
||||
|
||||
uint32_t DS1307::getTime() {
|
||||
// Obtain ss,mm,hh buffers from device
|
||||
uint8_t readBuffer[3];
|
||||
const uint8_t writeBuffer[1]={0};
|
||||
|
||||
// address register 0 for read.
|
||||
I2CManager.write(_I2CAddress, writeBuffer, 1);
|
||||
if (I2CManager.read(_I2CAddress, readBuffer, 3) != I2C_STATUS_OK) {
|
||||
_deviceState=DEVSTATE_FAILED;
|
||||
return 0;
|
||||
}
|
||||
_deviceState=DEVSTATE_NORMAL;
|
||||
|
||||
if (debug) {
|
||||
static const char hexchars[]="0123456789ABCDEF";
|
||||
USB_SERIAL.print(F("<*RTC"));
|
||||
for (int i=2;i>=0;i--) {
|
||||
USB_SERIAL.write(' ');
|
||||
USB_SERIAL.write(hexchars[readBuffer[i]>>4]);
|
||||
USB_SERIAL.write(hexchars[readBuffer[i]& 0x0F ]);
|
||||
}
|
||||
StringFormatter::send(&USB_SERIAL,F(" %d *>\n"),_deviceState);
|
||||
}
|
||||
|
||||
if (readBuffer[0] & 0x80) {
|
||||
_deviceState=DEVSTATE_INITIALISING;
|
||||
DIAG(F("DS1307 clock in standby"));
|
||||
return 0; // clock is not running
|
||||
}
|
||||
// convert device format to seconds since midnight
|
||||
uint8_t ss=d2b(readBuffer[0] & 0x7F);
|
||||
uint8_t mm=d2b(readBuffer[1]);
|
||||
uint8_t hh=d2b(readBuffer[2] & 0x3F);
|
||||
return (hh*60ul +mm)*60ul +ss;
|
||||
}
|
||||
|
||||
void DS1307::_begin() {
|
||||
// Initialise device and sync loop() to zero seconds
|
||||
I2CManager.begin();
|
||||
auto tstamp=getTime();
|
||||
if (_deviceState==DEVSTATE_NORMAL) {
|
||||
byte seconds=tstamp%60;
|
||||
delayUntil(micros() + ((60-seconds) * 1000000));
|
||||
}
|
||||
_display();
|
||||
}
|
||||
|
||||
// Processing loop to obtain clock time.
|
||||
// This self-synchronizes to the next minute tickover
|
||||
void DS1307::_loop(unsigned long currentMicros) {
|
||||
auto time=getTime();
|
||||
if (_deviceState==DEVSTATE_NORMAL) {
|
||||
byte ss=time%60;
|
||||
CommandDistributor::setClockTime(time/60, 1, 1);
|
||||
delayUntil(currentMicros + ((60-ss) * 1000000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Display device driver info.
|
||||
void DS1307::_display() {
|
||||
auto tstamp=getTime();
|
||||
byte ss=tstamp%60;
|
||||
tstamp/=60;
|
||||
byte mm=tstamp%60;
|
||||
byte hh=tstamp/60;
|
||||
DIAG(F("DS1307 on I2C:%s vpin %d %d:%d:%d %S"),
|
||||
_I2CAddress.toString(), _firstVpin,
|
||||
hh,mm,ss,
|
||||
(_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F(""));
|
||||
}
|
||||
|
||||
// allow user to set the clock
|
||||
void DS1307::_writeAnalogue(VPIN vpin, int hh, uint8_t mm, uint16_t ss) {
|
||||
(void) vpin;
|
||||
uint8_t writeBuffer[3];
|
||||
writeBuffer[0]=1; // write mm,hh first
|
||||
writeBuffer[1]=((mm/10)<<4) + (mm % 10);
|
||||
writeBuffer[2]=((hh/10)<<4) + (hh % 10);
|
||||
I2CManager.write(_I2CAddress, writeBuffer, 3);
|
||||
writeBuffer[0]=0; // write ss
|
||||
writeBuffer[1]=((ss/10)<<4) + (ss % 10);
|
||||
I2CManager.write(_I2CAddress, writeBuffer, 2);
|
||||
_loop(micros()); // resync with seconds rollover
|
||||
}
|
||||
|
||||
// Method to read analogue hh*60+mm time
|
||||
int DS1307::_readAnalogue(VPIN vpin) {
|
||||
(void)vpin;
|
||||
return getTime()/60;
|
||||
};
|
||||
|
54
IO_DS1307.h
Normal file
54
IO_DS1307.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The IO_DS1307 device driver is used to interface a standalone realtime clock.
|
||||
* The clock will announce every minute (which will trigger EXRAIL ONTIME events).
|
||||
* Seconds, and Day/date info is ignored, except that the announced hhmm time
|
||||
* will attempt to synchronize with the 0 seconds of the clock.
|
||||
* An analog read in EXRAIL (IFGTE(vpin, value) etc will check against the hh*60+mm time.
|
||||
* The clock can be easily set by an analog write to the vpin using 24 hr clock time
|
||||
* with the command <z vpin hh mm ss>
|
||||
*/
|
||||
|
||||
#ifndef IO_DS1307_h
|
||||
#define IO_DS1307_h
|
||||
|
||||
|
||||
#include "IODevice.h"
|
||||
|
||||
class DS1307 : public IODevice {
|
||||
public:
|
||||
static const bool debug=false;
|
||||
static void create(VPIN vpin, I2CAddress i2cAddress);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Constructor
|
||||
DS1307(VPIN vpin,I2CAddress i2cAddress);
|
||||
uint32_t getTime();
|
||||
void _begin() override;
|
||||
void _display() override;
|
||||
void _loop(unsigned long currentMicros) override;
|
||||
int _readAnalogue(VPIN vpin) override;
|
||||
void _writeAnalogue(VPIN vpin, int hh, uint8_t mm, uint16_t ss) override;
|
||||
};
|
||||
|
||||
#endif
|
@@ -16,7 +16,10 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define driverVer 305
|
||||
#define driverVer 306
|
||||
// v306 Pass vpin to regeister it in CamParser.
|
||||
// Move base vpin to camparser.
|
||||
// No more need for config.h settings.
|
||||
// v305 less debug & alpha ordered switch
|
||||
// v304 static oldb0; t(##[,%%];
|
||||
// v303 zipped with CS 5.2.76 and uploaded to repo (with debug)
|
||||
@@ -35,23 +38,18 @@
|
||||
* This device driver will configure the device on startup, along with CamParser.cpp
|
||||
* interacting with the sensorCAM device for all input/output duties.
|
||||
*
|
||||
* #include "CamParser.h" in DCCEXParser.cpp
|
||||
* #include "IO_EXSensorCAM.h" in IODevice.h
|
||||
* To create EX-SensorCAM devices, define them in myHal.cpp: with
|
||||
* EXSensorCAM::create(baseVpin,num_vpins,i2c_address) or
|
||||
* alternatively use HAL(EXSensorCAM baseVpin numpins i2c_address) in myAutomation.h
|
||||
* also #define SENSORCAM_VPIN baseVpin in config.h
|
||||
*
|
||||
* void halSetup() {
|
||||
* // EXSensorCAM::create(vpin, num_vpins, i2c_address);
|
||||
* EXSensorCAM::create(700, 80, 0x11);
|
||||
* }
|
||||
* To create EX-SensorCAM devices,
|
||||
* use HAL(EXSensorCAM, baseVpin, numpins, i2c_address) in myAutomation.h
|
||||
* e.g.
|
||||
* HAL(EXSensorCAM,700, 80, 0x11)
|
||||
*
|
||||
* or (deprecated) define them in myHal.cpp: with
|
||||
* EXSensorCAM::create(baseVpin,num_vpins,i2c_address);
|
||||
*
|
||||
* I2C packet size of 32 bytes (in the Wire library).
|
||||
*/
|
||||
# define DIGITALREFRESH 20000UL // min uSec delay between digital reads of digitalInputStates
|
||||
#ifndef IO_EX_EXSENSORCAM_H
|
||||
#define IO_EX_EXSENSORCAM_H
|
||||
#define DIGITALREFRESH 20000UL // min uSec delay between digital reads of digitalInputStates
|
||||
#define SEND StringFormatter::send
|
||||
#include "IODevice.h"
|
||||
#include "I2CManager.h"
|
||||
@@ -70,7 +68,7 @@ class EXSensorCAM : public IODevice {
|
||||
new EXSensorCAM(vpin, nPins, i2cAddress);
|
||||
}
|
||||
|
||||
static VPIN CAMBaseVpin;
|
||||
|
||||
|
||||
private:
|
||||
// Constructor
|
||||
@@ -81,6 +79,7 @@ class EXSensorCAM : public IODevice {
|
||||
_nPins = nPins;
|
||||
_I2CAddress = i2cAddress;
|
||||
addDevice(this);
|
||||
CamParser::addVpin(firstVpin);
|
||||
}
|
||||
//*************************
|
||||
void _begin() {
|
||||
|
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "IO_EncoderThrottle.h"
|
||||
#include "DIAG.h"
|
||||
#include "DCC.h"
|
||||
|
||||
|
@@ -511,6 +511,7 @@ public:
|
||||
if (pin == 0) { // Do nothing if not vPin 0
|
||||
return _playing;
|
||||
}
|
||||
return _playing; // fix for compile error: "control reaches end of non-void function [-Wreturn-type]"
|
||||
}
|
||||
|
||||
void _display() override {
|
||||
@@ -549,8 +550,8 @@ private:
|
||||
setChecksum(out);
|
||||
|
||||
// Prepend the DFPlayer command with REG address and UART Channel in _outbuffer
|
||||
_outbuffer[0] = REG_THR << 3 | _UART_CH << 1; //TX FIFO and UART Channel
|
||||
for ( int i = 1; i < sizeof(out)+1 ; i++){
|
||||
_outbuffer[0] = REG_THR << 3 | _UART_CH << 1; //TX FIFO and UART Channel
|
||||
for ( uint8_t i = 1; i < sizeof(out)+1 ; i++){
|
||||
_outbuffer[i] = out[i-1];
|
||||
}
|
||||
|
||||
@@ -616,6 +617,14 @@ private:
|
||||
uint16_t _divisor = (_sc16is752_xtal_freq/PRESCALER)/(BAUD_RATE * 16); // Calculate _divisor for baudrate
|
||||
TEMP_REG_VAL = 0x08; // UART Software reset
|
||||
UART_WriteRegister(REG_IOCONTROL, TEMP_REG_VAL);
|
||||
|
||||
// Extra delay when using low frequency xtal after soft reset
|
||||
// Test when using 1.8432 Mhz xtal
|
||||
if(_sc16is752_xtal_freq == SC16IS752_XTAL_FREQ_LOW){
|
||||
_timeoutTime = micros() + 10000UL; // 10mS timeout
|
||||
_awaitingResponse = true;
|
||||
}
|
||||
|
||||
TEMP_REG_VAL = 0x00; // Set pins to GPIO mode
|
||||
UART_WriteRegister(REG_IOCONTROL, TEMP_REG_VAL);
|
||||
TEMP_REG_VAL = 0xFF; //Set all pins as output
|
||||
|
121
IO_I2CRailcom.cpp
Normal file
121
IO_I2CRailcom.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* © 2024, Henk Kruisbrink & Chris Harlow. All rights reserved.
|
||||
* © 2023, Neil McKechnie. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC++EX 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Dec 2023, Added NXP SC16IS752 I2C Dual UART
|
||||
* The SC16IS752 has 64 bytes TX & RX FIFO buffer
|
||||
* First version without interrupts from I2C UART and only RX/TX are used, interrupts may not be
|
||||
* needed as the RX Fifo holds the reply
|
||||
*
|
||||
* Jan 2024, Issue with using both UARTs simultaniously, the secod uart seems to work but the first transmit
|
||||
* corrupt data. This need more analysis and experimenatation.
|
||||
* Will push this driver to the dev branch with the uart fixed to 0
|
||||
* Both SC16IS750 (single uart) and SC16IS752 (dual uart, but only uart 0 is enable)
|
||||
*
|
||||
* myHall.cpp configuration syntax:
|
||||
*
|
||||
* I2CRailcom::create(1st vPin, vPins, I2C address);
|
||||
*
|
||||
* myAutomation configuration
|
||||
* HAL(I2CRailcom, 1st vPin, vPins, I2C address)
|
||||
* Parameters:
|
||||
* 1st vPin : First virtual pin that EX-Rail can control to play a sound, use PLAYSOUND command (alias of ANOUT)
|
||||
* vPins : Total number of virtual pins allocated (to prevent overlaps)
|
||||
* I2C Address : I2C address of the serial controller, in 0x format
|
||||
*/
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "IO_I2CRailcom.h"
|
||||
#include "I2CManager.h"
|
||||
#include "DIAG.h"
|
||||
#include "DCC.h"
|
||||
#include "DCCWaveform.h"
|
||||
#include "Railcom.h"
|
||||
|
||||
|
||||
I2CRailcom::I2CRailcom(VPIN firstVpin, int nPins, I2CAddress i2cAddress){
|
||||
_firstVpin = firstVpin;
|
||||
_nPins = nPins;
|
||||
_I2CAddress = i2cAddress;
|
||||
addDevice(this);
|
||||
}
|
||||
|
||||
void I2CRailcom::create(VPIN firstVpin, int nPins, I2CAddress i2cAddress) {
|
||||
if (checkNoOverlap(firstVpin, nPins, i2cAddress))
|
||||
new I2CRailcom(firstVpin,nPins,i2cAddress);
|
||||
}
|
||||
|
||||
void I2CRailcom::_begin() {
|
||||
I2CManager.setClock(1000000); // TODO do we need this?
|
||||
I2CManager.begin();
|
||||
auto exists=I2CManager.exists(_I2CAddress);
|
||||
DIAG(F("I2CRailcom: %s RailcomCollector %S detected"),
|
||||
_I2CAddress.toString(), exists?F(""):F(" NOT"));
|
||||
if (!exists) return;
|
||||
|
||||
_deviceState=DEVSTATE_NORMAL;
|
||||
_display();
|
||||
}
|
||||
|
||||
|
||||
void I2CRailcom::_loop(unsigned long currentMicros) {
|
||||
// Read responses from device
|
||||
if (_deviceState!=DEVSTATE_NORMAL) return;
|
||||
|
||||
// have we read this cutout already?
|
||||
// basically we only poll once per packet when railcom cutout is working
|
||||
auto cut=DCCWaveform::getRailcomCutoutCounter();
|
||||
if (cutoutCounter==cut) return;
|
||||
cutoutCounter=cut;
|
||||
Railcom::loop(); // in case a csv read has timed out
|
||||
|
||||
// Obtain data length from the collector
|
||||
byte inbuf[1];
|
||||
byte queryLength[]={'?'};
|
||||
auto state=I2CManager.read(_I2CAddress, inbuf, 1,queryLength,sizeof(queryLength));
|
||||
if (state) {
|
||||
DIAG(F("RC ? state=%d"),state);
|
||||
return;
|
||||
}
|
||||
auto length=inbuf[0];
|
||||
if (length==0) return; // nothing to report
|
||||
|
||||
// Build a buffer and import the data from the collector
|
||||
byte inbuf2[length];
|
||||
byte queryData[]={'>'};
|
||||
state=I2CManager.read(_I2CAddress, inbuf2, length,queryData,sizeof(queryData));
|
||||
if (state) {
|
||||
DIAG(F("RC > %d state=%d"),length,state);
|
||||
return;
|
||||
}
|
||||
|
||||
// process incoming data buffer
|
||||
Railcom::process(_firstVpin,inbuf2,length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void I2CRailcom::_display() {
|
||||
DIAG(F("I2CRailcom: %s blocks %d-%d %S"), _I2CAddress.toString(), _firstVpin, _firstVpin+_nPins-1,
|
||||
(_deviceState!=DEVSTATE_NORMAL) ? F("OFFLINE") : F(""));
|
||||
}
|
||||
|
||||
|
58
IO_I2CRailcom.h
Normal file
58
IO_I2CRailcom.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* © 2024, Henk Kruisbrink & Chris Harlow. All rights reserved.
|
||||
* © 2023, Neil McKechnie. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC++EX 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This polls the RailcomCollecter device once per dcc packet
|
||||
* and obtains an abbreviated list of block occupancy changes which
|
||||
* are fortunately very rare compared with Railcom raw data.
|
||||
*
|
||||
* myAutomation configuration
|
||||
* HAL(I2CRailcom, 1st vPin, vPins, I2C address)
|
||||
* Parameters:
|
||||
* 1st vPin : First virtual pin that EX-Rail can control to play a sound, use PLAYSOUND command (alias of ANOUT)
|
||||
* vPins : Total number of virtual pins allocated
|
||||
* I2C Address : I2C address of the Railcom Collector, in 0x format
|
||||
*/
|
||||
|
||||
#ifndef IO_I2CRailcom_h
|
||||
#define IO_I2CRailcom_h
|
||||
#include "Arduino.h"
|
||||
#include "IODevice.h"
|
||||
|
||||
class I2CRailcom : public IODevice {
|
||||
private:
|
||||
byte cutoutCounter;
|
||||
public:
|
||||
// Constructor
|
||||
I2CRailcom(VPIN firstVpin, int nPins, I2CAddress i2cAddress);
|
||||
|
||||
static void create(VPIN firstVpin, int nPins, I2CAddress i2cAddress) ;
|
||||
|
||||
void _begin() ;
|
||||
void _loop(unsigned long currentMicros) override ;
|
||||
void _display() override ;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // IO_I2CRailcom_h
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "IODevice.h"
|
||||
#include "IO_TM1638.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
|
||||
|
82
Railcom.cpp
Normal file
82
Railcom.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* © 2025 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "Railcom.h"
|
||||
#include "DCC.h"
|
||||
#include "DCCWaveform.h"
|
||||
|
||||
uint16_t Railcom::expectLoco=0;
|
||||
uint16_t Railcom::expectCV=0;
|
||||
unsigned long Railcom::expectWait=0;
|
||||
ACK_CALLBACK Railcom::expectCallback=0;
|
||||
|
||||
// anticipate is used when waiting for a CV read from a railcom loco
|
||||
void Railcom::anticipate(uint16_t loco, uint16_t cv, ACK_CALLBACK callback) {
|
||||
expectLoco=loco;
|
||||
expectCV=cv;
|
||||
expectWait=millis(); // start of timeout
|
||||
expectCallback=callback;
|
||||
}
|
||||
|
||||
// process is called to handle data buffer sent by collector
|
||||
void Railcom::process(int16_t firstVpin,byte * buffer, byte length) {
|
||||
// block,locohi,locolow
|
||||
// block|0x80,data pom read cv
|
||||
byte i=0;
|
||||
while (i<length) {
|
||||
byte block=buffer[i] & 0x3f;
|
||||
byte type=buffer[i]>>6;
|
||||
|
||||
switch (type) {
|
||||
// a type=0 record has block,locohi,locolow
|
||||
case 0: {
|
||||
uint16_t locoid= ((uint16_t)buffer[i+1])<<8 | ((uint16_t)buffer[i+2]);
|
||||
DIAG(F("RC3 b=%d l=%d"),block,locoid);
|
||||
|
||||
if (locoid==0) DCC::clearBlock(firstVpin+block);
|
||||
else DCC::setLocoInBlock(locoid,firstVpin+block,true);
|
||||
i+=3;
|
||||
}
|
||||
break;
|
||||
case 2: { // csv value from POM read
|
||||
byte value=buffer[i+1];
|
||||
if (expectCV && DCCWaveform::getRailcomLastLocoAddress()==expectLoco) {
|
||||
DCC::setLocoInBlock(expectLoco,firstVpin+block,false);
|
||||
if (expectCallback) expectCallback(value);
|
||||
expectCV=0;
|
||||
}
|
||||
i+=2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DIAG(F("Unknown RC Collector code %d"),type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// loop() is called to detect timeouts waiting for a POM read result
|
||||
void Railcom::loop() {
|
||||
if (expectCV && (millis()-expectWait)> POM_READ_TIMEOUT) { // still waiting
|
||||
expectCallback(-1);
|
||||
expectCV=0;
|
||||
}
|
||||
}
|
40
Railcom.h
Normal file
40
Railcom.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* © 202 5Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef Railcom_h
|
||||
#define Railcom_h
|
||||
#include "Arduino.h"
|
||||
|
||||
typedef void (*ACK_CALLBACK)(int16_t result);
|
||||
|
||||
class Railcom {
|
||||
public:
|
||||
static void anticipate(uint16_t loco, uint16_t cv, ACK_CALLBACK callback);
|
||||
static void process(int16_t firstVpin,byte * buffer, byte length );
|
||||
static void loop();
|
||||
private:
|
||||
static const unsigned long POM_READ_TIMEOUT=500; // as per spec
|
||||
static uint16_t expectCV,expectLoco;
|
||||
static unsigned long expectWait;
|
||||
static ACK_CALLBACK expectCallback;
|
||||
static const byte MAX_WAIT_FOR_GLITCH=20; // number of dead or empty packets before assuming loco=0
|
||||
};
|
||||
|
||||
#endif
|
14
Release_Notes/AutoRefManual.html
Normal file
14
Release_Notes/AutoRefManual.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<script lang="javascript">
|
||||
function ZZ(header, body) {
|
||||
document.write( `<div class="html-block">
|
||||
<h2 style="font-family: monospace;"><${header}></h3>
|
||||
<p>${body}</p>
|
||||
</div>`);
|
||||
}
|
||||
</script>
|
||||
<script src="AutoRefManual.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
177
Release_Notes/AutoRefManual.js
Normal file
177
Release_Notes/AutoRefManual.js
Normal file
@@ -0,0 +1,177 @@
|
||||
ZZ('#','Request number of simultaneously supported locos');
|
||||
ZZ('!','Emergency stop all locos');
|
||||
ZZ('t loco','Request loco status');
|
||||
ZZ('t loco tspeed direction','Set throttle speed(0..127) and direction (0=reverse, 1=fwd) ');
|
||||
ZZ('t ignore loco tspeed direction','(Deprecated) Set throttle speed and direction');
|
||||
ZZ('T','List all turnouts');
|
||||
ZZ('T id','Delete turnout');
|
||||
ZZ('T id X','List turnout details');
|
||||
ZZ('T id T','Throw Turnout');
|
||||
ZZ('T id C','Close turnout#');
|
||||
ZZ('T id value','Close (value=0) ot Throw turnout');
|
||||
ZZ('T id SERVO vpin closedValue thrownValue','Create Servo turnout ');
|
||||
ZZ('T id VPIN vpin','Create pin turnout');
|
||||
ZZ('T id DCC addr subadd','Create DCC turnout ');
|
||||
ZZ('T id DCC linearAddr','Create DCC turnout');
|
||||
ZZ('T id addr subadd','Create DCC turnout');
|
||||
ZZ('T id vpin closedValue thrownValue','Create SERVO turnout');
|
||||
ZZ('S id vpin pullup','Create Sensor');
|
||||
ZZ('S id','Delete sensor');
|
||||
ZZ('S','List sensors');
|
||||
ZZ('J M','List stash values');
|
||||
ZZ('J M stash_id','get stash value');
|
||||
ZZ('J M CLEAR ALL','Clear all stash values');
|
||||
ZZ('J M CLEAR stash_id','Clear given stash');
|
||||
ZZ('J M stashId locoId','Set stash value');
|
||||
ZZ('J M CLEAR ANY locoId','Clear all stash entries that contain locoId');
|
||||
ZZ('J C','get fastclock time');
|
||||
ZZ('J C mmmm nn','Set fastclock time');
|
||||
ZZ('J G','FReport gauge limits ');
|
||||
ZZ('J I','Report currents ');
|
||||
ZZ('J L display row','Direct current displays to LCS/OLED');
|
||||
ZZ('J A','List Routes');
|
||||
ZZ('J R','List Roster');
|
||||
ZZ('J R id','Get roster for loco');
|
||||
ZZ('J T','Get turnout list ');
|
||||
ZZ('J T id','Get turnout state and description');
|
||||
ZZ('z vpin','Set pin. HIGH iv vpin positive, LOW if vpin negative ');
|
||||
ZZ('z vpin analog profile duration','Change analog value over duration (Fade or servo move)');
|
||||
ZZ('z vpin analog profile','Write analog device using profile number (Fade or servo movement)');
|
||||
ZZ('z vpin analog','Write analog device value');
|
||||
ZZ('I','List all turntables');
|
||||
ZZ('I id','Broadcast turntable type and current position ');
|
||||
ZZ('I id position','Rotate a DCC turntable');
|
||||
ZZ('I id DCC home','Create DCC turntable');
|
||||
ZZ('I id position activity','Rotate an EXTT turntable');
|
||||
ZZ('I id EXTT vpin home','Create an EXTT turntable');
|
||||
ZZ('I id ADD position value angle','Add turntable position');
|
||||
ZZ('Q','List all sensors ');
|
||||
ZZ('s','Command station status');
|
||||
ZZ('E','STORE EPROM');
|
||||
ZZ('e','CLEAR EPROM');
|
||||
ZZ('Z','List Output definitions ');
|
||||
ZZ('Z id pin iflag','Create Output');
|
||||
ZZ('Z id active','Set output ');
|
||||
ZZ('Z id','Delete output');
|
||||
ZZ('D ACK ON','Enable PROG track diagnostics');
|
||||
ZZ('D ACK OFF','Disable PROG track diagnostics');
|
||||
ZZ('D CABS','Diagnostic display loco state table');
|
||||
ZZ('D RAM','Diagnostic display free RAM');
|
||||
ZZ('D CMD ON','Enable command input diagnostics');
|
||||
ZZ('D CMD OFF','Disable command input diagnostics');
|
||||
ZZ('D RAILCOM ON','Enable Railcom diagnostics');
|
||||
ZZ('D RAILCOM OFF','DIsable Railcom diagnostics');
|
||||
ZZ('D WIFI ON','Enable Wifi diagnostics');
|
||||
ZZ('D WIFI OFF','Disable Wifi diagnostics');
|
||||
ZZ('D ETHERNET ON','Enable Ethernet diagnostics');
|
||||
ZZ('D ETHERNET OFF','Disabel Ethernet diagnostics ');
|
||||
ZZ('D WIT ON','Enable Withrottle diagnostics');
|
||||
ZZ('D WIT OFF','Disable Withrottle diagnostics ');
|
||||
ZZ('D LCN ON','Enable LCN Diagnostics');
|
||||
ZZ('D LCN OFF','Disabel LCN diagnostics');
|
||||
ZZ('D WEBSOCKET ON','Enable Websocket diagnostics ');
|
||||
ZZ('D WEBSOCKET OFF','Disable wensocket diagnostics ');
|
||||
ZZ('D EEPROM numentries','Dump EEPROM contents');
|
||||
ZZ('D ANOUT vpin position','see <z vpin position>');
|
||||
ZZ('D ANOUT vpin position profile','see <z vpin position profile>');
|
||||
ZZ('D SERVO vpin position','Test servo');
|
||||
ZZ('D SERVO vpin position profile','Test servo');
|
||||
ZZ('D ANIN vpin','Display analogue input value');
|
||||
ZZ('D HAL SHOW','Show HAL devices table');
|
||||
ZZ('D HAL RESET','Reset all HAL devices');
|
||||
ZZ('D TT vpin steps','Test turntable');
|
||||
ZZ('D TT vpin steps activity','Test turntable');
|
||||
ZZ('C PROGBOOST','Configute PROG track boost');
|
||||
ZZ('C RESET','Reset and restart command station');
|
||||
ZZ('C SPEED28','Set all DCC speed commands as 28 step to old decoders');
|
||||
ZZ('C SPEED128','Set all DCC speed commands to 128 step (default)');
|
||||
ZZ('C RAILCOM ON','Enable Railcom cutout ');
|
||||
ZZ('C RAILCOM OFF','Disable Railcom cutout');
|
||||
ZZ('C RAILCOM DEBUG','Enable Railcom cutout for easy scope reading test');
|
||||
ZZ('D ACK LIMIT value','Set ACK detection limit mA');
|
||||
ZZ('D ACK MIN value MS','Set ACK minimum duration mS');
|
||||
ZZ('D ACK MIN value','Set ACK minimum duration uS');
|
||||
ZZ('D ACK MAX value MS','Set ACK maximum duration mS');
|
||||
ZZ('D ACK MAX value','Set ACK maximum duration uS');
|
||||
ZZ('D ACK RETRY value','Set ACK retry count');
|
||||
ZZ('C WIFI "ssid" "password"','reconfigure stored wifi credentials ');
|
||||
ZZ('o vpin','Set neopixel on(vpin>0) or off(vpin<0)');
|
||||
ZZ('o vpin count','Set multiple neopixels on(vpin>0) or off(vpin<0)');
|
||||
ZZ('o vpin r g b','Set neopixel colour');
|
||||
ZZ('o vpin r g b count','Set multiple neopixels colour ');
|
||||
ZZ('1','Power ON all tracks');
|
||||
ZZ('1 MAIN','Power on MAIN track');
|
||||
ZZ('1 PROG','Power on PROG track');
|
||||
ZZ('1 JOIN','JOIN prog track to MAIN and power');
|
||||
ZZ('1 track','Power on given track');
|
||||
ZZ('0','Power off all tracks');
|
||||
ZZ('0 MAIN','Power off MAIN track');
|
||||
ZZ('0 PROG','Power off PROG track');
|
||||
ZZ('0 track','Power off given track');
|
||||
ZZ('c','Report main track currect (Deprecated)');
|
||||
ZZ('a address subaddress activate','Send DCC accessory command');
|
||||
ZZ('a address subaddress activate onoff','Send DCC accessory command with onoff control (TODO.. numbers) ');
|
||||
ZZ('a linearaddress activate','send dcc accessory command ');
|
||||
ZZ('A address value','Send DCC extended accessory (Aspect) command');
|
||||
ZZ('w loco cv value','POM write cv on main track');
|
||||
ZZ('r loco cv','POM read cv on main track');
|
||||
ZZ('b loco cv bit value','POM write cv bit on main track');
|
||||
ZZ('m LINEAR','Set Momentum algorithm to linear acceleration');
|
||||
ZZ('m POWER','Set momentum algortithm to very based on difference between current speed and throttle seting');
|
||||
ZZ('m loco momentum','set momentum for loco (accel and braking)');
|
||||
ZZ('m loco accelerating braking','set momentum for loco');
|
||||
ZZ('W cv value ignore1 ignore2','(Deprecated) Write cv value on PROG track');
|
||||
ZZ('W cab','Write loco address on PROG track');
|
||||
ZZ('W CONSIST cab REVERSE','Write consist address and reverse flag on PROG track ');
|
||||
ZZ('W CONSIST cab','write consist address on PROG track ');
|
||||
ZZ('W cv value','Write cv value on PROG track');
|
||||
ZZ('W cv value bit','Write cv bit on prog track');
|
||||
ZZ('V cv value','Fast read cv with expected value');
|
||||
ZZ('V cv bit value','Fast read bit with expected value');
|
||||
ZZ('B cv bit value','Write cv bit');
|
||||
ZZ('R cv ignore1 ignore2','(Deprecated) read cv');
|
||||
ZZ('R cv','Read cv');
|
||||
ZZ('R','Read driveable loco id (may be long, short or consist)');
|
||||
ZZ('-','Clear loco state and reminder table');
|
||||
ZZ('- loco','remove loco state amnd reminders');
|
||||
ZZ('F loco DCCFREQ value','Set DC frequencey for loco ');
|
||||
ZZ('F loco function value','Set loco function ON/OFF');
|
||||
ZZ('M ignore d0 d1 d2 d3 d4 d5','Send up to 5 byte DCC packet on MAIN track (all d values in hex)');
|
||||
ZZ('P ignore d0 d1 d2 d3 d4 d5','Send up to 5 byte DCC packet on PROG track (all d values in hex)');
|
||||
ZZ('J O','List turntable IDs');
|
||||
ZZ('J O id','List turntable state');
|
||||
ZZ('J P id','list turntable positions');
|
||||
ZZ('=','list track manager states');
|
||||
ZZ('= track MAIN','Set track to MAIN');
|
||||
ZZ('= track MAIN_INV','Set track to MAIN inverted polatity');
|
||||
ZZ('= track MAIN_AUTO','Set track to MAIN with auto reversing');
|
||||
ZZ('= track PROG','Set track to PROG');
|
||||
ZZ('= track OFF','Set track power OFF');
|
||||
ZZ('= track NONE','Set track no output');
|
||||
ZZ('= track EXT','Set track to use external sync');
|
||||
ZZ('= track AUTO','Update track to auto reverse');
|
||||
ZZ('= track INV','Update track to inverse polarity');
|
||||
ZZ('= track DC locoid','Set track to DC');
|
||||
ZZ('= track DC_INV locoid','Set track to DC with inverted polarity');
|
||||
ZZ('= track DCX locoid','Set track to DC with inverted polarity');ZZ('D EXRAIL ON','EXRAIL diagnostics on');
|
||||
ZZ('D EXRAIL OFF','EXRAIL doagnostics off');
|
||||
ZZ('L','LCC/CBUS adapter introducing self');
|
||||
ZZ('L eventid','LCC incoming event ');
|
||||
ZZ('J A','List automation ids');
|
||||
ZZ('J A id','list automation details');
|
||||
ZZ('K blockid loco','Loco entering Block');
|
||||
ZZ('k blockid loco','Loco exiting block');
|
||||
ZZ('/','Stream EXRAIL status');
|
||||
ZZ('/ PAUSE','pause all tasks ');
|
||||
ZZ('/ RESUME','Resume all tasks');
|
||||
ZZ('/ START route','Start a route or sequence');
|
||||
ZZ('/ START loco route','Start an AUTOMATION or sequence with a loco ');
|
||||
ZZ('/ KILL ALL','Kill all exrail tasks');
|
||||
ZZ('/ KILL taskid','Kill specific exrail tasks ');
|
||||
ZZ('/ RESERVE section','Flag section as reserved');
|
||||
ZZ('/ FREE section','Free reserve on section');
|
||||
ZZ('/ LATCH latch','Set pin latch');
|
||||
ZZ('/ UNLATCH latch','Removeve pin latch');
|
||||
ZZ('/ RED signal','Set signal to Red ');
|
||||
ZZ('/ AMBER signal','set Signal to Amber');
|
||||
ZZ('/ GREEN signal','Set signal to Green ');
|
15
Release_Notes/DCCEXCommands.awk
Normal file
15
Release_Notes/DCCEXCommands.awk
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/awk -f
|
||||
|
||||
{
|
||||
# Match the pattern ZZ(something) // comments
|
||||
if ($0 ~ /ZZ\([^)]*\)\s*\/\/.*/) {
|
||||
# Extract "something" and "comments"
|
||||
match($0, /ZZ\(([^)]*)\)\s*\/\/\s*(.*)/, arr);
|
||||
something = arr[1];
|
||||
comments = arr[2];
|
||||
# Replace commas in "something" with spaces
|
||||
gsub(/,/, " ", something);
|
||||
# Print in the new format as a JS call
|
||||
printf "ZZ('%s','%s');\n", something, comments;
|
||||
}
|
||||
}
|
71
Release_Notes/Railcom.md
Normal file
71
Release_Notes/Railcom.md
Normal file
@@ -0,0 +1,71 @@
|
||||
Railcom implementation notes, Chris Harlow Oct 2024
|
||||
|
||||
Railcom support is in 3 parts
|
||||
1. Generation of the DCC waveform with a Railcom cutout.
|
||||
2. Accessing the railcom feedback from a loco using hardware detectors
|
||||
3. Utilising the feedback to do something useful.
|
||||
|
||||
DCC Waveform Railcom cutout depends on using suitable motor shields (EX8874 primarily) as the standard Arduino shield is not suitable. (Too high resistance during cutout)
|
||||
The choice of track management also depends on wiring all the MAIN tracks to use the same signal and brake pins. This allows separate track power management but prevents switching a single track from MAIN to PROG or DC...
|
||||
Some CPUs require very specific choice of brake pins etc to match their internal timer register architecture.
|
||||
|
||||
- MEGA.. The default shield setting for an EX8874 is suitable for Railcom on Channel A (MAIN)
|
||||
- ESP32 .. not yet supported.
|
||||
- Nucleo ... TBA
|
||||
|
||||
Enabling the Railcom Cutout requires a `<C RAILCOM ON>` command. This can be added to myAutomation using `PARSE("<C RAILCOM ON>")`
|
||||
Code to calculate the cutout position and provide synchronization for the sampling is in `DCCWaveform.cpp` (not ESP32)
|
||||
and in general a global search for "railcom" will show all code changes that have been made to support this.
|
||||
|
||||
Code to actually implement the timing of the cutout is highly cpu dependent and can be found in the various implementations of `DCCTimer.h`. At this time only `DCCTimerAVR.cpp`has implemented this.
|
||||
|
||||
|
||||
Reading Railcom data:
|
||||
A new HAL handler (`IO_I2CRailcom.h`) has been added to process input from a 32-block railcom collecter which operates over I2C. The collector and its readers sit between the CS and the track and collect railcom data from locos during the cutout.
|
||||
The Collector device removes 99.9% of the railcom traffic and returns just a summary of what has changed since the last cutout.
|
||||
After the cutout the HAL driver reads the Collector summary over I2C and passes the raw data to the CS logic (`Railcom.cpp`) for analysis.
|
||||
|
||||
Each 32-block reader is described in myAutomation like `HAL(I2CRailcom,10000,32,0x08)` which will assign 32 blocks on i2c address 0x08 with vpin numbers 10000 and 10031. If you only use fewer channel in the collector, you can assign fewer pins here.
|
||||
(Implementation notes.. you may have multiple collectors, each one will requite a HAL line to define its i2c address and vpins to represent block numbers.)
|
||||
|
||||
Making use of Railcom data
|
||||
|
||||
Exrail has two additional event handlers which can capture locos entering and exiting blocks. These handlers are started with the loco information already set, so for example:
|
||||
```
|
||||
ONBLOCKENTER(10000)
|
||||
// a loco has entered block 10000
|
||||
FON(0) // turn the light on
|
||||
FON(1) // make a lot of noise
|
||||
SPEED(20) // slow down
|
||||
DONE
|
||||
|
||||
ONBLOCKEXIT(10000)
|
||||
// a loco has left block 10000
|
||||
FOFF(0) // turn the light off
|
||||
FOFF(1) // stop the noise
|
||||
SPEED(50) // speed up again
|
||||
DONE
|
||||
```
|
||||
|
||||
Note that the Railcom interpretation code is capable of detecting multiple locos in the same block at the same time and will create separate exrail tasks for each one.
|
||||
There is however one minor loophole in the block exit logic...
|
||||
If THREE or more locos are in the same block and ONE of them leaves, then ONBLOCKEXIT will not fire until
|
||||
EITHER - The leaving loco enters another railcom block
|
||||
OR - only ONE loco remains in the block just left.
|
||||
|
||||
To further support block management in railcom, two additional serial commands are available
|
||||
|
||||
`<K block loco >` to simulate a loco entering a block, and trigger any ONBLOCKENTER
|
||||
`<k block loco >` to simulate a loco leaving a block, and trigger and ONBLOCKEXIT
|
||||
|
||||
|
||||
Reading CV values on MAIN.
|
||||
|
||||
Railcom allows for the facility to read loco cv values while on the main track. This is considerably faster than PROG track access but depends on the loco being in a Railcom monitored block.
|
||||
|
||||
To read from PROG Track we use `<R cv>` response is `<r value>`
|
||||
|
||||
To read from MAIN track use `<r loco cv>`
|
||||
response is `<r loco cv value>`
|
||||
|
||||
|
21
Release_Notes/Stash.md
Normal file
21
Release_Notes/Stash.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# The STASH feature of exrail.
|
||||
|
||||
STASH is used for scenarios where it is helpful to relate a loco id to where it is parked. For example a fiddle yard may have 10 tracks and it's much easier for the operator to select a train to depart by using the track number, or pressing a button relating to that track, rather than by knowing the loco id which may be difficult to see.
|
||||
|
||||
Automated yard parking can use the stash to determine which tracks are empty without the need for block occupancy detectors.
|
||||
|
||||
Note that a negative locoid may be stashed to indicate that the loco will operate with inverted direction. For example a loco facing backwards, with the INVERT_DRECTION state may be stashed by exrail and the invert state will be restored along with the loco id when using the PICKUP_STASH. CLEAR_ANY_STASH will clear all references to the loco regardless of direction.
|
||||
|
||||
The following Stash commands are available:
|
||||
| EXRAIL command | Serial protocol | function |
|
||||
| -------------- | --------------- | -------- |
|
||||
| STASH(s) | `<JM s locoid>` | Save the current loco id in the stash array element s. |
|
||||
| CLEAR_STASH(s) | `<JM s 0>` | Sets stash array element s to zero. |
|
||||
| CLEAR_ALL_STASH | `<JM CLEAR ALL>` | sets all stash entries to zero |
|
||||
| CLEAR_ANY_STASH | `<JM CLEAR ANY locoid>` | removes current loco from all stash elements |
|
||||
| PICKUP_STASH(s) | N/A | sets current loco to stash element s |
|
||||
| IFSTASH(s) | N/A | True if stash element s is not zero |
|
||||
| N/A | `<JM>` | query all stashes (returns `<jM s loco>` where loco is not zero)
|
||||
| N/A | `<JM stash>` | Query loco in stash (returns `<jM s loco>`)
|
||||
|
||||
|
29
Release_Notes/momentum.md
Normal file
29
Release_Notes/momentum.md
Normal file
@@ -0,0 +1,29 @@
|
||||
New Momentum feature notes:
|
||||
|
||||
The command station can apply momentum to throttle movements in the same way that a standards compliant DCC decoder can be set to do. This momentum can be defaulted system wide and overridden on individual locos. It does not use or alter the loco CV values and so it also works when driving DC locos.
|
||||
The momentum is applied regardless of the throttle type used (or even EXRAIL).
|
||||
|
||||
Momentum is specified in mS / throttle_step.
|
||||
|
||||
There is a new command `<m cabid accelerating [brake]>`
|
||||
where the brake value defaults to the accelerating value.
|
||||
|
||||
For example:
|
||||
`<m 3 0>` sets loco 3 to no momentum.
|
||||
`<m 3 21>` sets loco 3 to 21 mS/step.
|
||||
`<m 3 21 42>` sets loco 3 to 21 mS/step accelerating and 42 mS/step when decelerating.
|
||||
|
||||
`<m 0 21>` sets the default momentum to 21mS/Step for all current and future locos that have not been specifically set.
|
||||
`<m 3 -1>` sets loco 3 to track the default momentum value.
|
||||
|
||||
EXRAIL
|
||||
A new macro `MOMENTUM(accel [, decel])` sets the momentum value of the current tasks loco ot the global default if loco=0.
|
||||
|
||||
Note: Setting Momentum 7,14,21 etc is similar in effect to setting a decoder CV03/CV04 to 1,2,3.
|
||||
|
||||
As an additional option, the momentum calculation is based on the
|
||||
difference in throttle setting and actual speed. For example, the time taken to reach speed 50 from a standing start would be less if the throttle were set to speed 100, thus increasing the acceleration.
|
||||
|
||||
`<m LINEAR>` - acceleration is uniform up to selected throttle speed.
|
||||
`<m POWER>` - acceleration depends on difference between loco speed and selected throttle speed.
|
||||
|
41
Release_Notes/websocketTester.html
Normal file
41
Release_Notes/websocketTester.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<html>
|
||||
<!-- Minimalist test page for the DCCEX websocket API.-->
|
||||
<head>
|
||||
<script>
|
||||
let socket = new WebSocket("ws://192.168.1.242:2560","DCCEX");
|
||||
|
||||
// send message from the form
|
||||
var sender = function() {
|
||||
var msg=document.getElementById('message').value;
|
||||
socket.send(msg);
|
||||
}
|
||||
// message received - show the message in div#messages
|
||||
socket.onmessage = function(event) {
|
||||
let message = event.data;
|
||||
|
||||
let messageElem = document.createElement('div');
|
||||
messageElem.textContent = message;
|
||||
document.getElementById('messages').prepend(messageElem);
|
||||
}
|
||||
socket.onerror = function(event) {
|
||||
let message = event.data;
|
||||
let messageElem = document.createElement('div');
|
||||
messageElem.textContent = message;
|
||||
document.getElementById('messages').prepend(messageElem);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
This is a minimalist test page for the DCCEX websocket API.
|
||||
It demonstrates the Websocket connection and how to send
|
||||
or receive websocket traffic.
|
||||
The connection string must be edited to address your command station
|
||||
correctly.<p>
|
||||
<!-- message form -->
|
||||
|
||||
<input type="text" id="message">
|
||||
<input type="button" value="Send" onclick="sender();">
|
||||
<!-- div with messages -->
|
||||
<div id="messages"></div>
|
||||
</body>
|
||||
</html>
|
101
STM32lwipopts.h.copyme
Normal file
101
STM32lwipopts.h.copyme
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* © 2024 Harald Barth
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
//
|
||||
// Rewrite of the STM32lwipopts.h file from STM
|
||||
// To be copied into where lwipopts_default.h resides
|
||||
// typically into STM32Ethernet/src/STM32lwipopts.h
|
||||
// or STM32Ethernet\src\STM32lwipopts.h
|
||||
// search for `lwipopts_default.h` and copy this file into the
|
||||
// same directory but name it STM32lwipopts.h
|
||||
//
|
||||
#ifndef __STM32LWIPOPTS_H__
|
||||
#define __STM32LWIPOPTS_H__
|
||||
|
||||
// include this here and then override things we do differnet
|
||||
#include "lwipopts_default.h"
|
||||
|
||||
// we can not include our "defines.h" here
|
||||
// so we need to duplicate that define
|
||||
#define MAX_NUM_TCP_CLIENTS_HERE 9
|
||||
|
||||
#ifdef MAX_NUM_TCP_CLIENTS
|
||||
#if MAX_NUM_TCP_CLIENTS != MAX_NUM_TCP_CLIENTS_HERE
|
||||
#error MAX_NUM_TCP_CLIENTS and MAX_NUM_TCP_CLIENTS_HERE must be same
|
||||
#endif
|
||||
#else
|
||||
#define MAX_NUM_TCP_CLIENTS MAX_NUM_TCP_CLIENTS_HERE
|
||||
#endif
|
||||
|
||||
// increase ARP cache
|
||||
#undef MEMP_NUM_APR_QUEUE
|
||||
#define MEMP_NUM_ARP_QUEUE MAX_NUM_TCP_CLIENTS+3 // one for each client (all on different HW) and a few extra
|
||||
|
||||
// Example for debug
|
||||
//#define LWIP_DEBUG 1
|
||||
//#define TCP_DEBUG LWIP_DBG_ON
|
||||
|
||||
// NOT STRICT NECESSARY ANY MORE BUT CAN BE USED TO SAVE RAM
|
||||
#undef MEM_LIBC_MALLOC
|
||||
#define MEM_LIBC_MALLOC 1 // use the same malloc as for everything else
|
||||
#undef MEMP_MEM_MALLOC
|
||||
#define MEMP_MEM_MALLOC 1 // uses malloc which means no pools which means slower but not mean 32KB up front
|
||||
|
||||
#undef MEMP_NUM_TCP_PCB
|
||||
#define MEMP_NUM_TCP_PCB MAX_NUM_TCP_CLIENTS+1 // one extra so we can reject number N+1 from our code
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 6
|
||||
|
||||
#undef MEMP_NUM_TCP_SEG
|
||||
#define MEMP_NUM_TCP_SEG MAX_NUM_TCP_CLIENTS
|
||||
|
||||
#undef MEMP_NUM_SYS_TIMEOUT
|
||||
#define MEMP_NUM_SYS_TIMEOUT MAX_NUM_TCP_CLIENTS+2
|
||||
|
||||
#undef PBUF_POOL_SIZE
|
||||
#define PBUF_POOL_SIZE MAX_NUM_TCP_CLIENTS
|
||||
|
||||
#undef LWIO_ICMP
|
||||
#define LWIP_ICMP 1
|
||||
#undef LWIP_RAW
|
||||
#define LWIP_RAW 1 /* PING changed to 1 */
|
||||
#undef DEFAULT_RAW_RECVMBOX_SIZE
|
||||
#define DEFAULT_RAW_RECVMBOX_SIZE 3 /* for ICMP PING */
|
||||
|
||||
#undef LWIP_DHCP
|
||||
#define LWIP_DHCP 1
|
||||
#undef LWIP_UDP
|
||||
#define LWIP_UDP 1
|
||||
|
||||
/*
|
||||
The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
|
||||
- To use this feature let the following define uncommented.
|
||||
- To disable it and process by CPU comment the the checksum.
|
||||
*/
|
||||
|
||||
#if CHECKSUM_GEN_TCP == 1
|
||||
#error On STM32 TCP checksum should be in HW
|
||||
#endif
|
||||
|
||||
#undef LWIP_IGMP
|
||||
#define LWIP_IGMP 1
|
||||
|
||||
//#define SO_REUSE 1
|
||||
//#define SO_REUSE_RXTOALL 1
|
||||
|
||||
#endif /* __STM32LWIPOPTS_H__ */
|
89
Stash.cpp
Normal file
89
Stash.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* © 2024 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include "Stash.h"
|
||||
#include "StringFormatter.h"
|
||||
|
||||
Stash::Stash(int16_t stash_id, int16_t loco_id) {
|
||||
this->stashId = stash_id;
|
||||
this->locoId = loco_id;
|
||||
this->next = first;
|
||||
first = this;
|
||||
}
|
||||
|
||||
void Stash::clearAll() {
|
||||
for (auto s=first;s;s=s->next) {
|
||||
s->locoId = 0;
|
||||
s->stashId =0;
|
||||
}
|
||||
}
|
||||
|
||||
void Stash::clearAny(int16_t loco_id) {
|
||||
auto lid=abs(loco_id);
|
||||
for (auto s=first;s;s=s->next)
|
||||
if (abs(s->locoId) == lid) {
|
||||
s->locoId = 0;
|
||||
s->stashId =0;
|
||||
}
|
||||
}
|
||||
|
||||
void Stash::clear(int16_t stash_id) {
|
||||
set(stash_id,0);
|
||||
}
|
||||
|
||||
int16_t Stash::get(int16_t stash_id) {
|
||||
for (auto s=first;s;s=s->next)
|
||||
if (s->stashId == stash_id) return s->locoId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Stash::set(int16_t stash_id, int16_t loco_id) {
|
||||
// replace any existing stash
|
||||
for (auto s=first;s;s=s->next)
|
||||
if (s->stashId == stash_id) {
|
||||
s->locoId=loco_id;
|
||||
if (loco_id==0) s->stashId=0; // recycle
|
||||
return;
|
||||
}
|
||||
if (loco_id==0) return; // no need to create a zero entry.
|
||||
|
||||
// replace any empty stash
|
||||
for (auto s=first;s;s=s->next)
|
||||
if (s->locoId == 0) {
|
||||
s->locoId=loco_id;
|
||||
s->stashId=stash_id;
|
||||
return;
|
||||
}
|
||||
// create a new stash
|
||||
new Stash(stash_id, loco_id);
|
||||
}
|
||||
|
||||
void Stash::list(Print * stream, int16_t stash_id) {
|
||||
bool sent=false;
|
||||
for (auto s=first;s;s=s->next)
|
||||
if ((s->locoId) && (stash_id==0 || s->stashId==stash_id)) {
|
||||
StringFormatter::send(stream,F("<jM %d %d>\n"),
|
||||
s->stashId,s->locoId);
|
||||
sent=true;
|
||||
}
|
||||
if (!sent) StringFormatter::send(stream,F("<jM %d 0>\n"),
|
||||
stash_id);
|
||||
}
|
||||
|
||||
Stash* Stash::first=nullptr;
|
39
Stash.h
Normal file
39
Stash.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* © 2024 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifndef Stash_h
|
||||
#define Stash_h
|
||||
#include <Arduino.h>
|
||||
|
||||
class Stash {
|
||||
public:
|
||||
static void clear(int16_t stash_id);
|
||||
static void clearAll();
|
||||
static void clearAny(int16_t loco_id);
|
||||
static int16_t get(int16_t stash_id);
|
||||
static void set(int16_t stash_id, int16_t loco_id);
|
||||
static void list(Print * stream, int16_t stash_id=0); // id0 = LIST ALL
|
||||
private:
|
||||
Stash(int16_t stash_id, int16_t loco_id);
|
||||
static Stash* first;
|
||||
Stash* next;
|
||||
int16_t stashId;
|
||||
int16_t locoId;
|
||||
};
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2020, Chris Harlow. All rights reserved.
|
||||
* © 2020=2025, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of Asbelos DCC API
|
||||
*
|
||||
@@ -27,6 +27,9 @@ bool Diag::WIFI=false;
|
||||
bool Diag::WITHROTTLE=false;
|
||||
bool Diag::ETHERNET=false;
|
||||
bool Diag::LCN=false;
|
||||
bool Diag::RAILCOM=false;
|
||||
bool Diag::WEBSOCKET=false;
|
||||
|
||||
|
||||
|
||||
void StringFormatter::diag( const FSH* input...) {
|
||||
@@ -120,6 +123,7 @@ void StringFormatter::send2(Print * stream,const FSH* format, va_list args) {
|
||||
case 's': stream->print(va_arg(args, char*)); break;
|
||||
case 'e': printEscapes(stream,va_arg(args, char*)); break;
|
||||
case 'E': printEscapes(stream,(const FSH*)va_arg(args, char*)); break;
|
||||
case '<': printCmdFormat(stream,(const FSH*)va_arg(args, char*)); break;
|
||||
case 'S':
|
||||
{
|
||||
const FSH* flash= (const FSH*)va_arg(args, char*);
|
||||
@@ -199,15 +203,27 @@ void StringFormatter::printEscapes(Print * stream,char * input) {
|
||||
|
||||
void StringFormatter::printEscapes(Print * stream, const FSH * input) {
|
||||
|
||||
if (!stream) return;
|
||||
char* flash=(char*)input;
|
||||
for(int i=0; ; ++i) {
|
||||
char c=GETFLASH(flash+i);
|
||||
printEscape(stream,c);
|
||||
if (c=='\0') return;
|
||||
if (!stream) return;
|
||||
char* flash=(char*)input;
|
||||
for(int i=0; ; ++i) {
|
||||
char c=GETFLASH(flash+i);
|
||||
printEscape(stream,c);
|
||||
if (c=='\0') return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StringFormatter::printCmdFormat(Print * stream, const FSH * input) {
|
||||
|
||||
if (!stream) return;
|
||||
char* flash=(char*)input;
|
||||
for(int i=0; ; ++i) {
|
||||
char c=GETFLASH(flash+i);
|
||||
if (c=='\0') return;
|
||||
if (c==',') c=' ';
|
||||
stream->write(c);
|
||||
}
|
||||
}
|
||||
|
||||
void StringFormatter::printEscape( char c) {
|
||||
printEscape(&USB_SERIAL,c);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2020, Chris Harlow. All rights reserved.
|
||||
* © 2020-2025, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of Asbelos DCC API
|
||||
*
|
||||
@@ -30,6 +30,8 @@ class Diag {
|
||||
static bool WITHROTTLE;
|
||||
static bool ETHERNET;
|
||||
static bool LCN;
|
||||
static bool RAILCOM;
|
||||
static bool WEBSOCKET;
|
||||
|
||||
};
|
||||
|
||||
@@ -41,6 +43,7 @@ class StringFormatter
|
||||
|
||||
static void printEscapes(Print * serial,char * input);
|
||||
static void printEscapes(Print * serial,const FSH* input);
|
||||
static void printCmdFormat(Print * serial,const FSH* input);
|
||||
static void printEscape(Print * serial, char c);
|
||||
|
||||
// DIAG support
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2022 Chris Harlow
|
||||
* © 2022-2025 Chris Harlow
|
||||
* © 2022-2024 Harald Barth
|
||||
* © 2023-2024 Paul M. Antoine
|
||||
* © 2024 Herb Morton
|
||||
@@ -197,7 +197,13 @@ void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
|
||||
}
|
||||
}
|
||||
|
||||
bool TrackManager::orTrackMode(byte trackToSet, TRACK_MODE mode) {
|
||||
if (trackToSet>='A' && trackToSet<='H') trackToSet-='A';
|
||||
return setTrackMode(trackToSet, track[trackToSet]->getMode() | mode);
|
||||
}
|
||||
|
||||
bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr) {
|
||||
if (trackToSet>='A' && trackToSet<='H') trackToSet-='A';
|
||||
if (trackToSet>lastTrack || track[trackToSet]==NULL) return false;
|
||||
|
||||
// Remember track mode we came from for later
|
||||
@@ -332,7 +338,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
canDo &= track[t]->trackPWM;
|
||||
}
|
||||
}
|
||||
if (!canDo) {
|
||||
if (canDo) DIAG(F("HA mode"));
|
||||
else {
|
||||
// if we discover that HA mode was globally impossible
|
||||
// we must adjust the trackPWM capabilities
|
||||
FOR_EACH_TRACK(t) {
|
||||
@@ -341,6 +348,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
}
|
||||
DCCTimer::clearPWM(); // has to be AFTER trackPWM changes because if trackPWM==true this is undone for that track
|
||||
}
|
||||
DCCWaveform::setRailcomPossible(canDo);
|
||||
#else
|
||||
// For ESP32 we just reinitialize the DCC Waveform
|
||||
DCCWaveform::begin();
|
||||
@@ -379,67 +387,16 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
}
|
||||
|
||||
void TrackManager::applyDCSpeed(byte t) {
|
||||
track[t]->setDCSignal(DCC::getThrottleSpeedByte(trackDCAddr[t]),
|
||||
track[t]->setDCSignal(DCC::getLocoSpeedByte(trackDCAddr[t]),
|
||||
DCC::getThrottleFrequency(trackDCAddr[t]));
|
||||
}
|
||||
|
||||
bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
|
||||
bool TrackManager::list(Print *stream)
|
||||
{
|
||||
|
||||
if (params==0) { // <=> List track assignments
|
||||
FOR_EACH_TRACK(t)
|
||||
streamTrackState(stream,t);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
p[0]-="A"_hk; // convert A... to 0....
|
||||
|
||||
if (params>1 && (p[0]<0 || p[0]>=MAX_TRACKS))
|
||||
return false;
|
||||
|
||||
if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN);
|
||||
if (params==2 && p[1]=="MAIN_INV"_hk) // <= id MAIN_INV>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN_INV);
|
||||
if (params==2 && p[1]=="MAIN_AUTO"_hk) // <= id MAIN_AUTO>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN_AUTO);
|
||||
|
||||
#ifndef DISABLE_PROG
|
||||
if (params==2 && p[1]=="PROG"_hk) // <= id PROG>
|
||||
return setTrackMode(p[0],TRACK_MODE_PROG);
|
||||
#endif
|
||||
|
||||
if (params==2 && (p[1]=="OFF"_hk || p[1]=="NONE"_hk)) // <= id OFF> <= id NONE>
|
||||
return setTrackMode(p[0],TRACK_MODE_NONE);
|
||||
|
||||
if (params==2 && p[1]=="EXT"_hk) // <= id EXT>
|
||||
return setTrackMode(p[0],TRACK_MODE_EXT);
|
||||
#ifdef BOOSTER_INPUT
|
||||
if (TRACK_MODE_BOOST != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST"_hk) // <= id BOOST>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST);
|
||||
if (TRACK_MODE_BOOST_INV != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST_INV"_hk) // <= id BOOST_INV>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST_INV);
|
||||
if (TRACK_MODE_BOOST_AUTO != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST_AUTO"_hk) // <= id BOOST_AUTO>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST_AUTO);
|
||||
#endif
|
||||
if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_AUTO);
|
||||
|
||||
if (params==2 && p[1]=="INV"_hk) // <= id INV>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_INV);
|
||||
|
||||
if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab>
|
||||
return setTrackMode(p[0],TRACK_MODE_DC,p[2]);
|
||||
|
||||
if (params==3 && (p[1]=="DC_INV"_hk || // <= id DC_INV cab>
|
||||
p[1]=="DCX"_hk) && p[2]>0) // <= id DCX cab>
|
||||
return setTrackMode(p[0],TRACK_MODE_DC_INV,p[2]);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const FSH* TrackManager::getModeName(TRACK_MODE tm) {
|
||||
|
@@ -72,7 +72,8 @@ class TrackManager {
|
||||
|
||||
static const int16_t MAX_TRACKS=8;
|
||||
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
|
||||
static bool parseEqualSign(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool orTrackMode(byte track, TRACK_MODE mode);
|
||||
static bool list(Print * stream);
|
||||
static void loop();
|
||||
static POWERMODE getMainPower();
|
||||
static POWERMODE getProgPower();
|
||||
|
211
Websockets.cpp
Normal file
211
Websockets.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* © 2023 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
/**************************************************
|
||||
HOW IT WORKS
|
||||
|
||||
1) Refer to https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers
|
||||
|
||||
2) When a new client sends in a socket stream, the
|
||||
CommandDistributor pass it to this code
|
||||
checkConnectionString() to check for an HTTP
|
||||
protocol GET requesting a change to websocket protocol.
|
||||
[Note that the WifiInboundHandler has a shortcut to detecting this so that
|
||||
it does not need to use up 500+ bytes of RAM just to get at the one parameter that
|
||||
actually means something.]
|
||||
If that is found, the relevant answer is generated and queued and
|
||||
the CommandDistributor marks this client as a websocket client awaiting connection.
|
||||
Once the outbound handshake has completed, the CommandDistributor promotes the client
|
||||
from awaiting connection to connected websocket so that all
|
||||
future traffic for this client is handled with websocket protocol.
|
||||
|
||||
3) When an input is received from a client marked as websocket,
|
||||
CommandDistributor calls unmask() to strip off the websocket header and
|
||||
un-mask the input bytes. The command distributor will flag the
|
||||
clientid in the ringstream so that anyone transmitting this
|
||||
output will know to handle it differently.
|
||||
|
||||
4) when the Wifi/Ethernet handler needs to transmit the result from the
|
||||
output ring, it recognises the websockets flag and adds the websocket
|
||||
header to the output dynamically.
|
||||
|
||||
*************************************************************/
|
||||
#include <Arduino.h>
|
||||
#include "FSH.h"
|
||||
#include "RingStream.h"
|
||||
#include "libsha1.h"
|
||||
#include "Websockets.h"
|
||||
#include "DIAG.h"
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
// ESP32 runtime or definitions has strlcat_P missing
|
||||
#define strlcat_P strlcat
|
||||
#endif
|
||||
static const char b64_table[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
bool Websockets::checkConnectionString(byte clientId,byte * cmd, RingStream * outbound ) {
|
||||
// returns true if this input is a websocket connect
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websock check connection"));
|
||||
/* Heuristic suppose this is a websocket GET
|
||||
typically looking like this:
|
||||
|
||||
GET / HTTP/1.1
|
||||
Host: 192.168.1.242:2560
|
||||
Connection: Upgrade
|
||||
Pragma: no-cache
|
||||
Cache-Control: no-cache
|
||||
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0
|
||||
Upgrade: websocket
|
||||
Origin: null
|
||||
Sec-WebSocket-Version: 13
|
||||
Accept-Encoding: gzip, deflate
|
||||
Accept-Language: en-US,en;q=0.9
|
||||
Sec-WebSocket-Key: SpRkQKPPNZcO62pYf1X6Yg==
|
||||
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
|
||||
*/
|
||||
|
||||
// check contents to find Sec-WebSocket-Key: and get key up to \n
|
||||
auto keyPos=strstr_P((char*)cmd,(char*)F("Sec-WebSocket-Key: "));
|
||||
if (!keyPos) return false;
|
||||
keyPos+=19; // length of Sec-Websocket-Key:
|
||||
auto endkeypos=strstr(keyPos,"\r");
|
||||
if (!endkeypos) return false;
|
||||
*endkeypos=0;
|
||||
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websock key=\"%s\""),keyPos);
|
||||
// generate the reply key
|
||||
uint8_t sha1HashBin[21] = { 0 }; // 21 to make it base64 div 3
|
||||
char replyKey[100];
|
||||
strlcpy(replyKey,keyPos, sizeof(replyKey));
|
||||
strlcat_P(replyKey,(char*)F("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"), sizeof(replyKey));
|
||||
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websock replykey=%s"),replyKey);
|
||||
|
||||
SHA1_CTX ctx;
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, (unsigned char *)replyKey, strlen(replyKey));
|
||||
SHA1Final(sha1HashBin, &ctx);
|
||||
|
||||
// generate the response and embed the base64 encode
|
||||
// of the key
|
||||
outbound->mark(clientId);
|
||||
outbound->print(F("HTTP/1.1 101 Switching Protocols\r\n"
|
||||
"Server: DCCEX-WebSocketsServer\r\n"
|
||||
"Upgrade: websocket\r\n"
|
||||
"Connection: Upgrade\r\n"
|
||||
"Origin: null\r\n"
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"Sec-WebSocket-Protocol: DCCEX\r\n"
|
||||
"Sec-WebSocket-Accept: "));
|
||||
// encode and emit the reply key as base 64
|
||||
auto * tmp=sha1HashBin;
|
||||
for (int i=0;i<7;i++) {
|
||||
outbound->print(b64_table[(tmp[0] & 0xfc) >> 2]);
|
||||
outbound->print(b64_table[((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4)]);
|
||||
outbound->print(b64_table[((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6)]);
|
||||
if (i<6) outbound->print(b64_table[tmp[2] & 0x3f]);
|
||||
tmp+=3;
|
||||
}
|
||||
outbound->print(F("=\r\n\r\n")); // because we have padded 1 byte
|
||||
outbound->commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
byte * Websockets::unmask(byte clientId,RingStream *ring, byte * buffer) {
|
||||
// buffer should have a websocket header
|
||||
//byte opcode=buffer[0] & 0x0f;
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websock in: %x %x %x %x %x %x %x"),
|
||||
buffer[0],buffer[1],buffer[2],buffer[3],
|
||||
buffer[4],buffer[5],buffer[6]);
|
||||
|
||||
byte opcode=buffer[0];
|
||||
bool maskbit=buffer[1]&0x80;
|
||||
int16_t payloadLength=buffer[1]&0x7f;
|
||||
|
||||
byte * mask;
|
||||
if (payloadLength<126) {
|
||||
mask=buffer+2;
|
||||
}
|
||||
else {
|
||||
payloadLength=(buffer[3]<<8)|(buffer[2]);
|
||||
mask=buffer+4;
|
||||
}
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websock op=%x mb=%b pl=%d m=%x %x %x %x"), opcode, maskbit, payloadLength,
|
||||
mask[0],mask[1],mask[2], mask[3]);
|
||||
|
||||
if (opcode==0x89) { // ping
|
||||
DIAG(F("Websock ping"));
|
||||
buffer[0]=0x8a; // pong.. and send it back
|
||||
ring->mark(clientId &0x7f); // dont readjust
|
||||
ring->print((char *)buffer);
|
||||
ring->commit();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (opcode!=0x81) {
|
||||
DIAG(F("Websock unknown opcode 0x%x"),opcode);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
byte * payload=mask+4;
|
||||
for (int i=0;i<payloadLength;i++) {
|
||||
payload[i]^=mask[i%4];
|
||||
}
|
||||
|
||||
if (Diag::WEBSOCKET) DIAG(F("Websoc payload=%s"),payload);
|
||||
|
||||
return payload; // payload will be parsed as normal
|
||||
|
||||
}
|
||||
|
||||
int16_t Websockets::getOutboundHeaderSize(uint16_t dataLength) {
|
||||
return (dataLength>=126)? 4:2;
|
||||
}
|
||||
|
||||
int Websockets::fillOutboundHeader(uint16_t dataLength, byte * buffer) {
|
||||
// text opcode, flag(126= use 2 length bytes, no mask bit) , length
|
||||
buffer[0]=0x81;
|
||||
if (dataLength<126) {
|
||||
buffer[1]=(byte)dataLength;
|
||||
return 2;
|
||||
}
|
||||
buffer[1]=126;
|
||||
buffer[2]=(byte)(dataLength & 0xFF);
|
||||
buffer[3]= (byte)(dataLength>>8);
|
||||
return 4;
|
||||
}
|
||||
|
||||
void Websockets::writeOutboundHeader(Print * stream,uint16_t dataLength) {
|
||||
byte prefix[4];
|
||||
int headerlen=fillOutboundHeader(dataLength,prefix);
|
||||
stream->write(prefix,sizeof(headerlen));
|
||||
}
|
||||
|
||||
|
||||
|
34
Websockets.h
Normal file
34
Websockets.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* © 2023 Chris Harlow
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifndef Websockets_h
|
||||
#define Websockets_h
|
||||
#include <Arduino.h>
|
||||
#include "RingStream.h"
|
||||
class Websockets {
|
||||
public:
|
||||
static bool checkConnectionString(byte clientId,byte * cmd, RingStream * outbound );
|
||||
static byte * unmask(byte clientId,RingStream *ring, byte * buffer);
|
||||
static int16_t getOutboundHeaderSize(uint16_t dataLength);
|
||||
static int fillOutboundHeader(uint16_t dataLength, byte * buffer);
|
||||
static void writeOutboundHeader(Print * stream,uint16_t dataLength);
|
||||
static const byte WEBSOCK_CLIENT_MARKER=0x80;
|
||||
};
|
||||
|
||||
#endif
|
@@ -2,6 +2,8 @@
|
||||
© 2023 Paul M. Antoine
|
||||
© 2021 Harald Barth
|
||||
© 2023 Nathan Kellenicki
|
||||
© 2025 Chris Harlow
|
||||
|
||||
|
||||
This file is part of CommandStation-EX
|
||||
|
||||
@@ -30,6 +32,7 @@
|
||||
#include "CommandDistributor.h"
|
||||
#include "WiThrottle.h"
|
||||
#include "DCC.h"
|
||||
#include "Websockets.h"
|
||||
/*
|
||||
#include "soc/rtc_wdt.h"
|
||||
#include "esp_task_wdt.h"
|
||||
@@ -378,6 +381,8 @@ void WifiESP::loop() {
|
||||
|
||||
// something to write out?
|
||||
clientId=outboundRing->read();
|
||||
bool useWebsocket=clientId & Websockets::WEBSOCK_CLIENT_MARKER;
|
||||
clientId &= ~ Websockets::WEBSOCK_CLIENT_MARKER;
|
||||
if (clientId >= 0) {
|
||||
// We have data to send in outboundRing
|
||||
// and we have a valid clientId.
|
||||
@@ -385,25 +390,28 @@ void WifiESP::loop() {
|
||||
// and then look if it can be sent because
|
||||
// we can not leave it in the ring for ever
|
||||
int count=outboundRing->count();
|
||||
auto wsHeaderLen=useWebsocket? Websockets::getOutboundHeaderSize(count) : 0;
|
||||
{
|
||||
char buffer[count+1]; // one extra for '\0'
|
||||
for(int i=0;i<count;i++) {
|
||||
int c = outboundRing->read();
|
||||
if (c >= 0) // Panic check, should never be false
|
||||
buffer[i] = (char)c;
|
||||
else {
|
||||
DIAG(F("Ringread fail at %d"),i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// buffer filled, end with '\0' so we can use it as C string
|
||||
buffer[count]='\0';
|
||||
byte buffer[wsHeaderLen + count + 1]; // one extra for '\0'
|
||||
if (useWebsocket) Websockets::fillOutboundHeader(count, buffer);
|
||||
for (int i = 0; i < count; i++) {
|
||||
int c = outboundRing->read();
|
||||
if (!c) {
|
||||
DIAG(F("Ringread fail at %d"), i);
|
||||
break;
|
||||
}
|
||||
// websocket implementations at browser end can barf at \n
|
||||
if (useWebsocket && (c == '\n')) c = '\r';
|
||||
buffer[i + wsHeaderLen] = (char)c;
|
||||
}
|
||||
// buffer filled, end with '\0' so we can use it as C string
|
||||
buffer[wsHeaderLen+count]='\0';
|
||||
if((unsigned int)clientId <= clients.size() && clients[clientId].active(clientId)) {
|
||||
if (Diag::CMD || Diag::WITHROTTLE)
|
||||
DIAG(F("SEND %d:%s"), clientId, buffer);
|
||||
clients[clientId].wifi.write(buffer,count);
|
||||
if (Diag::WIFI)
|
||||
DIAG(F("SEND%S %d:%s"), useWebsocket?F("ws"):F(""),clientId, buffer+wsHeaderLen);
|
||||
clients[clientId].wifi.write(buffer,count+wsHeaderLen);
|
||||
} else {
|
||||
DIAG(F("Unsent(%d): %s"), clientId, buffer);
|
||||
DIAG(F("Unsent(%d): %s"), clientId, buffer+wsHeaderLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* © 2021 Fred Decker
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2025 Chris Harlow
|
||||
* © 2020, Chris Harlow. All rights reserved.
|
||||
* © 2020, Harald Barth.
|
||||
*
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "RingStream.h"
|
||||
#include "CommandDistributor.h"
|
||||
#include "DIAG.h"
|
||||
#include "Websockets.h"
|
||||
|
||||
WifiInboundHandler * WifiInboundHandler::singleton;
|
||||
|
||||
@@ -67,8 +68,13 @@ void WifiInboundHandler::loop1() {
|
||||
|
||||
|
||||
if (pendingCipsend && millis()-lastCIPSEND > CIPSENDgap) {
|
||||
if (Diag::WIFI) DIAG( F("WiFi: [[CIPSEND=%d,%d]]"), clientPendingCIPSEND, currentReplySize);
|
||||
StringFormatter::send(wifiStream, F("AT+CIPSEND=%d,%d\r\n"), clientPendingCIPSEND, currentReplySize);
|
||||
// add allowances for websockets
|
||||
bool websocket=clientPendingCIPSEND & Websockets::WEBSOCK_CLIENT_MARKER;
|
||||
byte realClient=clientPendingCIPSEND & ~Websockets::WEBSOCK_CLIENT_MARKER;
|
||||
int16_t realSize=currentReplySize;
|
||||
if (websocket) realSize+=Websockets::getOutboundHeaderSize(currentReplySize);
|
||||
if (Diag::WIFI) DIAG( F("WiFi: [[CIPSEND=%d,%d]]"), realClient, realSize);
|
||||
StringFormatter::send(wifiStream, F("AT+CIPSEND=%d,%d\r\n"), realClient,realSize);
|
||||
pendingCipsend=false;
|
||||
return;
|
||||
}
|
||||
@@ -80,7 +86,9 @@ void WifiInboundHandler::loop1() {
|
||||
int count=inboundRing->count();
|
||||
if (Diag::WIFI) DIAG(F("Wifi EXEC: %d %d:"),clientId,count);
|
||||
byte cmd[count+1];
|
||||
for (int i=0;i<count;i++) cmd[i]=inboundRing->read();
|
||||
// Copy raw bytes to avoid websocket masked data being
|
||||
// confused with a ram-saving flash insert marker.
|
||||
for (int i=0;i<count;i++) cmd[i]=inboundRing->readRawByte();
|
||||
cmd[count]=0;
|
||||
if (Diag::WIFI) DIAG(F("%e"),cmd);
|
||||
|
||||
@@ -94,6 +102,9 @@ void WifiInboundHandler::loop1() {
|
||||
// This is a Finite State Automation (FSA) handling the inbound bytes from an ES AT command processor
|
||||
|
||||
WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||
const char WebSocketKeyName[]="Sec-WebSocket-Key: ";
|
||||
static byte prescanPoint=0;
|
||||
|
||||
while (wifiStream->available()) {
|
||||
int ch = wifiStream->read();
|
||||
|
||||
@@ -112,9 +123,12 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||
}
|
||||
|
||||
if (ch=='>') {
|
||||
if (Diag::WIFI) DIAG(F("[XMIT %d]"),currentReplySize);
|
||||
bool websocket=clientPendingCIPSEND & Websockets::WEBSOCK_CLIENT_MARKER;
|
||||
if (Diag::WIFI) DIAG(F("[XMIT %d ws=%b]"),currentReplySize,websocket);
|
||||
if (websocket) Websockets::writeOutboundHeader(wifiStream,currentReplySize);
|
||||
for (int i=0;i<currentReplySize;i++) {
|
||||
int cout=outboundRing->read();
|
||||
if (websocket && (cout=='\n')) cout='\r';
|
||||
wifiStream->write(cout);
|
||||
if (Diag::WIFI) StringFormatter::printEscape(cout); // DIAG in disguise
|
||||
}
|
||||
@@ -195,14 +209,19 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||
break;
|
||||
}
|
||||
if (Diag::WIFI) DIAG(F("Wifi inbound data(%d:%d):"),runningClientId,dataLength);
|
||||
if (inboundRing->freeSpace()<=(dataLength+1)) {
|
||||
|
||||
// we normally dont read >100 bytes
|
||||
// so assume its an HTTP GET or similar
|
||||
|
||||
if (dataLength<100 && inboundRing->freeSpace()<=(dataLength+1)) {
|
||||
// This input would overflow the inbound ring, ignore it
|
||||
loopState=IPD_IGNORE_DATA;
|
||||
if (Diag::WIFI) DIAG(F("Wifi OVERFLOW IGNORING:"));
|
||||
break;
|
||||
}
|
||||
inboundRing->mark(runningClientId);
|
||||
loopState=IPD_DATA;
|
||||
prescanPoint=0;
|
||||
loopState=(dataLength>100)? IPD_PRESCAN: IPD_DATA;
|
||||
break;
|
||||
}
|
||||
dataLength = dataLength * 10 + (ch - '0');
|
||||
@@ -217,6 +236,38 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
|
||||
}
|
||||
break;
|
||||
|
||||
case IPD_PRESCAN: // prescan reading data
|
||||
dataLength--;
|
||||
if (dataLength == 0) {
|
||||
// Nothing found, this input is lost
|
||||
DIAG(F("Wifi prescan for websock not found"));
|
||||
inboundRing->commit();
|
||||
loopState = ANYTHING;
|
||||
}
|
||||
if (ch!=WebSocketKeyName[prescanPoint]) {
|
||||
prescanPoint=0;
|
||||
break;
|
||||
}
|
||||
// matched the next char of the key
|
||||
prescanPoint++;
|
||||
if (WebSocketKeyName[prescanPoint]==0) {
|
||||
if (Diag::WEBSOCKET) DIAG(F("Wifi prescan found"));
|
||||
// prescan has detected full key
|
||||
inboundRing->print(WebSocketKeyName);
|
||||
loopState=IPD_POSTSCAN; // continmue as normal
|
||||
}
|
||||
break;
|
||||
|
||||
case IPD_POSTSCAN: // reading data
|
||||
inboundRing->write(ch);
|
||||
dataLength--;
|
||||
if (ch=='\n') {
|
||||
inboundRing->commit();
|
||||
loopState = IPD_IGNORE_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IPD_IGNORE_DATA: // ignoring data that would not fit in inbound ring
|
||||
dataLength--;
|
||||
if (dataLength == 0) loopState = ANYTHING;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* © 2021 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
* (c) 2021 Fred Decker. All rights reserved.
|
||||
* (c) 2020 Chris Harlow. All rights reserved.
|
||||
* (c) 2020-2025 Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
@@ -55,7 +55,8 @@ class WifiInboundHandler {
|
||||
IPD6_LENGTH, // got +IPD,c, reading length
|
||||
IPD_DATA, // got +IPD,c,ll,: collecting data
|
||||
IPD_IGNORE_DATA, // got +IPD,c,ll,: ignoring the data that won't fit inblound Ring
|
||||
|
||||
IPD_PRESCAN, // prescanning data for websocket keys
|
||||
IPD_POSTSCAN, // copyimg data for websocket keys
|
||||
GOT_CLIENT_ID, // clientid prefix to CONNECTED / CLOSED
|
||||
GOT_CLIENT_ID2 // clientid prefix to CONNECTED / CLOSED
|
||||
};
|
||||
@@ -67,7 +68,7 @@ class WifiInboundHandler {
|
||||
void purgeCurrentCIPSEND();
|
||||
Stream * wifiStream;
|
||||
|
||||
static const int INBOUND_RING = 512;
|
||||
static const int INBOUND_RING = 128;
|
||||
static const int OUTBOUND_RING = sizeof(void*)==2?2048:8192;
|
||||
|
||||
static const int CIPSENDgap=100; // millis() between retries of cipsend.
|
||||
|
@@ -137,6 +137,16 @@ The configuration file for DCC-EX Command Station
|
||||
//
|
||||
//#define ENABLE_ETHERNET true
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MAX_NUM_TCP_CLIENTS: If you on STM32 Ethernet (and only there) want more than
|
||||
// 9 (*) TCP clients, change this number to for example 20 here **AND** in
|
||||
// STM32lwiopts.h and follow the instructions in STM32lwiopts.h
|
||||
//
|
||||
// (*) It would be 10 if there would not be a bug in LwIP by STM32duino.
|
||||
//
|
||||
//#define MAX_NUM_TCP_CLIENTS 20
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
21
defines.h
21
defines.h
@@ -239,4 +239,25 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
// The LwIP library for the STM32 wired ethernet has by default 10 TCP
|
||||
// clients defined but because of a bug in the library #11 is not
|
||||
// rejected but kicks out any old connection. By restricting our limit
|
||||
// to 9 the #10 will be rejected by our code so that the number can
|
||||
// never get to 11 which would kick an existing connection.
|
||||
// If you want to change this value, do that in
|
||||
// config.h AND in STM32lwipopts.h.
|
||||
#ifndef MAX_NUM_TCP_CLIENTS
|
||||
#define MAX_NUM_TCP_CLIENTS 9
|
||||
#endif
|
||||
#else
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// Espressif LWIP stack
|
||||
#define MAX_NUM_TCP_CLIENTS 10
|
||||
#else
|
||||
// Wifi shields etc
|
||||
#define MAX_NUM_TCP_CLIENTS 8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //DEFINES_H
|
||||
|
2813
docs/DoxyfileEXRAIL
Normal file
2813
docs/DoxyfileEXRAIL
Normal file
File diff suppressed because it is too large
Load Diff
20
docs/Makefile
Normal file
20
docs/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
888
docs/_static/css/dccex_theme.css
vendored
Normal file
888
docs/_static/css/dccex_theme.css
vendored
Normal file
@@ -0,0 +1,888 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Audiowide);
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto);
|
||||
|
||||
h1, .h1 {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif !important;
|
||||
font-weight: 500 !important;
|
||||
color: #00353d !important;
|
||||
/* font-size: 200% !important; */
|
||||
font-size: 180% !important;
|
||||
text-shadow: 1px 1px #ffffff78;
|
||||
}
|
||||
html[data-theme='dark'] h1, .h1 {
|
||||
color: #ffffff !important;
|
||||
text-shadow: 1px 1px #00353d;
|
||||
}
|
||||
|
||||
h2, .h2 {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
color: #00353d !important;
|
||||
/* font-size: 190% !important; */
|
||||
font-size: 160% !important;
|
||||
text-shadow: 1px 1px #ffffff78;
|
||||
}
|
||||
html[data-theme='dark'] h2, .h2 {
|
||||
color: #ffffff !important;
|
||||
text-shadow: 1px 1px #00353d;
|
||||
}
|
||||
html[data-theme='dark'] h2 a,
|
||||
html[data-theme='dark'] h2 a:visited {
|
||||
color: #00a3b9ff !important;
|
||||
}
|
||||
|
||||
h3, .h3 {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
color: #00353d !important;
|
||||
/* font-size: 160% !important; */
|
||||
font-size: 140% !important;
|
||||
font-style: italic !important;
|
||||
text-shadow: 1px 1px #ffffff78;
|
||||
}
|
||||
html[data-theme='dark'] h3, .h3 {
|
||||
color: #ffffff !important;
|
||||
text-shadow: 1px 1px #00353d;
|
||||
}
|
||||
html[data-theme='dark'] h3 a,
|
||||
html[data-theme='dark'] h3 a:visited {
|
||||
color: #00a3b9ff !important;
|
||||
}
|
||||
h4, .h4 {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
color: #00353d !important;
|
||||
/* font-size: 130% !important; */
|
||||
font-size: 120% !important;
|
||||
text-shadow: 1px 1px #ffffff78;
|
||||
}
|
||||
html[data-theme='dark'] h4, .h4 {
|
||||
color: #00a3b9ff !important;
|
||||
text-shadow: 1px 1px #00353d;
|
||||
}
|
||||
html[data-theme='dark'] h4 a,
|
||||
html[data-theme='dark'] h4 a:visited {
|
||||
color: #00a3b9ff !important;
|
||||
text-shadow: 1px 1px #00353d;
|
||||
}
|
||||
h5, .h5 {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
color: #00a3b9ff !important;
|
||||
/* font-size: 110% !important; */
|
||||
font-size: 100% !important;
|
||||
}
|
||||
|
||||
h6, .h6 {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
color: #00a3b9ff !important;
|
||||
font-size: 90% !important;
|
||||
font-style: italic !important;
|
||||
}
|
||||
|
||||
.clearer {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.wy-nav-side {
|
||||
background: #031c20 !important;
|
||||
/* background: #031214 !important; */
|
||||
}
|
||||
|
||||
.caption-text {
|
||||
color: #00a3b9ff !important;
|
||||
}
|
||||
|
||||
.wy-nav-top {
|
||||
background:#00a3b9ff !important;
|
||||
font-size: 80% !important;
|
||||
}
|
||||
|
||||
.wy-nav-top a {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif !important;
|
||||
font-weight: 100 !important;
|
||||
}
|
||||
|
||||
.wy-nav-content {
|
||||
max-width: 1024px;
|
||||
}
|
||||
|
||||
.wy-breadcrumbs {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
}
|
||||
|
||||
.wy-side-nav-search>a img.logo {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.rst-content table.docutils th {
|
||||
background-color: #F3F6F6;
|
||||
}
|
||||
|
||||
.rst-content table.docutils td {
|
||||
background-color: #F3F6F6;
|
||||
}
|
||||
|
||||
.rst-content table.docutils:not(.field-list) tr:nth-child(2n-1) td {
|
||||
background-color: #E0E0E0;
|
||||
}
|
||||
html[data-theme='dark'] .rst-content table.docutils:not(.field-list) tr:nth-child(2n-1) td {
|
||||
background-color: #ffffff08 !important;
|
||||
}
|
||||
|
||||
.caption-number {
|
||||
font-size: small !important;
|
||||
}
|
||||
|
||||
.caption-text {
|
||||
font-size: small !important;
|
||||
}
|
||||
|
||||
table.intro-table {
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.intro-table img {
|
||||
width: 70%;
|
||||
height: auto;
|
||||
margin: 5% 15%;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .btn-neutral {
|
||||
color: #c1c1c1 !important;
|
||||
}
|
||||
|
||||
#ex-rail-command-summary .wy-table-responsive {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* product titles */
|
||||
.ex-prefix {
|
||||
font-weight: bold;
|
||||
color: #00a3b9;
|
||||
font-size: 110%;
|
||||
}
|
||||
.ex-suffix {
|
||||
font-weight: bold;
|
||||
color: #00353d;
|
||||
font-size: 110%;
|
||||
}
|
||||
html[data-theme='dark'] .ex-suffix {
|
||||
font-weight: bold;
|
||||
color: #006979;
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
/* main dcc-ex text only */
|
||||
.dccex-prefix {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif;
|
||||
font-weight: 600;
|
||||
color: #00353d;
|
||||
font-size: 110%;
|
||||
}
|
||||
html[data-theme='dark'] .dccex-prefix {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif;
|
||||
font-weight: 600;
|
||||
color: #006979;
|
||||
font-size: 110%;
|
||||
}
|
||||
.dccex-suffix {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif;
|
||||
font-weight: 600;
|
||||
color: #00a3b9;
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
/***************************/
|
||||
|
||||
.command-table thead th {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.command-table tbody td {
|
||||
white-space: normal;
|
||||
margin: 10px;
|
||||
padding: 8px 8px 8px 8px !important;
|
||||
}
|
||||
|
||||
.command-table tbody tr:first-child td p code {
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.command-table tbody tr td p code {
|
||||
font-size: 110% !important;
|
||||
}
|
||||
|
||||
.command-table tbody tr td p {
|
||||
font-size: 90% !important;
|
||||
}
|
||||
|
||||
.command-table tbody tr td ol li p {
|
||||
font-size: 90% !important;
|
||||
}
|
||||
|
||||
.command-table tbody tr td ol {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
.command-table .category {
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.command-table tr:nth-child(odd) {
|
||||
background-color: #f1f1f1 !important;
|
||||
}
|
||||
|
||||
.command-table tr:nth-child(even) {
|
||||
background-color: #f8f8f8 !important;
|
||||
}
|
||||
html[data-theme='dark'] .command-table tr:nth-child(even) {
|
||||
background-color: #ffffff08 !important;
|
||||
}
|
||||
|
||||
.command-table td {
|
||||
background-color: #ffffff00 !important;
|
||||
}
|
||||
|
||||
/* html[data-theme='dark'] .rst-content table.docutils tr:nth-child(odd) {
|
||||
background-color: #ffffff08 !important;
|
||||
} */
|
||||
html[data-theme='dark'] .rst-content table.docutils td, .wy-table-bordered-all td {
|
||||
background-color: #fff40000 !important;
|
||||
}
|
||||
/* html[data-theme='dark'] .rst-content table.docutils .row-odd {
|
||||
background-color: #36ff0000 !important;
|
||||
} */
|
||||
|
||||
html[data-theme='dark'] .rst-content table.docutils th {
|
||||
background-color: #36ff0000 !important;
|
||||
color: white !important;
|
||||
font-style: italic !important;;
|
||||
font-weight: 700 !important;;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
html[data-theme='dark'] .sd-card {
|
||||
background-color: #0000008a;
|
||||
box-shadow: 0 0.5rem 1rem rgb(32 88 91 / 25%) !important;
|
||||
}
|
||||
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
.dcclink a {
|
||||
background-color: #00a3b9ff;
|
||||
box-shadow: 0 2px 0 #00353dff;
|
||||
color: white !important;
|
||||
padding: 0.5em 0.5em;
|
||||
position: relative;
|
||||
text-decoration: none;
|
||||
text-transform: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.dcclink-right a {
|
||||
background-color: #00a3b9ff;
|
||||
box-shadow: 0 2px 0 #00353dff;
|
||||
color: white !important;
|
||||
padding: 0.5em 0.5em;
|
||||
position: relative;
|
||||
text-decoration: none;
|
||||
text-transform: none;
|
||||
border-radius: 10px;
|
||||
float:right;
|
||||
margin: 0px 0px 0px 10px;
|
||||
}
|
||||
|
||||
.dcclink a:visited {
|
||||
color: whitesmoke !important;
|
||||
}
|
||||
|
||||
.dcclink a:hover {
|
||||
background-color: darkslategrey;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dcclink a:active {
|
||||
box-shadow: none;
|
||||
top: 5px;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .rst-content .guilabel {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.hr-dashed {
|
||||
margin: -10px 0px -10px 0px;
|
||||
border-top: 1px dashed #d2dfe3;
|
||||
}
|
||||
|
||||
.hr-heavy {
|
||||
margin: -10px 0px -10px 0px;
|
||||
border-top: 5px solid #d2dfe3;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .hr-dashed {
|
||||
border-top: 1px dashed #114759;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
a.githublink, .githublink a {
|
||||
background-color: #f7b656;
|
||||
box-shadow: 0 2px 0 #00353dff;
|
||||
color: white;
|
||||
padding: 3px 5px 3px 5px;
|
||||
position: relative;
|
||||
font-size: 90% !important;
|
||||
text-decoration: none;
|
||||
text-transform: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.githublink-right a {
|
||||
background-color: #f7b656;
|
||||
box-shadow: 0 2px 0 #00353dff;
|
||||
color: white;
|
||||
padding: 3px 5px 3px 5px;
|
||||
position: relative;
|
||||
font-size: 90% !important;
|
||||
text-decoration: none;
|
||||
text-transform: none;
|
||||
border-radius: 10px;
|
||||
float:right;
|
||||
margin: 0px 0px 0px 0px;
|
||||
}
|
||||
|
||||
.githublink a:visited {
|
||||
color: whitesmoke
|
||||
}
|
||||
|
||||
.githublink a:hover {
|
||||
background-color: rgb(172, 95, 7);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.githublink a:active {
|
||||
box-shadow: none;
|
||||
top: 5px;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
svg {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.responsive-image {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
.warning-float-right {
|
||||
float: right;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.warning-float-right-narrow {
|
||||
float: right;
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.warning-float-right-wide {
|
||||
float: right;
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.note-float-right {
|
||||
float: right;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.note-float-right-narrow {
|
||||
float: right;
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.code-block-float-right {
|
||||
float: right;
|
||||
width: 40%;
|
||||
margin: 0px 0px 0px 24px;
|
||||
}
|
||||
|
||||
.note {
|
||||
background: #f7fcff !important;
|
||||
clear: none !important;
|
||||
}
|
||||
html[data-theme='dark'] .note {
|
||||
background: #ffffff24 !important;
|
||||
}
|
||||
|
||||
.note p.admonition-title {
|
||||
background: #cbe1ef !important;
|
||||
}
|
||||
html[data-theme='dark'] .note p.admonition-title {
|
||||
background: #256a97 !important;
|
||||
}
|
||||
|
||||
.tip {
|
||||
background: #eef5f4 !important;
|
||||
clear: none !important;
|
||||
}
|
||||
html[data-theme='dark'] .tip {
|
||||
background: #ffffff24 !important;
|
||||
clear: none !important;
|
||||
}
|
||||
|
||||
.tip p.admonition-title {
|
||||
background: #9cd7cb !important;
|
||||
}
|
||||
html[data-theme='dark'] .tip p.admonition-title {
|
||||
background: #256a97 !important;
|
||||
}
|
||||
|
||||
.admonition-todo {
|
||||
background: #f9f0e0 !important;
|
||||
clear: none !important;
|
||||
}
|
||||
html[data-theme='dark'] .admonition-todo {
|
||||
background: #ffffff24 !important;
|
||||
clear: none !important;
|
||||
}
|
||||
|
||||
.admonition-todo p.admonition-title {
|
||||
background: #f7d1b0 !important;
|
||||
}
|
||||
html[data-theme='dark'] .admonition-todo p.admonition-title {
|
||||
background: #6d3403 !important;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
.menuselection {
|
||||
font-style: italic;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
.wy-table-responsive {
|
||||
margin-bottom: 12px !important;
|
||||
}
|
||||
|
||||
/* override table width restrictions */
|
||||
.table-wrap-text p, .table-grid-homepage p, .table-list-homepage p {
|
||||
white-space: normal !important;
|
||||
font-size: 110% !important;
|
||||
line-height: 140% !important;
|
||||
}
|
||||
|
||||
.table-wrap-text tr:nth-child(odd), .table-grid-homepage tr:nth-child(odd), .table-list-homepage tr:nth-child(odd) {
|
||||
background-color: white !important;
|
||||
border-style: none !important;
|
||||
border-width:0px !important;
|
||||
}
|
||||
html[data-theme='dark'] tr:nth-child(odd), .table-grid-homepage tr:nth-child(odd), .table-list-homepage tr:nth-child(odd) {
|
||||
background-color: #ffffff08 !important;
|
||||
}
|
||||
|
||||
.table-wrap-text tr:nth-child(even), .table-grid-homepage tr:nth-child(even), .table-list-homepage tr:nth-child(even) {
|
||||
background-color: #ffffff00 !important;
|
||||
border-style: none !important;
|
||||
border-width:0px !important;
|
||||
}
|
||||
|
||||
.table-wrap-text td {
|
||||
background-color: white !important;
|
||||
border-style: none !important;
|
||||
border-width:0px !important;
|
||||
}
|
||||
html[data-theme='dark'] .table-wrap-text td {
|
||||
background-color: ffffff08 !important;
|
||||
}
|
||||
|
||||
.table-grid-homepage td, .table-list-homepage td {
|
||||
font-size: 80% !important;
|
||||
color: #666666 !important;
|
||||
vertical-align:top !important;
|
||||
background-color: #ffffff00 !important;
|
||||
border-style: none !important;
|
||||
border-width: 0px !important;
|
||||
}
|
||||
|
||||
.table-wrap-text, .table-grid-homepage, .table-list-homepage {
|
||||
margin-bottom: 24px;
|
||||
max-width: 100% !important;
|
||||
overflow: visible !important;
|
||||
border-style: none !important;
|
||||
border-width: 0px !important;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 900px) {
|
||||
.table-grid-homepage {
|
||||
display: none;
|
||||
}
|
||||
.table-list-homepage {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
@media not screen and (max-width: 900px) {
|
||||
.table-grid-homepage {
|
||||
display: block;
|
||||
}
|
||||
.table-list-homepage {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.table-wrap-text th p, table-wrap-text-align-top th p {
|
||||
margin-bottom: unset;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
.image-min-width-144 {
|
||||
min-width: 144px;
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
.image-min-width-72 {
|
||||
min-width: 72px;
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
.image-float-right img {
|
||||
float:right;
|
||||
}
|
||||
|
||||
.image-product-logo-float-right img {
|
||||
float:right;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1000px) {
|
||||
.image-product-logo-float-right img {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
/* Google search */
|
||||
|
||||
.gsc-input-box {
|
||||
border: 0px !important;
|
||||
}
|
||||
|
||||
.gsib_a input {
|
||||
padding: 5px !important;
|
||||
background-color: #141414 !important;
|
||||
color:white !important;
|
||||
}
|
||||
|
||||
.gsc-search-button .gsc-search-button-v2 {
|
||||
width: 40px !important;
|
||||
height: 21px !important;
|
||||
padding: 4px 4px !important;
|
||||
background-color: #00a3b9ff !important;
|
||||
border-color: #00a3b9ff !important;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
/* .gsc-search-button .gsc-search-button-v2 {
|
||||
width: 0px !important;
|
||||
padding: 7px 7px !important;
|
||||
border-color: #009300 !important;
|
||||
background-color: #009300 !important;
|
||||
} */
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
/* sidebar level 3 bullet points */
|
||||
nav#on-this-page ul.simple li ul li p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* sidebar level 3 bullet points */
|
||||
nav#on-this-page ul.simple li ul li {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* sidebar level 2 bullet points */
|
||||
nav#on-this-page ul.simple li p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* sidebar level 2 bullet points */
|
||||
nav#on-this-page ul.simple li {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
nav#on-this-page ul.simple {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
nav#on-this-page p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
margin-top: 0px !important;
|
||||
margin-bottom: 6px !important;
|
||||
}
|
||||
|
||||
nav#on-this-page {
|
||||
margin-bottom: 10px !important;
|
||||
}
|
||||
|
||||
|
||||
/* in-this-section level 3 bullet points */
|
||||
nav.in-this-section ul.simple li ul li p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* in-this-section level 3 bullet points */
|
||||
nav.in-this-section ul.simple li ul li {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* in-this-section level 2 bullet points */
|
||||
nav.in-this-section ul.simple li p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
/* in-this-section level 2 bullet points */
|
||||
nav.in-this-section ul.simple li {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
line-height: 120% !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
nav.in-this-section ul.simple {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
nav.in-this-section p {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-style: italic;
|
||||
font-size: 90%;
|
||||
margin-top: 0px !important;
|
||||
margin-bottom: 6px !important;
|
||||
margin-left: -30px;
|
||||
}
|
||||
|
||||
nav.in-this-section {
|
||||
margin-bottom: 20px !important;
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
|
||||
/* sidebars */
|
||||
.rst-content .sidebar {
|
||||
padding: 12px 24px 12px 24px !important;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .rst-content .sidebar {
|
||||
background: #000000ff !important;
|
||||
border:#000000ff !important;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .sidebar-title {
|
||||
background: #002735 !important;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* news */
|
||||
section#dcc-ex-model-railroading aside p.sidebar-title {
|
||||
font-size: 110% !important;
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif !important;
|
||||
font-weight: 500 !important;
|
||||
color: #00a3b9ff;
|
||||
text-shadow: 1px 1px 0 #00353dff;
|
||||
margin: -24px -24px 12px !important;
|
||||
}
|
||||
|
||||
/* news */
|
||||
p.ablog-post-title {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 90% !important;
|
||||
line-height: 130% !important;
|
||||
margin-bottom: 0px !important;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
p.ablog-post-excerpt {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 90% !important;
|
||||
line-height: 130% !important;
|
||||
margin-bottom: 0px !important;
|
||||
margin-top: 6px !important;
|
||||
}
|
||||
|
||||
p.ablog-post-expand {
|
||||
font-family: Roboto,Helvetica,Arial,sans-serif !important;
|
||||
font-size: 80% !important;
|
||||
line-height: 130% !important;
|
||||
margin-bottom: 10px !important;
|
||||
margin-top: 0px !important;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
li.ablog-post {
|
||||
list-style-type: none !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
img.sd-card-img-top {
|
||||
max-width: 30% !important;
|
||||
display: block !important;
|
||||
margin-left: auto !important;
|
||||
margin-right: auto !important;
|
||||
margin-top: 10px;
|
||||
margin-bottom: -5px !important;
|
||||
}
|
||||
|
||||
.sd-card-header {
|
||||
margin-bottom: -10px !important;
|
||||
margin-top: 10px !important;
|
||||
padding-top: 0px !important;
|
||||
padding-bottom: 0px !important;
|
||||
}
|
||||
|
||||
.sd-card-header p {
|
||||
line-height: 18px !important;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .sd-card-header {
|
||||
border-bottom: 1px solid rgb(255 253 253 / 13%);
|
||||
}
|
||||
|
||||
.sd-card-body ul li p {
|
||||
margin-bottom: 5px !important;
|
||||
}
|
||||
|
||||
.sd-card-text {
|
||||
margin: 0 0 12px !important;
|
||||
}
|
||||
|
||||
/* code */
|
||||
.rst-content code {
|
||||
font-size: 100% !important;
|
||||
}
|
||||
.rst-content code.literal, .rst-content tt.literal {
|
||||
color: #ba2121 !important;
|
||||
font-size: 100% important;
|
||||
}
|
||||
html[data-theme='dark'] .rst-content code.literal, .rst-content tt.literal {
|
||||
color: #ff6000 !important;
|
||||
}
|
||||
|
||||
/* general purpose */
|
||||
|
||||
.dcc-ex-red {
|
||||
color:red;
|
||||
}
|
||||
|
||||
.dcc-ex-red-bold {
|
||||
color:red;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.dcc-ex-red-bold-italic {
|
||||
color:red;
|
||||
font-weight: bold !important;
|
||||
font-style: italic !important;
|
||||
}
|
||||
|
||||
.dcc-ex-code {
|
||||
color:#ba2121;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.dcc-ex-text-size-200pct {
|
||||
font-size: 200% !important;
|
||||
line-height: 110% !important;
|
||||
}
|
||||
|
||||
.dcc-ex-text-size-80pct {
|
||||
font-size: 80% !important;
|
||||
}
|
||||
|
||||
.dcc-ex-text-size-60pct {
|
||||
font-size: 80% !important;
|
||||
}
|
||||
|
||||
.new-in-v5 {
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif;
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
color: #00a3b9;
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .new-in-v5 {
|
||||
font-weight: normal;
|
||||
color: #ffffff;
|
||||
text-shadow: 0px 0px 10px #00a3b9;
|
||||
}
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
@media not screen and (max-width: 900px) {
|
||||
div.rst-footer-buttons {
|
||||
position: fixed;
|
||||
bottom:5px;
|
||||
width:350px;
|
||||
background: #c9c9c999;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
border-color: white !important;
|
||||
border: 4px solid;
|
||||
transform: translateX(50%);
|
||||
}
|
||||
html[data-theme='dark'] div.rst-footer-buttons {
|
||||
border-color: #141414 !important;
|
||||
background: #c9c9c92e;
|
||||
}
|
||||
footer {
|
||||
padding-bottom: 40px;
|
||||
font-size: 80% !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 900px) {
|
||||
div.rst-footer-buttons {
|
||||
display:block;
|
||||
font-size: 80% !important;
|
||||
}
|
||||
}
|
||||
|
||||
html[data-theme='dark'] .rst-content span.descname {
|
||||
color: #dbdd7c !important;
|
||||
}
|
9
docs/_static/css/sphinx_design_overrides.css
vendored
Normal file
9
docs/_static/css/sphinx_design_overrides.css
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Override for the sphinx-design extension classes */
|
||||
.sd-card-header {
|
||||
font-size: 110% !important;
|
||||
font-family: Audiowide,Helvetica,Arial,sans-serif !important;
|
||||
font-weight: 500 !important;
|
||||
color: #00a3b9ff;
|
||||
text-shadow: 1px 1px 0 #00353dff;
|
||||
margin-bottom: .5rem !important;
|
||||
}
|
BIN
docs/_static/images/favicon.ico
vendored
Normal file
BIN
docs/_static/images/favicon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 627 KiB |
BIN
docs/_static/images/logo.png
vendored
Normal file
BIN
docs/_static/images/logo.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
docs/_static/images/product-logo-ex-rail.png
vendored
Normal file
BIN
docs/_static/images/product-logo-ex-rail.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
94
docs/conf.py
Normal file
94
docs/conf.py
Normal file
@@ -0,0 +1,94 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# For the full list of built-in configuration values, see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
# Doxygen
|
||||
subprocess.call('doxygen DoxyfileEXRAIL', shell=True)
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
project = 'EXRAIL Language'
|
||||
copyright = '2025 - Peter Cole'
|
||||
author = 'Peter Cole'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = [
|
||||
'sphinx_sitemap',
|
||||
'sphinxcontrib.spelling',
|
||||
'sphinx_rtd_dark_mode',
|
||||
'breathe'
|
||||
]
|
||||
|
||||
autosectionlabel_prefix_document = True
|
||||
|
||||
# Don't make dark mode the user default
|
||||
default_dark_mode = False
|
||||
|
||||
spelling_lang = 'en_UK'
|
||||
tokenizer_lang = 'en_UK'
|
||||
spelling_word_list_filename = ['spelling_wordlist.txt']
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
highlight_language = 'c++'
|
||||
|
||||
numfig = True
|
||||
|
||||
numfig_format = {'figure': 'Figure %s'}
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_static_path = ['_static']
|
||||
|
||||
html_logo = "./_static/images/product-logo-ex-rail.png"
|
||||
|
||||
html_favicon = "./_static/images/favicon.ico"
|
||||
|
||||
html_theme_options = {
|
||||
'style_nav_header_background': 'white',
|
||||
'logo_only': True,
|
||||
# Toc options
|
||||
'includehidden': True,
|
||||
'titles_only': False,
|
||||
# 'titles_only': True,
|
||||
'collapse_navigation': False,
|
||||
# 'navigation_depth': 3,
|
||||
'navigation_depth': 1,
|
||||
'analytics_id': 'G-L5X0KNBF0W',
|
||||
}
|
||||
|
||||
html_context = {
|
||||
'display_github': True,
|
||||
'github_user': 'DCC-EX',
|
||||
'github_repo': 'CommandStation-EX',
|
||||
'github_version': 'sphinx/docs/',
|
||||
}
|
||||
|
||||
html_css_files = [
|
||||
'css/dccex_theme.css',
|
||||
'css/sphinx_design_overrides.css',
|
||||
]
|
||||
|
||||
html_baseurl = 'https://dcc-ex.com/CommandStation-EX/'
|
||||
|
||||
# Sphinx sitemap
|
||||
html_extra_path = [
|
||||
'robots.txt',
|
||||
]
|
||||
|
||||
# -- Breathe configuration -------------------------------------------------
|
||||
|
||||
breathe_projects = {
|
||||
"EXRAIL Language": "_build/xml/"
|
||||
}
|
||||
breathe_default_project = "EXRAIL Language"
|
||||
breathe_default_members = ()
|
15
docs/index.rst
Normal file
15
docs/index.rst
Normal file
@@ -0,0 +1,15 @@
|
||||
EXRAIL Language documentation
|
||||
=============================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
EXRAIL - Extended Railroad Automation Instruction Language
|
||||
|
||||
This page is a reference to all EXRAIL commands available with EX-CommandStation.
|
||||
|
||||
Macros
|
||||
------
|
||||
|
||||
.. doxygenfile:: EXRAIL2MacroReset.h
|
||||
:project: EXRAIL Language
|
35
docs/make.bat
Normal file
35
docs/make.bat
Normal file
@@ -0,0 +1,35 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.https://www.sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
39
docs/requirements.txt
Normal file
39
docs/requirements.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
alabaster==1.0.0
|
||||
attrs==25.1.0
|
||||
babel==2.17.0
|
||||
breathe==4.35.0
|
||||
cattrs==24.1.2
|
||||
certifi==2025.1.31
|
||||
charset-normalizer==3.4.1
|
||||
colorama==0.4.6
|
||||
docutils==0.21.2
|
||||
esbonio==0.16.5
|
||||
exceptiongroup==1.2.2
|
||||
idna==3.10
|
||||
imagesize==1.4.1
|
||||
Jinja2==3.1.5
|
||||
lsprotocol==2023.0.1
|
||||
MarkupSafe==3.0.2
|
||||
packaging==24.2
|
||||
platformdirs==4.3.6
|
||||
pyenchant==3.2.2
|
||||
pygls==1.3.1
|
||||
Pygments==2.19.1
|
||||
pyspellchecker==0.8.2
|
||||
requests==2.32.3
|
||||
snowballstemmer==2.2.0
|
||||
Sphinx==8.1.3
|
||||
sphinx-rtd-dark-mode==1.3.0
|
||||
sphinx-rtd-theme==3.0.2
|
||||
sphinx-sitemap==2.6.0
|
||||
sphinxcontrib-applehelp==2.0.0
|
||||
sphinxcontrib-devhelp==2.0.0
|
||||
sphinxcontrib-htmlhelp==2.1.0
|
||||
sphinxcontrib-jquery==4.1
|
||||
sphinxcontrib-jsmath==1.0.1
|
||||
sphinxcontrib-qthelp==2.0.0
|
||||
sphinxcontrib-serializinghtml==2.0.0
|
||||
sphinxcontrib-spelling==8.0.1
|
||||
tomli==2.2.1
|
||||
typing_extensions==4.12.2
|
||||
urllib3==2.3.0
|
3
docs/robots.txt
Normal file
3
docs/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
User-agent: *
|
||||
|
||||
Sitemap: https://dcc-ex.com/CommandStation-EX/sitemap.xml
|
206
libsha1.cpp
Normal file
206
libsha1.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
// For DCC-EX: This file downloaded from:
|
||||
// https://github.com/Links2004/arduinoWebSockets
|
||||
// All due credit to Steve Reid
|
||||
|
||||
/* from valgrind tests */
|
||||
|
||||
/* ================ sha1.c ================ */
|
||||
/*
|
||||
SHA-1 in C
|
||||
By Steve Reid <steve@edmweb.com>
|
||||
100% Public Domain
|
||||
|
||||
Test Vectors (from FIPS PUB 180-1)
|
||||
"abc"
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
A million repetitions of "a"
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
|
||||
/* #define SHA1HANDSOFF * Copies data before messing with it. */
|
||||
|
||||
// DCC-EX removed #if !defined(ESP8266) && !defined(ESP32)
|
||||
|
||||
#define SHA1HANDSOFF
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libsha1.h"
|
||||
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/* blk0() and blk() perform the initial expand. */
|
||||
/* I got the idea of expanding during the round function from SSLeay */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|
||||
|(rol(block->l[i],8)&0x00FF00FF))
|
||||
#elif BYTE_ORDER == BIG_ENDIAN
|
||||
#define blk0(i) block->l[i]
|
||||
#else
|
||||
#error "Endianness not defined!"
|
||||
#endif
|
||||
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
||||
^block->l[(i+2)&15]^block->l[i&15],1))
|
||||
|
||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
||||
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
||||
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
||||
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
|
||||
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
|
||||
{
|
||||
uint32_t a, b, c, d, e;
|
||||
typedef union {
|
||||
unsigned char c[64];
|
||||
uint32_t l[16];
|
||||
} CHAR64LONG16;
|
||||
#ifdef SHA1HANDSOFF
|
||||
CHAR64LONG16 block[1]; /* use array to appear as a pointer */
|
||||
memcpy(block, buffer, 64);
|
||||
#else
|
||||
/* The following had better never be used because it causes the
|
||||
* pointer-to-const buffer to be cast into a pointer to non-const.
|
||||
* And the result is written through. I threw a "const" in, hoping
|
||||
* this will cause a diagnostic.
|
||||
*/
|
||||
CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
|
||||
#endif
|
||||
/* Copy context->state[] to working vars */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
/* 4 rounds of 20 operations each. Loop unrolled. */
|
||||
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
||||
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
||||
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
||||
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
||||
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
||||
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
||||
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
||||
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
||||
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
||||
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
||||
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
||||
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
||||
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
||||
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
||||
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
||||
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
||||
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
||||
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
||||
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
||||
/* Add the working vars back into context.state[] */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
/* Wipe variables */
|
||||
a = b = c = d = e = 0;
|
||||
#ifdef SHA1HANDSOFF
|
||||
memset(block, '\0', sizeof(block));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* SHA1Init - Initialize new context */
|
||||
|
||||
void SHA1Init(SHA1_CTX* context)
|
||||
{
|
||||
/* SHA1 initialization constants */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xEFCDAB89;
|
||||
context->state[2] = 0x98BADCFE;
|
||||
context->state[3] = 0x10325476;
|
||||
context->state[4] = 0xC3D2E1F0;
|
||||
context->count[0] = context->count[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Run your data through this. */
|
||||
|
||||
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len)
|
||||
{
|
||||
uint32_t i, j;
|
||||
|
||||
j = context->count[0];
|
||||
if ((context->count[0] += len << 3) < j)
|
||||
context->count[1]++;
|
||||
context->count[1] += (len>>29);
|
||||
j = (j >> 3) & 63;
|
||||
if ((j + len) > 63) {
|
||||
memcpy(&context->buffer[j], data, (i = 64-j));
|
||||
SHA1Transform(context->state, context->buffer);
|
||||
for ( ; i + 63 < len; i += 64) {
|
||||
SHA1Transform(context->state, &data[i]);
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
memcpy(&context->buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
|
||||
/* Add padding and return the message digest. */
|
||||
|
||||
void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned char finalcount[8];
|
||||
unsigned char c;
|
||||
|
||||
#if 0 /* untested "improvement" by DHR */
|
||||
/* Convert context->count to a sequence of bytes
|
||||
* in finalcount. Second element first, but
|
||||
* big-endian order within element.
|
||||
* But we do it all backwards.
|
||||
*/
|
||||
unsigned char *fcp = &finalcount[8];
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
uint32_t t = context->count[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; t >>= 8, j++)
|
||||
*--fcp = (unsigned char) t;
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
|
||||
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||
}
|
||||
#endif
|
||||
c = 0200;
|
||||
SHA1Update(context, &c, 1);
|
||||
while ((context->count[0] & 504) != 448) {
|
||||
c = 0000;
|
||||
SHA1Update(context, &c, 1);
|
||||
}
|
||||
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
||||
for (i = 0; i < 20; i++) {
|
||||
digest[i] = (unsigned char)
|
||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||
}
|
||||
/* Wipe variables */
|
||||
memset(context, '\0', sizeof(*context));
|
||||
memset(&finalcount, '\0', sizeof(finalcount));
|
||||
}
|
||||
/* ================ end of sha1.c ================ */
|
||||
|
||||
|
||||
// DCC-EX Removed: #endif
|
26
libsha1.h
Normal file
26
libsha1.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// For DCC-EX: This file downloaded from:
|
||||
// https://github.com/Links2004/arduinoWebSockets
|
||||
// All due credit to Steve Reid
|
||||
|
||||
/* ================ sha1.h ================ */
|
||||
/*
|
||||
SHA-1 in C
|
||||
By Steve Reid <steve@edmweb.com>
|
||||
100% Public Domain
|
||||
*/
|
||||
|
||||
// DCC-EX REMOVED #if !defined(ESP8266) && !defined(ESP32)
|
||||
#ifndef libsha1_h
|
||||
#define libsha1_h
|
||||
typedef struct {
|
||||
uint32_t state[5];
|
||||
uint32_t count[2];
|
||||
unsigned char buffer[64];
|
||||
} SHA1_CTX;
|
||||
|
||||
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
|
||||
void SHA1Init(SHA1_CTX* context);
|
||||
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
|
||||
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
|
||||
|
||||
#endif
|
27
objdump.bat
27
objdump.bat
@@ -1,16 +1,17 @@
|
||||
ECHO ON
|
||||
FOR /F "delims=" %%i IN ('dir %TMP%\arduino_build_* /b /ad-h /t:c /od') DO SET a=%%i
|
||||
echo Most recent subfolder: %a% >%TMP%\OBJDUMP_%a%.txt
|
||||
SET ELF=%TMP%\%a%\CommandStation-EX.ino.elf
|
||||
FOR /F "delims=" %%i IN ('dir %TMP%\arduino\sketches\CommandStation-EX.ino.elf /s /b /o-D') DO SET ELF=%%i
|
||||
SET DUMP=%TEMP%\OBJDUMP.txt
|
||||
echo Most recent subfolder: %ELF% >%DUMP%
|
||||
|
||||
set PATH="C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\";%PATH%
|
||||
avr-objdump --private=mem-usage %ELF% >>%TMP%\OBJDUMP_%a%.txt
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%TMP%\OBJDUMP_%a%.txt
|
||||
avr-objdump -x -C %ELF% | find ".text" | sort /+25 /R >>%TMP%\OBJDUMP_%a%.txt
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%TMP%\OBJDUMP_%a%.txt
|
||||
avr-objdump -x -C %ELF% | find ".data" | sort /+25 /R >>%TMP%\OBJDUMP_%a%.txt
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%TMP%\OBJDUMP_%a%.txt
|
||||
avr-objdump -x -C %ELF% | find ".bss" | sort /+25 /R >>%TMP%\OBJDUMP_%a%.txt
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%TMP%\OBJDUMP_%a%.txt
|
||||
avr-objdump -D -S %ELF% >>%TMP%\OBJDUMP_%a%.txt
|
||||
%TMP%\OBJDUMP_%a%.txt
|
||||
avr-objdump --private=mem-usage %ELF% >>%DUMP%
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%DUMP%
|
||||
avr-objdump -x -C %ELF% | find ".text" | sort /+25 /R >>%DUMP%
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%DUMP%
|
||||
avr-objdump -x -C %ELF% | find ".data" | sort /+25 /R >>%DUMP%
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%DUMP%
|
||||
avr-objdump -x -C %ELF% | find ".bss" | sort /+25 /R >>%DUMP%
|
||||
ECHO ++++++++++++++++++++++++++++++++++ >>%DUMP%
|
||||
avr-objdump -D -S %ELF% >>%DUMP%
|
||||
%DUMP%
|
||||
EXIT
|
||||
|
@@ -11,11 +11,12 @@
|
||||
[platformio]
|
||||
default_envs =
|
||||
mega2560
|
||||
uno
|
||||
nano
|
||||
; uno
|
||||
; nano
|
||||
ESP32
|
||||
Nucleo-F411RE
|
||||
Nucleo-F446RE
|
||||
Nucleo-F429ZI
|
||||
src_dir = .
|
||||
include_dir = .
|
||||
|
||||
@@ -96,7 +97,6 @@ lib_deps =
|
||||
${env.lib_deps}
|
||||
arduino-libraries/Ethernet
|
||||
SPI
|
||||
MDNS_Generic
|
||||
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
@@ -115,7 +115,6 @@ framework = arduino
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
arduino-libraries/Ethernet
|
||||
MDNS_Generic
|
||||
SPI
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
@@ -194,7 +193,7 @@ monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
[env:Nucleo-F411RE]
|
||||
platform = ststm32 @ 17.6.0
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f411re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@@ -203,7 +202,7 @@ monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
[env:Nucleo-F446RE]
|
||||
platform = ststm32 @ 17.6.0
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f446re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@@ -215,7 +214,7 @@ monitor_echo = yes
|
||||
; tested as yet
|
||||
;
|
||||
[env:Nucleo-F401RE]
|
||||
platform = ststm32 @ 17.6.0
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f401re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@@ -228,7 +227,7 @@ monitor_echo = yes
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
; [env:Nucleo-F413ZH]
|
||||
; platform = ststm32 @ 17.6.0
|
||||
; platform = ststm32 @ 19.0.0
|
||||
; board = nucleo_f413zh
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
@@ -240,7 +239,7 @@ monitor_echo = yes
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
[env:Nucleo-F446ZE]
|
||||
platform = ststm32 @ 17.6.0
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f446ze
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@@ -252,7 +251,7 @@ monitor_echo = yes
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
; [env:Nucleo-F412ZG]
|
||||
; platform = ststm32 @ 17.6.0
|
||||
; platform = ststm32 @ 19.0.0
|
||||
; board = nucleo_f412zg
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
@@ -261,46 +260,40 @@ monitor_echo = yes
|
||||
; monitor_echo = yes
|
||||
; upload_protocol = stlink
|
||||
|
||||
; Experimental - Ethernet work still in progress
|
||||
; Experimental - Ethernet beta test
|
||||
;
|
||||
[env:Nucleo-F429ZI]
|
||||
platform = ststm32 @ 17.6.0
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f429zi
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
stm32duino/STM32Ethernet @ ^1.4.0
|
||||
stm32duino/STM32duino LwIP @ ^2.1.3
|
||||
MDNS_Generic
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable -DCUSTOM_PERIPHERAL_PINS
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
upload_protocol = stlink
|
||||
|
||||
; Experimental - Ethernet work still in progress
|
||||
; Experimental - Ethernet beta test
|
||||
;
|
||||
[env:Nucleo-F439ZI]
|
||||
platform = ststm32 @ 17.6.0
|
||||
; board = nucleo_f439zi
|
||||
; Temporarily treat it as an F429ZI (they are code compatible) until
|
||||
; the PR to PlatformIO to update the F439ZI JSON file is available
|
||||
; PMA - 28-Sep-2024
|
||||
board = nucleo_f429zi
|
||||
platform = ststm32 @ 19.0.0
|
||||
board = nucleo_f439zi
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
stm32duino/STM32Ethernet @ ^1.4.0
|
||||
stm32duino/STM32duino LwIP @ ^2.1.3
|
||||
MDNS_Generic
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable -DCUSTOM_PERIPHERAL_PINS
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
upload_protocol = stlink
|
||||
|
38
version.h
38
version.h
@@ -3,7 +3,43 @@
|
||||
|
||||
#include "StringFormatter.h"
|
||||
|
||||
#define VERSION "5.4.3"
|
||||
#define VERSION "5.5.21"
|
||||
// 5.5.21 - Backed out the broken merge with frequency change and
|
||||
// 5.5.20 - EXRAIL SET/RESET assert fix
|
||||
// 5.5.19 - Railcom change to use RailcomCollector device
|
||||
// 5.5.18 - New STASH internals
|
||||
// - EXRAIL IFSTASH/CLEAR_ANY_STASH
|
||||
// - <JM CLEAR ANY id> to clear any stash with loco id
|
||||
// - See Release_Notes/Stash.md
|
||||
// 5.5.17 - Extensive new compile time checking in exrail scripts (duplicate sequences etc), no function change
|
||||
// 5.5.16 - DOXYGEN comments in EXRAIL2MacroReset.h
|
||||
// 5.5.15 - Support for F429ZI/F329ZI
|
||||
// - Own mDNS support for (wired) Ethernet
|
||||
// 5.5.14 - DCC Non-blocking packet queue with priority
|
||||
// 5.5.13 - Update STM32duino core to v19.0.0. for updated PeripheralPins.c in preparation for F429/439ZI Ethernet support
|
||||
// 5.5.12 - Websocket support (wifi only)
|
||||
// 5.5.11 - (5.4.2) accessory command reverse
|
||||
// 5.5.10 - CamParser fix
|
||||
// 5.5.9 - (5.4.3) fix changeFn for functions 29..31
|
||||
// 5.5.8 - EXSensorCam clean up to match other filters and
|
||||
// - avoid need for config.h settings
|
||||
// - Test: IO_I2CDFPlayer.h inserted 10mS deleay in Init_SC16IS752() just after soft-reset for board with 1.8432 Mhz xtal
|
||||
// - IO_I2CDFPlayer.h: fixed 2 compiler errors as the compilers are getting stricter
|
||||
// 5.5.7 - ESP32 bugfix packet buffer race (as 5.4.1)
|
||||
// 5.5.6 - Fix ESP32 build bug caused by include reference loop
|
||||
// 5.5.5 - Railcom implementation with IO_I2CRailcom driver
|
||||
// - response analysis and block management.
|
||||
// - <r locoid cv> POM read using Railcom.
|
||||
// - See Release_notes/Railcom.md
|
||||
// 5.5.4 - Split ESP32 from DCCWaveform to DCCWaveformRMT
|
||||
// - Railcom Cutout control (DCCTimerAVR Mega only so far)
|
||||
// 5.5.3 - EXRAIL ESTOPALL,XPOM,
|
||||
// - Bugfix RESERVE to cause ESTOP.(was STOP)
|
||||
// - Correct direction sync after manual throttle change.
|
||||
// - plus ONBLOCKENTER/EXIT in preparation for Railcom
|
||||
// 5.5.2 - DS1307 Real Time clock
|
||||
// 5.5.1 - Momentum
|
||||
// 5.5.0 - New version on devel
|
||||
// 5.4.3 - bugfix changeFn for functions 29..31
|
||||
// 5.4.2 - Reversed turnout bugfix
|
||||
// 5.4.1 - ESP32 bugfix packet buffer race
|
||||
|
Reference in New Issue
Block a user