Class SerialNode
- java.lang.Object
-
- jmri.jmrix.AbstractNode
-
- jmri.jmrix.grapevine.SerialNode
-
public class SerialNode extends AbstractNode
Models a serial node.Nodes are numbered ala their address, from 0 to 255. 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanhasActiveSensors(package private) static int[]inputBitsprotected intlastUsedSensor(package private) static intMAXSENSORSMaximum number of sensors a node can carry.static intNODE2000static intNODE2002V1static intNODE2002V6protected intnodeType(package private) static intoffsetA(package private) static intoffsetM(package private) static intoffsetP(package private) static intoffsetSprotected byte[]outputArray(package private) static int[]outputBitsprotected boolean[]outputByteChangedprotected Sensor[]sensorArrayprotected int[]sensorLastSettingprotected int[]sensorTempSetting(package private) inttimeout(package private) booleanwarned-
Fields inherited from class jmri.jmrix.AbstractNode
nodeAddress
-
-
Constructor Summary
Constructors Constructor Description SerialNode(int address, int type, SerialTrafficController tc)Create a new SerialNode and initialize default instance variables.SerialNode(int address, SerialTrafficController tc)SerialNode(SerialTrafficController tc)Assumes a node address of 1, and a node type of 0 (NODE2002V6).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckNodeAddress(int address)Check for valid node address.AbstractMRMessagecreateInitPacket()Create Initialization packets (SerialMessage) for this node.AbstractMRMessagecreateOutPacket()Public method to create a Transmit packet (SerialMessage).static java.lang.String[]getBoardNames()intgetNodeType()Get node type.booleangetSensorsActive()Get state of Sensors.booleanhandleTimeout(AbstractMRMessage m, AbstractMRListener l)Deal with a timeout in the transmission controller.(package private) voidmarkBit(boolean input, int sensorNum)Mark and act on a single input bit.voidmarkChanges(SerialReply l)Use the contents of a reply from the Grapevine to mark changes in the sensors on the layout.voidregisterSensor(Sensor s, int i)Register a sensor on a node.voidresetMustSend()Reset state of needSend flag.voidresetTimeout(AbstractMRMessage m)A reply was received, so there was no timeout, do any needed processing.voidsetNodeType(int type)Set node type.voidsetOutputBit(int bitNumber, boolean state)Set an output bit on this node.(package private) voidwarn(java.lang.String s)-
Methods inherited from class jmri.jmrix.AbstractNode
getNodeAddress, mustSend, 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.SENSORSPERNODE- See Also:
- Constant Field Values
-
NODE2002V6
public static final int NODE2002V6
- See Also:
- Constant Field Values
-
NODE2002V1
public static final int NODE2002V1
- See Also:
- Constant Field Values
-
NODE2000
public static final int NODE2000
- See Also:
- Constant Field Values
-
outputBits
static final int[] outputBits
-
inputBits
static final int[] inputBits
-
nodeType
protected int nodeType
-
outputArray
protected byte[] outputArray
-
outputByteChanged
protected boolean[] outputByteChanged
-
hasActiveSensors
protected boolean hasActiveSensors
-
lastUsedSensor
protected int lastUsedSensor
-
sensorArray
protected Sensor[] sensorArray
-
sensorLastSetting
protected int[] sensorLastSetting
-
sensorTempSetting
protected int[] sensorTempSetting
-
warned
boolean warned
-
offsetA
static final int offsetA
- See Also:
- Constant Field Values
-
offsetM
static final int offsetM
- See Also:
- Constant Field Values
-
offsetP
static final int offsetP
- See Also:
- Constant Field Values
-
offsetS
static final int offsetS
- See Also:
- Constant Field Values
-
timeout
int timeout
-
-
Constructor Detail
-
SerialNode
public SerialNode(SerialTrafficController tc)
Assumes a node address of 1, and a node type of 0 (NODE2002V6). 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, SerialTrafficController tc)
-
SerialNode
public SerialNode(int address, int type, SerialTrafficController tc)
Create a new SerialNode and initialize default instance variables.- Parameters:
address- the address of node on serial bus (1-127)type- a type constant from the classtc- the TrafficController for this connection
-
-
Method Detail
-
getBoardNames
public static java.lang.String[] getBoardNames()
-
setOutputBit
public void setOutputBit(int bitNumber, boolean state)
Set an output bit on this node.- Parameters:
bitNumber- the bit index. Bits are numbered from 1 (not 0)state- 'true' for 0, 'false' for 1.
-
getSensorsActive
public boolean getSensorsActive()
Get state of Sensors.- Specified by:
getSensorsActivein classAbstractNode- Returns:
- 'true' if at least one sensor is active for this node
-
resetMustSend
public void resetMustSend()
Reset state of needSend flag. Can only reset if there are no bytes that need to be sent.- Overrides:
resetMustSendin classAbstractNode
-
getNodeType
public int getNodeType()
Get node type.- Returns:
- node type, e.g. NODE2002V1 or NODE2002V6.
-
setNodeType
public void setNodeType(int type)
Set node type.- Parameters:
type- node type, e.g. NODE2002V1 or NODE2002V6.
-
checkNodeAddress
protected boolean checkNodeAddress(int address)
Check for valid node address.- Specified by:
checkNodeAddressin classAbstractNode- Parameters:
address- node number to check.- Returns:
- true if valid
-
createInitPacket
public AbstractMRMessage createInitPacket()
Create Initialization packets (SerialMessage) for this node. Initialization consists of multiple parts:- Turn on the ASD input 0x71 to bank 0
- After a wait, another ASD message 0x73 to bank 0
As an Ugly Hack to keep these separate, only the first is put in the reply from this. The other(s) are sent via the usual output methods.
- Specified by:
createInitPacketin classAbstractNode- Returns:
- the packet, or 'null' if not needed
-
createOutPacket
public AbstractMRMessage createOutPacket()
Public method to create a 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 a reply from the Grapevine to mark changes in the sensors on the layout.- Parameters:
l- Reply to a poll operation
-
markBit
void markBit(boolean input, int sensorNum)
Mark and act on a single input bit.- Parameters:
input- true if sensor says activesensorNum- from 1 to lastUsedSensor+1 on this node
-
registerSensor
public void registerSensor(Sensor s, int i)
Register a sensor on a node.The numbers here are 0 to MAXSENSORS, not 1 to MAXSENSORS. E.g. the integer argument is one less than the name of the sensor object.
- Parameters:
s- Sensor objecti- bit number corresponding, a 1-based value corresponding to the low digits of the system name
-
handleTimeout
public boolean handleTimeout(AbstractMRMessage m, AbstractMRListener l)
Deal 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)
A reply was received, so there was no timeout, do any needed processing.- Specified by:
resetTimeoutin classAbstractNode- Parameters:
m- GrapevineSerialMessage (ignored)
-
-