mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 04:41:24 +01:00
return success/fail from <f> and <F> command handling (setFn, parsef)
This commit is contained in:
parent
58bac3dc51
commit
a9ce9101e6
10
DCC.cpp
10
DCC.cpp
@ -163,8 +163,9 @@ bool DCC::getThrottleDirection(int cab) {
|
||||
}
|
||||
|
||||
// Set function to value on or off
|
||||
void DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
if (cab<=0 ) return;
|
||||
bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
if (cab<=0 ) return false;
|
||||
if (functionNumber < 0) return false;
|
||||
|
||||
if (functionNumber>28) {
|
||||
//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
|
||||
}
|
||||
DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
int reg = lookupSpeedTable(cab);
|
||||
if (reg<0) return;
|
||||
if (reg<0) return false;
|
||||
|
||||
// Take care of functions:
|
||||
// Set state of function
|
||||
@ -202,6 +203,7 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Flip function state
|
||||
|
2
DCC.h
2
DCC.h
@ -62,7 +62,7 @@ public:
|
||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
||||
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 int getFn(int cab, int16_t functionNumber);
|
||||
static uint32_t getFunctionMap(int cab);
|
||||
|
@ -546,8 +546,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
if(params!=3) break;
|
||||
if (Diag::CMD)
|
||||
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);
|
||||
return;
|
||||
if (DCC::setFn(p[0], p[1], p[2] == 1)) return;
|
||||
break;
|
||||
|
||||
#if WIFI_ON
|
||||
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[])
|
||||
{
|
||||
// JMRI sends this info in DCC message format but it's not exactly
|
||||
// convenient for other processing
|
||||
if (params == 2)
|
||||
{
|
||||
byte instructionField = p[1] & 0xE0; // 1110 0000
|
||||
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);
|
||||
funcmap(p[0], normalized, 0, 4);
|
||||
}
|
||||
else if (instructionField == 0xA0) // 1010 0000 Function group 2
|
||||
{
|
||||
if (p[1] & 0x10) // 0001 0000 Bit selects F5toF8 / F9toF12
|
||||
funcmap(p[0], p[1], 5, 8);
|
||||
else
|
||||
funcmap(p[0], p[1], 9, 12);
|
||||
}
|
||||
}
|
||||
if (params == 3)
|
||||
{
|
||||
if (p[1] == 222)
|
||||
funcmap(p[0], p[2], 13, 20);
|
||||
else if (p[1] == 223)
|
||||
funcmap(p[0], p[2], 21, 28);
|
||||
}
|
||||
(void)stream; // NO RESPONSE
|
||||
return true;
|
||||
// JMRI sends this info in DCC message format but it's not exactly
|
||||
// convenient for other processing
|
||||
if (params == 2) {
|
||||
byte instructionField = p[1] & 0xE0; // 1110 0000
|
||||
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);
|
||||
return (funcmap(p[0], normalized, 0, 4));
|
||||
} else if (instructionField == 0xA0) { // 1010 0000 Function group 2
|
||||
if (p[1] & 0x10) // 0001 0000 Bit selects F5toF8 / F9toF12
|
||||
return (funcmap(p[0], p[1], 5, 8));
|
||||
else
|
||||
return (funcmap(p[0], p[1], 9, 12));
|
||||
}
|
||||
}
|
||||
if (params == 3) {
|
||||
if (p[1] == 222) {
|
||||
return (funcmap(p[0], p[2], 13, 20));
|
||||
} else if (p[1] == 223) {
|
||||
return (funcmap(p[0], p[2], 21, 28));
|
||||
}
|
||||
}
|
||||
(void)stream; // NO RESPONSE
|
||||
return false;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
DCC::setFn(cab, i, value & 1);
|
||||
value >>= 1;
|
||||
}
|
||||
for (int16_t i = fstart; i <= fstop; i++) {
|
||||
if (! DCC::setFn(cab, i, value & 1)) return false;
|
||||
value >>= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//===================================
|
||||
|
@ -71,7 +71,7 @@ struct DCCEXParser
|
||||
static FILTER_CALLBACK filterCallback;
|
||||
static FILTER_CALLBACK filterRMFTCallback;
|
||||
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[]);
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user