mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-21 20:38:55 +02:00
DCCQ single loco leak
This commit is contained in:
parent
d87c3bc87e
commit
3eac6a57b0
14
DCC.cpp
14
DCC.cpp
@ -162,7 +162,7 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) {
|
|||||||
else DCCQueue::scheduleDCCSpeedPacket( b, nB, 0, cab);
|
else DCCQueue::scheduleDCCSpeedPacket( b, nB, 0, cab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) {
|
void DCC::setFunctionInternal(int cab, byte group, byte byte1, byte byte2) {
|
||||||
// DIAG(F("setFunctionInternal %d %x %x"),cab,byte1,byte2);
|
// DIAG(F("setFunctionInternal %d %x %x"),cab,byte1,byte2);
|
||||||
byte b[4];
|
byte b[4];
|
||||||
byte nB = 0;
|
byte nB = 0;
|
||||||
@ -173,7 +173,7 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) {
|
|||||||
if (byte1!=0) b[nB++] = byte1;
|
if (byte1!=0) b[nB++] = byte1;
|
||||||
b[nB++] = byte2;
|
b[nB++] = byte2;
|
||||||
|
|
||||||
DCCQueue::scheduleDCCPacket(b, nB, 0, cab);
|
DCCQueue::scheduleDCCFunctionPacket(b, nB, cab,group);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns speed steps 0 to 127 (1 == emergency stop)
|
// returns speed steps 0 to 127 (1 == emergency stop)
|
||||||
@ -949,31 +949,31 @@ bool DCC::issueReminder(LOCO * slot) {
|
|||||||
return true; // reminder sent
|
return true; // reminder sent
|
||||||
case 1: // remind function group 1 (F0-F4)
|
case 1: // remind function group 1 (F0-F4)
|
||||||
if (flags & FN_GROUP_1) {
|
if (flags & FN_GROUP_1) {
|
||||||
setFunctionInternal(loco,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4)); // 100D DDDD
|
setFunctionInternal(loco,1,0, 128 | ((functions>>1)& 0x0F) | ((functions & 0x01)<<4)); // 100D DDDD
|
||||||
return true; // reminder sent
|
return true; // reminder sent
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // remind function group 2 F5-F8
|
case 3: // remind function group 2 F5-F8
|
||||||
if (flags & FN_GROUP_2) {
|
if (flags & FN_GROUP_2) {
|
||||||
setFunctionInternal(loco,0, 176 | ((functions>>5)& 0x0F)); // 1011 DDDD
|
setFunctionInternal(loco,2,0, 176 | ((functions>>5)& 0x0F)); // 1011 DDDD
|
||||||
return true; // reminder sent
|
return true; // reminder sent
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5: // remind function group 3 F9-F12
|
case 5: // remind function group 3 F9-F12
|
||||||
if (flags & FN_GROUP_3) {
|
if (flags & FN_GROUP_3) {
|
||||||
setFunctionInternal(loco,0, 160 | ((functions>>9)& 0x0F)); // 1010 DDDD
|
setFunctionInternal(loco,3,0, 160 | ((functions>>9)& 0x0F)); // 1010 DDDD
|
||||||
return true; // reminder sent
|
return true; // reminder sent
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7: // remind function group 4 F13-F20
|
case 7: // remind function group 4 F13-F20
|
||||||
if (flags & FN_GROUP_4) {
|
if (flags & FN_GROUP_4) {
|
||||||
setFunctionInternal(loco,222, ((functions>>13)& 0xFF));
|
setFunctionInternal(loco,4,222, ((functions>>13)& 0xFF));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 9: // remind function group 5 F21-F28
|
case 9: // remind function group 5 F21-F28
|
||||||
if (flags & FN_GROUP_5) {
|
if (flags & FN_GROUP_5) {
|
||||||
setFunctionInternal(loco,223, ((functions>>21)& 0xFF));
|
setFunctionInternal(loco,5,223, ((functions>>21)& 0xFF));
|
||||||
return true; // reminder sent
|
return true; // reminder sent
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
2
DCC.h
2
DCC.h
@ -130,7 +130,7 @@ private:
|
|||||||
static byte defaultMomentumA; // Accelerating
|
static byte defaultMomentumA; // Accelerating
|
||||||
static byte defaultMomentumD; // Accelerating
|
static byte defaultMomentumD; // Accelerating
|
||||||
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
||||||
static void setFunctionInternal(int cab, byte fByte, byte eByte);
|
static void setFunctionInternal(int cab, byte group, byte fByte, byte eByte);
|
||||||
static bool issueReminder(LOCO * slot);
|
static bool issueReminder(LOCO * slot);
|
||||||
static LOCO* nextLocoReminder;
|
static LOCO* nextLocoReminder;
|
||||||
static FSH *shieldName;
|
static FSH *shieldName;
|
||||||
|
30
DCCQueue.cpp
30
DCCQueue.cpp
@ -94,9 +94,35 @@ uint16_t DCCQueue::lastSentPacketLocoId=0; // used to prevent two packets to the
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highPriorityQueue->addQueue(getSlot(NORMAL_PACKET,packet,length,repeats,loco));
|
highPriorityQueue->addQueue(getSlot(SPEED_PACKET,packet,length,repeats,loco));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Packet replaces existing loco function packet or joins end of high priority queue.
|
||||||
|
|
||||||
|
void DCCQueue::scheduleDCCFunctionPacket(byte* packet, byte length, uint16_t loco, byte group) {
|
||||||
|
PendingType type=DEAD_PACKET;
|
||||||
|
switch(group) {
|
||||||
|
case 1: type=FUNCTION1_PACKET; break;
|
||||||
|
case 2: type=FUNCTION2_PACKET; break;
|
||||||
|
case 3: type=FUNCTION3_PACKET; break;
|
||||||
|
case 4: type=FUNCTION4_PACKET; break;
|
||||||
|
case 5: type=FUNCTION5_PACKET; break;
|
||||||
|
default:
|
||||||
|
DIAG(F("DCCQueue::scheduleDCCFunctionPacket invalid group %d"),group);
|
||||||
|
return; // invalid group
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto p=lowPriorityQueue->head;p;p=p->next) {
|
||||||
|
if (p->locoId==loco && p->type==type) {
|
||||||
|
// replace existing packet for same loco and function group
|
||||||
|
memcpy(p->packet,packet,length);
|
||||||
|
p->packetLength=length;
|
||||||
|
p->packetRepeat=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lowPriorityQueue->addQueue(getSlot(type,packet,length,0,loco));
|
||||||
|
}
|
||||||
|
|
||||||
// ESTOP -
|
// ESTOP -
|
||||||
// any outstanding throttle packet for this loco (all if loco=0) discarded
|
// any outstanding throttle packet for this loco (all if loco=0) discarded
|
||||||
@ -119,7 +145,7 @@ uint16_t DCCQueue::lastSentPacketLocoId=0; // used to prevent two packets to the
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add the estop packet to the start of the queue
|
// add the estop packet to the start of the queue
|
||||||
highPriorityQueue->jumpQueue(getSlot(NORMAL_PACKET,packet,length,repeats,0));
|
highPriorityQueue->jumpQueue(getSlot(SPEED_PACKET,packet,length,repeats,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessory coil-On Packet joins end of queue as normal.
|
// Accessory coil-On Packet joins end of queue as normal.
|
||||||
|
@ -23,7 +23,10 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "DCCWaveform.h"
|
#include "DCCWaveform.h"
|
||||||
|
|
||||||
enum PendingType:byte {NORMAL_PACKET,SPEED_PACKET,FUNCTION_PACKET,ACC_ON_PACKET,ACC_OFF_PACKET,DEAD_PACKET};
|
enum PendingType:byte {NORMAL_PACKET,
|
||||||
|
FUNCTION1_PACKET, FUNCTION2_PACKET, FUNCTION3_PACKET, FUNCTION4_PACKET, FUNCTION5_PACKET,
|
||||||
|
SPEED_PACKET,ACC_ON_PACKET,ACC_OFF_PACKET,DEAD_PACKET};
|
||||||
|
|
||||||
struct PendingSlot {
|
struct PendingSlot {
|
||||||
PendingSlot* next;
|
PendingSlot* next;
|
||||||
PendingType type;
|
PendingType type;
|
||||||
@ -41,13 +44,15 @@ enum PendingType:byte {NORMAL_PACKET,SPEED_PACKET,FUNCTION_PACKET,ACC_ON_PACKET,
|
|||||||
class DCCQueue {
|
class DCCQueue {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
// Non-speed packets are queued in the main queue
|
// Non-speed packets are queued in the main queue
|
||||||
static void scheduleDCCPacket(byte* packet, byte length, byte repeats, uint16_t loco=0);
|
static void scheduleDCCPacket(byte* packet, byte length, byte repeats, uint16_t loco=0);
|
||||||
|
|
||||||
// Speed packets are queued in the high priority queue
|
// Speed packets are queued in the high priority queue
|
||||||
static void scheduleDCCSpeedPacket(byte* packet, byte length, byte repeats, uint16_t loco);
|
static void scheduleDCCSpeedPacket(byte* packet, byte length, byte repeats, uint16_t loco);
|
||||||
|
|
||||||
|
// Function group packets are queued in the low priority queue
|
||||||
|
static void scheduleDCCFunctionPacket(byte* packet, byte length, uint16_t loco, byte group);
|
||||||
|
|
||||||
// ESTOP packets jump the high priority queue and discard any outstanding throttle packets for this loco
|
// ESTOP packets jump the high priority queue and discard any outstanding throttle packets for this loco
|
||||||
static void scheduleEstopPacket(byte* packet, byte length, byte repeats,uint16_t loco);
|
static void scheduleEstopPacket(byte* packet, byte length, byte repeats,uint16_t loco);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user