Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TractionTestTrain.cxx
1
36
38#include "utils/logging.h"
39
40namespace openlcb
41{
42
43LoggingTrain::LoggingTrain(
44 uint32_t legacy_address, dcc::TrainAddressType address_type)
45 : legacyAddress_(legacy_address)
46 , legacyAddressType_(address_type)
47{
48 LOG(INFO, "Created train %s.",
49 TractionDefs::train_node_name_from_legacy(
50 legacyAddressType_, legacyAddress_)
51 .c_str());
52}
53
54LoggingTrain::~LoggingTrain()
55{
56 LOG(INFO, "Destructed train %s.",
57 TractionDefs::train_node_name_from_legacy(
58 legacyAddressType_, legacyAddress_)
59 .c_str());
60}
61
62void LoggingTrain::set_speed(SpeedType speed)
63{
64 LOG(INFO, "train %s : set speed to %c %.0f mph.",
65 TractionDefs::train_node_name_from_legacy(
66 legacyAddressType_, legacyAddress_)
67 .c_str(),
68 speed.direction() == speed.FORWARD ? 'F' : 'R', speed.mph());
69 currentSpeed_ = speed;
70 estopActive_ = false;
71}
72
73SpeedType LoggingTrain::get_speed()
74{
75 LOG(INFO, "train %s : get speed -> returns %c %.0f mph.",
76 TractionDefs::train_node_name_from_legacy(
77 legacyAddressType_, legacyAddress_)
78 .c_str(),
79 currentSpeed_.direction() == currentSpeed_.FORWARD ? 'F' : 'R',
80 currentSpeed_.mph());
81 return currentSpeed_;
82}
83
84void LoggingTrain::set_emergencystop()
85{
86 LOG(INFO, "train %s : set emergency stop.",
87 TractionDefs::train_node_name_from_legacy(
88 legacyAddressType_, legacyAddress_)
89 .c_str());
90 currentSpeed_.set_mph(0); // keeps sign
91 estopActive_ = true;
92}
93
94bool LoggingTrain::get_emergencystop()
95{
96 LOG(INFO, "train %s : get emergency stop.",
97 TractionDefs::train_node_name_from_legacy(
98 legacyAddressType_, legacyAddress_)
99 .c_str());
100 return estopActive_;
101}
102
103void LoggingTrain::set_fn(uint32_t address, uint16_t value)
104{
105 LOG(INFO, "train %s : set fn %" PRIu32 " to %u.",
106 TractionDefs::train_node_name_from_legacy(
107 legacyAddressType_, legacyAddress_)
108 .c_str(),
109 address, value);
110 fnValues_[address] = value;
111}
112
113uint16_t LoggingTrain::get_fn(uint32_t address)
114{
115 uint16_t resp = fnValues_[address];
116 LOG(INFO, "train %s : get fn %" PRIu32 " -> current value is %u.",
117 TractionDefs::train_node_name_from_legacy(
118 legacyAddressType_, legacyAddress_)
119 .c_str(),
120 address, resp);
121 return resp;
122}
123
124uint32_t LoggingTrain::legacy_address()
125{
126 return legacyAddress_;
127}
128
129dcc::TrainAddressType LoggingTrain::legacy_address_type()
130{
131 return legacyAddressType_;
132}
133
134} // namespace openlcb
This class provides a mechanism for working with velocity in different forms.
Definition Velocity.hxx:73
float mph() const
Convert the native meters/sec representation into mile per hour.
Definition Velocity.hxx:206
@ FORWARD
forward direction
Definition Velocity.hxx:79
bool direction() const
Return the direction independent of speed.
Definition Velocity.hxx:164
TrainAddressType
Which address type this legacy train node uses.
Definition dcc/Defs.hxx:46
#define LOG(level, message...)
Conditionally write a message to the logging output.
Definition logging.h:99
static const int INFO
Loglevel that is printed by default, reporting some status information.
Definition logging.h:57