Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TractionDefs.cxx
Go to the documentation of this file.
1
36
37#include <string.h>
38#include "utils/macros.h"
39
40namespace openlcb {
41
42SpeedType fp16_to_speed(const void *fp16) {
43 Velocity speed;
44 DASSERT(sizeof(speed) == 4);
45 float16_t input;
46 const uint8_t* in_p = static_cast<const uint8_t*>(fp16);
47 // We assemble the input assuming it is big-endian.
48 input = *in_p++;
49 input <<= 8;
50 input |= *in_p;
51 speed.set_wire(input);
52 return speed;
53}
54
55void speed_to_fp16(SpeedType speed, void *fp16) {
56 DASSERT(sizeof(speed) == 4);
57 float16_t output = speed.get_wire();
58 uint8_t* o = static_cast<uint8_t*>(fp16);
59 *o++ = output >> 8;
60 *o = output & 0xff;
61}
62
63const uint64_t TractionDefs::IS_TRAIN_EVENT;
64const uint64_t TractionDefs::IS_PROXY_EVENT;
65
67const uint64_t TractionDefs::NODE_ID_DCC;
68const uint64_t TractionDefs::NODE_ID_TMCC;
71
72} // namespace openlcb
uint16_t float16_t
This type represents how velocity is seen on the wire (16 bit float).
Definition Velocity.hxx:55
This class provides a mechanism for working with velocity in different forms.
Definition Velocity.hxx:73
void set_wire(float16_t value)
Set the value based on the wire version of velocity.
Definition Velocity.hxx:295
float16_t get_wire() const
Get a wire version of the velocity.
Definition Velocity.hxx:285
#define DASSERT(x)
Debug assertion facility.
Definition macros.h:159
void speed_to_fp16(SpeedType speed, void *fp16)
Renders a SpeedType value to an unaligned memory address, typically to the output buffer.
SpeedType fp16_to_speed(const void *fp16)
Parses a SpeedType value from an unaligned memory address, typically from the input buffer.
static const uint64_t NODE_ID_DC_BLOCK
Node ID space allocated for DC blocks.
static const uint64_t NODE_ID_MTH_DCS
Node ID space allocated for the MTH DCS protocol.
static const uint64_t NODE_ID_DCC
Node ID space allocated for DCC locomotives.
static const uint64_t NODE_ID_MARKLIN_MOTOROLA
Node ID space allocated for the Marklin-Motorola protocol.
static const uint64_t IS_TRAIN_EVENT
This event should be produced by train nodes.
static const uint64_t IS_PROXY_EVENT
This event should be produced by traction proxy nodes.
static const uint64_t NODE_ID_TMCC
Node ID space allocated for TMCC protocol.