mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
cleaner IO_I2CRailcom
This commit is contained in:
parent
0341d803cc
commit
7bd790dfbf
|
@ -59,7 +59,7 @@
|
||||||
class I2CRailcom : public IODevice {
|
class I2CRailcom : public IODevice {
|
||||||
private:
|
private:
|
||||||
// SC16IS752 defines
|
// SC16IS752 defines
|
||||||
uint8_t _UART_CH=0x00;
|
uint8_t _UART_CH=0x00; // channel 0 or 1 flips each loop if npins>1
|
||||||
byte _inbuf[65];
|
byte _inbuf[65];
|
||||||
byte _outbuf[2];
|
byte _outbuf[2];
|
||||||
Railcom _channelMonitors[2];
|
Railcom _channelMonitors[2];
|
||||||
|
@ -107,48 +107,37 @@ public:
|
||||||
// return if in cutout or cutout very soon.
|
// return if in cutout or cutout very soon.
|
||||||
if (!DCCWaveform::isRailcomSampleWindow()) return;
|
if (!DCCWaveform::isRailcomSampleWindow()) return;
|
||||||
|
|
||||||
// flip channels each loop
|
// IF we have 2 channels, flip channels each loop
|
||||||
_UART_CH=0;
|
|
||||||
if (_nPins>1) _UART_CH=_UART_CH?0:1;
|
if (_nPins>1) _UART_CH=_UART_CH?0:1;
|
||||||
|
|
||||||
// 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){
|
if (inlength==0) return;
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
#ifdef DIAG_I2CRailcom
|
|
||||||
DIAG(F("Railcom: %s/%d RX Fifo length: %d"),_I2CAddress.toString(), _UART_CH, inlength);
|
|
||||||
#endif
|
|
||||||
_outbuf[0]=(byte)(REG_RHR << 3 | _UART_CH << 1);
|
|
||||||
I2CManager.read(_I2CAddress, _inbuf, inlength, _outbuf, 1);
|
|
||||||
#ifdef DIAG_I2CRailcom_data
|
|
||||||
DIAG(F("Railcom %s/%d RX FIFO Data"), _I2CAddress.toString(), _UART_CH);
|
|
||||||
for (int i = 0; i < inlength; i++){
|
|
||||||
DIAG(F("[0x%x]: 0x%x"), i, _inbuf[i]);
|
|
||||||
}
|
|
||||||
auto locoid=_channelMonitors[_UART_CH].getChannel1Loco(_inbuf);
|
|
||||||
DIAG(F("Railcom Channel1=%d"), locoid);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef DIAG_I2CRailcom
|
||||||
// Ask UART for the data
|
DIAG(F("Railcom: %s/%d RX Fifo length: %d"),_I2CAddress.toString(), _UART_CH, inlength);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Read data buffer from UART
|
||||||
_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);
|
||||||
|
|
||||||
|
// HK: Reset FIFO at end of read cycle
|
||||||
|
UART_WriteRegister(REG_FCR, 0x07,false);
|
||||||
|
|
||||||
#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
|
#endif
|
||||||
|
|
||||||
// Ask Railcom to interpret the channel1 loco
|
// 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);
|
#ifdef DIAG_I2CRailcom
|
||||||
|
DIAG(F("Railcom Channel1=%d"), locoid);
|
||||||
|
#endif
|
||||||
if (locoid<0) return; // -1 indicates Railcom needs another packet
|
if (locoid<0) return; // -1 indicates Railcom needs another packet
|
||||||
|
|
||||||
// determine if loco in this block has changed
|
// determine if loco in this block has changed
|
||||||
|
@ -161,8 +150,6 @@ public:
|
||||||
// new loco, if any, is entering block
|
// new loco, if any, is entering block
|
||||||
_locoInBlock[_UART_CH]=locoid;
|
_locoInBlock[_UART_CH]=locoid;
|
||||||
if (locoid) RMFT3::blockEvent(_firstVpin+_UART_CH,locoid,true);
|
if (locoid) RMFT3::blockEvent(_firstVpin+_UART_CH,locoid,true);
|
||||||
|
|
||||||
UART_WriteRegister(REG_FCR, 0x07,false); // HK: Reset FIFO at end of read cycle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user