Skip to content

Commit

Permalink
Adds a second stage of the traction throttle assign to add the curren…
Browse files Browse the repository at this point in the history
…t node as a listener.
  • Loading branch information
balazsracz committed Jul 5, 2017
1 parent 3707a34 commit 159d1c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/openlcb/TractionConsist.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TEST_F(ConsistTest, CreateDestroy) {

TEST_F(ConsistTest, CreateAndRunConsist) {
auto b = invoke_flow(
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, nodeIdLead);
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, nodeIdLead, false);
ASSERT_EQ(0, b->data()->resultCode);
wait();

Expand Down
2 changes: 2 additions & 0 deletions src/openlcb/TractionDefs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ struct TractionDefs {
CNSTRESP_DETACH_NODE = CNSTREQ_DETACH_NODE,
CNSTRESP_QUERY_NODES = CNSTREQ_QUERY_NODES,

CNSTFLAGS_ALIASVALID = 0x01,
CNSTFLAGS_REVERSE = 0x02,
CNSTFLAGS_LINKF0 = 0x04,
CNSTFLAGS_LINKFN = 0x08,
CNSTFLAGS_HIDE = 0x80,

// Byte 1 of Traction Management replies
MGMTRESP_RESERVE = MGMTREQ_RESERVE,
Expand Down
22 changes: 11 additions & 11 deletions src/openlcb/TractionThrottle.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_F(ThrottleTest, SendAssign)
Action send_assign()
{
return invoke_subflow_and_wait(&throttle_, STATE(assign_done),
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID, false);
}

Action assign_done()
Expand Down Expand Up @@ -131,7 +131,7 @@ TEST_F(ThrottleTest, SendAssignRelease)
Action send_assign()
{
return invoke_subflow_and_wait(&throttle_, STATE(assign_done),
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID, false);
}

Action send_release()
Expand Down Expand Up @@ -191,7 +191,7 @@ TEST_F(ThrottleTest, SendQuery)
Action send_assign()
{
return invoke_subflow_and_wait(&throttle_, STATE(assign_done),
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID, false);
}

Action send_load()
Expand Down Expand Up @@ -252,8 +252,8 @@ TEST_F(ThrottleClientTest, SendConsistAdd)
{
NodeID n1 = 0x050101011837;

auto b = invoke_flow(
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
auto b = invoke_flow(&throttle_, TractionThrottleCommands::ASSIGN_TRAIN,
TRAIN_NODE_ID, false);
ASSERT_EQ(0, b->data()->resultCode);

b = invoke_flow(&throttle_, TractionThrottleCommands::CONSIST_ADD,
Expand All @@ -268,8 +268,8 @@ TEST_F(ThrottleClientTest, SendConsistAddDel)
NodeID n1 = 0x050101011837;
NodeID n2 = 0x050101012188;

auto b = invoke_flow(
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
auto b = invoke_flow(&throttle_, TractionThrottleCommands::ASSIGN_TRAIN,
TRAIN_NODE_ID, false);
ASSERT_EQ(0, b->data()->resultCode);

b = invoke_flow(
Expand Down Expand Up @@ -308,8 +308,8 @@ TEST_F(ThrottleClientTest, SendConsistQry)
NodeID n1 = 0x050101011837;
NodeID n2 = 0x050101012188;

auto b = invoke_flow(
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
auto b = invoke_flow(&throttle_, TractionThrottleCommands::ASSIGN_TRAIN,
TRAIN_NODE_ID, false);
ASSERT_EQ(0, b->data()->resultCode);
wait();

Expand Down Expand Up @@ -375,8 +375,8 @@ TEST_F(ThrottleClientTest, SendSelfConsist)
{
NodeID n1 = TRAIN_NODE_ID;

auto b = invoke_flow(
&throttle_, TractionThrottleCommands::ASSIGN_TRAIN, TRAIN_NODE_ID);
auto b = invoke_flow(&throttle_, TractionThrottleCommands::ASSIGN_TRAIN,
TRAIN_NODE_ID, false);
ASSERT_EQ(0, b->data()->resultCode);

b = invoke_flow(
Expand Down
31 changes: 30 additions & 1 deletion src/openlcb/TractionThrottle.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ struct TractionThrottleInput : public CallableFlowRequestBase
CMD_CONSIST_QRY,
};

void reset(const TractionThrottleCommands::AssignTrain &, const NodeID &dst)
void reset(const TractionThrottleCommands::AssignTrain &, const NodeID &dst, bool listen)
{
cmd = CMD_ASSIGN_TRAIN;
this->dst = dst;
this->flags = listen ? 1 : 0;
}

void reset(const TractionThrottleCommands::ReleaseTrain &)
Expand Down Expand Up @@ -388,6 +389,32 @@ private:
return return_with_error(Defs::ERROR_REJECTED);
}
set_assigned();
if (input()->flags) {
// need to add consist listener
handler_.wait_for_response(
NodeHandle(dst_), TractionDefs::RESP_CONSIST_CONFIG, &timer_);
send_traction_message(TractionDefs::consist_add_payload(
node_->node_id(),
TractionDefs::CNSTFLAGS_HIDE | TractionDefs::CNSTFLAGS_LINKF0 |
TractionDefs::CNSTFLAGS_LINKFN));
return sleep_and_call(
&timer_, TIMEOUT_NSEC, STATE(assign_consist_response));
}
return return_ok();
}

Action assign_consist_response() {
// All error responses are actually okay here; we succeeded in the
// assignment but the listener setup didn't work.
handler_.wait_timeout();
if (!handler_.response())
{
return return_ok();
}

AutoReleaseBuffer<GenMessage> rb(handler_.response());
// Marks that we are owning the listener.
listenConsist_ = true;
return return_ok();
}

Expand Down Expand Up @@ -629,6 +656,8 @@ private:
StateFlowTimer timer_{this};
/// True if the assign controller has returned positive.
bool assigned_{false};
/// True if we also have a consist link with the assigned loco.
bool listenConsist_{false};
NodeID dst_;
Node *node_;
/// Helper class for stateful query/return flows.
Expand Down
3 changes: 1 addition & 2 deletions src/withrottle/ServerCommandLoco.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ StateFlowBase::Action ServerCommandLoco::address_long()
dcc::TrainAddressType::DCC_LONG_ADDRESS, value);

return invoke_subflow_and_wait(&throttle->olcbThrottle, STATE(assign_train),
openlcb::TractionThrottleCommands::ASSIGN_TRAIN, node_id);
openlcb::TractionThrottleCommands::ASSIGN_TRAIN, node_id, 0);
}

/*
Expand Down Expand Up @@ -129,4 +129,3 @@ StateFlowBase::Action ServerCommandLoco::load_state()
}

} /* namespace withrottle */

0 comments on commit 159d1c9

Please sign in to comment.