Model Railroad System  2.2.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
azatrax::Azatrax Class Reference

Azatrax I/O Class. More...

#include <Azatrax.h>

Inheritance diagram for azatrax::Azatrax:
azatrax::MRD azatrax::SL2 azatrax::SR4

Classes

struct  StateDataPacket
 Raw USB Data Packet. More...
 

Public Types

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

 ~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...
 

Static Public Member Functions

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...
 

Protected Member Functions

 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...
 

Static Protected Member Functions

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

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

static int deviceOpenCount
 Device open count. More...
 

Friends

class MRD
 
class SL2
 
class SR4
 

Detailed Description

Azatrax I/O Class.

Base Azatrax interface class. From this base class, a class is derived that implements the device-specific functions. The base class only implements the shared core functions. It also includes a static method that implements a factor that creates device instances from device serial numbers.

There are two static methods, one that return the number of open devices (active instances) and another that returns a list of discovered serial numbers.

Author
Robert Heller <heller@deepsoft.com>

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Azatrax vendor and product codes.

This is the vendor and product codes (Azatrax) was granted for their USB products.

Enumerator
idAzatraxVendor 

Azatrax vendor id.

idMRDProduct 

MRD2 Product id.

idSL2Product 

SL2 Product id.

idSR4Product 

SR4 Product id.

◆ commands

Command codes.

Enumerator
cmd_SetChan1 

Set channel 1 (MRD2 only)

cmd_SetChan2 

Set channel 2 (MRD2 only)

cmd_ClearExternallyChanged 

Clear Externally Changed (MRD2 only)

cmd_DisableExternal 

Disable External Changes (MRD2 only)

cmd_EnableExternal 

Enable External Changes (MRD2 only)

cmd_Q1posQ2neg 

(SL2 only) Sets output terminal Q1 to positive, Q2 to negative.

cmd_Q1negQ2pos 

(SL2 only) Sets output terminal Q1 to negative, Q2 to positive.

cmd_Q1Q2open 

