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

Speed broadcast

This commit is contained in:
Asbelos 2021-12-05 18:06:28 +00:00
parent a4fc10d466
commit b8293d07f2
4 changed files with 18 additions and 6 deletions

View File

@ -24,6 +24,7 @@
#include "DIAG.h"
#include "defines.h"
#include "DCCWaveform.h"
#include "DCC.h"
const byte NO_CLIENT=255;
@ -93,8 +94,10 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
broadcast();
}
void CommandDistributor::broadcastLoco(int16_t cab, int16_t slot, byte speed, uint32_t functions) {
StringFormatter::send(broadcastBufferWriter,F("<l %d %d %d %x>\n"), cab,slot,speed,functions);
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();
}

View File

@ -25,7 +25,7 @@ class CommandDistributor {
public :
static void parse(byte clientId,byte* buffer, RingStream * ring);
static void broadcastLoco(int16_t cab, int16_t slot, byte speed, uint32_t functions);
static void broadcastLoco(byte slot);
static void broadcastSensor(int16_t id, bool value);
static void broadcastTurnout(int16_t id, bool isClosed);
static void broadcastPower();

10
DCC.cpp
View File

@ -27,6 +27,7 @@
#include "version.h"
#include "FSH.h"
#include "IODevice.h"
#include "CommandDistributor.h"
// This module is responsible for converting API calls into
// messages to be sent to the waveform generator.
@ -185,6 +186,7 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) {
speedTable[reg].functions &= ~funcmask;
}
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
CommandDistributor::broadcastLoco(reg);
return;
}
@ -218,6 +220,7 @@ int DCC::changeFn( int cab, int16_t functionNumber, bool pressed) {
funcstate = (speedTable[reg].functions & funcmask)? 1 : 0;
}
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
CommandDistributor::broadcastLoco(reg);
return funcstate;
}
@ -667,6 +670,7 @@ int DCC::lookupSpeedTable(int locoId) {
speedTable[reg].speedCode=128; // default direction forward
speedTable[reg].groupFlags=0;
speedTable[reg].functions=0;
CommandDistributor::broadcastLoco(reg);
}
return reg;
}
@ -677,13 +681,17 @@ void DCC::updateLocoReminder(int loco, byte speedCode) {
// 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);
}
return;
}
// determine speed reg for this loco
int reg=lookupSpeedTable(loco);
if (reg>=0) speedTable[reg].speedCode = speedCode;
if (reg>=0) {
speedTable[reg].speedCode = speedCode;
CommandDistributor::broadcastLoco(reg);
}
}
DCC::LOCO DCC::speedTable[MAX_LOCOS];

5
DCC.h
View File

@ -134,7 +134,6 @@ public:
return ackRetryPSum;
};
private:
struct LOCO
{
int loco;
@ -142,6 +141,9 @@ private:
byte groupFlags;
unsigned long functions;
};
static LOCO speedTable[MAX_LOCOS];
private:
static byte joinRelay;
static byte loopStatus;
static void setThrottle2(uint16_t cab, uint8_t speedCode);
@ -152,7 +154,6 @@ private:
static FSH *shieldName;
static byte globalSpeedsteps;
static LOCO speedTable[MAX_LOCOS];
static byte cv1(byte opcode, int cv);
static byte cv2(int cv);
static int lookupSpeedTable(int locoId);