Class SerialNode
- java.lang.Object
-
- jmri.jmrix.AbstractNode
-
- jmri.jmrix.cmri.serial.SerialNode
-
public class SerialNode extends AbstractNode
Models a serial C/MRI node, consisting of a (S)USIC and attached cards.Nodes are numbered ala the UA number, from 1 to 63. Node number 1 carries sensors 1 to 999, node 2 1001 to 1999 etc.
The array of sensor states is used to update sensor known state only when there's a change on the serial bus. This allows for the sensor state to be updated within the program, keeping this updated state until the next change on the serial bus. E.g. you can manually change a state via an icon, and not have it change back the next time that node is polled.
The SMINI is defined as having 1 input and 2 outputs cards.
USIC/SUSIC nodes can have 0-63 inputs and 0-63 output cards, but no more than 64 total cards. A CPNODE (Control Point Node) is defined as having 2 inputs and 2 outputs //c2 on the node board and 0-128 bits of input or output (in 8 bit increments) for added I/O extender cards IOX16,IOX32. A CPMEGA (Open Source Node) is defined as having 8 bytes of input or output //c2 on the node board and 0-128 bits of input or output (in 8 bit increments) for added I/O extender cards IOX16,IOX32.
-
-
Field Summary
Fields Modifier and Type Field Description protected intbitsPerCardprotected byte[]cardTypeLocationprotected int[]cmrinetOptionsprotected java.lang.StringcmriNodeDescstatic intCPMEGAstatic intCPNODEprotected int[]cpnodeOptionsprotected booleanhasActiveSensorsstatic intINITMSGLENstatic byteINPUT_CARDprotected intlastUsedSensorprotected byte[]locSearchLightBitsstatic intMAXCARDLOCATIONBYTESstatic intMAXSEARCHLIGHTBYTES(package private) static intMAXSENSORSMaximum number of sensors a node can carry.protected booleanmonitorNodePacketsprotected boolean[]monitorPacketBitsstatic intNDP_CPMEGAstatic intNDP_CPNODEstatic intNDP_SMINIstatic intNDP_USICSUSIC24static intNDP_USICSUSIC32static byteNO_CARDprotected intnodeTypeprotected intnum2LSearchLightsstatic intNUMCMRINETOPTSstatic intNUMCPNODEOPTSstatic intoptbitNet_AUTOPOLLstatic intoptbitNet_BIT15static intoptbitNet_BIT8static intoptbitNet_USEBCCstatic intoptbitNet_USECMRIXstatic intoptbitNode_BIT15static intoptbitNode_BIT8static intoptbitNode_SENDEOTstatic intoptbitNode_USEBCCstatic intoptbitNode_USECMRIXstatic byteOUTPUT_CARDprotected byte[]outputArrayprotected intpollListPositionintpollStatusstatic intPOLLSTATUS_ERRORstatic intPOLLSTATUS_IDLEstatic intPOLLSTATUS_INITstatic intPOLLSTATUS_POLLINGstatic intPOLLSTATUS_TIMEOUTprotected intpulseWidthprotected Sensor[]sensorArrayprotected int[]sensorLastSettingprotected int[]sensorTempSettingstatic intSMINI(package private) inttimeoutprotected inttransmissionDelaystatic intUSIC_SUSIC(package private) booleanwarned-
Fields inherited from class jmri.jmrix.AbstractNode
nodeAddress
-
-
Constructor Summary
Constructors Constructor Description SerialNode(int address, int type, SerialTrafficController tc)Creates a new SerialNode and initialize default instance variables.SerialNode(SerialTrafficController tc)Assumes a node address of 0, and a node type of SMINI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckNodeAddress(int address)Check valid node address, must match value in dip switches (0 - 127).voidclear2LeadSearchLight(int bit)Clear location of SearchLightBits (SMINI only).AbstractMRMessagecreateInitPacket()Create an Initialization packet (SerialMessage) for this nodeAbstractMRMessagecreateOutPacket()Create an Transmit packet (SerialMessage)byte[]getCardTypeLocation()intgetCMRInetOpts(int optionbit)Get CMRInet options.java.lang.StringgetcmriNodeDesc()Get node description.intgetcpnodeOpts(int optionbit)Get cpNode options.intgetInputCardIndex(int cardNum)Get 'Input Card Index'.byte[]getLocSearchLightBits()booleangetMonitorNodePackets()Get packet monitoring for the node .booleangetMonitorPacketBit(int pktTypeBit)intgetNodeType()Get node type Current types are: SMINI, USIC_SUSIC,intgetNum2LSearchLights()intgetNumBitsPerCard()Get number of bits per card.booleangetOptNet_AUTOPOLL()Get if Autopoll bit set.booleangetOptNet_BIT15()booleangetOptNet_BIT8()intgetOptNet_byte0()intgetOptNet_byte1()booleangetOptNet_USEBCC()booleangetOptNet_USECMRIX()booleangetOptNode_BIT15()booleangetOptNode_BIT8()intgetOptNode_byte0()intgetOptNode_byte1()booleangetOptNode_SENDEOT()Get Node Option SENDEOT.booleangetOptNode_USEBCC()booleangetOptNode_USECMRIX()booleangetOutputBit(int bitNumber)Get the current state of a single output bit.intgetOutputCardIndex(int cardNum)Get 'Output Card Index'.booleangetPollingEnabled()Check cpNode polling enabled state.intgetPollListPosition()Get cpNode poll list position.intgetPollStatus()Get cpNode polling status.intgetPulseWidth()Get pulse width.booleangetSensorsActive()Get state of Sensor polling.intgetTransmissionDelay()Get transmission delay.booleanhandleTimeout(AbstractMRMessage m, AbstractMRListener l)Deal with a timeout in the transmission controller.booleanisCMRInetBit(int optionbit)booleaniscpnodeBit(int optionbit)booleanisInputCard(int cardNum)Test for INPUT_CARD type.booleanisOutputCard(int cardNum)Test for OUTPUT_CARD type.booleanisPollingOK()booleanisSearchLightBit(int bit)Query SearchLightBits by bit number (SMINI only).voidmarkChanges(SerialReply l)Use the contents of the poll reply to mark changesintnumInputCards()Get number of input cards.intnumOutputCards()Get number of output cards.voidregisterSensor(Sensor s, int i)The numbers here are 0 to MAXSENSORS, not 1 to MAXSENSORS.voidresetTimeout(AbstractMRMessage m)A reply was received, so there was no timeout, do any needed processing.voidset2LeadSearchLight(int bit)Set location of SearchLightBits (SMINI only).voidsetCardTypeByAddress(int address, int type)Set the type of one card.voidsetCardTypeLocation(int num, int value)voidsetCMRInetOpts(int optionbit, int val)voidsetcmriNodeDesc(java.lang.String nodeDesc)voidsetcpnodeOpts(int optionbit, int val)voidsetLocSearchLightBits(int num, int value)voidsetMonitorNodePackets(boolean onoff)voidsetMonitorPacketBit(int pktTypeBit, boolean onoff)Set the specific packet monitoring enable bit.voidsetNodeType(int type)Set node type.voidsetNum2LSearchLights(int n)voidsetNumBitsPerCard(int bits)Set number of bits per card.voidsetOptNet_AUTOPOLL(int val)update Autopoll bitvoidsetOptNet_BIT15(int val)voidsetOptNet_BIT8(int val)voidsetOptNet_USEBCC(int val)voidsetOptNet_USECMRIX(int val)voidsetOptNode_BIT15(int val)voidsetOptNode_BIT8(int val)voidsetOptNode_SENDEOT(int val)voidsetOptNode_USEBCC(int val)voidsetOptNode_USECMRIX(int val)voidsetOutputBit(int bitNumber, boolean state)Set a single output bit.voidsetPollingEnabled(boolean isEnabled)voidsetPollListPosition(int pos)voidsetPollStatus(int status)voidsetPulseWidth(int width)Set pulse width.voidsetSensorsActive(boolean flag)Set state of Sensor polling.voidsetTransmissionDelay(int delay)Set transmission delay.(package private) voidwarn(java.lang.String s)-
Methods inherited from class jmri.jmrix.AbstractNode
getNodeAddress, mustSend, resetMustSend, setMustSend, setNodeAddress
-
-
-
-
Field Detail
-
MAXSENSORS
static final int MAXSENSORS
Maximum number of sensors a node can carry.Note this is less than a current SUSIC motherboard can have, but should be sufficient for all reasonable layouts.
Must be less than, and is general one less than,
SerialSensorManager.SENSORSPERUA- See Also:
- Constant Field Values
-
MAXSEARCHLIGHTBYTES
public static final int MAXSEARCHLIGHTBYTES
- See Also:
- Constant Field Values
-
MAXCARDLOCATIONBYTES
public static final int MAXCARDLOCATIONBYTES
- See Also:
- Constant Field Values
-
SMINI
public static final int SMINI
- See Also:
- Constant Field Values
-
USIC_SUSIC
public static final int USIC_SUSIC
- See Also:
- Constant Field Values
-
CPNODE
public static final int CPNODE
- See Also:
- Constant Field Values
-
CPMEGA
public static final int CPMEGA
- See Also:
- Constant Field Values
-
NDP_USICSUSIC24
public static final int NDP_USICSUSIC24
- See Also:
- Constant Field Values
-
NDP_USICSUSIC32
public static final int NDP_USICSUSIC32
- See Also:
- Constant Field Values
-
NDP_SMINI
public static final int NDP_SMINI
- See Also:
- Constant Field Values
-
NDP_CPNODE
public static final int NDP_CPNODE
- See Also:
- Constant Field Values
-
NDP_CPMEGA
public static final int NDP_CPMEGA
- See Also:
- Constant Field Values
-
INPUT_CARD
public static final byte INPUT_CARD
- See Also:
- Constant Field Values
-
OUTPUT_CARD
public static final byte OUTPUT_CARD
- See Also:
- Constant Field Values
-
NO_CARD
public static final byte NO_CARD
- See Also:
- Constant Field Values
-
nodeType
protected int nodeType
-
bitsPerCard
protected int bitsPerCard
-
transmissionDelay
protected int transmissionDelay
-
pulseWidth
protected int pulseWidth
-
num2LSearchLights
protected int num2LSearchLights
-
locSearchLightBits
protected byte[] locSearchLightBits
-
cardTypeLocation
protected byte[] cardTypeLocation
-
INITMSGLEN
public static final int INITMSGLEN
- See Also:
- Constant Field Values
-
NUMCMRINETOPTS
public static final int NUMCMRINETOPTS
- See Also:
- Constant Field Values
-
NUMCPNODEOPTS
public static final int NUMCPNODEOPTS
- See Also:
- Constant Field Values
-
cmrinetOptions
protected int[] cmrinetOptions
-
cpnodeOptions
protected int[] cpnodeOptions
-
cmriNodeDesc
protected java.lang.String cmriNodeDesc
-
pollListPosition
protected int pollListPosition
-
pollStatus
public int pollStatus
-
POLLSTATUS_ERROR
public static final int POLLSTATUS_ERROR
- See Also:
- Constant Field Values
-
POLLSTATUS_IDLE
public static final int POLLSTATUS_IDLE
- See Also:
- Constant Field Values
-
POLLSTATUS_POLLING
public static final int POLLSTATUS_POLLING
- See Also:
- Constant Field Values
-
POLLSTATUS_TIMEOUT
public static final int POLLSTATUS_TIMEOUT
- See Also:
- Constant Field Values
-
POLLSTATUS_INIT
public static final int POLLSTATUS_INIT
- See Also:
- Constant Field Values
-
optbitNet_AUTOPOLL
public static final int optbitNet_AUTOPOLL
- See Also:
- Constant Field Values
-
optbitNet_USECMRIX
public static final int optbitNet_USECMRIX
- See Also:
- Constant Field Values
-
optbitNet_USEBCC
public static final int optbitNet_USEBCC
- See Also:
- Constant Field Values
-
optbitNet_BIT8
public static final int optbitNet_BIT8
- See Also:
- Constant Field Values
-
optbitNet_BIT15
public static final int optbitNet_BIT15
- See Also:
- Constant Field Values
-
optbitNode_USECMRIX
public static final int optbitNode_USECMRIX
- See Also:
- Constant Field Values
-
optbitNode_SENDEOT
public static final int optbitNode_SENDEOT
- See Also:
- Constant Field Values
-
optbitNode_USEBCC
public static final int optbitNode_USEBCC
- See Also:
- Constant Field Values
-
optbitNode_BIT8
public static final int optbitNode_BIT8
- See Also:
- Constant Field Values
-
optbitNode_BIT15
public static final int optbitNode_BIT15
- See Also:
- Constant Field Values
-
outputArray
protected byte[] outputArray
-
hasActiveSensors
protected boolean hasActiveSensors
-
lastUsedSensor
protected int lastUsedSensor
-
sensorArray
protected Sensor[] sensorArray
-
sensorLastSetting
protected int[] sensorLastSetting
-
sensorTempSetting
protected int[] sensorTempSetting
-
monitorNodePackets
protected boolean monitorNodePackets
-
monitorPacketBits
protected boolean[] monitorPacketBits
-
warned
boolean warned
-
timeout
int timeout
-
-
Constructor Detail
-
SerialNode
public SerialNode(SerialTrafficController tc)
Assumes a node address of 0, and a node type of SMINI. If this constructor is used, actual node address must be set using setNodeAddress, and actual node type using 'setNodeType'- Parameters:
tc- system connection traffic controller.
-
SerialNode
public SerialNode(int address, int type, SerialTrafficController tc)
Creates a new SerialNode and initialize default instance variables.- Parameters:
address- Address of node on CMRI serial bus (0-127).type- Node type, e.g. SMINI or USIC_SUSIC.tc- system connection traffic controller.
-
-
Method Detail
-
getNum2LSearchLights
public int getNum2LSearchLights()
-
setNum2LSearchLights
public void setNum2LSearchLights(int n)
-
getLocSearchLightBits
public byte[] getLocSearchLightBits()
-
setLocSearchLightBits
public void setLocSearchLightBits(int num, int value)
-
getCardTypeLocation
public byte[] getCardTypeLocation()
-
setCardTypeLocation
public void setCardTypeLocation(int num, int value)
-
setOutputBit
public void setOutputBit(int bitNumber, boolean state)
Set a single output bit.- Parameters:
bitNumber- bit number, bits are numbered from 1 (not 0).state- true for 0, false for 1.
-
getOutputBit
public boolean getOutputBit(int bitNumber)
Get the current state of a single output bit.- Parameters:
bitNumber- bit number, bits are numbered from 1 (not 0).- Returns:
- true for 0, false for 1.
-
getSensorsActive
public boolean getSensorsActive()
Get state of Sensor polling. Note: returns 'true' if at least one sensor is active for this node- Specified by:
getSensorsActivein classAbstractNode- Returns:
- 'true' if at least one sensor is active for this node
-
setSensorsActive
public void setSensorsActive(boolean flag)
Set state of Sensor polling. Used to disable polling for test purposes only.- Parameters:
flag- true to set active flag, else false.
-
numInputCards
public int numInputCards()
Get number of input cards.- Returns:
- number of input cards.
-
numOutputCards
public int numOutputCards()
Get number of output cards.- Returns:
- number of output cards.
-
getNodeType
public int getNodeType()
Get node type Current types are: SMINI, USIC_SUSIC,- Returns:
- node type, e.g. USIC_SUSIC.
-
setNodeType
public void setNodeType(int type)
Set node type.Current types are: SMINI, USIC_SUSIC For SMINI, also sets cardTypeLocation[] and bitsPerCard. For USIC_SUSIC, also clears cardTypeLocation.
- Parameters:
type- node type, e.g. USIC_SUSIC.
-
getNumBitsPerCard
public int getNumBitsPerCard()
Get number of bits per card.- Returns:
- number of bits per card.
-
setNumBitsPerCard
public void setNumBitsPerCard(int bits)
Set number of bits per card.- Parameters:
bits- number of bits.
-
getCMRInetOpts
public int getCMRInetOpts(int optionbit)
Get CMRInet options.- Parameters:
optionbit- option index.- Returns:
- option value: meaning depends on option
-
setCMRInetOpts
public void setCMRInetOpts(int optionbit, int val)
-
isCMRInetBit
public boolean isCMRInetBit(int optionbit)
-
getcpnodeOpts
public int getcpnodeOpts(int optionbit)
Get cpNode options.- Parameters:
optionbit- option index.- Returns:
- option value: meaning depends on option
-
setcpnodeOpts
public void setcpnodeOpts(int optionbit, int val)
-
iscpnodeBit
public boolean iscpnodeBit(int optionbit)
-
getOptNet_AUTOPOLL
public boolean getOptNet_AUTOPOLL()
Get if Autopoll bit set.- Returns:
- true if set, else false.
-
getOptNet_USECMRIX
public boolean getOptNet_USECMRIX()
-
getOptNet_USEBCC
public boolean getOptNet_USEBCC()
-
getOptNet_BIT8
public boolean getOptNet_BIT8()
-
getOptNet_BIT15
public boolean getOptNet_BIT15()
-
setOptNet_AUTOPOLL
public void setOptNet_AUTOPOLL(int val)
update Autopoll bit- Parameters:
val- 1 sets autopoll on, 0 sets it off
-
setOptNet_USECMRIX
public void setOptNet_USECMRIX(int val)
-
setOptNet_USEBCC
public void setOptNet_USEBCC(int val)
-
setOptNet_BIT8
public void setOptNet_BIT8(int val)
-
setOptNet_BIT15
public void setOptNet_BIT15(int val)
-
getOptNet_byte0
public int getOptNet_byte0()
-
getOptNet_byte1
public int getOptNet_byte1()
-
getOptNode_SENDEOT
public boolean getOptNode_SENDEOT()
Get Node Option SENDEOT.- Returns:
- true if SENDEOT, else false.
-
getOptNode_USECMRIX
public boolean getOptNode_USECMRIX()
-
getOptNode_USEBCC
public boolean getOptNode_USEBCC()
-
getOptNode_BIT8
public boolean getOptNode_BIT8()
-
getOptNode_BIT15
public boolean getOptNode_BIT15()
-
setOptNode_SENDEOT
public void setOptNode_SENDEOT(int val)
-
setOptNode_USECMRIX
public void setOptNode_USECMRIX(int val)
-
setOptNode_USEBCC
public void setOptNode_USEBCC(int val)
-
setOptNode_BIT8
public void setOptNode_BIT8(int val)
-
setOptNode_BIT15
public void setOptNode_BIT15(int val)
-
getOptNode_byte0
public int getOptNode_byte0()
-
getOptNode_byte1
public int getOptNode_byte1()
-
getcmriNodeDesc
public java.lang.String getcmriNodeDesc()
Get node description.- Returns:
- node description.
-
setcmriNodeDesc
public void setcmriNodeDesc(java.lang.String nodeDesc)
-
getPollListPosition
public int getPollListPosition()
Get cpNode poll list position.- Returns:
- poll list position.
-
setPollListPosition
public void setPollListPosition(int pos)
-
getPollStatus
public int getPollStatus()
Get cpNode polling status.- Returns:
- true if polling status flag set, else false.
-
setPollStatus
public void setPollStatus(int status)
-
getPollingEnabled
public boolean getPollingEnabled()
Check cpNode polling enabled state.- Returns:
- true if polling is enabled.
-
setPollingEnabled
public void setPollingEnabled(boolean isEnabled)
-
getMonitorNodePackets
public boolean getMonitorNodePackets()
Get packet monitoring for the node .- Returns:
- true if packet monitoring flag set true, else false.
-
setMonitorNodePackets
public void setMonitorNodePackets(boolean onoff)
-
setMonitorPacketBit
public void setMonitorPacketBit(int pktTypeBit, boolean onoff)
Set the specific packet monitoring enable bit.- Parameters:
pktTypeBit- index.onoff- true enables, false disabled.
-
getMonitorPacketBit
public boolean getMonitorPacketBit(int pktTypeBit)
-
checkNodeAddress
protected boolean checkNodeAddress(int address)
Check valid node address, must match value in dip switches (0 - 127). Check for valid address with respect to range, etc.- Specified by:
checkNodeAddressin classAbstractNode- Parameters:
address- node number to check.- Returns:
- true if valid
-
getTransmissionDelay
public int getTransmissionDelay()
Get transmission delay.- Returns:
- delay, ms.
-
setTransmissionDelay
public void setTransmissionDelay(int delay)
Set transmission delay.two bytes are used, so range is 0-65,535. If delay is out of range, it is restricted to the allowable range.
- Parameters:
delay- - delay between bytes on receive (units of 10 microsec.)
-
getPulseWidth
public int getPulseWidth()
Get pulse width. Used with pulsed turnout control.- Returns:
- pulse width, ms.
-
setPulseWidth
public void setPulseWidth(int width)
Set pulse width.- Parameters:
width- width of pulse used for pulse controlled turnout control (millisec.) Note: Pulse width must be between 100 and 10000 milliseconds. If width is out of range, it is restricted to the allowable range
-
setCardTypeByAddress
public void setCardTypeByAddress(int address, int type)
Set the type of one card.- Parameters:
address- address recognized for this card by the node hardware. for USIC_SUSIC address set in card's dip switches (0 - 63)type- INPUT_CARD, OUTPUT_CARD, or NO_CARD
-
isOutputCard
public boolean isOutputCard(int cardNum)
Test for OUTPUT_CARD type.- Parameters:
cardNum- index number.- Returns:
- true if card with 'cardNum' is an output card. false if card is not an output card, or if 'cardNum' is out of range.
-
isInputCard
public boolean isInputCard(int cardNum)
Test for INPUT_CARD type.- Parameters:
cardNum- index number.- Returns:
- true if card with 'cardNum' is an input card, false if card is not an input card, or if 'cardNum' is out of range.
-
getOutputCardIndex
public int getOutputCardIndex(int cardNum)
Get 'Output Card Index'.Can be used to locate this card's bytes in an output message. Array is ordered by increasing node address.
- Parameters:
cardNum- index number.- Returns:
- the index this output card would have in an array of output cards for this node.
-
getInputCardIndex
public int getInputCardIndex(int cardNum)
Get 'Input Card Index'.Can be used to locate this card's bytes in an receive message. Array is ordered by increasing node address.
- Parameters:
cardNum- index number.- Returns:
- the index this input card would have in an array of input cards for this node.
-
set2LeadSearchLight
public void set2LeadSearchLight(int bit)
Set location of SearchLightBits (SMINI only).- Parameters:
bit- - bitNumber of the low bit of an oscillating search light bit pairBits are numbered from 0. Two bits are set by each call - bit and bit + 1. If either bit is already set, an error is logged and no bits are set.
-
clear2LeadSearchLight
public void clear2LeadSearchLight(int bit)
Clear location of SearchLightBits (SMINI only).- Parameters:
bit- - bitNumber of the low bit of an oscillating search light bit pairNotes: Bits are numbered from 0 Two bits are cleared by each call - bit and bit + 1. If either bit is already clear, an error is logged and no bits are set.
-
isSearchLightBit
public boolean isSearchLightBit(int bit)
Query SearchLightBits by bit number (SMINI only).- Parameters:
bit- bitNumber of the either bit of an oscillating search light bit pair.- Returns:
- true if bit is an oscillating SearchLightBit, otherwise false.
-
createInitPacket
public AbstractMRMessage createInitPacket()
Create an Initialization packet (SerialMessage) for this node- Specified by:
createInitPacketin classAbstractNode- Returns:
- the packet, or 'null' if not needed
-
createOutPacket
public AbstractMRMessage createOutPacket()
Create an Transmit packet (SerialMessage)- Specified by:
createOutPacketin classAbstractNode- Returns:
- packet to send current node state.
-
warn
void warn(java.lang.String s)
-
markChanges
public void markChanges(SerialReply l)
Use the contents of the poll reply to mark changes- Parameters:
l- Reply to a poll operation
-
registerSensor
public void registerSensor(Sensor s, int i)
The numbers here are 0 to MAXSENSORS, not 1 to MAXSENSORS.- Parameters:
s- Sensor objecti- 0 to MAXSENSORS number of sensor's input bit on this node
-
isPollingOK
public boolean isPollingOK()
- Returns:
- true if polling active and currently OK
-
handleTimeout
public boolean handleTimeout(AbstractMRMessage m, AbstractMRListener l)
Description copied from class:AbstractNodeDeal with a timeout in the transmission controller.- Specified by:
handleTimeoutin classAbstractNode- Parameters:
m- message that didn't receive a replyl- listener that sent the message- Returns:
- true if initialization required
-
resetTimeout
public void resetTimeout(AbstractMRMessage m)
Description copied from class:AbstractNodeA reply was received, so there was no timeout, do any needed processing.- Specified by:
resetTimeoutin classAbstractNode- Parameters:
m- message received that has reset the timeout and is waiting to be handled
-
-