Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DCCEXProtocol
version=1.3.1
version=1.3.2
author=Peter Cole, Peter Akers <akersp62@gmail.com>
maintainer=Peter Cole, Peter Akers <akersp62@gmail.com>
sentence=DCC-EX Native Protocol implementation
Expand Down
16 changes: 16 additions & 0 deletions src/DCCEXCSConsist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/DCCEXCSConsist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifndef DCCEXCSCONSIST_H
#define DCCEXCSCONSIST_H

#include "DCCEXLoco.h"
#include <Arduino.h>

/**
Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion src/DCCEXProtocolVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/test_CSConsists/test_CSConsistClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion test/test_General/test_Infrastructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down
Loading