Class SerialProtocol

java.lang.Object
com.inertia.promove.SerialProtocol

public class SerialProtocol
extends java.lang.Object
This class allows parsing and generating messages over serial to the ProMove nodes and FastGateway the serial connection can be over bluetooth or USB serial.
  • Field Details

  • Constructor Details

    • SerialProtocol

      public SerialProtocol​(ProtocolListener listener)
      Create a new SerialProtocl data parser
      Parameters:
      listener - The ProtocolListener
  • Method Details

    • createMessage

      public byte[] createMessage​(Config config) throws InertiaException
      Create a serial message for a Config. Message will be addressed to all nodes.
      Parameters:
      config - The configuration
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Command command) throws InertiaException
      Create a serial message for a Command. Message will be addressed to all nodes.
      Parameters:
      command - The command
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Config config, int destination) throws InertiaException
      Create a serial message for a Config.
      Parameters:
      config - The configuration
      destination - the nodeID
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Command command, int destination) throws InertiaException
      Create a serial message for a Command.
      Parameters:
      command - The command
      destination - the nodeID
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Config config, SerialProtocol.ProtocolVersion version) throws InertiaException
      Create a serial message for a Config. Message will be addressed to all nodes.
      Parameters:
      config - The configuration
      version - the protocol version
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Command command, SerialProtocol.ProtocolVersion version) throws InertiaException
      Create a serial message for a Command. Message will be addressed to all nodes.
      Parameters:
      command - The command
      version - the protocol version
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Config config, SerialProtocol.ProtocolVersion version, int destination) throws InertiaException
      Create a serial message for a Config.
      Parameters:
      config - The configuration
      version - the protocol version
      destination - the nodeID
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • createMessage

      public byte[] createMessage​(Command command, SerialProtocol.ProtocolVersion version, int destination) throws InertiaException
      Create a serial message for a Command.
      Parameters:
      command - The command
      version - the protocol version
      destination - the nodeID
      Returns:
      bytes to send according to serial protocol
      Throws:
      InertiaException - unable to create message
    • getTransformerIDs

      public java.util.Set<java.lang.Integer> getTransformerIDs()
      Get the nodeIDs of the available Transformers.
      Returns:
      A Set with nodeIDs.
    • getTransformer

      public Transformer getTransformer​(int nodeID)
      Get the Transformer for the specified nodeID. The transformer contains configuration information.
      Parameters:
      nodeID - The nodeID
      Returns:
      The Transformer
    • getProtocolVersion

      public SerialProtocol.ProtocolVersion getProtocolVersion()
      Get the ProtocolVersion of the serial messages.
      Returns:
      The ProtocolVersion
    • parseSerialMessages

      public java.util.Vector<SerialProtocol.Message> parseSerialMessages​(byte[] data)
      Parse serial data and construct Messages. data bytes are internally buffered until a valid Message can be parsed.
      Parameters:
      data - input bytes to be parsed
      Returns:
      parsed messages
    • parseSerialMessages

      public java.util.Vector<SerialProtocol.Message> parseSerialMessages​(byte[] data, int offset, int length)
      Parse serial data and construct Messages. data bytes are internally buffered until a valid Message can be parsed. If offset and/or length do not match the size of data, data is not processed and an empty vector is returned. (offset >= 0, offset < data.length, length > 0, length <= data.length, offset+length <= data.length)
      Parameters:
      data - input bytes to be parsed
      offset - starting position in data
      length - number of bytes to parse
      Returns:
      parsed messages
    • parseFlashMessages

      public java.util.Vector<SerialProtocol.Message> parseFlashMessages​(int sourceID, byte[] data)
      Parse data from a flash log and construct Messages. data bytes are internally buffered until a valid Message can be parsed.
      Parameters:
      sourceID - source (nodeID) of the data
      data - input bytes to be parsed
      Returns:
      parsed messages
    • parseFlashMessages

      public java.util.Vector<SerialProtocol.Message> parseFlashMessages​(int sourceID, byte[] data, int offset, int length)
      Parse data from a flash log and construct Messages. data bytes are internally buffered until a valid Message can be parsed. If offset and/or length do not match the size of data, data is not processed and an empty vector is returned. (offset >= 0, offset < data.length, length > 0, length <= data.length, offset+length <= data.length)
      Parameters:
      sourceID - source (nodeID) of the data
      data - input bytes to be parsed
      offset - starting position in data
      length - number of bytes to parse
      Returns:
      parsed messages