server: Z21 reply queue, use encoded speed and steps

- To save space we use the same encoding as done
  in Z21 protocol.
- This way we also can directly compare without decoding
- Now also direction and emergency stop are checked
Dieser Commit ist enthalten in:
Filippo Gentile 2024-07-06 14:27:50 +02:00
Ursprung 8a8772ede0
Commit fc2ff35856
3 geänderte Dateien mit 33 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -1047,9 +1047,10 @@ std::optional<ClientKernel::PendingRequest> ClientKernel::matchPendingReplyAndRe
if(message.header() == LAN_X if(message.header() == LAN_X
&& static_cast<const LanX&>(message).xheader == LAN_X_LOCO_INFO) && static_cast<const LanX&>(message).xheader == LAN_X_LOCO_INFO)
{ {
// TODO: Do extensive matching
const LanXLocoInfo& locoInfo = static_cast<const LanXLocoInfo&>(message); const LanXLocoInfo& locoInfo = static_cast<const LanXLocoInfo&>(message);
if(locoInfo.speedStep() != request->reply.speedStep) if(locoInfo.speedAndDirection != request->reply.speedAndDirection)
continue;
if(locoInfo.speedSteps() != request->reply.speedSteps())
continue; continue;
} }
} }

Datei anzeigen

@ -496,7 +496,8 @@ MessageReplyType getReplyType(const Message &message)
setLocoDrive.db0 >= 0x10 && setLocoDrive.db0 <= 0x13) setLocoDrive.db0 >= 0x10 && setLocoDrive.db0 <= 0x13)
{ {
reply.address = setLocoDrive.address(); reply.address = setLocoDrive.address();
reply.speedStep = setLocoDrive.speedStep(); reply.speedAndDirection = setLocoDrive.speedAndDirection;
reply.setSpeedSteps(setLocoDrive.speedSteps());
reply.setFlag(MessageReplyType::Flags::CheckSpeedStep); reply.setFlag(MessageReplyType::Flags::CheckSpeedStep);
} }
else if(const auto& setLocoFunction = static_cast<const LanXSetLocoFunction&>(message); else if(const auto& setLocoFunction = static_cast<const LanXSetLocoFunction&>(message);

Datei anzeigen

@ -1749,6 +1749,30 @@ struct MessageReplyType
m_flags = uint8_t(flags) << 4 | (uint8_t(priority()) & 0xF); m_flags = uint8_t(flags) << 4 | (uint8_t(priority()) & 0xF);
} }
inline uint8_t speedSteps() const
{
switch(speedStepsEncoded & LanXLocoInfo::db2_speed_steps_mask)
{
case LanXLocoInfo::db2_speed_steps_14: return 14;
case LanXLocoInfo::db2_speed_steps_28: return 28;
case LanXLocoInfo::db2_speed_steps_128: return 126;
}
return 0;
}
inline void setSpeedSteps(uint8_t value)
{
speedStepsEncoded &= ~LanXLocoInfo::db2_speed_steps_mask;
switch(value)
{
case 14: speedStepsEncoded |= LanXLocoInfo::db2_speed_steps_14; break;
case 28: speedStepsEncoded |= LanXLocoInfo::db2_speed_steps_28; break;
case 126:
case 128:
default: speedStepsEncoded |= LanXLocoInfo::db2_speed_steps_128; break;
}
}
static constexpr Header noReply = Header(0); static constexpr Header noReply = Header(0);
Header header = noReply; Header header = noReply;
@ -1756,7 +1780,10 @@ struct MessageReplyType
uint8_t db0 = 0; uint8_t db0 = 0;
uint16_t address = 0; uint16_t address = 0;
uint8_t m_flags = uint8_t(Priority::Normal); uint8_t m_flags = uint8_t(Priority::Normal);
uint8_t speedStep = 0;
// Encoded as LAN_X_
uint8_t speedAndDirection = 0;
uint8_t speedStepsEncoded = 0;
}; };
MessageReplyType getReplyType(const Message &message); MessageReplyType getReplyType(const Message &message);