Model Railroad System  2.2.1
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
xpressnet::XPressNet Class Reference

Main XPressNet interface class. More...

Public Member Functions

 XPressNet (name, port="/dev/ttyS0")
 The constructor opens the serial port and initializes the port. More...
 
 ~XPressNet ()
 The destructor restores the serial port's state and closes it. More...
 
 CheckForResponse (timeout=5)
 Check for a response from the command station. More...
 
 GetNextCommandStationResponse (timeout=5)
 Return the next response from the command station. More...
 
 ResumeOperations ()
 Resume operations request. More...
 
 StopOperations ()
 Stop operations request. More...
 
 EmergencyStopAllLocomotives ()
 Emergency stop all locomotives. More...
 
 EmergencyStopALocomotive (la)
 Emergency stop a locomotive. More...
 
 RegisterModeRead (r)
 Register mode read. More...
 
 DirectModeCVRead (cv)
 Direct mode CV read. More...
 
 PagedModeCVRead (cv)
 Paged mode CV read. More...
 
 RequestForServiceModeResults ()
 Request for service mode results. More...
 
 RegisterModeWrite (r, d)
 Register mode write. More...
 
 DirectModeCVWrite (cv, d)
 Direct mode CV write. More...
 
 PagedModeCVWrite (cv, d)
 Paged mode CV write. More...
 
 CommandStationSoftwareVersion ()
 Command station software version request. More...
 
 CommandStationStatusRequest ()
 Command station status request. More...
 
 SetCommandStationPowerUpMode (mode)
 Set command station power up mode. More...
 
 AccessoryDecoderInformationRequest (address, nibble)
 Accessory decoder information request. More...
 
 AccessoryDecoderOperation (groupaddr, elementaddr, activateOutput, useOutput2)
 Accessory decoder operation request. More...
 
 LocomotiveInformationRequest (address)
 Locomotive information request. More...
 
 FunctionStatusRequest (address)
 Function status request. More...
 
 SetLocomotiveSpeedAndDirection (address, ssm, dir, speed)
 Set locomotive speed and direction. More...
 
 SetLocomotiveFunctionsGroup1 (address, f0, f1, f2, f3, f4)
 Set locomotive functions, group 1. More...
 
 SetLocomotiveFunctionsGroup2 (address, f5, f6, f7, f8)
 Set locomotive functions, group 2. More...
 
 SetLocomotiveFunctionsGroup3 (address, f9, f10, f11, f12)
 Set locomotive functions, group 3. More...
 
 SetFunctionStateGroup1 (address, f0, f1, f2, f3, f4)
 Set locomotive function state, group 1. More...
 
 SetFunctionStateGroup2 (address, f5, f6, f7, f8)
 Set locomotive function state, group 2. More...
 
 SetFunctionStateGroup3 (address, f9, f10, f11, f12)
 Set locomotive function state, group 3. More...
 
 EstablishDoubleHeader (address1, address2)
 Establish a double header. More...
 
 DissolveDoubleHeader (address1)
 Dissolve a double header. More...
 
 OperatingModeProgrammingByteModeWrite (address, cv, data)
 Operating mode programming byte mode write. More...
 
 OperatingModeProgrammingBitModeWrite (address, cv, bitnum, value)
 Operating mode programming bit mode write. More...
 
 AddLocomotiveToMultiUnit (address, mtr, samedirection)
 Add locomotive to Multi-Unit. More...
 
 RemoveLocomotiveFromMultiUnit (address, mtr)
 Remove locomotive to Multi-Unit. More...
 
 AddressInquiryNextMUMember (mtr, address)
 Address inquire next MU member. More...
 
 AddressInquiryPreviousMUMember (mtr, address)
 Address inquire previous MU member. More...
 
 AddressInquiryNextMU (mtr)
 Address inquire next MU. More...
 
 AddressInquiryPreviousMU (mtr)
 Address inquire previous MU. More...
 
 AddressInquiryNextStack (address)
 Address inquire next stack. More...
 
 AddressInquiryPreviousStack (address)
 Address inquire previous stack. More...
 
 DeleteLocomotiveFromStack (address)
 Delete locomotive from stack. More...
 
 GetLI100VersionNumbers ()
 Fetch version numbers from LI100F and LI101. More...
 
 SetLI101Address (addr)
 Set LI101's XPressNet address. More...
 
 readevent (script)
 Establish an external read event handler. More...
 

Private Member Functions

 _appendXORByte (messageVar)
 Compute and append the XOR check byte. More...
 
 _readevent ()
 Read event handler, toggle timeout flag. More...
 
 _timeoutevent ()
 Timeout event handler, toggle timeout flag. More...
 
 _transmit (themessage)
 Transmit a message. More...
 
 _readbyte (thebytevar, timeout)
 Read next available byte or return false. More...
 

