Model Railroad System  2.2.2
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
RaildriverIO Class Reference

Low-level Raildriver I/O functions. More...

#include <RaildriverIO.h>

Public Types

enum  Eventmask_bits {
  NONE_M = 0 , REVERSER_M = 1 << 0 , THROTTLE_M = 1 << 1 , AUTOBRAKE_M = 1 << 2 ,
  INDEPENDBRK_M = 1 << 3 , BAILOFF_M = 1 << 4 , WIPER_M = 1 << 5 , HEADLIGHT_M = 1 << 6 ,
  DIGITAL1_M = 1 << 7 , DIGITAL2_M = 1 << 8 , DIGITAL3_M = 1 << 9 , DIGITAL4_M = 1 << 10 ,
  DIGITAL5_M = 1 << 11 , DIGITAL6_M = 1 << 12
}
 Event Masks. More...
 
enum  Eventcodes {
  NONE = 0 , REVERSER , THROTTLE , AUTOBRAKE ,
  INDEPENDBRK , BAILOFF , WIPER , HEADLIGHT ,
  DIGITAL1 , DIGITAL2 , DIGITAL3 , DIGITAL4 ,
  DIGITAL5 , DIGITAL6
}
 Event Codes. More...
 

Public Member Functions

 RaildriverIO (const char *path, char **outmessage=NULL)
 Constructor. More...
 
 ~RaildriverIO ()
 Destructor. More...
 
void SetLEDS (const char *ledstring, char **outmessage=NULL)
 Set the Speedometer LEDs. More...
 
void SpeakerOn (char **outmessage=NULL)
 Turn the speaker on. More...
 
void SpeakerOff (char **outmessage=NULL)
 Turn the speaker off. More...
 
unsigned char GetReverser () const
 Get Reverser value (0-255). More...
 
unsigned char GetThrottle () const
 Get Throttle value (0-255). More...
 
unsigned char GetAutoBrake () const
 Get Auto Brake value (0-255). More...
 
unsigned char GetIndependBrake () const
 Get Indepenent Brake value (0-255). More...
 
unsigned char GetBailOff () const
 Get Bail Off value (0-255). More...
 
unsigned char GetHeadlight () const
 Get Headlight value (0-255). More...
 
unsigned char GetWiper () const
 Get Wiper value (0-255). More...
 
bool GetBlueButton1 () const
 Get Blue Button 1. More...
 
bool GetBlueButton2 () const
 Get Blue Button 2. More...
 
bool GetBlueButton3 () const
 Get Blue Button 3. More...
 
bool GetBlueButton4 () const
 Get Blue Button 4. More...
 
bool GetBlueButton5 () const
 Get Blue Button 5. More...
 
bool GetBlueButton6 () const
 Get Blue Button 6. More...
 
bool GetBlueButton7 () const
 Get Blue Button 7. More...
 
bool GetBlueButton8 () const
 Get Blue Button 8. More...
 
bool GetBlueButton9 () const
 Get Blue Button 9. More...
 
bool GetBlueButton10 () const
 Get Blue Button 10. More...
 
bool GetBlueButton11 () const
 Get Blue Button 11. More...
 
bool GetBlueButton12 () const
 Get Blue Button 12. More...
 
bool GetBlueButton13 () const
 Get Blue Button 13. More...
 
bool GetBlueButton14 () const
 Get Blue Button 14. More...
 
bool GetBlueButton15 () const
 Get Blue Button 15. More...
 
bool GetBlueButton16 () const
 Get Blue Button 16. More...
 
bool GetBlueButton17 () const
 Get Blue Button 17. More...
 
bool GetBlueButton18 () const
 Get Blue Button 18. More...
 
bool GetBlueButton19 () const
 Get Blue Button 19. More...
 
bool GetBlueButton20 () const
 Get Blue Button 20. More...
 
bool GetBlueButton21 () const
 Get Blue Button 21. More...
 
bool GetBlueButton22 () const
 Get Blue Button 22. More...
 
