server: Z21 LanXLocoInfo support F29 to F31

Z21 Firmware 1.42 adds F29 to F31 to LAN_X_LOCO_INFO
Dieser Commit ist enthalten in:
Filippo Gentile 2023-05-08 23:27:36 +02:00
Ursprung 50279a12d9
Commit 373c277cc7
2 geänderte Dateien mit 25 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -116,13 +116,13 @@ void ClientKernel::receive(const Message& message)
case LAN_X_LOCO_INFO:
{
const int n = message.dataLen() - 7;
if(n >= 7 && n <= 14)
if(message.dataLen() >= LanXLocoInfo::minMessageSize && message.dataLen() <= LanXLocoInfo::maxMessageSize)
{
const auto& reply = static_cast<const LanXLocoInfo&>(message);
const int maxFunc = reply.supportsF29F31() ? 31 : 28;
bool val[31 + 1] = {};
const int maxFunc = (n >= 8) ? 31 : 28;
for(int i = 0; i <= maxFunc; i++)
{
val[i] = reply.getFunction(i);

Datei anzeigen

@ -1123,6 +1123,9 @@ struct LanXLocoInfo : LanX
static constexpr uint8_t flagF0 = 0x10;
static constexpr uint8_t functionIndexMax = 28;
static constexpr uint8_t minMessageSize = 7 + 7;
static constexpr uint8_t maxMessageSize = 7 + 14;
uint8_t addressHigh = 0; //db0
uint8_t addressLow = 0; //db1
uint8_t db2 = 0;
@ -1131,6 +1134,7 @@ struct LanXLocoInfo : LanX
uint8_t f5f12 = 0; //db5
uint8_t f13f20 = 0; //db6
uint8_t f21f28 = 0; //db7
uint8_t f29f31 = 0; //db8 (firmware >= 1.42)
uint8_t checksum = 0;
LanXLocoInfo() :
@ -1223,6 +1227,12 @@ struct LanXLocoInfo : LanX
Z21::Utils::setSpeedStep(speedAndDirection, speedSteps(), value);
}
inline bool supportsF29F31() const
{
//Firmware >= 1.42 adds db8 to store F29-F31 so dataLen increases to 15
return dataLen() >= 15;
}
bool getFunction(uint8_t index) const
{
if(index == 0)
@ -1235,6 +1245,8 @@ struct LanXLocoInfo : LanX
return f13f20 & (1 << (index - 13));
else if(index <= 28)
return f21f28 & (1 << (index - 21));
else if(index <= 31 && supportsF29F31())
return f29f31 & (1 << (index - 29));
else
return false;
}
@ -1280,6 +1292,14 @@ struct LanXLocoInfo : LanX
else
f21f28 &= ~flag;
}
else if(index <= 31 && supportsF29F31())
{
const uint8_t flag = (1 << (index - 29));
if(value)
f29f31 |= flag;
else
f29f31 &= ~flag;
}
}
inline void updateChecksum()
@ -1288,7 +1308,8 @@ struct LanXLocoInfo : LanX
LanX::updateChecksum(dataLen() - 6);
}
} ATTRIBUTE_PACKED;
static_assert(sizeof(LanXLocoInfo) == 14);
static_assert(sizeof(LanXLocoInfo) >= LanXLocoInfo::minMessageSize &&
sizeof(LanXLocoInfo) <= LanXLocoInfo::maxMessageSize);
// Reply to LAN_X_GET_FIRMWARE_VERSION