Class SerialNode
- java.lang.Object
-
- jmri.jmrix.AbstractNode
-
- jmri.jmrix.oaktree.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 carries 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 (package private) OakTreeSystemConnectionMemo
_memo
protected boolean
hasActiveSensors
(package private) static int[]
inputBytes
static int
IO24
static int
IO48
protected int
lastUsedSensor
(package private) static int
MAXSENSORS
Maximum number of sensors a node can carry.protected int
nodeType
static int
O48
protected byte[]
outputArray
protected boolean[]
outputByteChanged
(package private) static int[]
outputBytes
protected Sensor[]
sensorArray
protected int[]
sensorLastSetting
protected int[]
sensorTempSetting
(package private) int
timeout
(package private) boolean
warned
-
Fields inherited from class jmri.jmrix.AbstractNode
nodeAddress
-
-
Constructor Summary
Constructors Constructor Description SerialNode(int address, int type, OakTreeSystemConnectionMemo memo)
Create a new SerialNode and initialize default instance variablesSerialNode(OakTreeSystemConnectionMemo memo)
Create a new SerialNode without a name supplied.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
checkNodeAddress(int address)
Check for valid node address.AbstractMRMessage
createInitPacket()
Create an Initialization packet (SerialMessage) for this node.AbstractMRMessage
createOutPacket()
Create an Transmit packet (SerialMessage).static java.lang.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.void
markChanges(SerialReply l)
Use the contents of the poll reply to mark changes.void
registerSensor(Sensor s, int i)
The numbers here are 0 to MAXSENSORS, not 1 to MAXSENSORS.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.(package private) void
warn(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
-
IO24
public static final int IO24
- See Also:
- Constant Field Values
-
IO48
public static final int IO48
- See Also:
- Constant Field Values
-
O48
public static final int O48
- See Also:
- Constant Field Values
-
outputBytes
static final int[] outputBytes
-
inputBytes
static final int[] inputBytes
-
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
-
timeout
int timeout
-
-
Constructor Detail
-
SerialNode
public SerialNode(OakTreeSystemConnectionMemo memo)
Create a new SerialNode without a name supplied.Assumes a node address of 0, and a node type of 0 (IO24). If this constructor is used, actual node address must be set using setNodeAddress, and actual node type using 'setNodeType'
- Parameters:
memo
- system connection.
-
SerialNode
public SerialNode(int address, int type, OakTreeSystemConnectionMemo memo)
Create a new SerialNode and initialize default instance variables- Parameters:
address
- Address of node on serial bus (0-255).type
- type constant from the class.memo
- system connection.
-
-
Method Detail
-
getBoardNames
public static java.lang.String[] getBoardNames()
-
setOutputBit
public void setOutputBit(int bitNumber, boolean state)
Set an output bit.- Parameters:
bitNumber
- bit id, numbered from 1 (not 0)state
- 'true' for 0, 'false' for 1
-
getSensorsActive
public boolean getSensorsActive()
Get state of Sensors.- Specified by:
getSensorsActive
in 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:
resetMustSend
in classAbstractNode
-
getNodeType
public int getNodeType()
Get Node type.Current types are: IO24, I048, O48.
- Returns:
- node type.
-
setNodeType
public void setNodeType(int type)
Set Node type.- Parameters:
type
- node type e.g. IO48 , IO24
-
checkNodeAddress
protected boolean checkNodeAddress(int address)
Check for valid node address.- Specified by:
checkNodeAddress
in classAbstractNode
- Parameters:
address
- node number to check.- Returns:
- true if valid
-
createInitPacket
public AbstractMRMessage createInitPacket()
Create an Initialization packet (SerialMessage) for this node. There are currently no Oak Tree boards that need an init message, so this returns null.- Specified by:
createInitPacket
in classAbstractNode
- Returns:
- the packet, or 'null' if not needed
-
createOutPacket
public AbstractMRMessage createOutPacket()
Create an Transmit packet (SerialMessage).- Specified by:
createOutPacket
in 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
- number of sensor's input bit on this node (0 to MAXSENSORS)
-
handleTimeout
public boolean handleTimeout(AbstractMRMessage m, AbstractMRListener l)
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 is required
-
resetTimeout
public void resetTimeout(AbstractMRMessage m)
Description copied from class:AbstractNode
A reply was received, so there was no timeout, do any needed processing.- Specified by:
resetTimeout
in classAbstractNode
- Parameters:
m
- message received that has reset the timeout and is waiting to be handled
-
-