bool GetBlueButton23 () const
 Get Blue Button 23. More...
 
bool GetBlueButton24 () const
 Get Blue Button 24. More...
 
bool GetBlueButton25 () const
 Get Blue Button 25. More...
 
bool GetBlueButton26 () const
 Get Blue Button 26. More...
 
bool GetBlueButton27 () const
 Get Blue Button 27. More...
 
bool GetBlueButton28 () const
 Get Blue Button 28. More...
 
bool GetZoomUp () const
 Get Zoom Up. More...
 
bool GetZoopDown () const
 Get Zoom Down. More...
 
bool GetPanUp () const
 Get Pan Up. More...
 
bool GetPanRight () const
 Get Pan Right. More...
 
bool GetPanDown () const
 Get Pan Down. More...
 
bool GetPanLeft () const
 Get Pan Left. More...
 
bool GetRangeUp () const
 Get Range Up. More...
 
bool GetRangeDown () const
 Get Range Down. More...
 
bool GetEBrakeUp () const
 Get Emergency Brake Up. More...
 
bool GetEBrakeDown () const
 Get Emergency Brake Down. More...
 
bool GetAlert () const
 Get Alert. More...
 
bool GetSand () const
 Get Sand. More...
 
bool GetPantograph () const
 Get Pantograph. More...
 
bool GetBell () const
 Get Bell. More...
 
bool GetWhistleUp () const
 Get Whistle Up. More...
 
bool GetWhistleDown () const
 Get Whistle Down. More...
 
unsigned char GetProductCodeId () const
 Get Product Code Id. More...
 
bool ReadInputs (Eventmask_bits &mask, int &status)
 Poll the interface. More...
 

Private Member Functions

 RaildriverIO ()
 Default constructor. More...
 

Private Attributes

hid_device * rdriverdev
 Rail Driver Device. More...
 
union {
   unsigned char   ReportBuffer [14]
 Event Buffer. More...
 
   struct bytes {
      unsigned char   Reverser
 Reverser lever, 0-255. More...
 
      unsigned char   Throttle
 Throttle / Dynamic Brake lever, 0-255. More...
 
      unsigned char   AutoBrake
 Automatic Brake lever, 0-255. More...
 
      unsigned char   IndependBrake
 Independent Brake lever, 0-255. More...
 
      unsigned char   BailOff
 Bail Off (Independent Brake lever), 0-255. More...
 
      unsigned char   Wiper
 Wiper switch, 0-255. More...
 
      unsigned char   Headlight
 Headlight switch, 0-255. More...
 
      unsigned char   Digital1
 Blue Buttons 1-8. More...
 
      unsigned char   Digital2
 Blue Buttons 9-16. More...
 
      unsigned char   Digital3
 Blue Buttons 17-24. More...
 
      unsigned char   Digital4
 Blue Buttons 25-28, Zoom, Pan Buttons. More...
 
      unsigned char   Digital5
 Pan, Cab buttons. More...
 
      unsigned char   Digital6
 Cab Buttons, Whistle Switch. More...
 
