Class SerialNode
public class SerialNode extends AbstractNode
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 boolean
hasActiveSensors
(package private) static int[]
inputBits
protected int
lastUsedSensor
(package private) static int
MAXSENSORS
Maximum number of sensors a node can carry.static int
NODE2000
static int
NODE2002V1
static int
NODE2002V6
protected int
nodeType
(package private) static int
offsetA
(package private) static int
offsetM
(package private) static int
offsetP
(package private) static int
offsetS
protected byte[]
outputArray
(package private) static int[]
outputBits
protected boolean[]
outputByteChanged
protected Sensor[]
sensorArray
protected int[]
sensorLastSetting
protected int[]
sensorTempSetting
(package private) int
timeout
(package private) boolean
warned
-
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
Modifier and Type Method Description protected boolean
checkNodeAddress(int address)
Check for valid node address.AbstractMRMessage
createInitPacket()
Create Initialization packets (SerialMessage) for this node.AbstractMRMessage
createOutPacket()
Public method to create a Transmit packet (SerialMessage).static String[]
getBoardNames()
int
getNodeType()
Get node type.boolean
getSensorsActive()
Get state of Sensors.boolean
handleTimeout(AbstractMRMessage m, AbstractMRListener l)
Deal with a timeout in the transmission controller.(package private) void
markBit(boolean input, int sensorNum)
Mark and act on a single input bit.void
markChanges(SerialReply l)
Use the contents of a reply from the Grapevine to mark changes in the sensors on the layout.void
registerSensor(Sensor s, int i)
Register a sensor on a node.void
resetMustSend()
Reset state of needSend flag.void
resetTimeout(AbstractMRMessage m)
A reply was received, so there was no timeout, do any needed processing.void
setNodeType(int type)
Set node type.void
setOutputBit(int bitNumber, boolean state)
Set an output bit on this node.(package private) void
warn(String s)
Methods inherited from class jmri.jmrix.AbstractNode
getNodeAddress, mustSend, setMustSend, setNodeAddress
-
Field Details
-
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
- See Also:
- Constant Field Values
-
NODE2002V1
- See Also:
- Constant Field Values
-
NODE2000
- See Also:
- Constant Field Values
-
outputBits
-
inputBits
-
nodeType
-
outputArray
-
outputByteChanged
-
hasActiveSensors
-
lastUsedSensor
-
sensorArray
-
sensorLastSetting
-
sensorTempSetting
-
warned
boolean warned -
offsetA
- See Also:
- Constant Field Values
-
offsetM
- See Also:
- Constant Field Values
-
offsetP
- See Also:
- Constant Field Values
-
offsetS
- See Also:
- Constant Field Values
-
timeout
int timeout
-
-
Constructor Details
-
SerialNode
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
-
SerialNode
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 Details
-
getBoardNames
-
setOutputBit
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
Get state of Sensors.- Specified by:
getSensorsActive
in classAbstractNode
- Returns:
- 'true' if at least one sensor is active for this node
-
resetMustSend
Reset state of needSend flag. Can only reset if there are no bytes that need to be sent.- Overrides:
resetMustSend
in classAbstractNode
-
getNodeType
Get node type.- Returns:
- node type, e.g. NODE2002V1 or NODE2002V6.
-
setNodeType
Set node type.- Parameters:
type
- node type, e.g. NODE2002V1 or NODE2002V6.
-
checkNodeAddress
Check for valid node address.- Specified by:
checkNodeAddress
in classAbstractNode
- Parameters:
address
- node number to check.- Returns:
- true if valid
-
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:
createInitPacket
in classAbstractNode
- Returns:
- the packet, or 'null' if not needed
-
createOutPacket
Public method to create a Transmit packet (SerialMessage).- Specified by:
createOutPacket
in classAbstractNode
- Returns:
- packet to send current node state.
-
warn
-
markChanges
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
Mark and act on a single input bit.- Parameters:
input
- true if sensor says activesensorNum
- from 1 to lastUsedSensor+1 on this node
-
registerSensor
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
Deal with a timeout in the transmission controller.- Specified by:
handleTimeout
in classAbstractNode
- Parameters:
m
- message that didn't receive a replyl
- listener that sent the message- Returns:
- true if initialization required
-
resetTimeout
A reply was received, so there was no timeout, do any needed processing.- Specified by:
resetTimeout
in classAbstractNode
- Parameters:
m
- GrapevineSerialMessage (ignored)
-