Class Frame
-
- All Implemented Interfaces:
public final class FrameRSCP data frame that can be sent to or received from an E3DC home power plant.
A frame always consists of 3 logical parts: Timestamp reflecting the creation time of the frame Control area, contains the protocol version and a control information whether the checksum feature is used or not. Data, the RSCP data itself.
- Since:
2.0
2.1 new functions:
-
-
Field Summary
Fields Modifier and Type Field Description private final Instanttimestampprivate final ByteArraycontrolBytesprivate final List<Data>dataprivate final DataParserparser
-
Method Summary
Modifier and Type Method Description final InstantgetTimestamp()final ByteArraygetControlBytes()final List<Data>getData()final DataParsergetParser()final ByteArrayasByteArray()Provides the byte representation of the frame as it may be sent to or received from the home power plant. final DatadataByTag(Tag tag, Tag containerPath)Searches for a data block with the specified tag final IntegerintByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Int. final ShortshortByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Short. final BytebyteByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Byte. final LonglongByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Long. final FloatfloatByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Float. final DoubledoubleByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Double. final BooleanbooleanByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Boolean. final List<Data>containerByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as DataType.CONTAINER. final StringstringByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as String. final InstantinstantByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Instant. final DurationdurationByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as Duration. final ResultCoderesultCodeByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as ResultCode. final BooleanisDataBlockInError(Tag tag, Tag containerPath)Checks whether the data block in the frame is of data type DataType.ERROR. final ErrorCodeerrorCodeByTag(Tag tag, Tag containerPath)Searches for a data block of type tag and returns the value as ErrorCode. final BooleanisChecksumEnabled()Query whether the frame calculates the checksum or not. Booleanequals(Object other)IntegerhashCode()StringtoString()-
-
Constructor Detail
-
Frame
Frame(Instant timestamp, ByteArray controlBytes, List<Data> data, DataParser parser)
- Parameters:
timestamp- Creation time of the framecontrolBytes- Control functions.data- The data itself.parser- The parser to use for parsing container data
-
-
Method Detail
-
getTimestamp
final Instant getTimestamp()
-
getControlBytes
final ByteArray getControlBytes()
-
getParser
final DataParser getParser()
-
asByteArray
final ByteArray asByteArray()
Provides the byte representation of the frame as it may be sent to or received from the home power plant.
A frame is structured according to the following pattern:
Byte 0 - 1: So-called magic bytes. Are fixed on the byte value of the hex string E3DC.
Byte 2 - 3: Control area. The first byte is always 00 and is reserved for the future according to E3DC. The second byte contains the protocol version (currently always 1) and a 0 (without checksum) or 1 (with checksum).
Byte 4 - 15: Contain the timestamp. 4 - 11 in seconds since 01.01.1970, and 12 - 15 the nanoseconds.
Byte 16 - 17: Length in bytes for the following data block
Bytes 18 - n: Data range
Bytes n+1 - n + 4: CRC32 Checksum of the frame when bytes 0 - n are considered. This block is omitted if the checksum bit is set to 0 in the control area.
- Returns:
ByteArray of the whole frame
- Since:
2.0
-
dataByTag
final Data dataByTag(Tag tag, Tag containerPath)
Searches for a data block with the specified tag
- Parameters:
tag- To be searched TagcontainerPath- Path, if the block is to be searched nested in container blocks- Returns:
Data block or null if not found
- Since:
2.0
-
intByTag
final Integer intByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Int.
If the block is not found, or is not a valid Int type (see DataType.isIntType, the value 0 is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Int or 0 if the data block does not exist or is not a valid Int type.
- Since:
2.0
-
shortByTag
final Short shortByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Short.
If the block is not found, or is not a valid Short type (see DataType.isShortType, the value 0 is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Short or 0 if the data block does not exist or is not a valid Short type.
- Since:
2.0
-
byteByTag
final Byte byteByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Byte.
If the block is not found, or is not a valid Byte type (see DataType.isByteType, the value 0 is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Byte or 0 if the data block does not exist or is not a valid Byte type.
- Since:
2.0
-
longByTag
final Long longByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Long.
If the block is not found, or is not a valid Long type (see DataType.isLongType, the value 0 is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Long or 0 if the data block does not exist or is not a valid Long type.
- Since:
2.0
-
floatByTag
final Float floatByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Float.
If the block is not found, or is not a valid Float type (see DataType.FLOAT32), the value 0.0f is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Float or 0.0f if the data block does not exist or is not a valid Float type.
- Since:
2.0
-
doubleByTag
final Double doubleByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Double.
If the block is not found, or is not a valid Double type (see DataType.DOUBLE64), the value 0.0 is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Double or 0.0 if the data block does not exist or is not a valid Double type.
- Since:
2.0
-
booleanByTag
final Boolean booleanByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Boolean.
If the block is not found, or is not a valid Boolean type (see DataType.BOOL), the value false is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Boolean or false if the data block does not exist or is not a valid Boolean type.
- Since:
2.0
-
containerByTag
final List<Data> containerByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as DataType.CONTAINER.
If the block is not found, or is not a valid DataType.CONTAINER, an empty list is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as DataType.CONTAINER or an empty list if the data block does not exist or is not a valid DataType.CONTAINER type.
- Since:
2.0
-
stringByTag
final String stringByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as String.
If the block is not found, the empty String is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as String or the empty String if the data block does not exist.
- Since:
2.0
-
instantByTag
final Instant instantByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Instant.
If the block is not found, or is not a valid Instant type (see DataType.TIMESTAMP), Instant.now is returned
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Instant or Instant.now if the data block does not exist or is not of DataType.TIMESTAMP type.
- Since:
2.0
-
durationByTag
final Duration durationByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as Duration.
If the block is not found, or is not a valid Duration type (see DataType.TIMESTAMP), Instant.now is returned
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as Duration or Instant.now if the data block does not exist or is not a DataType.TIMESTAMP type.
- Since:
2.0
-
resultCodeByTag
final ResultCode resultCodeByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as ResultCode.
If the block is not found ResultCode.UNKNOWN is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as ResultCode or ResultCode.UNKNOWN if the data block does not exist.
- Since:
2.0
-
isDataBlockInError
final Boolean isDataBlockInError(Tag tag, Tag containerPath)
Checks whether the data block in the frame is of data type DataType.ERROR.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
true if the data block is of type DataType.ERROR, otherwise false
- Since:
2.1
-
errorCodeByTag
final ErrorCode errorCodeByTag(Tag tag, Tag containerPath)
Searches for a data block of type tag and returns the value as ErrorCode.
If the block is not found ErrorCode.UNKNOWN is returned.
- Parameters:
tag- The Tag to search forcontainerPath- Optional path through datablocks of type DataType.CONTAINER.- Returns:
Value of the data block as ErrorCode or ErrorCode.UNKNOWN if the data block does not exist.
- Since:
2.1
-
isChecksumEnabled
final Boolean isChecksumEnabled()
Query whether the frame calculates the checksum or not.
- Returns:
true wenn ja, ansonsten false
- Since:
2.0
-
-
-
-