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

less broadcast noise

Avoids erroneous broadcast of all slots with no loco on ESTOP.
Avoids sending <l> states and <q>  to withrottles
This commit is contained in:
Asbelos 2021-12-21 09:14:27 +00:00
parent b05cbc1fdf
commit 0912ad484a
3 changed files with 16 additions and 9 deletions

View File

@ -55,7 +55,7 @@ void CommandDistributor::forget(byte clientId) {
} }
void CommandDistributor::broadcast() { void CommandDistributor::broadcast(bool includeWithrottleClients) {
broadcastBufferWriter->write((byte)'\0'); broadcastBufferWriter->write((byte)'\0');
/* Boadcast to Serials */ /* Boadcast to Serials */
@ -70,6 +70,7 @@ void CommandDistributor::broadcast() {
/* loop through ring clients */ /* loop through ring clients */
for (byte clientId=0; clientId<sizeof(clients); clientId++) { for (byte clientId=0; clientId<sizeof(clients); clientId++) {
if (clients[clientId]==NONE_TYPE) continue; if (clients[clientId]==NONE_TYPE) continue;
if ( clients[clientId]==WITHROTTLE_TYPE && !includeWithrottleClients) continue;
ring->mark(clientId); ring->mark(clientId);
broadcastBufferWriter->printBuffer(ring); broadcastBufferWriter->printBuffer(ring);
ring->commit(); ring->commit();
@ -84,12 +85,14 @@ void CommandDistributor::broadcast() {
// Redirect ring output ditrect to Serial // Redirect ring output ditrect to Serial
#define broadcastBufferWriter &Serial #define broadcastBufferWriter &Serial
// and ignore the internal broadcast call. // and ignore the internal broadcast call.
void CommandDistributor::broadcast() {} void CommandDistributor::broadcast(bool includeWithrottleClients) {
(void)includeWithrottleClients;
}
#endif #endif
void CommandDistributor::broadcastSensor(int16_t id, bool on ) { void CommandDistributor::broadcastSensor(int16_t id, bool on ) {
StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id); StringFormatter::send(broadcastBufferWriter,F("<%c %d>\n"), on?'Q':'q', id);
broadcast(); broadcast(false);
} }
void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
@ -100,14 +103,14 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
#if defined(WIFI_ON) | defined(ETHERNET_ON) #if defined(WIFI_ON) | defined(ETHERNET_ON)
StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id); StringFormatter::send(broadcastBufferWriter,F("PTA%c%d\n"), isClosed?'2':'4', id);
#endif #endif
broadcast(); broadcast(true);
} }
void CommandDistributor::broadcastLoco(byte slot) { void CommandDistributor::broadcastLoco(byte slot) {
DCC::LOCO * sp=&DCC::speedTable[slot]; DCC::LOCO * sp=&DCC::speedTable[slot];
StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %l>\n"), StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %l>\n"),
sp->loco,slot,sp->speedCode,sp->functions); sp->loco,slot,sp->speedCode,sp->functions);
broadcast(); broadcast(false);
#if defined(WIFI_ON) | defined(ETHERNET_ON) #if defined(WIFI_ON) | defined(ETHERNET_ON)
WiThrottle::markForBroadcast(sp->loco); WiThrottle::markForBroadcast(sp->loco);
#endif #endif
@ -128,7 +131,7 @@ void CommandDistributor::broadcastPower() {
StringFormatter::send(broadcastBufferWriter, StringFormatter::send(broadcastBufferWriter,
F("<p%c%S>\nPPA%c\n"),state,reason, main?'1':'0'); 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); LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
broadcast(); broadcast(true);
} }

View File

@ -31,7 +31,7 @@ public :
static void broadcastPower(); static void broadcastPower();
static void forget(byte clientId); static void forget(byte clientId);
private: private:
static void broadcast(); static void broadcast(bool includeWithrottleClients);
static RingStream * ring; static RingStream * ring;
static RingStream * broadcastBufferWriter; static RingStream * broadcastBufferWriter;
static byte ringClient; static byte ringClient;

View File

@ -665,9 +665,13 @@ void DCC::updateLocoReminder(int loco, byte speedCode) {
if (loco==0) { if (loco==0) {
// broadcast stop/estop but dont change direction // broadcast stop/estop but dont change direction
for (int reg = 0; reg < MAX_LOCOS; reg++) { for (int reg = 0; reg < MAX_LOCOS; reg++) {
speedTable[reg].speedCode = (speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f); 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); CommandDistributor::broadcastLoco(reg);
} }
}
return; return;
} }