Skip to content

Commit

Permalink
less broadcast noise
Browse files Browse the repository at this point in the history
Avoids erroneous broadcast of all slots with no loco on ESTOP.
Avoids sending <l> states and <q>  to withrottles
  • Loading branch information
Asbelos committed Dec 21, 2021
1 parent b05cbc1 commit 0912ad4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 9 additions & 6 deletions CommandDistributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CommandDistributor::forget(byte clientId) {
}


void CommandDistributor::broadcast() {
void CommandDistributor::broadcast(bool includeWithrottleClients) {
broadcastBufferWriter->write((byte)'\0');

/* Boadcast to Serials */
Expand All @@ -70,6 +70,7 @@ void CommandDistributor::broadcast() {
/* loop through ring clients */
for (byte clientId=0; clientId<sizeof(clients); clientId++) {
if (clients[clientId]==NONE_TYPE) continue;
if ( clients[clientId]==WITHROTTLE_TYPE && !includeWithrottleClients) continue;
ring->mark(clientId);
broadcastBufferWriter->printBuffer(ring);
ring->commit();
Expand All @@ -84,12 +85,14 @@ void CommandDistributor::broadcast() {
// Redirect ring output ditrect to Serial
#define broadcastBufferWriter &Serial
// and ignore the internal broadcast call.
void CommandDistributor::broadcast() {}
void CommandDistributor::broadcast(bool includeWithrottleClients) {
(void)includeWithrottleClients;
}
#endif

void CommandDistributor::broadcastSensor(int16_t id, bool on ) {
StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id);
broadcast();
broadcast(false);
}

void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
Expand All @@ -100,14 +103,14 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
#if defined(WIFI_ON) | defined(ETHERNET_ON)
StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id);
#endif
broadcast();
broadcast(true);
}

void CommandDistributor::broadcastLoco(byte slot) {
DCC::LOCO * sp=&DCC::speedTable[slot];
StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %l>\n"),
sp->loco,slot,sp->speedCode,sp->functions);
broadcast();
broadcast(false);
#if defined(WIFI_ON) | defined(ETHERNET_ON)
WiThrottle::markForBroadcast(sp->loco);
#endif
Expand All @@ -128,7 +131,7 @@ void CommandDistributor::broadcastPower() {
StringFormatter::send(broadcastBufferWriter,
F("<p%c%S>\nPPA%c\n"),state,reason, main?'1':'0');
LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
broadcast();
broadcast(true);
}


2 changes: 1 addition & 1 deletion CommandDistributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public :
static void broadcastPower();
static void forget(byte clientId);
private:
static void broadcast();
static void broadcast(bool includeWithrottleClients);
static RingStream * ring;
static RingStream * broadcastBufferWriter;
static byte ringClient;
Expand Down
8 changes: 6 additions & 2 deletions DCC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,12 @@ void DCC::updateLocoReminder(int loco, byte speedCode) {
if (loco==0) {
// broadcast stop/estop but dont change direction
for (int reg = 0; reg < MAX_LOCOS; reg++) {
speedTable[reg].speedCode = (speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f);
CommandDistributor::broadcastLoco(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;
}
Expand Down

0 comments on commit 0912ad4

Please sign in to comment.