public class RtuModbusMessage extends Object implements RtuModbusMessage, net.solarnetwork.io.modbus.netty.msg.ModbusPayloadEncoder
CRC_MISMATCH_VALIDATION_MESSAGE| Constructor and Description |
|---|
RtuModbusMessage(int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
Constructor.
|
RtuModbusMessage(long timestamp,
int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
Constructor.
|
RtuModbusMessage(long timestamp,
net.solarnetwork.io.modbus.ModbusMessage body,
short crc)
Constructor.
|
RtuModbusMessage(net.solarnetwork.io.modbus.ModbusMessage body,
short crc)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
short |
computeCrc()
Compute the 16-bit cyclic redundancy check value from the message data.
|
static short |
computeCrc(int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
Compute the cyclic redundancy check of a message and given unit ID.
|
void |
encodeModbusPayload(io.netty.buffer.ByteBuf out) |
net.solarnetwork.io.modbus.ModbusMessage |
getBody()
Get the wrapped message.
|
short |
getCrc()
Get the 16-bit cyclic redundancy check value presented in the RTU message
frame.
|
net.solarnetwork.io.modbus.ModbusError |
getError() |
net.solarnetwork.io.modbus.ModbusFunction |
getFunction() |
long |
getTimestamp()
Get a message creation date.
|
int |
getUnitId() |
boolean |
isSameAs(net.solarnetwork.io.modbus.ModbusMessage obj) |
int |
payloadLength() |
String |
toString() |
<T extends net.solarnetwork.io.modbus.ModbusMessage> |
unwrap(Class<T> msgType) |
RtuModbusMessage |
validate() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisCrcValidpublic RtuModbusMessage(int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
The current system time will be used for the timestamp value, and the CRC
will be calculated from the unitId and body values.
unitId - the unit IDbody - the message body, must implement ModbusPayloadEncoder.ClassCastException - if body does not implement ModbusPayloadEncoderpublic RtuModbusMessage(long timestamp,
int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
The CRC will be calculated from the unitId and body
values.
timestamp - the timestampunitId - the unit IDbody - the message body, must implement ModbusPayloadEncoder.ClassCastException - if body does not implement ModbusPayloadEncoderpublic RtuModbusMessage(net.solarnetwork.io.modbus.ModbusMessage body,
short crc)
The current system time will be used for the timestamp value.
body - the message body, must implement ModbusPayloadEncoder.crc - the provided cyclic redundancy check valueIllegalArgumentException - if body does not implement ModbusPayloadEncoderpublic RtuModbusMessage(long timestamp,
net.solarnetwork.io.modbus.ModbusMessage body,
short crc)
timestamp - the timestampbody - the message body, must implement ModbusPayloadEncoder.crc - the provided cyclic redundancy check valueIllegalArgumentException - if body does not implement ModbusPayloadEncoderpublic RtuModbusMessage validate() throws net.solarnetwork.io.modbus.ModbusValidationException
validate in interface net.solarnetwork.io.modbus.ModbusMessagevalidate in interface RtuModbusMessagenet.solarnetwork.io.modbus.ModbusValidationExceptionpublic boolean isSameAs(net.solarnetwork.io.modbus.ModbusMessage obj)
isSameAs in interface net.solarnetwork.io.modbus.ModbusMessagepublic <T extends net.solarnetwork.io.modbus.ModbusMessage> T unwrap(Class<T> msgType)
unwrap in interface net.solarnetwork.io.modbus.ModbusMessagepublic net.solarnetwork.io.modbus.ModbusMessage getBody()
public long getTimestamp()
RtuModbusMessagegetTimestamp in interface RtuModbusMessagepublic short getCrc()
RtuModbusMessagegetCrc in interface RtuModbusMessagepublic short computeCrc()
RtuModbusMessage
If the RtuModbusMessage.getCrc() and this value differ, the message should be
considered corrupted.
computeCrc in interface RtuModbusMessagepublic static short computeCrc(int unitId,
net.solarnetwork.io.modbus.ModbusMessage body)
unitId - the unit IDbody - the messagepublic int getUnitId()
getUnitId in interface net.solarnetwork.io.modbus.ModbusMessagepublic net.solarnetwork.io.modbus.ModbusFunction getFunction()
getFunction in interface net.solarnetwork.io.modbus.ModbusMessagepublic net.solarnetwork.io.modbus.ModbusError getError()
getError in interface net.solarnetwork.io.modbus.ModbusMessagepublic void encodeModbusPayload(io.netty.buffer.ByteBuf out)
encodeModbusPayload in interface net.solarnetwork.io.modbus.netty.msg.ModbusPayloadEncoderpublic int payloadLength()
payloadLength in interface net.solarnetwork.io.modbus.netty.msg.ModbusPayloadEncoder