Static Private Member Functions

static _CheckForResponse_0x00 (message)
 Helper function for CheckForResponse: handles the 0x00 arm. More...
 
static _CheckForResponse_0x40 (message)
 Helper function for CheckForResponse: handles the 0x40 arm. More...
 
static _CheckForResponse_0x60 (message)
 Helper function for CheckForResponse: handles the 0x60 arm. More...
 
static _CheckForResponse_0x80 (message)
 Helper function for CheckForResponse: handles the 0x80 arm. More...
 
static _CheckForResponse_0xa0 (message)
 Helper function for CheckForResponse: handles the 0xa0 arm. More...
 
static _CheckForResponse_0xc0 (message)
 Helper function for CheckForResponse: handles the 0xc0 arm. More...
 
static _CheckForResponse_0xe0 (message)
 Helper function for CheckForResponse: handles the 0xe0 arm. More...
 
static _ADDRESS (a)
 Helper function to insure a proper address. More...
 

Private Attributes

 ttyfd
 Terminal file descriptor. More...
 
 responseList
 Response list. More...
 
 _timeout
 Timeout or data available flag. More...
 

Detailed Description

Main XPressNet interface class.

This class implements the interface logic to connect to the XpressNet.

Author
Robert Heller <heller@deepsoft.com>

Constructor & Destructor Documentation

◆ XPressNet()

xpressnet::XPressNet::XPressNet ( name  ,
port  = "/dev/ttyS0" 
)

The constructor opens the serial port and initializes the port.

Parameters
portThe serial port device file.

◆ ~XPressNet()

xpressnet::XPressNet::~XPressNet ( )

The destructor restores the serial port's state and closes it.

Member Function Documentation

◆ _ADDRESS()

static xpressnet::XPressNet::_ADDRESS ( )
staticprivate

Helper function to insure a proper address.

If it is a long address (>= 100), 0x0c000 is added.

Parameters
aRaw address.

◆ _appendXORByte()

xpressnet::XPressNet::_appendXORByte ( messageVar  )
private

Compute and append the XOR check byte.

Parameters
messageVarName of the list holding the message bytes.

◆ _CheckForResponse_0x00()

static xpressnet::XPressNet::_CheckForResponse_0x00 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0x00 arm.

◆ _CheckForResponse_0x40()

static xpressnet::XPressNet::_CheckForResponse_0x40 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0x40 arm.

◆ _CheckForResponse_0x60()

static xpressnet::XPressNet::_CheckForResponse_0x60 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0x60 arm.

◆ _CheckForResponse_0x80()

static xpressnet::XPressNet::_CheckForResponse_0x80 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0x80 arm.

◆ _CheckForResponse_0xa0()

static xpressnet::XPressNet::_CheckForResponse_0xa0 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0xa0 arm.

◆ _CheckForResponse_0xc0()

static xpressnet::XPressNet::_CheckForResponse_0xc0 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0xc0 arm.

◆ _CheckForResponse_0xe0()

static xpressnet::XPressNet::_CheckForResponse_0xe0 ( message  )
staticprivate

Helper function for CheckForResponse: handles the 0xe0 arm.

◆ _readbyte()

xpressnet::XPressNet::_readbyte ( thebytevar  ,
timeout   
)
private

Read next available byte or return false.

Parameters
thebytevarName of a variable to receive the byte.
timeoutTimeout in seconds.

If there is a defined external read event handler, the timeout parameter is ignored and false is returned if there are no bytes available. The presumption is that the read is being called from event handler and that means that there is data available.

◆ _readevent()

xpressnet::XPressNet::_readevent ( )
private

Read event handler, toggle timeout flag.

◆ _timeoutevent()

xpressnet::XPressNet::_timeoutevent ( )
private

Timeout event handler, toggle timeout flag.

◆ _transmit()

xpressnet::XPressNet::_transmit ( themessage  )
private

Transmit a message.

◆ AccessoryDecoderInformationRequest()

xpressnet::XPressNet::AccessoryDecoderInformationRequest ( address  ,
nibble   
)

Accessory decoder information request.

Parameters
addressAddress of decoder.
nibbleWhich nibble.

◆ AccessoryDecoderOperation()

xpressnet::XPressNet::AccessoryDecoderOperation ( groupaddr  ,
elementaddr  ,
activateOutput  ,
useOutput2   
)

Accessory decoder operation request.

Parameters
groupaddrAddress of decoder.
elementaddrAddress of element.
activateOutputSet or clear output.
useOutput2Use output 2?

