Model Railroad System 2.2.2
Classes | Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
azatrax::MRD Class Reference

MRD I/O Class. More...

#include <mrd.h>

Inheritance diagram for azatrax::MRD:
azatrax::Azatrax

Classes

union  status1_union
 Status byte 1 union type. More...
 
union  status2_union
 Status byte 2 union type. More...
 

Public Types

enum  OperatingMode_Type { NonTurnoutSeparate =0x31 , NonTurnoutDirectionSensing =0x32 , TurnoutSolenoid =0x34 , TurnoutMotor =0x37 }
 Operating Mode codes. More...
 
- Public Types inherited from azatrax::Azatrax
enum  commands {
  cmd_SetChan1 =0x31 , cmd_SetChan2 =0x32 , cmd_ClearExternallyChanged =0x34 , cmd_DisableExternal =0x37 ,
  cmd_EnableExternal =0x38 , cmd_Q1posQ2neg =0x39 , cmd_Q1negQ2pos =0x3A , cmd_Q1Q2open =0x3F ,
  cmd_Q3posQ4neg =0x49 , cmd_Q3negQ4pos =0x4A , cmd_Q3Q4open =0x4F , cmd_RestoreLEDFunction =0x50 ,
  cmd_Identify_1 =0x51 , cmd_Identify_2 =0x52 , cmd_Identify_1_2 =0x53 , cmd_ResetStopwatch =0x54 ,
  cmd_GetStateData =0x57 , cmd_OutputRelayBlink =0x61 , cmd_OutputRelayOff =0x67 , cmd_OutputRelayOn =0x6B ,
  cmd_OutputRelayPulse =0x6D , cmd_OutputRelayInputControl =0x6E
}
 Command codes. More...
 
enum  DeviceConnectionList { _InitSize = 10 , _GrowSize = 10 }
 Device connection list constants. More...
 
enum  { idAzatraxVendor = 0x265F , idMRDProduct = 0xfcb2 , idSL2Product = 0xfca1 , idSR4Product = 0xfca2 }
 Azatrax vendor and product codes. More...
 

Public Member Functions

 ~MRD ()
 Base destructor. More...
 
ErrorCode SetChan1 () const
 Set channel 1 relays and status bits. More...
 
ErrorCode SetChan2 () const
 Set channel 2 relays and status bits. More...
 
ErrorCode ClearExternallyChanged () const
 Clear ‘ExternallyChanged’ status bit. More...
 
ErrorCode DisableExternal () const
 Disable external changes of turnout state. More...
 
ErrorCode EnableExternal () const
 Enable external changes of turnout state. More...
 
ErrorCode Identify_2 () const
 Identify 2. More...
 
ErrorCode Identify_1_2 () const
 Identify 1 and 2. More...
 
ErrorCode ResetStopwatch () const
 Reset Stopwatch. More...
 
bool Sense_1 () const
 Sensor one active. More...
 
bool Sense_2 () const
 Sensor two active. More...
 
bool Latch_1 () const
 Latch one. More...
 
bool Latch_2 () const
 Latch two. More...
 
bool HasRelays () const
 Has Relays? More...
 
bool ResetStatus () const
 Reset status? More...
 
bool StopwatchTicking () const
 Stopwatch Ticking? More...
 
bool ExternallyChanged () const
 Externally changed? More...
 
bool AllowingExternalChanges () const
 Allowing External Changes? More...
 
OperatingMode_Type OperatingMode () const
 Operating mode. More...
 
void Stopwatch (uint8_t &fract, uint8_t &seconds, uint8_t &minutes, uint8_t &hours) const
 Stopwatch time. More...
 
- Public Member Functions inherited from azatrax::Azatrax
 ~Azatrax ()
 Base destructor. More...
 
ErrorCode RestoreLEDFunction () const
 Restore LED function. More...
 
ErrorCode Identify_1 () const
 Identify 1. More...
 
ErrorCode GetStateData ()
 Get State Data. More...
 
uint8_t PacketCount () const
 Packet count. More...
 