      unsigned char   ProductCodeId
 Product Code Id, usually 210. More...
 
   }   theBytes
 
RDInput
 Event data. More...
 

Static Private Attributes

static const unsigned short int PIEngineering
 Rail Driver vendor code. More...
 
static const unsigned short int RailDriverModernDesktop
 Rail Driver product code. More...
 
static const int LEDCommand
 LED Command code. More...
 
static const int SpeakerCommand
 Speaker command code. More...
 

Detailed Description

Low-level Raildriver I/O functions.

This class implements the low-level Raildriver I/O functions and provides access to the two endpoints, one input (controls, switches, and buttons) and one output (LED display and speaker switch).

The Raildriver `‘game’' console contains a collection of levers, buttons, and switches that simulate a locomotive control stand. There is a reverser lever, a throttle, two brake levers, switches for the lights and wipers, and buttons, switches, and levers for things like the bell, alerter, whistle (or horn), sand, pantograph, and other functions, plus a collection of general purpose buttons that can be programmed to provide any other function. The console also contains a three digit seven-segment display and there is a built in speaker.

Author
Robert Heller <heller@deepsoft.com>

Tcl Package Provided

Raildriverio 1.0.0

Library Provided

libraildriverio 1.0.0

Member Enumeration Documentation

◆ Eventcodes

Event Codes.

These are the event codes for the Rail Driver's report message. There is a code for each of the thirteen bytes in the report buffer.

Enumerator
NONE 

No bits set.

REVERSER 

Reverser lever.

             This is a value between 0 and 255
            representing the position of the reverser lever.
THROTTLE 

Throttle lever.

            This is a value between 0 and 255
            representing the position of the throttle / dynamic brake 
            lever.
AUTOBRAKE 

Automatic Brake lever.

             This is a value between 0 and 255
            representing the position of the automatic brake lever.
INDEPENDBRK 

Independent Brake lever.

            This is a value between 0 and 255
             representing the position of the independent brake lever.
BAILOFF 

Independent Brake bail off.

            This is a value between 0 and
            255 representing the position of the independent brake lever
            bail off.
WIPER 

Wiper switch.

             This is a value between 0 and 255
            representing the position of the wiper switch.
HEADLIGHT 

Headlight switch.

             This is a value between 0 and 255
            representing the position of the headlight switch.
DIGITAL1 

Blue Buttons 1-8.

             This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL2 

Blue Buttons 9-16.

             This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL3 

Blue Buttons 17-24.

              This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL4 

Blue Buttons 25-28, Zoom, Pan.

             This is a bitfield
            representing the last 4 of the generic ``blue'' buttons,
            the zoom rocker, and one-half of the pan (2d) rocker.
DIGITAL5 

Pan, Cab Buttons.

             This is a bitfield representing
            the second half of the pan (2d) rocker, and several
            of the two of the cab rocker switches.
DIGITAL6 

Cab Buttons, Whistle.

            This is a bitfield representing
            the cab buttons and the whistle lever.

◆ Eventmask_bits

Event Masks.

These are the mask bits for the Rail Driver's report message. Each bit represents one of the thirteen bytes in the report buffer.

Enumerator
NONE_M 

No bits set.

            This is the empty mask.
REVERSER_M 

Reverser lever.

             This is a value between 0 and 255
            representing the position of the reverser lever.
THROTTLE_M 

Throttle lever.

            This is a value between 0 and 255
            representing the position of the throttle / dynamic brake 
            lever.
AUTOBRAKE_M 

Automatic Brake lever.

             This is a value between 0 and 255
            representing the position of the automatic brake lever.
INDEPENDBRK_M 

Independent Brake lever.

            This is a value between 0 and 255
             representing the position of the independent brake lever.
BAILOFF_M 

Independent Brake bail off.

            This is a value between 0 and
            255 representing the position of the independent brake lever
            bail off.
WIPER_M 

Wiper switch.

             This is a value between 0 and 255
            representing the position of the wiper switch.
HEADLIGHT_M 

Headlight switch.

             This is a value between 0 and 255
            representing the position of the headlight switch.
DIGITAL1_M 

Blue Buttons 1-8.

             This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL2_M 

Blue Buttons 9-16.

             This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL3_M 

Blue Buttons 17-24.

              This is a bitfield representing 8
            of the generic ``blue'' buttons.
DIGITAL4_M 

Blue Buttons 25-28, Zoom, Pan.

             This is a bitfield
            representing the last 4 of the generic ``blue'' buttons,
            the zoom rocker, and one-half of the pan (2d) rocker.
DIGITAL5_M 

Pan, Cab Buttons.

            This is a bitfield representing
            the second half of the pan (2d) rocker, and several
            of the two of the cab rocker switches.
DIGITAL6_M 

Cab Buttons, whistle.

            This is a bitfield representing
            the cab buttons and the whistle lever.

Constructor & Destructor Documentation

◆ RaildriverIO() [1/2]

RaildriverIO::RaildriverIO ( const char *  path,
char **  outmessage = NULL 
)

Constructor.

The argument is the bus number and device number that identifies the specific device. Finds and opens the device and initializes various data objects, generally preparing for I/O to the connnected rail driver console.

Parameters
pathThe path name or the empty string or NULL.
outmessageReceives error messages.

◆ ~RaildriverIO()

RaildriverIO::~RaildriverIO ( )

Destructor.

Closes the device and free up system resources.

◆ RaildriverIO() [2/2]

RaildriverIO::RaildriverIO ( )
inlineprivate

Default constructor.

This constructor is never called. It is made private to force a compiler error if an attempt is made to use it.

Member Function Documentation

◆ GetAlert()

bool RaildriverIO::GetAlert ( ) const
inline

Get Alert.

References RDInput.

◆ GetAutoBrake()

unsigned char RaildriverIO::GetAutoBrake ( ) const
inline

Get Auto Brake value (0-255).

References RDInput.

◆ GetBailOff()

unsigned char RaildriverIO::GetBailOff ( ) const
inline

Get Bail Off value (0-255).

References RDInput.

◆ GetBell()

bool RaildriverIO::GetBell ( ) const
inline

Get Bell.

References RDInput.

◆ GetBlueButton1()

bool RaildriverIO::GetBlueButton1 ( ) const
inline

Get Blue Button 1.

References RDInput.

◆ GetBlueButton10()

bool RaildriverIO::GetBlueButton10 ( ) const
inline

Get Blue Button 10.

References RDInput.

◆ GetBlueButton11()

bool RaildriverIO::GetBlueButton11 ( ) const
inline

Get Blue Button 11.

References RDInput.

◆ GetBlueButton12()

bool RaildriverIO::GetBlueButton12 ( ) const
inline

Get Blue Button 12.

References RDInput.

◆ GetBlueButton13()

bool RaildriverIO::GetBlueButton13 ( ) const
inline

Get Blue Button 13.

References RDInput.

◆ GetBlueButton14()

bool RaildriverIO::GetBlueButton14 ( ) const
inline

Get Blue Button 14.

References RDInput.

◆ GetBlueButton15()

bool RaildriverIO::GetBlueButton15 ( ) const
inline

Get Blue Button 15.

References RDInput.

◆ GetBlueButton16()

bool RaildriverIO::GetBlueButton16 ( ) const
inline

Get Blue Button 16.

References RDInput.

◆ GetBlueButton17()

bool RaildriverIO::GetBlueButton17 ( ) const
inline

Get Blue Button 17.

References RDInput.

◆ GetBlueButton18()

bool RaildriverIO::GetBlueButton18 ( ) const
inline

Get Blue Button 18.

References RDInput.

◆ GetBlueButton19()

bool RaildriverIO::GetBlueButton19 ( ) const
inline

Get Blue Button 19.

References RDInput.

◆ GetBlueButton2()

bool RaildriverIO::GetBlueButton2 ( ) const
inline

Get Blue Button 2.

References RDInput.

◆ GetBlueButton20()

bool RaildriverIO::GetBlueButton20 ( ) const
inline

Get Blue Button 20.

References RDInput.

◆ GetBlueButton21()

bool RaildriverIO::GetBlueButton21 ( ) const
inline

Get Blue Button 21.

References RDInput.

◆ GetBlueButton22()

bool RaildriverIO::GetBlueButton22 ( ) const
inline

Get Blue Button 22.

References RDInput.

◆ GetBlueButton23()

bool RaildriverIO::GetBlueButton23 ( ) const
inline

Get Blue Button 23.

References RDInput.

◆ GetBlueButton24()

bool RaildriverIO::GetBlueButton24 ( ) const
inline

Get Blue Button 24.

References RDInput.

◆ GetBlueButton25()

bool RaildriverIO::GetBlueButton25 ( ) const
inline

Get Blue Button 25.

References RDInput.

◆ GetBlueButton26()

bool RaildriverIO::GetBlueButton26 ( ) const
inline

Get Blue Button 26.

References RDInput.

◆ GetBlueButton27()

bool RaildriverIO::GetBlueButton27 ( ) const
inline

Get Blue Button 27.

References RDInput.

◆ GetBlueButton28()

bool RaildriverIO::GetBlueButton28 ( ) const
inline

Get Blue Button 28.

References RDInput.

◆ GetBlueButton3()

bool RaildriverIO::GetBlueButton3 ( ) const
inline

Get Blue Button 3.

References RDInput.

◆ GetBlueButton4()

bool RaildriverIO::GetBlueButton4 ( ) const
inline

Get Blue Button 4.

References RDInput.

◆ GetBlueButton5()

bool RaildriverIO::GetBlueButton5 ( ) const
inline

Get Blue Button 5.

References RDInput.

◆ GetBlueButton6()

bool RaildriverIO::GetBlueButton6 ( ) const
inline

Get Blue Button 6.

References RDInput.

◆ GetBlueButton7()

bool RaildriverIO::GetBlueButton7 ( ) const
inline

Get Blue Button 7.

References RDInput.

◆ GetBlueButton8()

bool RaildriverIO::GetBlueButton8 ( ) const
inline

Get Blue Button 8.

References RDInput.

◆ GetBlueButton9()

bool RaildriverIO::GetBlueButton9 ( ) const
inline

Get Blue Button 9.

References RDInput.

◆ GetEBrakeDown()

bool RaildriverIO::GetEBrakeDown ( ) const
inline

Get Emergency Brake Down.

References RDInput.

◆ GetEBrakeUp()

bool RaildriverIO::GetEBrakeUp ( ) const
inline

Get Emergency Brake Up.

References RDInput.

◆ GetHeadlight()

unsigned char RaildriverIO::GetHeadlight ( ) const
inline

Get Headlight value (0-255).

References RDInput.

◆ GetIndependBrake()

unsigned char RaildriverIO::GetIndependBrake ( ) const
inline

Get Indepenent Brake value (0-255).

References RDInput.

◆ GetPanDown()

bool RaildriverIO::GetPanDown ( ) const
inline

Get Pan Down.

References RDInput.

◆ GetPanLeft()

bool RaildriverIO::GetPanLeft ( ) const
inline

Get Pan Left.

References RDInput.

◆ GetPanRight()

bool RaildriverIO::GetPanRight ( ) const
inline

Get Pan Right.

References RDInput.

◆ GetPantograph()

bool RaildriverIO::GetPantograph ( ) const
inline

Get Pantograph.

References RDInput.

◆ GetPanUp()

bool RaildriverIO::GetPanUp ( ) const
inline

Get Pan Up.

References RDInput.

◆ GetProductCodeId()

unsigned char RaildriverIO::GetProductCodeId ( ) const
inline

Get Product Code Id.

This is a unsigned char value filled in upon reading the input report buffer from the Raildriver.

References RDInput.

◆ GetRangeDown()

bool RaildriverIO::GetRangeDown ( ) const
inline

Get Range Down.

References RDInput.

◆ GetRangeUp()

bool RaildriverIO::GetRangeUp ( ) const
inline

Get Range Up.

References RDInput.

◆ GetReverser()

unsigned char RaildriverIO::GetReverser ( ) const
inline

Get Reverser value (0-255).

References RDInput.

◆ GetSand()

bool RaildriverIO::GetSand ( ) const
inline

Get Sand.

References RDInput.

◆ GetThrottle()

unsigned char RaildriverIO::GetThrottle ( ) const
inline

Get Throttle value (0-255).

References RDInput.

◆ GetWhistleDown()

bool RaildriverIO::GetWhistleDown ( ) const
inline

Get Whistle Down.

References RDInput.

◆ GetWhistleUp()

bool RaildriverIO::GetWhistleUp ( ) const
inline

Get Whistle Up.

References RDInput.

◆ GetWiper()

unsigned char RaildriverIO::GetWiper ( ) const
inline

Get Wiper value (0-255).

References RDInput.

◆ GetZoomUp()

bool RaildriverIO::GetZoomUp ( ) const
inline

Get Zoom Up.

References RDInput.

◆ GetZoopDown()

bool RaildriverIO::GetZoopDown ( ) const
inline

Get Zoom Down.

References RDInput.

◆ ReadInputs()

bool RaildriverIO::ReadInputs ( Eventmask_bits mask,
int &  status 
)

Poll the interface.

Called in the event loop. Returns true if something has changed, that is if any of the bytes in the freshly read report buffer are different from the stored report buffer.

Parameters
maskMask of changed bits. This parameter is updated to reflect any changed state information.
statusIO Status of the read.

◆ SetLEDS()

void RaildriverIO::SetLEDS ( const char *  ledstring,
char **  outmessage = NULL 
)

Set the Speedometer LEDs.

Does a bulk write to set the speedometer LEDs on the Raid Driver unit.

◆ SpeakerOff()

void RaildriverIO::SpeakerOff ( char **  outmessage = NULL)

Turn the speaker off.

◆ SpeakerOn()

void RaildriverIO::SpeakerOn ( char **  outmessage = NULL)

Turn the speaker on.

Member Data Documentation

◆ AutoBrake

unsigned char RaildriverIO::AutoBrake

Automatic Brake lever, 0-255.

◆ BailOff

unsigned char RaildriverIO::BailOff

Bail Off (Independent Brake lever), 0-255.

◆ Digital1

unsigned char RaildriverIO::Digital1

Blue Buttons 1-8.

This is an 8-bit bit field.

◆ Digital2

unsigned char RaildriverIO::Digital2

Blue Buttons 9-16.

This is an 8-bit bit field.

◆ Digital3

unsigned char RaildriverIO::Digital3

Blue Buttons 17-24.

This is an 8-bit bit field.

◆ Digital4

unsigned char RaildriverIO::Digital4

Blue Buttons 25-28, Zoom, Pan Buttons.

This is an 8-bit bit field.

◆ Digital5

unsigned char RaildriverIO::Digital5

Pan, Cab buttons.

This is an 8-bit bit field.

◆ Digital6

unsigned char RaildriverIO::Digital6

Cab Buttons, Whistle Switch.

This is an 8-bit bit field.

◆ Headlight

unsigned char RaildriverIO::Headlight

Headlight switch, 0-255.

◆ IndependBrake

unsigned char RaildriverIO::IndependBrake

Independent Brake lever, 0-255.

◆ LEDCommand

const int RaildriverIO::LEDCommand
staticprivate

LED Command code.

This is the command code used to change the LED display.

◆ PIEngineering

const unsigned short int RaildriverIO::PIEngineering
staticprivate

Rail Driver vendor code.

This is the vendor code PI Engineering was granted for their USB products.

◆ ProductCodeId

unsigned char RaildriverIO::ProductCodeId

Product Code Id, usually 210.

◆ RailDriverModernDesktop

const unsigned short int RaildriverIO::RailDriverModernDesktop
staticprivate

Rail Driver product code.

This is the product PI Engineering uses for their Rail Driver consoles.

◆ 

union { ... } RaildriverIO::RDInput

◆ rdriverdev

hid_device* RaildriverIO::rdriverdev
private

Rail Driver Device.

This is the HID device structure for the device.

◆ ReportBuffer

unsigned char RaildriverIO::ReportBuffer[14]

Event Buffer.

This is the I/O buffer used to hold the information about the state of the Rail Driver console.

◆ Reverser

unsigned char RaildriverIO::Reverser

Reverser lever, 0-255.

◆ SpeakerCommand

const int RaildriverIO::SpeakerCommand
staticprivate

Speaker command code.

This is the command code used to toggle the speaker state.

◆ 

struct { ... } ::bytes RaildriverIO::theBytes

◆ Throttle

unsigned char RaildriverIO::Throttle

Throttle / Dynamic Brake lever, 0-255.

◆ Wiper

unsigned char RaildriverIO::Wiper

Wiper switch, 0-255.