1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Asbelos
4739bb16ff Fix ESP32 compile error 2024-10-01 12:32:58 +01:00
Asbelos
39c598f195 Connect IO_Railcom to Exrail 2024-10-01 12:29:16 +01:00
5 changed files with 52 additions and 19 deletions

View File

@ -267,6 +267,8 @@ DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false);
RMTChannel *DCCWaveform::rmtMainChannel = NULL; RMTChannel *DCCWaveform::rmtMainChannel = NULL;
RMTChannel *DCCWaveform::rmtProgChannel = NULL; RMTChannel *DCCWaveform::rmtProgChannel = NULL;
volatile bool DCCWaveform::railcomSampleWindow=false; // true during packet transmit
DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) { DCCWaveform::DCCWaveform(byte preambleBits, bool isMain) {
isMainTrack = isMain; isMainTrack = isMain;

5
EXRAIL3.cpp Normal file
View File

@ -0,0 +1,5 @@
// file exists to break #include dependency loop
#include "EXRAIL2.h"
void RMFT3::blockEvent(int16_t block, int16_t loco, bool entering) {
RMFT2::blockEvent(block,loco,entering);
};

5
EXRAIL3.h Normal file
View File

@ -0,0 +1,5 @@
// file exists to break #include dependency loop
class RMFT3 {
public:
static void blockEvent(int16_t block, int16_t loco, bool entering);
};

View File

@ -45,7 +45,7 @@
#ifndef IO_I2CRailcom_h #ifndef IO_I2CRailcom_h
#define IO_I2CRailcom_h #define IO_I2CRailcom_h
#include "EXRAIL3.h"
#include "IODevice.h" #include "IODevice.h"
#include "I2CManager.h" #include "I2CManager.h"
#include "DIAG.h" #include "DIAG.h"
@ -63,6 +63,7 @@ private:
byte _inbuf[65]; byte _inbuf[65];
byte _outbuf[2]; byte _outbuf[2];
Railcom _channelMonitors[2]; Railcom _channelMonitors[2];
int16_t _locoInBlock[2];
public: public:
// Constructor // Constructor
I2CRailcom(VPIN firstVpin, int nPins, I2CAddress i2cAddress){ I2CRailcom(VPIN firstVpin, int nPins, I2CAddress i2cAddress){
@ -111,23 +112,38 @@ public:
// Read incoming raw Railcom data, and process accordingly // Read incoming raw Railcom data, and process accordingly
auto inlength= UART_ReadRegister(REG_RXLV); auto inlength= UART_ReadRegister(REG_RXLV);
if (inlength==0) return; if (inlength==0) return;
{
#ifdef DIAG_I2CRailcom #ifdef DIAG_I2CRailcom
DIAG(F("Railcom: %s/%d RX Fifo: %d"),_I2CAddress.toString(), _UART_CH, inlength); DIAG(F("Railcom: %s/%d RX Fifo: %d"),_I2CAddress.toString(), _UART_CH, inlength);
#endif #endif
// Ask UART for the data
_outbuf[0]=(byte)(REG_RHR << 3 | _UART_CH << 1); _outbuf[0]=(byte)(REG_RHR << 3 | _UART_CH << 1);
I2CManager.read(_I2CAddress, _inbuf, inlength, _outbuf, 1); I2CManager.read(_I2CAddress, _inbuf, inlength, _outbuf, 1);
#ifdef DIAG_I2CRailcom_data #ifdef DIAG_I2CRailcom_data
// Dump data buffer
DIAG(F("Railcom %s/%d RX FIFO Data"), _I2CAddress.toString(), _UART_CH); DIAG(F("Railcom %s/%d RX FIFO Data"), _I2CAddress.toString(), _UART_CH);
for (int i = 0; i < inlength; i++){ for (int i = 0; i < inlength; i++){
DIAG(F("[0x%x]: 0x%x"), i, _inbuf[i]); DIAG(F("[0x%x]: 0x%x"), i, _inbuf[i]);
} }
#endif
// Ask Railcom to interpret the channel1 loco
auto locoid=_channelMonitors[_UART_CH].getChannel1Loco(_inbuf); auto locoid=_channelMonitors[_UART_CH].getChannel1Loco(_inbuf);
DIAG(F("Railcom Channel1=%d"), locoid); DIAG(F("Railcom Channel1=%d"), locoid);
if (locoid<0) return; // -1 indicates Railcom needs another packet
#endif // determine if loco in this block has changed
} auto prevLoco=_locoInBlock[_UART_CH];
if (locoid==prevLoco) return;
// Previous loco (if any) is exiting block
if (prevLoco) RMFT3::blockEvent(_firstVpin+_UART_CH,prevLoco,false);
// new loco, if any, is entering block
_locoInBlock[_UART_CH]=locoid;
if (locoid) RMFT3::blockEvent(_firstVpin+_UART_CH,locoid,true);
} }

View File

@ -25,6 +25,11 @@
class Railcom { class Railcom {
public: public:
Railcom(); Railcom();
/* returns -1: Call again next packet
0: No loco on track
>0: loco id
*/
int16_t getChannel1Loco(uint8_t * inbound); int16_t getChannel1Loco(uint8_t * inbound);
private: private: