diff --git a/library.properties b/library.properties index 7cfd841..d549887 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=DCCEXProtocol -version=1.3.1 +version=1.3.2 author=Peter Cole, Peter Akers maintainer=Peter Cole, Peter Akers sentence=DCC-EX Native Protocol implementation diff --git a/src/DCCEXCSConsist.cpp b/src/DCCEXCSConsist.cpp index 360ee15..7a70981 100644 --- a/src/DCCEXCSConsist.cpp +++ b/src/DCCEXCSConsist.cpp @@ -178,6 +178,22 @@ void CSConsist::setReplicateFunctions(bool replicate) { _replicateFunctions = re bool CSConsist::getReplicateFunctions() { return _replicateFunctions; } +int CSConsist::getSpeed() { + if (!_firstMember) + return 0; + + Loco *loco = Loco::getByAddress(_firstMember->address); + return (loco != nullptr) ? loco->getSpeed() : 0; +} + +Direction CSConsist::getDirection() { + if (!_firstMember) + return Direction::Forward; + + Loco *loco = Loco::getByAddress(_firstMember->address); + return (loco != nullptr) ? loco->getDirection() : Direction::Forward; +} + CSConsist::~CSConsist() { // Clean up the member list first removeAllMembers(); diff --git a/src/DCCEXCSConsist.h b/src/DCCEXCSConsist.h index 1e07919..b8c439f 100644 --- a/src/DCCEXCSConsist.h +++ b/src/DCCEXCSConsist.h @@ -23,6 +23,7 @@ #ifndef DCCEXCSCONSIST_H #define DCCEXCSCONSIST_H +#include "DCCEXLoco.h" #include /** @@ -176,6 +177,18 @@ class CSConsist { */ bool getReplicateFunctions(); + /** + * @brief Get the speed from the lead Loco + * @return int Speed of the lead Loco, 0 always if no Loco object matches + */ + int getSpeed(); + + /** + * @brief Get the direction from the lead Loco + * @return Direction Direction of the lead Loco, Forward always if no Loco object matches + */ + Direction getDirection(); + /** * @brief Destroy the CSConsist object */ diff --git a/src/DCCEXProtocolVersion.h b/src/DCCEXProtocolVersion.h index 46d70cb..dfff3dd 100644 --- a/src/DCCEXProtocolVersion.h +++ b/src/DCCEXProtocolVersion.h @@ -29,11 +29,12 @@ #ifndef DCCEXPROTOCOLVERSION_H #define DCCEXPROTOCOLVERSION_H -#define DCCEX_PROTOCOL_VERSION "1.3.1" +#define DCCEX_PROTOCOL_VERSION "1.3.2" /* Version information: +1.3.2 - Add missing getSpeed() and getDirection() to CSConsist class 1.3.1 - Fix bug where function 28 is masked off incorrectly and not received in Loco updates 1.3.0 - Introduce queued throttle updates to prevent buffer overloads and broadcast storms - Additional constructor attribute "userChangeDelay" enables user configuration of the queue time diff --git a/test/test_CSConsists/test_CSConsistClass.cpp b/test/test_CSConsists/test_CSConsistClass.cpp index c9ee734..ea3c8d1 100644 --- a/test/test_CSConsists/test_CSConsistClass.cpp +++ b/test/test_CSConsists/test_CSConsistClass.cpp @@ -389,3 +389,42 @@ TEST_F(CSConsistTests, TestRemoveAllMembers) { ASSERT_EQ(csConsist->getFirstMember(), nullptr); EXPECT_EQ(csConsist->getMemberCount(), 0); } + +/** + * @brief Test get speed and direction with no Loco objects + */ +TEST_F(CSConsistTests, TestSpeedDirectionNoLoco) { + // Create the consist and add members + CSConsist *csConsist = new CSConsist(); + csConsist->addMember(42, false); + csConsist->addMember(24, true); + + // Speed should be zero when no Loco object exists, direction should be forward + EXPECT_EQ(csConsist->getSpeed(), 0); + EXPECT_EQ(csConsist->getDirection(), Direction::Forward); +} + +/** + * @brief Test get speed and direction with lead Loco objects + */ +TEST_F(CSConsistTests, TestSpeedDirectionWithLoco) { + // Create the consist and add members + CSConsist *csConsist = new CSConsist(); + csConsist->addMember(42, false); + csConsist->addMember(24, true); + + // Speed should be zero when no Loco object exists, direction should be forward + EXPECT_EQ(csConsist->getSpeed(), 0); + EXPECT_EQ(csConsist->getDirection(), Direction::Forward); + + // Create lead Loco object and should be same results + Loco *loco42 = new Loco(42, LocoSource::LocoSourceEntry); + EXPECT_EQ(csConsist->getSpeed(), 0); + EXPECT_EQ(csConsist->getDirection(), Direction::Forward); + + // Set speed/direction for Loco and CSConsist should match + loco42->setSpeed(10); + loco42->setDirection(Direction::Reverse); + EXPECT_EQ(csConsist->getSpeed(), 10); + EXPECT_EQ(csConsist->getDirection(), Direction::Reverse); +} diff --git a/test/test_General/test_Infrastructure.cpp b/test/test_General/test_Infrastructure.cpp index 110b8f1..49ba268 100644 --- a/test/test_General/test_Infrastructure.cpp +++ b/test/test_General/test_Infrastructure.cpp @@ -50,4 +50,4 @@ TEST_F(DCCEXProtocolTests, testGenericSendCommand) { /** * @brief Test the library version can be retrieved via the static method */ -TEST_F(DCCEXProtocolTests, TestLibraryVersion) { ASSERT_STREQ(DCCEXProtocol::getLibraryVersion(), "1.3.1"); } +TEST_F(DCCEXProtocolTests, TestLibraryVersion) { ASSERT_STREQ(DCCEXProtocol::getLibraryVersion(), "1.3.2"); } diff --git a/test/test_General/test_Version.cpp b/test/test_General/test_ServerVersion.cpp similarity index 95% rename from test/test_General/test_Version.cpp rename to test/test_General/test_ServerVersion.cpp index 7d7c12e..8ef283b 100644 --- a/test/test_General/test_Version.cpp +++ b/test/test_General/test_ServerVersion.cpp @@ -1,10 +1,6 @@ /* -*- c++ -*- * - * DCCEXProtocol - * - * This package implements a DCCEX native protocol connection, - * allow a device to communicate with a DCC-EX EX-CommandStation. - * + * Copyright © 2026 Peter Cole * Copyright © 2024 Vincent Hamp * Copyright © 2024 Peter Cole *