forked from bakerstu/openmrn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds example CS and decoder with partial logon implementation (bakers…
…tu#565) CS example app: Adds logon components to the command station with logon example application: - Adds an extension to the LogonModule that stores the openlcb train node and similar components. - Instantiates the logon component in the CS main. - Makes the railcom pin weak pull-up. - Adds logging via stdout and moves openlcb packets to ttyUSB Decoder example app: - Makes the railcom pin open-drain to allow parallel connecting multiple decoders. - Makes it parametrizable whether ch1 broadcast and ch2 acks are generated or not. These are useful to keep the scope plot clean and logs sparse. - Adds a piece of code that generates a deterministic decoder ID. - Fills in the logon decoder feedback packets during initialization - Recognizes the logon requests during the IRQ processing and assigns the logon feedback railcom packets. Logon core implementation changes: - Makes the default logon modules templated so that command stations can define their own storage fields. - Adds a hook to the logon module to allow custom code to be run for the command station at login. Misc logon-related changes: - Updates the DCC debug parser code to output logon and S-9.2.1.1 packets in some form (hex for now) - Adds some helper constants for packet decoding code. - Makes INFO logs more targeted and useful for following what's happening for login. === * Merges PacketFlowInterface and TrackIf as these are the same definitions. Moves the mock track IF to a header file to be reused. * Starts implementing the state flow for sending logon packets. * Fixes compile errors. * Adds feedback callbacks to the logon class. Instantiates it in a test. Checks that logon messages are sent every 300 msec. * Adds the state flow that sends out addressed packets to the decoders found. Adds a default (inefficient) implementation of the storage module. * Adds a test that the logon class compiles with the empty logon module. * Wires up the logon feedback to the storage module. Adds a test for checking the select / get short info. * Adds an error state into which locomotives end up when the logon flow fails for some reason. * Completes the assignment sequence. * Fixes style. * update comment * Adds a storage module for the cs example login. Instantiates the login handler flow. Creates the trains for decoders that logged in. * Makes the decoder run UART in open drain mode. * Adds a minimum support for the 254 and 253 address partitions. * Starts up the logon flow in the CS. * Adds a partial implementation of the logon feedback to the example decoder. The IRQ level parsing is completed and the railcom feedback should be genrated. * replace the use of uninitialized with std::unique_ptr because the structure gets copied around all the time. * Fixes incorrect constant value. * Adds some log statements. * Makes space for virtual train nodes. * Fixes logon bugs: - Having no railcom response (empty feedback) should not signal the flow that there was a decoder logging on. - Correctly define the packet repetition count. * Adjusts info logging related to logon process. * Fixes incorrect constant value. * Fixes logon bugs: - Having no railcom response (empty feedback) should not signal the flow that there was a decoder logging on. - Correctly define the packet repetition count. * Fixes comments. * Fixes comments.
- Loading branch information
1 parent
7c8e61b
commit 0cc5749
Showing
8 changed files
with
343 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** \copyright | ||
* Copyright (c) 2021, Balazs Racz | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* \file TrainStorage.hxx | ||
* | ||
* Storage policies for trains in the automatic logon example. | ||
* | ||
* @author Balazs Racz | ||
* @date 14 Aug 2021 | ||
*/ | ||
|
||
#ifndef _APPLICATION_CS_LOGON_TRAINSTORAGE_HXX_ | ||
#define _APPLICATION_CS_LOGON_TRAINSTORAGE_HXX_ | ||
|
||
|
||
#include "dcc/Defs.hxx" | ||
#include "dcc/Loco.hxx" | ||
#include "dcc/LogonModule.hxx" | ||
#include "openlcb/EventHandlerTemplates.hxx" | ||
#include "openlcb/TractionTrain.hxx" | ||
#include "utils/macros.h" | ||
|
||
class ModuleBase { | ||
public: | ||
struct Storage | ||
{ | ||
std::unique_ptr<dcc::Dcc28Train> impl_; | ||
std::unique_ptr<openlcb::TrainNodeForProxy> node_; | ||
std::unique_ptr< | ||
openlcb::FixedEventProducer<openlcb::TractionDefs::IS_TRAIN_EVENT>> | ||
eventProducer_; | ||
}; | ||
}; | ||
|
||
class TrainLogonModule : public dcc::ParameterizedLogonModule<ModuleBase> { | ||
public: | ||
TrainLogonModule(openlcb::TrainService *s) | ||
: trainService_(s) | ||
{ | ||
} | ||
|
||
using Base = ParameterizedLogonModule<ModuleBase>; | ||
|
||
void assign_complete(unsigned loco_id) | ||
{ | ||
Base::assign_complete(loco_id); | ||
auto& t = locos_[loco_id]; | ||
uint8_t part = (t.assignedAddress_ >> 8) & dcc::Defs::ADR_MASK; | ||
|
||
if (part == dcc::Defs::ADR_MOBILE_SHORT) { | ||
LOG(INFO, "started a short address decoder"); | ||
t.impl_.reset(new dcc::Dcc28Train( | ||
dcc::DccShortAddress(t.assignedAddress_ & 0x7f))); | ||
} | ||
else if (part >= dcc::Defs::ADR_MOBILE_LONG && | ||
part <= dcc::Defs::MAX_MOBILE_LONG) | ||
{ | ||
LOG(INFO, "started a long address decoder"); | ||
t.impl_.reset(new dcc::Dcc28Train(dcc::DccLongAddress( | ||
t.assignedAddress_ - (dcc::Defs::ADR_MOBILE_LONG << 8)))); | ||
} else { | ||
// Not a mobile decoder. We don't have an implementation for those | ||
// yet. | ||
LOG(INFO, "started a non-mobile decoder %04x %x", | ||
t.assignedAddress_, part); | ||
return; | ||
} | ||
t.node_.reset(new openlcb::TrainNodeForProxy( | ||
trainService_, t.impl_.get())); | ||
t.eventProducer_.reset(new openlcb::FixedEventProducer< | ||
openlcb::TractionDefs::IS_TRAIN_EVENT>(t.node_.get())); | ||
} | ||
|
||
private: | ||
openlcb::TrainService* trainService_; | ||
}; | ||
|
||
|
||
#endif // _APPLICATION_CS_LOGON_TRAINSTORAGE_HXX_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.