◆ AddLocomotiveToMultiUnit()

xpressnet::XPressNet::AddLocomotiveToMultiUnit ( address  ,
mtr  ,
samedirection   
)

Add locomotive to Multi-Unit.

Parameters
addressLocomotive address.
mtrMulti-Unit address.
samedirectionThe locomotive direction is the same as the consist direction.

◆ AddressInquiryNextMU()

xpressnet::XPressNet::AddressInquiryNextMU ( mtr  )

Address inquire next MU.

Parameters
mtrMulti-Unit address.

◆ AddressInquiryNextMUMember()

xpressnet::XPressNet::AddressInquiryNextMUMember ( mtr  ,
address   
)

Address inquire next MU member.

Parameters
mtrMulti-Unit address.
addressLocomotive address.

◆ AddressInquiryNextStack()

xpressnet::XPressNet::AddressInquiryNextStack ( address  )

Address inquire next stack.

Parameters
addressLocomotive address.

◆ AddressInquiryPreviousMU()

xpressnet::XPressNet::AddressInquiryPreviousMU ( mtr  )

Address inquire previous MU.

Parameters
mtrMulti-Unit address.

◆ AddressInquiryPreviousMUMember()

xpressnet::XPressNet::AddressInquiryPreviousMUMember ( mtr  ,
address   
)

Address inquire previous MU member.

Parameters
mtrMulti-Unit address.
addressLocomotive address.

◆ AddressInquiryPreviousStack()

xpressnet::XPressNet::AddressInquiryPreviousStack ( address  )

Address inquire previous stack.

Parameters
addressLocomotive address.

◆ CheckForResponse()

xpressnet::XPressNet::CheckForResponse ( timeout  = 5)

Check for a response from the command station.

Parameters
timeoutTimeout in seconds

◆ CommandStationSoftwareVersion()

xpressnet::XPressNet::CommandStationSoftwareVersion ( )

Command station software version request.

◆ CommandStationStatusRequest()

xpressnet::XPressNet::CommandStationStatusRequest ( )

Command station status request.

◆ DeleteLocomotiveFromStack()

xpressnet::XPressNet::DeleteLocomotiveFromStack ( address  )

Delete locomotive from stack.

Parameters
addressLocomotive address.

◆ DirectModeCVRead()

xpressnet::XPressNet::DirectModeCVRead ( cv  )

Direct mode CV read.

Parameters
cvCV to read.

◆ DirectModeCVWrite()

xpressnet::XPressNet::DirectModeCVWrite ( cv  ,
 
)

Direct mode CV write.

Parameters
cvCV to write to.
dData to write.

◆ DissolveDoubleHeader()

xpressnet::XPressNet::DissolveDoubleHeader ( address1  )

Dissolve a double header.

Parameters
address1Locomotive address1.

◆ EmergencyStopAllLocomotives()

xpressnet::XPressNet::EmergencyStopAllLocomotives ( )

Emergency stop all locomotives.

◆ EmergencyStopALocomotive()

xpressnet::XPressNet::EmergencyStopALocomotive ( la  )

Emergency stop a locomotive.

Parameters
laAddress of the locomotive to stop.

◆ EstablishDoubleHeader()

xpressnet::XPressNet::EstablishDoubleHeader ( address1  ,
address2   
)

Establish a double header.

Parameters
address1Locomotive address1.
address2Locomotive address2.

◆ FunctionStatusRequest()

xpressnet::XPressNet::FunctionStatusRequest ( address  )

Function status request.

Parameters
addressAddress of locomotive.

◆ GetLI100VersionNumbers()

xpressnet::XPressNet::GetLI100VersionNumbers ( )

Fetch version numbers from LI100F and LI101.

◆ GetNextCommandStationResponse()

xpressnet::XPressNet::GetNextCommandStationResponse ( timeout  = 5)

Return the next response from the command station.

Parameters
timeoutTimeout in seconds

◆ LocomotiveInformationRequest()

xpressnet::XPressNet::LocomotiveInformationRequest ( address  )

Locomotive information request.

Parameters
addressAddress of locomotive.

◆ OperatingModeProgrammingBitModeWrite()

xpressnet::XPressNet::OperatingModeProgrammingBitModeWrite ( address  ,
cv  ,
bitnum  ,
value   
)

Operating mode programming bit mode write.

Parameters
addressLocomotive address.
cvCV to set.
bitnumBit number.
valueValue to set.

◆ OperatingModeProgrammingByteModeWrite()

xpressnet::XPressNet::OperatingModeProgrammingByteModeWrite ( address  ,
cv  ,
data   
)

Operating mode programming byte mode write.

