Skip to content

Commit

Permalink
pom read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbelos committed Oct 23, 2024
1 parent a0a503a commit 44869a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 8 additions & 10 deletions Railcom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Railcom::Railcom(uint16_t blockvpin) {
}
uint16_t Railcom::expectLoco=0;
uint16_t Railcom::expectCV=0;
uint16_t Railcom::expectWait=0;
unsigned long Railcom::expectWait=0;
ACK_CALLBACK Railcom::expectCallback=0;


Expand Down Expand Up @@ -183,22 +183,20 @@ void Railcom::process(uint8_t * inbound, uint8_t length) {
byte type=(packet>>8) & 0x0F;
byte data= packet & 0xFF;
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);
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 v2=(length>1) ? GETHIGHFLASH(decode,inbound[1]):INV;
uint16_t packet=(v1<<6) | (v2 & 0x3f);
Expand Down
6 changes: 4 additions & 2 deletions Railcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class Railcom {
static void anticipate(uint16_t loco, uint16_t cv, ACK_CALLBACK callback) {
expectLoco=loco;
expectCV=cv;
expectWait=10; // channel3 packets
expectWait=millis(); // start of timeout
expectCallback=callback;
};

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;
void noData();
uint16_t vpin;
Expand Down

0 comments on commit 44869a5

Please sign in to comment.