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 Details

  • 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

      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 class
      tc - the TrafficController for this connection
  • Method Details

    • getBoardNames

      public static 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:
      getSensorsActive in class AbstractNode
      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 class AbstractNode
    • 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:
      checkNodeAddress in class AbstractNode
      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
      (Eventually, it should also request input values, once we know what message does that)

      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 class AbstractNode
      Returns:
      the packet, or 'null' if not needed
    • createOutPacket

      Public method to create a Transmit packet (SerialMessage).
      Specified by:
      createOutPacket in class AbstractNode
      Returns:
      packet to send current node state.
    • warn

      void warn(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 active
      sensorNum - 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 object
      i - 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 class AbstractNode
      Parameters:
      m - message that didn't receive a reply
      l - 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 class AbstractNode
      Parameters:
      m - GrapevineSerialMessage (ignored)