Class ConnectionBuilder<T extends ConnectionBuilder<T>>
- java.lang.Object
-
- org.openmuc.jdlms.ConnectionBuilder<T>
-
- Type Parameters:
T
- the concrete connection builder.
- Direct Known Subclasses:
SerialConnectionBuilder
,TcpConnectionBuilder
public abstract class ConnectionBuilder<T extends ConnectionBuilder<T>> extends java.lang.Object
- See Also:
TcpConnectionBuilder
,SerialConnectionBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ConnectionBuilder.SettingsImpl
This Settings can be overridden by an implementing Settings.
-
Constructor Summary
Constructors Constructor Description ConnectionBuilder()
Create a new connection builder, with default settings.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DlmsConnection
build()
Builds a new DLMS/COSEM Connection, which is connected to the remote meter.protected abstract <S extends Settings>
SessionLayerbuildSessionLayer(S settings)
protected abstract Settings
buildSettings()
DlmsSnConnection
buildSnConnection()
Builds a new DLMS/COSEM short name (SN) referencing Connection, which is connected to the remote meter.T
setAlwaysSendSecurityMechanismName(boolean alwaysSendSecurityMechanismName)
If set to true, the Security Mechanism Name is sent even if there is no security mechanismT
setChallengeLength(int challengeLength)
Change the used challenge length.T
setClientId(int clientId)
Set the client ID which should be used to connect to the server.T
setFrameCounter(long frameCounter)
Change the start frame counter (32 Bit unsigned).void
setHdlcMaxInformationLength(int hdlcMaxInformationLength)
Set the maximum HDLC information length.T
setLnToSnMapping(java.util.Collection<SnObjectInfo> lnSnMapping)
Set the LN -> SN mapping, so the connection does not have to retrieve the mapping when opening the SN connection.T
setLogicalDeviceId(int logicalDeviceId)
Set the logical device ID of the logical device in the physical server.T
setPhysicalDeviceAddress(int physicalDeviceAddress)
Sets the physical device address.T
setRawMessageListener(RawMessageListener rawMessageListener)
Set the a RawMessageListener to log the incoming and outgoing messages as byte arrays.T
setReferencingMethod(ReferencingMethod referencingMethod)
Set the referencing method used to address COSEM objects in the remote meter.T
setResponseTimeout(int responseTimeout)
Sets the time in milliseconds the client waits for a response.T
setSecuritySuite(SecuritySuite securitySuite)
SetSecuritySuite
.T
setSkipAARQEncryption(boolean skipAARQEncryption)
If set to true, the AARQ is not encrypted even if the security suite requires it.T
setSnClassInfo(java.util.Collection<SnClassInfo> snClassInfos)
Set the SN class info in order to compute the SN attribute/method offset.T
setSystemTitle(java.lang.String manufacturerId, long deviceId)
Set the client's system title.T
setUserId(int userId)
Set the user ID which should be used to connect to the server.
-
-
-
Method Detail
-
setLnToSnMapping
public T setLnToSnMapping(java.util.Collection<SnObjectInfo> lnSnMapping)
Set the LN -> SN mapping, so the connection does not have to retrieve the mapping when opening the SN connection.Access the mapping of a short name addressing connection with SnObjectInfo.retrieveLnToSnMappingFrom(DlmsConnection).
This also sets the referencing method to short.
- Parameters:
lnSnMapping
- the OBIS code to SN object info map- Returns:
- the ConnectionBuilder
- See Also:
SnObjectInfo.retrieveLnToSnMappingFrom(DlmsConnection)
,setSnClassInfo(Collection)
-
setSnClassInfo
public T setSnClassInfo(java.util.Collection<SnClassInfo> snClassInfos)
Set the SN class info in order to compute the SN attribute/method offset.- Parameters:
snClassInfos
- the class info.- Returns:
- the ConnectionBuilder
-
setReferencingMethod
public T setReferencingMethod(ReferencingMethod referencingMethod)
Set the referencing method used to address COSEM objects in the remote meter.The default referencing method is
ReferencingMethod.LOGICAL
.- Parameters:
referencingMethod
- the referencing method.- Returns:
- the ConnectionBuilder
-
setHdlcMaxInformationLength
public void setHdlcMaxInformationLength(int hdlcMaxInformationLength)
Set the maximum HDLC information length.The information length is in the range of [128, 2030].
- Parameters:
hdlcMaxInformationLength
- the information length in #bytes.
-
setAlwaysSendSecurityMechanismName
public T setAlwaysSendSecurityMechanismName(boolean alwaysSendSecurityMechanismName)
If set to true, the Security Mechanism Name is sent even if there is no security mechanismDefault is false.
- Parameters:
alwaysSendSecurityMechanismName
- the flag- Returns:
- the ConnectionBuilder
-
setSkipAARQEncryption
public T setSkipAARQEncryption(boolean skipAARQEncryption)
If set to true, the AARQ is not encrypted even if the security suite requires it. (Non-standard)Default is false.
- Parameters:
skipAARQEncryption
- the flag- Returns:
- the ConnectionBuilder
-
setSecuritySuite
public T setSecuritySuite(SecuritySuite securitySuite)
SetSecuritySuite
.Default authentication is NONE.
- Parameters:
securitySuite
- authentication object- Returns:
- the ConnectionBuilder
-
setClientId
public T setClientId(int clientId)
Set the client ID which should be used to connect to the server.Default client ID is 16 (Public Client).
- Parameters:
clientId
- the client id.- Returns:
- the ConnectionBuilder
-
setUserId
public T setUserId(int userId)
Set the user ID which should be used to connect to the server.No default user ID
- Parameters:
userId
- the user id.- Returns:
- the ConnectionBuilder
-
setLogicalDeviceId
public T setLogicalDeviceId(int logicalDeviceId)
Set the logical device ID of the logical device in the physical server.Default logical device ID is 1 (Management Logical Device).
- Parameters:
logicalDeviceId
- the logical device ID.- Returns:
- the ConnectionBuilder
-
setChallengeLength
public T setChallengeLength(int challengeLength)
Change the used challenge length.The length must be in the range
[8, 64]
. Default is64
.- Parameters:
challengeLength
- challenge length- Returns:
- the ConnectionBuilder
- Throws:
java.lang.IllegalArgumentException
- if the integer is not in the range[8, 64]
.
-
setFrameCounter
public T setFrameCounter(long frameCounter)
Change the start frame counter (32 Bit unsigned).- Parameters:
frameCounter
- frame counter- Returns:
- the ConnectionBuilder * @throws IllegalArgumentException if the frame counter value is not in the range
[0, 4294967295]
.
-
setPhysicalDeviceAddress
public T setPhysicalDeviceAddress(int physicalDeviceAddress)
Sets the physical device address.This is only relevant if a connection over HDLC is used. In this case the physical device address is by default 0.
- Parameters:
physicalDeviceAddress
- the physical device address.- Returns:
- the ConnectionBuilder
-
setResponseTimeout
public T setResponseTimeout(int responseTimeout)
Sets the time in milliseconds the client waits for a response.- Parameters:
responseTimeout
- time in milliseconds.- Returns:
- the ConnectionBuilder
-
setSystemTitle
public T setSystemTitle(java.lang.String manufacturerId, long deviceId)
Set the client's system title. It consists of 8 bytes: 3 characters for the manufacturer ID and 5 bytes for the device ID. The default is "MMM" (manufacturer ID) and 1 (device ID).- Parameters:
manufacturerId
- the manufacturer IDdeviceId
- the device ID- Returns:
- the ConnectionBuilder
-
setRawMessageListener
public T setRawMessageListener(RawMessageListener rawMessageListener)
Set the a RawMessageListener to log the incoming and outgoing messages as byte arrays.NOTE: listening to the data costs extra computation time.
- Parameters:
rawMessageListener
- the RawMessageListener.- Returns:
- the builder.
- See Also:
RawMessageData
-
build
public DlmsConnection build() throws java.io.IOException
Builds a new DLMS/COSEM Connection, which is connected to the remote meter.- Returns:
- A new
DlmsConnection
with the given settings. - Throws:
java.io.IOException
- if an error occurs, while connecting to the meter.- See Also:
buildSnConnection()
-
buildSnConnection
public DlmsSnConnection buildSnConnection() throws java.io.IOException
Builds a new DLMS/COSEM short name (SN) referencing Connection, which is connected to the remote meter.This also sets the referencing method to short.
- Returns:
- A new
DlmsSnConnection
with the given settings. - Throws:
java.io.IOException
- if an error occurs, while connecting to the meter.- See Also:
build()
-
buildSettings
protected abstract Settings buildSettings()
-
buildSessionLayer
protected abstract <S extends Settings> SessionLayer buildSessionLayer(S settings) throws java.io.IOException
- Throws:
java.io.IOException
-
-