const char * SerialNumber () const
 Serial Number. More...
 
const char * MyProduct () const
 My product name. More...
 
unsigned short int MyProductId () const
 My product code. More...
 

Protected Member Functions

 MRD (const char *serialnumber, char **outmessage=NULL)
 Base constructor. More...
 
- Protected Member Functions inherited from azatrax::Azatrax
 Azatrax (const char *serialnumber, unsigned short int idProduct, char **outmessage=NULL)
 Base constructor. More...
 
ErrorCode sendByte (uint8_t commandByte) const
 Send a command byte. More...
 
ErrorCode send2Bytes (uint8_t commandByte, uint8_t byte2) const
 Send a command byte with 1 data byte. More...
 
ErrorCode send3Bytes (uint8_t commandByte, uint8_t byte2, uint8_t byte3) const
 Send a command bytewith 2 data bytes. More...
 

Friends

class Azatrax
 

Additional Inherited Members

- Static Public Member Functions inherited from azatrax::Azatrax
static int NumberOfOpenDevices ()
 Open device count. More...
 
static char ** AllConnectedDevices ()
 List serial numbers of all connected devices. More...
 
static AzatraxOpenDevice (const char *serialnumber, unsigned short int idProduct=0, char **outmessage=NULL)
 Open an Azatrax device by serial number. More...
 
static unsigned short int ProductIdCode (const char *productName)
 Product id code. More...
 
- Static Protected Member Functions inherited from azatrax::Azatrax
static bool IsThisTheAzatraxWeAreLookingFor (libusb_device *dev, const char *serialnumber, unsigned short int idProduct)
 Is this the device we want? More...
 
static unsigned short int GetProductId (libusb_device *dev, const char *serialnumber, unsigned short int idProductMatch=0)
 Return the matching product id for this device and serial number. More...
 
- Protected Attributes inherited from azatrax::Azatrax
struct libusb_device_handle * handle
 USB Device Handle. More...
 
char mySerialNumber [10]
 Serial number buffer. More...
 
unsigned short int myProductId
 Product id. More...
 
struct azatrax::Azatrax::StateDataPacket stateDataPacket
 
- Static Protected Attributes inherited from azatrax::Azatrax
static int deviceOpenCount
 Device open count. More...
 

Detailed Description

MRD I/O Class.

MRD interface class.

This class implements the interface logic for a MRD2-S or MRD2-U device.

The constructor opens a connection to a MRD2-S or MRD2-U device, given its serial number. Each MRD2-S or MRD2-U device has a unique, factory defined serial number, which is printed on a sticker attached to the module. This serial number is much like the MAC address of an Ethernet interface. The destructor closes the connection to the device and frees any resources allocated.

The class provides methods to send commands to the device, read back its state and interrogate the state read back. This way each class instance encapsulates each device instance.

Author
Robert Heller <heller@deepsoft.com>

Member Enumeration Documentation

◆ OperatingMode_Type

Operating Mode codes.

Enumerator
NonTurnoutSeparate 

Non Turnout, separate (-U always reports this).

NonTurnoutDirectionSensing 

Non Turnout, Direction Sensing.

TurnoutSolenoid 

Turnout, Solenoid (momentary action)

TurnoutMotor 

Turnout, Motor (sustained action)

Constructor & Destructor Documentation

◆ MRD()

azatrax::MRD::MRD ( const char *  serialnumber,
char **  outmessage = NULL 
)
inlineprotected

Base constructor.

Parameters
serialnumberThe serial number of the device to open.
outmessageTo hold an error message, if any.

◆ ~MRD()

azatrax::MRD::~MRD ( )
inline

Base destructor.

Member Function Documentation

◆ AllowingExternalChanges()

bool azatrax::MRD::AllowingExternalChanges ( ) const
inline

◆ ClearExternallyChanged()

ErrorCode azatrax::MRD::ClearExternallyChanged ( ) const
inline

Clear ‘ExternallyChanged’ status bit.