(SL2 only) Outputs Q1 & Q2 both set to open circuit (disconnects switch machine #1)

cmd_Q3posQ4neg 

(SL2 only) Sets output terminal Q3 to positive, Q4 to negative.

cmd_Q3negQ4pos 

(SL2 only) Sets output terminal Q3 to negative, Q4 to positive.

cmd_Q3Q4open 

(SL2 only) Outputs Q3 & Q4 both set to open circuit (disconnects switch machine #1)

cmd_RestoreLEDFunction 

Restore LED Function (All devices)

cmd_Identify_1 

Identify LED 1 (All devices)

cmd_Identify_2 

Identify LED 2 (MRD2 only)

cmd_Identify_1_2 

Identify both LEDs (MRD2 only)

cmd_ResetStopwatch 

Reset Stopwatch (MRD2 only)

cmd_GetStateData 

Get State Data (All devices)

cmd_OutputRelayBlink 

3 bytes - Sets output relay contacts to blinking state.

2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected 3rd Byte is the output on/off rate (50% duty cycle): bits<7:2>: ignored bits<1:0>: 1,1 - one cycle / 2 seconds 1,0 - one cycle / second 0,1 - two cycles / second 0,0 - four cycles / second

cmd_OutputRelayOff 

2 bytes - Sets output relay contacts to 'off' state.

2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected

cmd_OutputRelayOn 

(SR4 only) 2 bytes - Sets output relay contacts to 'on' state.

2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected

cmd_OutputRelayPulse 

(SR4 only) 3 bytes - Pulses output relay contacts to momentary 'on' state.

2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 if Q4 affected bit 2: 1 if Q3 affected bit 1: 1 if Q2 affected bit 0: 1 if Q1 affected 3rd Byte is pulse duration in 0.5 second increments: 0x00: no pulse generated 0x01: 0.5 sec 0x02: 1.0 sec ... ... 0xFE 63.0 sec 0xFF 63.5 sec

cmd_OutputRelayInputControl 

(SR4 and SL2 only) 2 bytes - Enables/disables discrete input lines from controlling outputs For SL2: When enabled, I1 & I2 affect Q1 & Q2 (switch 1), I3 & I4 affect Q3 & Q4 (switch 2).

2nd Byte is a bit map of the outputs to be affected: bits 7-4: ignored bit 3: 1 enables I4, 0 disables bit 2: 1 enables I3, 0 disables bit 1: 1 enables I2, 0 disables bit 0: 1 enables I1, 0 disables For SR4: 2nd Byte is a bit map of the inputs: bits 7-4: ignored bit 3: 1 if I4 active causes Q4 on, else 0 (I4 does not affect Q4) bit 2: 1 if I3 active causes Q3 on, else 0 (I3 does not affect Q3) bit 1: 1 if I2 active causes Q2 on, else 0 (I2 does not affect Q2) bit 0: 1 if I1 active causes Q1 on, else 0 (I1 does not affect Q1)

◆ DeviceConnectionList

Device connection list constants.

Enumerator
_InitSize 
_GrowSize 

Constructor & Destructor Documentation

◆ Azatrax()

azatrax::Azatrax::Azatrax ( const char *  serialnumber,
unsigned short int  idProduct,
char **  outmessage = NULL 
)
protected

Base constructor.

Parameters
serialnumberThe serial number of the device to open.
idProductThe product Id to look for.
outmessageTo hold an error message, if any.

◆ ~Azatrax()

azatrax::Azatrax::~Azatrax ( )

Base destructor.

Member Function Documentation

◆ AllConnectedDevices()

static char** azatrax::Azatrax::AllConnectedDevices ( )
static

List serial numbers of all connected devices.

Return a vector of serial number strings.

Referenced by NumberOfOpenDevices().

◆ GetProductId()

static unsigned short int azatrax::Azatrax::GetProductId ( libusb_device *  dev,
const char *  serialnumber,
unsigned short int  idProductMatch = 0 
)
staticprotected

Return the matching product id for this device and serial number.

Checks if the dev is a Azatrax device, with the specified serial number, matching for product id.

Parameters
devlibusb_device struct pointer (from libusb_get_device_list).
serialnumberthe serial number we are looking for.
idProductMatcheither an exact product id or 0 (means any product id)
Returns
The actual product id (device matched) or 0 (no match).

Referenced by ProductIdCode().

◆ GetStateData()

ErrorCode azatrax::Azatrax::GetStateData ( )

Get State Data.

Get State Data - retrieve 16 byte data packet from sensor to in memory copy.

Referenced by Identify_1().

◆ Identify_1()

ErrorCode azatrax::Azatrax::Identify_1 ( ) const
inline

Identify 1.

Identify 1 - Flashes sensor 1's LED.

References cmd_Identify_1, ErrorCode, GetStateData(), and sendByte().

◆ IsThisTheAzatraxWeAreLookingFor()

static bool azatrax::Azatrax::IsThisTheAzatraxWeAreLookingFor ( libusb_device *  dev,
const char *  serialnumber,
unsigned short int  idProduct 
)
staticprotected

Is this the device we want?

Check to see if this device is a Azatrax device and if it has the serial number we want.

Parameters
devlibusb_device struct pointer (from libusb_get_device_list).
serialnumberthe serial number we are looking for.
idProductthe product id code.

Referenced by ProductIdCode().

◆ MyProduct()

const char* azatrax::Azatrax::MyProduct ( ) const
inline

My product name.

Return our Product name.

References idMRDProduct, idSL2Product, idSR4Product, and myProductId.

◆ MyProductId()

unsigned short int azatrax::Azatrax::MyProductId ( ) const
inline

My product code.

Return our Product Id.

References myProductId.

◆ NumberOfOpenDevices()

static int azatrax::Azatrax::NumberOfOpenDevices ( )
inlinestatic

Open device count.

Return the number of open devices.

References AllConnectedDevices(), deviceOpenCount, and OpenDevice().

◆ OpenDevice()

static Azatrax* azatrax::Azatrax::OpenDevice ( const char *  serialnumber,
unsigned short int  idProduct = 0,
char **  outmessage = NULL 
)
static

Open an Azatrax device by serial number.

Parameters
serialnumberthe serial number to open.
idProductThe product id code identifing the type of device to open. Passing 0 means open any Azatrax device.
outmessageTo hold an error message, if any.

Referenced by NumberOfOpenDevices().

◆ PacketCount()

uint8_t azatrax::Azatrax::PacketCount ( ) const
inline

◆ ProductIdCode()

static unsigned short int azatrax::Azatrax::ProductIdCode ( const char *  productName)
inlinestatic

Product id code.

Return a product ID code.

Parameters
productNameThe name of the product.

References ErrorCode, GetProductId(), idMRDProduct, idSL2Product, idSR4Product, IsThisTheAzatraxWeAreLookingFor(), send2Bytes(), send3Bytes(), and sendByte().

◆ RestoreLEDFunction()

ErrorCode azatrax::Azatrax::RestoreLEDFunction ( ) const
inline

Restore LED function.

Restore LED function - On-board LEDs return to their normal function of indicating status of sensors 1 and 2.

References cmd_RestoreLEDFunction, and sendByte().

◆ send2Bytes()

ErrorCode azatrax::Azatrax::send2Bytes ( uint8_t  commandByte,
uint8_t  byte2 
) const
protected

Send a command byte with 1 data byte.

Sends one command byte on endpoint 01, with one data byte.

Parameters
commandByteThe command byte to send.
byte2The data byte to send.

Referenced by azatrax::SL2::OutputRelayInputControl(), azatrax::SR4::OutputRelayInputControl(), ProductIdCode(), azatrax::SR4::RelaysOff(), and azatrax::SR4::RelaysOn().

◆ send3Bytes()

ErrorCode azatrax::Azatrax::send3Bytes ( uint8_t  commandByte,
uint8_t  byte2,
uint8_t  byte3 
) const
protected

Send a command bytewith 2 data bytes.

Sends one command byte on endpoint 01, with two data bytes.

Parameters
commandByteThe command byte to send.
byte2The first data byte to send.
byte3The second data byte to send.

Referenced by azatrax::SR4::BlinkRelays(), ProductIdCode(), and azatrax::SR4::PulseRelays().

◆ sendByte()

ErrorCode azatrax::Azatrax::sendByte ( uint8_t  commandByte) const
protected

◆ SerialNumber()

const char* azatrax::Azatrax::SerialNumber ( ) const
inline

Serial Number.

Return our serial number.

References mySerialNumber.

Friends And Related Function Documentation

◆ MRD

friend class MRD
friend

◆ SL2

friend class SL2
friend

◆ SR4

friend class SR4
friend

Member Data Documentation

◆ deviceOpenCount

int azatrax::Azatrax::deviceOpenCount
staticprotected

Device open count.

This is used to decide if and when to call libusb_init and libusb_exit.

Referenced by NumberOfOpenDevices().

◆ handle

struct libusb_device_handle* azatrax::Azatrax::handle
protected

USB Device Handle.

This is the USB device handle for the device.

◆ myProductId

unsigned short int azatrax::Azatrax::myProductId
protected

Product id.

Referenced by MyProduct(), and MyProductId().

◆ mySerialNumber

char azatrax::Azatrax::mySerialNumber[10]
protected

Serial number buffer.

This holds the serial number of the device.

Referenced by SerialNumber().

◆ stateDataPacket

struct azatrax::Azatrax::StateDataPacket azatrax::Azatrax::stateDataPacket
protected