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

return success/fail from <f> and <F> command handling (setFn, parsef)

This commit is contained in:
Harald Barth 2022-08-20 18:15:18 +02:00
parent 58bac3dc51
commit a9ce9101e6
4 changed files with 40 additions and 42 deletions

10
DCC.cpp
View File

@ -163,8 +163,9 @@ bool DCC::getThrottleDirection(int cab) {
} }
// Set function to value on or off // Set function to value on or off
void DCC::setFn( int cab, int16_t functionNumber, bool on) { bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
if (cab<=0 ) return; if (cab<=0 ) return false;
if (functionNumber < 0) return false;
if (functionNumber>28) { if (functionNumber>28) {
//non reminding advanced binary bit set //non reminding advanced binary bit set
@ -183,11 +184,11 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) {
b[nB++] = functionNumber >>7 ; // high order bits b[nB++] = functionNumber >>7 ; // high order bits
} }
DCCWaveform::mainTrack.schedulePacket(b, nB, 4); DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
return; return true;
} }
int reg = lookupSpeedTable(cab); int reg = lookupSpeedTable(cab);
if (reg<0) return; if (reg<0) return false;
// Take care of functions: // Take care of functions:
// Set state of function // Set state of function
@ -202,6 +203,7 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) {
updateGroupflags(speedTable[reg].groupFlags, functionNumber); updateGroupflags(speedTable[reg].groupFlags, functionNumber);
CommandDistributor::broadcastLoco(reg); CommandDistributor::broadcastLoco(reg);
} }
return true;
} }
// Flip function state // Flip function state

2
DCC.h
View File

@ -62,7 +62,7 @@ public:
static void writeCVByteMain(int cab, int cv, byte bValue); static void writeCVByteMain(int cab, int cv, byte bValue);
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue); static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
static void setFunction(int cab, byte fByte, byte eByte); static void setFunction(int cab, byte fByte, byte eByte);
static void setFn(int cab, int16_t functionNumber, bool on); static bool setFn(int cab, int16_t functionNumber, bool on);
static void changeFn(int cab, int16_t functionNumber); static void changeFn(int cab, int16_t functionNumber);
static int getFn(int cab, int16_t functionNumber); static int getFn(int cab, int16_t functionNumber);
static uint32_t getFunctionMap(int cab); static uint32_t getFunctionMap(int cab);

View File

@ -546,8 +546,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
if(params!=3) break; if(params!=3) break;
if (Diag::CMD) if (Diag::CMD)
DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF")); DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF"));
DCC::setFn(p[0], p[1], p[2] == 1); if (DCC::setFn(p[0], p[1], p[2] == 1)) return;
return; break;
#if WIFI_ON #if WIFI_ON
case '+': // Complex Wifi interface command (not usual parse) case '+': // Complex Wifi interface command (not usual parse)
@ -689,43 +689,39 @@ bool DCCEXParser::parseZ(Print *stream, int16_t params, int16_t p[])
//=================================== //===================================
bool DCCEXParser::parsef(Print *stream, int16_t params, int16_t p[]) bool DCCEXParser::parsef(Print *stream, int16_t params, int16_t p[])
{ {
// JMRI sends this info in DCC message format but it's not exactly // JMRI sends this info in DCC message format but it's not exactly
// convenient for other processing // convenient for other processing
if (params == 2) if (params == 2) {
{ byte instructionField = p[1] & 0xE0; // 1110 0000
byte instructionField = p[1] & 0xE0; // 1110 0000 if (instructionField == 0x80) { // 1000 0000 Function group 1
if (instructionField == 0x80) // 1000 0000 Function group 1 // Shuffle bits from order F0 F4 F3 F2 F1 to F4 F3 F2 F1 F0
{ byte normalized = (p[1] << 1 & 0x1e) | (p[1] >> 4 & 0x01);
// Shuffle bits from order F0 F4 F3 F2 F1 to F4 F3 F2 F1 F0 return (funcmap(p[0], normalized, 0, 4));
byte normalized = (p[1] << 1 & 0x1e) | (p[1] >> 4 & 0x01); } else if (instructionField == 0xA0) { // 1010 0000 Function group 2
funcmap(p[0], normalized, 0, 4); if (p[1] & 0x10) // 0001 0000 Bit selects F5toF8 / F9toF12
} return (funcmap(p[0], p[1], 5, 8));
else if (instructionField == 0xA0) // 1010 0000 Function group 2 else
{ return (funcmap(p[0], p[1], 9, 12));
if (p[1] & 0x10) // 0001 0000 Bit selects F5toF8 / F9toF12 }
funcmap(p[0], p[1], 5, 8); }
else if (params == 3) {
funcmap(p[0], p[1], 9, 12); if (p[1] == 222) {
} return (funcmap(p[0], p[2], 13, 20));
} } else if (p[1] == 223) {
if (params == 3) return (funcmap(p[0], p[2], 21, 28));
{ }
if (p[1] == 222) }
funcmap(p[0], p[2], 13, 20); (void)stream; // NO RESPONSE
else if (p[1] == 223) return false;
funcmap(p[0], p[2], 21, 28);
}
(void)stream; // NO RESPONSE
return true;
} }
void DCCEXParser::funcmap(int16_t cab, byte value, byte fstart, byte fstop) bool DCCEXParser::funcmap(int16_t cab, byte value, byte fstart, byte fstop)
{ {
for (int16_t i = fstart; i <= fstop; i++) for (int16_t i = fstart; i <= fstop; i++) {
{ if (! DCC::setFn(cab, i, value & 1)) return false;
DCC::setFn(cab, i, value & 1); value >>= 1;
value >>= 1; }
} return true;
} }
//=================================== //===================================

View File

@ -71,7 +71,7 @@ struct DCCEXParser
static FILTER_CALLBACK filterCallback; static FILTER_CALLBACK filterCallback;
static FILTER_CALLBACK filterRMFTCallback; static FILTER_CALLBACK filterRMFTCallback;
static AT_COMMAND_CALLBACK atCommandCallback; static AT_COMMAND_CALLBACK atCommandCallback;
static void funcmap(int16_t cab, byte value, byte fstart, byte fstop); static bool funcmap(int16_t cab, byte value, byte fstart, byte fstop);
static void sendFlashList(Print * stream,const int16_t flashList[]); static void sendFlashList(Print * stream,const int16_t flashList[]);
}; };