mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Added DCC api readCVBit and getLocoId
Sanity check needed
This commit is contained in:
parent
3a8c83afa6
commit
26dffa3be3
27
DCC.cpp
27
DCC.cpp
|
@ -130,6 +130,13 @@ bool DCC::verifyCVBit(int cv, byte bNum, bool bValue) {
|
|||
return DCCWaveform::progTrack.schedulePacketWithAck(message, sizeof(message), 5); // NMRA recommends 6 write or reset packets for decoder recovery time
|
||||
}
|
||||
|
||||
int DCC::readCVBit(int cv, byte bNum) {
|
||||
if (bNum>=8) return -1;
|
||||
if (verifyCVBit(cv, bNum,true)) return 1;
|
||||
// failed verify might be a zero, or an error so must check again
|
||||
if (verifyCVBit(cv, bNum,false)) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DCC::readCV(int cv) {
|
||||
|
@ -164,6 +171,26 @@ void DCC::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
int DCC::getLocoId() {
|
||||
switch (readCVBit(29,5)) {
|
||||
case 1:
|
||||
// long address : get CV#17 and CV#18
|
||||
{
|
||||
int cv17=readCV(17);
|
||||
|
||||
if (cv17<0) break;
|
||||
int cv18=readCV(18);
|
||||
if (cv18<0) break;
|
||||
return cv18 + ((cv17 - 192) <<8);
|
||||
}
|
||||
case 0: // short address in CV1
|
||||
return readCV(1);
|
||||
default: // No response or loco
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
///// Private helper functions below here /////////////////////
|
||||
|
||||
byte DCC::cv1(byte opcode, int cv) {
|
||||
|
|
2
DCC.h
2
DCC.h
|
@ -13,6 +13,7 @@ class DCC {
|
|||
// Public DCC API functions
|
||||
static void setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||
static int readCV(int cv);
|
||||
static int readCVBit(int cv, byte bNum); // -1 for error
|
||||
static bool writeCVByte(int cv, byte bValue) ;
|
||||
static bool verifyCVByte(int cv,byte bValue);
|
||||
static bool writeCVBit(int cv, byte bNum, bool bValue);
|
||||
|
@ -23,6 +24,7 @@ class DCC {
|
|||
static void setFunction( int cab, byte fByte);
|
||||
static void setAccessory(int aAdd, byte aNum, bool activate) ;
|
||||
static bool writeTextPacket( byte *b, int nBytes);
|
||||
static int getLocoId();
|
||||
|
||||
private:
|
||||
struct LOCO {
|
||||
|
|
Loading…
Reference in New Issue
Block a user