Skip to content

Commit

Permalink
Fix incorrect consumer identified message being emitted by dcc accy p…
Browse files Browse the repository at this point in the history
…roducer. (#768)

The range was not set properly, we use two ranges of 4095, but we only identified two ranges of about 2048.

Fixes unintentional repetition of the range identify messages. We have two registrations in the event handler tree.

===

* Fix incorrect consumer identified message being emitted by dcc accy producer.

The range was not set properly, we use two ranges of 4095, but we only identified two ranges of about 2048.

* Adds tests.

* Fixes global handler. It was sending each identify twice.

* Fix typo
  • Loading branch information
balazsracz authored Feb 4, 2024
1 parent c1047c7 commit d2c82ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/openlcb/DccAccyConsumer.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public:
class DccAccyTest : public AsyncNodeTest
{
protected:
DccAccyTest()
{
wait();
}

StrictMock<MockPacketQueue> trackSendQueue_;
DccAccyConsumer consumer_{node_, &trackSendQueue_};
};
Expand All @@ -72,6 +77,19 @@ TEST_F(DccAccyTest, identify_boot_invalid)
":X198F4111N0101020000FF01F0;", ":X194C722AN0101020000FF01F0;");
}

TEST_F(DccAccyTest, global_identify)
{
clear_expect(true);
// Consumer range for two 4096 long ranges.
expect_packet(":X194A422AN0101020000FF0FFF;");
expect_packet(":X194A422AN0101020000FE0FFF;");

// identify events addressed.
send_packet(":X19968111N022A;");
wait();
}


TEST_F(DccAccyTest, identify_throw_identify)
{
EXPECT_CALL(trackSendQueue_, arrived(_, _)).Times(2);
Expand Down
34 changes: 22 additions & 12 deletions src/openlcb/DccAccyConsumer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,31 @@ protected:
void handle_identify_global(const EventRegistryEntry &registry_entry,
EventReport *event, BarrierNotifiable *done) OVERRIDE
{
AutoNotify an(done);
if (event->dst_node && event->dst_node != node_)
{
return done->notify();
return;
}
if (registry_entry.event ==
TractionDefs::ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE)
{
event->event_write_helper<1>()->WriteAsync(node_,
Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
eventid_to_buffer(EncodeRange(
TractionDefs::ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE,
4095)),
done->new_child());
}
if (registry_entry.event ==
TractionDefs::INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE)
{
event->event_write_helper<2>()->WriteAsync(node_,
Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
eventid_to_buffer(EncodeRange(
TractionDefs::INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE,
4095)),
done->new_child());
}
event->event_write_helper<1>()->WriteAsync(node_,
Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
eventid_to_buffer(EncodeRange(
TractionDefs::ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE, 2044)),
done->new_child());
event->event_write_helper<2>()->WriteAsync(node_,
Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
eventid_to_buffer(EncodeRange(
TractionDefs::INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE, 2044)),
done->new_child());
done->notify();
}

void handle_event_report(const EventRegistryEntry &registry_entry,
Expand Down

0 comments on commit d2c82ca

Please sign in to comment.