Clear ‘ExternallyChanged’ status bit (data packet byte 2).

References azatrax::Azatrax::cmd_ClearExternallyChanged, and azatrax::Azatrax::sendByte().

◆ DisableExternal()

ErrorCode azatrax::MRD::DisableExternal ( ) const
inline

Disable external changes of turnout state.

Disable external changes of turnout state (-S only).

References azatrax::Azatrax::cmd_DisableExternal, and azatrax::Azatrax::sendByte().

◆ EnableExternal()

ErrorCode azatrax::MRD::EnableExternal ( ) const
inline

Enable external changes of turnout state.

Enable external changes of turnout state (-S only).

References azatrax::Azatrax::cmd_EnableExternal, and azatrax::Azatrax::sendByte().

◆ ExternallyChanged()

bool azatrax::MRD::ExternallyChanged ( ) const
inline

◆ HasRelays()

bool azatrax::MRD::HasRelays ( ) const
inline

◆ Identify_1_2()

ErrorCode azatrax::MRD::Identify_1_2 ( ) const
inline

Identify 1 and 2.

Identify 1 and 2 - Flashes sensor 1 and 2 LEDs.

References azatrax::Azatrax::cmd_Identify_1_2, and azatrax::Azatrax::sendByte().

◆ Identify_2()

ErrorCode azatrax::MRD::Identify_2 ( ) const
inline

Identify 2.

Identify 2 - Flashes sensor 2's LED.

References azatrax::Azatrax::cmd_Identify_2, and azatrax::Azatrax::sendByte().

◆ Latch_1()

bool azatrax::MRD::Latch_1 ( ) const
inline

◆ Latch_2()

bool azatrax::MRD::Latch_2 ( ) const
inline

◆ OperatingMode()

OperatingMode_Type azatrax::MRD::OperatingMode ( ) const
inline

Operating mode.

Returns the operating mode.

References azatrax::Azatrax::StateDataPacket::operatingMode, and azatrax::Azatrax::stateDataPacket.

◆ ResetStatus()

bool azatrax::MRD::ResetStatus ( ) const
inline

◆ ResetStopwatch()

ErrorCode azatrax::MRD::ResetStopwatch ( ) const
inline

Reset Stopwatch.

ResetStopwatch - Stops the stopwatch and resets time to 0.

References azatrax::Azatrax::cmd_ResetStopwatch, and azatrax::Azatrax::sendByte().

◆ Sense_1()

bool azatrax::MRD::Sense_1 ( ) const
inline

◆ Sense_2()

bool azatrax::MRD::Sense_2 ( ) const
inline

◆ SetChan1()

ErrorCode azatrax::MRD::SetChan1 ( ) const
inline

Set channel 1 relays and status bits.

Sets the relays and status bits as it a train activated channel 1 (-S, turnour mode only).

References azatrax::Azatrax::cmd_SetChan1, and azatrax::Azatrax::sendByte().

◆ SetChan2()

ErrorCode azatrax::MRD::SetChan2 ( ) const
inline

Set channel 2 relays and status bits.

Sets the relays and status bits as it a train activated channel 2 (-S, turnour mode only).

References azatrax::Azatrax::cmd_SetChan2, and azatrax::Azatrax::sendByte().

◆ Stopwatch()

void azatrax::MRD::Stopwatch ( uint8_t &  fract,
uint8_t &  seconds,
uint8_t &  minutes,
uint8_t &  hours 
) const
inline

Stopwatch time.

Returns the current Stopwatch time.

Parameters
fract1/100s of a second.
secondsWhole seconds.
minutesWhole minutes.
hoursWhole hours.

References azatrax::Azatrax::stateDataPacket, azatrax::Azatrax::StateDataPacket::stopwatchHours, and azatrax::Azatrax::StateDataPacket::stopwatchMinutes.

◆ StopwatchTicking()

bool azatrax::MRD::StopwatchTicking ( ) const
inline

Friends And Related Function Documentation

◆ Azatrax

friend class Azatrax
friend