Parameters
addressLocomotive address.
cvCV to set.
dataData to set.

◆ PagedModeCVRead()

xpressnet::XPressNet::PagedModeCVRead ( cv  )

Paged mode CV read.

Parameters
cvCV to read.

◆ PagedModeCVWrite()

xpressnet::XPressNet::PagedModeCVWrite ( cv  ,
 
)

Paged mode CV write.

Parameters
cvCV to write to.
dData to write.

◆ readevent()

xpressnet::XPressNet::readevent ( script  )

Establish an external read event handler.

Parameters
scriptThe external event handler script.

◆ RegisterModeRead()

xpressnet::XPressNet::RegisterModeRead ( )

Register mode read.

Parameters
rRegister to read.

◆ RegisterModeWrite()

xpressnet::XPressNet::RegisterModeWrite ( ,
 
)

Register mode write.

Parameters
rRegister to write to.
dData to write.

◆ RemoveLocomotiveFromMultiUnit()

xpressnet::XPressNet::RemoveLocomotiveFromMultiUnit ( address  ,
mtr   
)

Remove locomotive to Multi-Unit.

Parameters
addressLocomotive address.
mtrMulti-Unit address.

◆ RequestForServiceModeResults()

xpressnet::XPressNet::RequestForServiceModeResults ( )

Request for service mode results.

◆ ResumeOperations()

xpressnet::XPressNet::ResumeOperations ( )

Resume operations request.

◆ SetCommandStationPowerUpMode()

xpressnet::XPressNet::SetCommandStationPowerUpMode ( mode  )

Set command station power up mode.

Parameters
modeMode to set.

◆ SetFunctionStateGroup1()

xpressnet::XPressNet::SetFunctionStateGroup1 ( address  ,
f0  ,
f1  ,
f2  ,
f3  ,
f4   
)

Set locomotive function state, group 1.

Parameters
addressLocomotive address.
f0Function 0.
f1Function 1.
f2Function 2.
f3Function 3.
f4Function 4.

◆ SetFunctionStateGroup2()

xpressnet::XPressNet::SetFunctionStateGroup2 ( address  ,
f5  ,
f6  ,
f7  ,
f8   
)

Set locomotive function state, group 2.

Parameters
addressLocomotive address.
f5Function 5.
f6Function 6.
f7Function 7.
f8Function 8.

◆ SetFunctionStateGroup3()

xpressnet::XPressNet::SetFunctionStateGroup3 ( address  ,
f9  ,
f10  ,
f11  ,
f12   
)

Set locomotive function state, group 3.

Parameters
addressLocomotive address.
f9Function 9.
f10Function 10.
f11Function 11.
f12Function 12.

◆ SetLI101Address()

xpressnet::XPressNet::SetLI101Address ( addr  )

Set LI101's XPressNet address.

◆ SetLocomotiveFunctionsGroup1()

xpressnet::XPressNet::SetLocomotiveFunctionsGroup1 ( address  ,
f0  ,
f1  ,
f2  ,
f3  ,
f4   
)

Set locomotive functions, group 1.

Parameters
addressLocomotive address.
f0Function 0.
f1Function 1.
f2Function 2.
f3Function 3.
f4Function 4.

◆ SetLocomotiveFunctionsGroup2()

xpressnet::XPressNet::SetLocomotiveFunctionsGroup2 ( address  ,
f5  ,
f6  ,
f7  ,
f8   
)

Set locomotive functions, group 2.

Parameters
addressLocomotive address.
f5Function 5.
f6Function 6.
f7Function 7.
f8Function 8.

◆ SetLocomotiveFunctionsGroup3()

xpressnet::XPressNet::SetLocomotiveFunctionsGroup3 ( address  ,
f9  ,
f10  ,
f11  ,
f12   
)

Set locomotive functions, group 3.

Parameters
addressLocomotive address.
f9Function 9.
f10Function 10.
f11Function 11.
f12Function 12.

◆ SetLocomotiveSpeedAndDirection()

xpressnet::XPressNet::SetLocomotiveSpeedAndDirection ( address  ,
ssm  ,
dir  ,
speed   
)

Set locomotive speed and direction.

Parameters
addressAddress of locomotive.
ssmSpeed step mode to use.
dirDesired direction.
speedDesired speed.

◆ StopOperations()

xpressnet::XPressNet::StopOperations ( )

Stop operations request.

Member Data Documentation

◆ _timeout

xpressnet::XPressNet::_timeout
private

Timeout or data available flag.

◆ responseList

xpressnet::XPressNet::responseList
private

Response list.

◆ ttyfd

xpressnet::XPressNet::ttyfd
private

Terminal file descriptor.