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

pom read timeout

This commit is contained in:
Asbelos 2024-10-23 15:45:44 +01:00
parent a0a503ad7d
commit 44869a549d
2 changed files with 12 additions and 12 deletions

View File

@ -147,7 +147,7 @@ Railcom::Railcom(uint16_t blockvpin) {
} }
uint16_t Railcom::expectLoco=0; uint16_t Railcom::expectLoco=0;
uint16_t Railcom::expectCV=0; uint16_t Railcom::expectCV=0;
uint16_t Railcom::expectWait=0; unsigned long Railcom::expectWait=0;
ACK_CALLBACK Railcom::expectCallback=0; ACK_CALLBACK Railcom::expectCallback=0;
@ -183,22 +183,20 @@ void Railcom::process(uint8_t * inbound, uint8_t length) {
byte type=(packet>>8) & 0x0F; byte type=(packet>>8) & 0x0F;
byte data= packet & 0xFF; byte data= packet & 0xFF;
if (type==RMOB_POM) { if (type==RMOB_POM) {
DIAG(F("POM READ loco=%d cv(%d)=%d/0x%x"), expectLoco, expectCV,data,data); // DIAG(F("POM READ loco=%d cv(%d)=%d/0x%x"), expectLoco, expectCV,data,data);
expectCallback(data); expectCallback(data);
expectCV=0; expectCV=0;
} }
} }
if (expectCV) { // still waiting
expectWait--;
if (expectWait==0) {
DIAG(F("POM READ loco=%d cv(%d) FAIL"), expectLoco, expectCV);
expectCallback(-1);
expectCV=0;
}
}
} }
if (expectCV && (millis()-expectWait)> POM_READ_TIMEOUT) { // still waiting
expectCallback(-1);
expectCV=0;
}
auto v1=GETHIGHFLASH(decode,inbound[0]); auto v1=GETHIGHFLASH(decode,inbound[0]);
auto v2=(length>1) ? GETHIGHFLASH(decode,inbound[1]):INV; auto v2=(length>1) ? GETHIGHFLASH(decode,inbound[1]):INV;
uint16_t packet=(v1<<6) | (v2 & 0x3f); uint16_t packet=(v1<<6) | (v2 & 0x3f);

View File

@ -36,12 +36,14 @@ class Railcom {
static void anticipate(uint16_t loco, uint16_t cv, ACK_CALLBACK callback) { static void anticipate(uint16_t loco, uint16_t cv, ACK_CALLBACK callback) {
expectLoco=loco; expectLoco=loco;
expectCV=cv; expectCV=cv;
expectWait=10; // channel3 packets expectWait=millis(); // start of timeout
expectCallback=callback; expectCallback=callback;
}; };
private: private:
static uint16_t expectCV,expectLoco,expectWait; 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 ACK_CALLBACK expectCallback;
void noData(); void noData();
uint16_t vpin; uint16_t vpin;