Package com.inertia.promove
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SerialProtocol.Message
class for parsing and holding serial message datastatic class
SerialProtocol.ProtocolVersion
The ProtocolVersion identifies how the serial data is and should be encoded. -
Field Summary
Fields Modifier and Type Field Description static java.lang.String
LIB_VERSION_STR
-
Constructor Summary
Constructors Constructor Description SerialProtocol(ProtocolListener listener)
Create a new SerialProtocl data parser -
Method Summary
Modifier and Type Method Description byte[]
createMessage(Command command)
Create a serial message for a Command.byte[]
createMessage(Command command, int destination)
Create a serial message for a Command.byte[]
createMessage(Command command, SerialProtocol.ProtocolVersion version)
Create a serial message for a Command.byte[]
createMessage(Command command, SerialProtocol.ProtocolVersion version, int destination)
Create a serial message for a Command.byte[]
createMessage(Config config)
Create a serial message for a Config.byte[]
createMessage(Config config, int destination)
Create a serial message for a Config.byte[]
createMessage(Config config, SerialProtocol.ProtocolVersion version)
Create a serial message for a Config.byte[]
createMessage(Config config, SerialProtocol.ProtocolVersion version, int destination)
Create a serial message for a Config.SerialProtocol.ProtocolVersion
getProtocolVersion()
Get the ProtocolVersion of the serial messages.Transformer
getTransformer(int nodeID)
Get the Transformer for the specified nodeID.java.util.Set<java.lang.Integer>
getTransformerIDs()
Get the nodeIDs of the available Transformers.java.util.Vector<SerialProtocol.Message>
parseFlashMessages(int sourceID, byte[] data)
Parse data from a flash log and construct Messages.java.util.Vector<SerialProtocol.Message>
parseFlashMessages(int sourceID, byte[] data, int offset, int length)
Parse data from a flash log and construct Messages.java.util.Vector<SerialProtocol.Message>
parseSerialMessages(byte[] data)
Parse serial data and construct Messages.java.util.Vector<SerialProtocol.Message>
parseSerialMessages(byte[] data, int offset, int length)
Parse serial data and construct Messages.
-
Field Details
-
LIB_VERSION_STR
public static final java.lang.String LIB_VERSION_STR- See Also:
- Constant Field Values
-
-
Constructor Details
-
SerialProtocol
Create a new SerialProtocl data parser- Parameters:
listener
- The ProtocolListener
-
-
Method Details
-
createMessage
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
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
Create a serial message for a Config.- Parameters:
config
- The configurationdestination
- the nodeID- Returns:
- bytes to send according to serial protocol
- Throws:
InertiaException
- unable to create message
-
createMessage
Create a serial message for a Command.- Parameters:
command
- The commanddestination
- 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 InertiaExceptionCreate a serial message for a Config. Message will be addressed to all nodes.- Parameters:
config
- The configurationversion
- 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 InertiaExceptionCreate a serial message for a Command. Message will be addressed to all nodes.- Parameters:
command
- The commandversion
- 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 InertiaExceptionCreate a serial message for a Config.- Parameters:
config
- The configurationversion
- the protocol versiondestination
- 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 InertiaExceptionCreate a serial message for a Command.- Parameters:
command
- The commandversion
- the protocol versiondestination
- 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
Get the Transformer for the specified nodeID. The transformer contains configuration information.- Parameters:
nodeID
- The nodeID- Returns:
- The Transformer
-
getProtocolVersion
Get the ProtocolVersion of the serial messages.- Returns:
- The ProtocolVersion
-
parseSerialMessages
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 parsedoffset
- starting position in datalength
- number of bytes to parse- Returns:
- parsed messages
-
parseFlashMessages
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 datadata
- 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 datadata
- input bytes to be parsedoffset
- starting position in datalength
- number of bytes to parse- Returns:
- parsed messages
-