pull/33/merge
Abdelaziz Said 2 years ago committed by GitHub
commit a0b9d04f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,226 +17,266 @@ import com.beanit.asn1bean.ber.types.BerNull;
import com.beanit.iec61850bean.internal.mms.asn1.Data;
import com.beanit.iec61850bean.internal.mms.asn1.TypeDescription;
import com.beanit.iec61850bean.internal.mms.asn1.UtcTime;
import java.time.Instant;
import java.util.Date;
public final class BdaTimestamp extends BasicDataAttribute {
private volatile byte[] value;
public BdaTimestamp(
ObjectReference objectReference, Fc fc, String sAddr, boolean dchg, boolean dupd) {
super(objectReference, fc, sAddr, dchg, dupd);
basicType = BdaType.TIMESTAMP;
setDefault();
}
/**
* The SecondSinceEpoch shall be the interval in seconds continuously counted from the epoch
* 1970-01-01 00:00:00 UTC
*/
/**
* Returns the value as the number of seconds since epoch 1970-01-01 00:00:00 UTC
*
* @return the number of seconds since epoch 1970-01-01 00:00:00 UTC
*/
private long getSecondsSinceEpoch() {
return ((0xffL & value[0]) << 24
| (0xffL & value[1]) << 16
| (0xffL & value[2]) << 8
| (0xffL & value[3]));
}
/**
* The attribute FractionOfSecond shall be the fraction of the current second when the value of
* the TimeStamp has been determined. The fraction of second shall be calculated as <code>
* (SUM from I = 0 to 23 of bi*2**(I+1) s).</code> NOTE 1 The resolution is the smallest unit by
* which the time stamp is updated. The 24 bits of the integer provides 1 out of 16777216 counts
* as the smallest unit; calculated by 1/2**24 which equals approximately 60 ns.
*
* <p>NOTE 2 The resolution of a time stamp may be 1/2**1 (= 0,5 s) if only the first bit is used;
* or may be 1/2**2 (= 0,25 s) if the first two bits are used; or may be approximately 60 ns if
* all 24 bits are used. The resolution provided by an IED is outside the scope of this standard.
*
* @return the fraction of seconds
*/
private int getFractionOfSecond() {
return ((0xff & value[4]) << 16 | (0xff & value[5]) << 8 | (0xff & value[6]));
}
@Override
public void setValueFrom(BasicDataAttribute bda) {
byte[] srcValue = ((BdaTimestamp) bda).getValue();
if (value.length != srcValue.length) {
value = new byte[srcValue.length];
}
System.arraycopy(srcValue, 0, value, 0, srcValue.length);
}
public Instant getInstant() {
if (value == null || value.length == 0) {
return null;
}
long time =
getSecondsSinceEpoch() * 1000L
+ (long) (((float) getFractionOfSecond()) / (1 << 24) * 1000 + 0.5);
return Instant.ofEpochMilli(time);
}
public void setInstant(Instant instant) {
setInstant(instant, true, false, false, 10);
}
public void setInstant(
Instant instant,
boolean leapSecondsKnown,
boolean clockFailure,
boolean clockNotSynchronized,
int timeAccuracy) {
if (value == null) {
value = new byte[8];
}
int secondsSinceEpoch = (int) (instant.toEpochMilli() / 1000L);
int fractionOfSecond = (int) ((instant.toEpochMilli() % 1000L) / 1000.0 * (1 << 24));
int timeQuality = timeAccuracy & 0x1f;
if (leapSecondsKnown) {
timeQuality = timeQuality | 0x80;
}
if (clockFailure) {
timeQuality = timeQuality | 0x40;
}
if (clockNotSynchronized) {
timeQuality = timeQuality | 0x20;
}
value =
new byte[] {
(byte) ((secondsSinceEpoch >> 24) & 0xff),
(byte) ((secondsSinceEpoch >> 16) & 0xff),
(byte) ((secondsSinceEpoch >> 8) & 0xff),
(byte) (secondsSinceEpoch & 0xff),
(byte) ((fractionOfSecond >> 16) & 0xff),
(byte) ((fractionOfSecond >> 8) & 0xff),
(byte) (fractionOfSecond & 0xff),
(byte) timeQuality
};
}
public byte[] getValue() {
return value;
}
public void setValue(byte[] value) {
if (value == null) {
this.value = new byte[8];
}
this.value = value;
}
/**
* The value TRUE of the attribute LeapSecondsKnown shall indicate that the value for
* SecondSinceEpoch takes into account all leap seconds occurred. If it is FALSE then the value
* does not take into account the leap seconds that occurred before the initialization of the time
* source of the device.
*
* @return TRUE of the attribute LeapSecondsKnown shall indicate that the value for
* SecondSinceEpoch takes into account all leap seconds occurred
*/
public boolean getLeapSecondsKnown() {
return ((value[7] & 0x80) != 0);
}
/**
* The attribute clockFailure shall indicate that the time source of the sending device is
* unreliable. The value of the TimeStamp shall be ignored.
*
* @return true if the time source of the sending device is unreliable
*/
public boolean getClockFailure() {
return ((value[7] & 0x40) != 0);
}
/**
* The attribute clockNotSynchronized shall indicate that the time source of the sending device is
* not synchronized with the external UTC time.
*
* @return true if the time source of the sending device is not synchronized
*/
public boolean getClockNotSynchronized() {
return ((value[7] & 0x20) != 0);
}
/**
* The attribute TimeAccuracy shall represent the time accuracy class of the time source of the
* sending device relative to the external UTC time. The timeAccuracy classes shall represent the
* number of significant bits in the FractionOfSecond
*
* <p>If the time is set via Java {@link Date} objects, the accuracy is 1 ms, that is a
* timeAccuracy value of 10.
*
* @return the time accuracy
*/
public int getTimeAccuracy() {
return ((value[7] & 0x1f));
}
/** Sets Timestamp the empty byte array (indicating an invalid Timestamp) */
@Override
public void setDefault() {
value = new byte[8];
}
/** Sets Timestamp to current time */
public void setCurrentTime() {
setInstant(Instant.now());
}
@Override
public BdaTimestamp copy() {
BdaTimestamp copy = new BdaTimestamp(objectReference, fc, sAddr, dchg, dupd);
byte[] valueCopy = new byte[value.length];
System.arraycopy(value, 0, valueCopy, 0, value.length);
copy.setValue(valueCopy);
if (mirror == null) {
copy.mirror = this;
} else {
copy.mirror = mirror;
}
return copy;
}
@Override
Data getMmsDataObj() {
Data data = new Data();
data.setUtcTime(new UtcTime(value));
return data;
}
@Override
void setValueFromMmsDataObj(Data data) throws ServiceError {
if (data.getUtcTime() == null) {
throw new ServiceError(ServiceError.TYPE_CONFLICT, "expected type: utc_time/timestamp");
}
value = data.getUtcTime().value;
}
@Override
TypeDescription getMmsTypeSpec() {
TypeDescription typeDescription = new TypeDescription();
typeDescription.setUtcTime(new BerNull());
return typeDescription;
}
@Override
public String toString() {
return getReference().toString() + ": " + getInstant();
}
@Override
public String getValueString() {
return getInstant().toString();
}
private volatile byte[] value;
public BdaTimestamp(
ObjectReference objectReference, Fc fc, String sAddr, boolean dchg, boolean dupd) {
super(objectReference, fc, sAddr, dchg, dupd);
basicType = BdaType.TIMESTAMP;
setDefault();
}
/**
* The SecondSinceEpoch shall be the interval in seconds continuously counted from the epoch
* 1970-01-01 00:00:00 UTC
*/
/**
* Returns the value as the number of seconds since epoch 1970-01-01 00:00:00 UTC
*
* @return the number of seconds since epoch 1970-01-01 00:00:00 UTC
*/
private long getSecondsSinceEpoch() {
return ((0xffL & value[0]) << 24
| (0xffL & value[1]) << 16
| (0xffL & value[2]) << 8
| (0xffL & value[3]));
}
/**
* The attribute FractionOfSecond shall be the fraction of the current second when the value of
* the TimeStamp has been determined. The fraction of second shall be calculated as <code>
* (SUM from I = 0 to 23 of bi*2**(I+1) s).</code> NOTE 1 The resolution is the smallest unit by
* which the time stamp is updated. The 24 bits of the integer provides 1 out of 16777216 counts
* as the smallest unit; calculated by 1/2**24 which equals approximately 60 ns.
*
* <p>NOTE 2 The resolution of a time stamp may be 1/2**1 (= 0,5 s) if only the first bit is used;
* or may be 1/2**2 (= 0,25 s) if the first two bits are used; or may be approximately 60 ns if
* all 24 bits are used. The resolution provided by an IED is outside the scope of this standard.
*
* @return the fraction of seconds
*/
private int getFractionOfSecond() {
return ((0xff & value[4]) << 16 | (0xff & value[5]) << 8 | (0xff & value[6]));
}
public Date getDate() {
if (value == null || value.length == 0) {
return null;
}
long time =
getSecondsSinceEpoch() * 1000L
+ (long) (((float) getFractionOfSecond()) / (1 << 24) * 1000 + 0.5);
return new Date(time);
}
public void setDate(Date date) {
if (value == null) {
value = new byte[8];
}
int secondsSinceEpoch = (int) (date.getTime() / 1000L);
int fractionOfSecond = (int) ((date.getTime() % 1000L) / 1000.0 * (1 << 24));
// 0x8a = time accuracy of 10 and LeapSecondsKnown = true, ClockFailure
// = false, ClockNotSynchronized = false
value =
new byte[] {
(byte) ((secondsSinceEpoch >> 24) & 0xff),
(byte) ((secondsSinceEpoch >> 16) & 0xff),
(byte) ((secondsSinceEpoch >> 8) & 0xff),
(byte) (secondsSinceEpoch & 0xff),
(byte) ((fractionOfSecond >> 16) & 0xff),
(byte) ((fractionOfSecond >> 8) & 0xff),
(byte) (fractionOfSecond & 0xff),
(byte) 0x8a
};
}
@Override
public void setValueFrom(BasicDataAttribute bda) {
byte[] srcValue = ((BdaTimestamp) bda).getValue();
if (value.length != srcValue.length) {
value = new byte[srcValue.length];
}
System.arraycopy(srcValue, 0, value, 0, srcValue.length);
}
public Instant getInstant() {
if (value == null || value.length == 0) {
return null;
}
long time =
getSecondsSinceEpoch() * 1000L
+ (long) (((float) getFractionOfSecond()) / (1 << 24) * 1000 + 0.5);
return Instant.ofEpochMilli(time);
}
public void setInstant(Instant instant) {
setInstant(instant, true, false, false, 10);
}
public void setInstant(
Instant instant,
boolean leapSecondsKnown,
boolean clockFailure,
boolean clockNotSynchronized,
int timeAccuracy) {
if (value == null) {
value = new byte[8];
}
int secondsSinceEpoch = (int) (instant.toEpochMilli() / 1000L);
int fractionOfSecond = (int) ((instant.toEpochMilli() % 1000L) / 1000.0 * (1 << 24));
int timeQuality = timeAccuracy & 0x1f;
if (leapSecondsKnown) {
timeQuality = timeQuality | 0x80;
}
if (clockFailure) {
timeQuality = timeQuality | 0x40;
}
if (clockNotSynchronized) {
timeQuality = timeQuality | 0x20;
}
value =
new byte[]{
(byte) ((secondsSinceEpoch >> 24) & 0xff),
(byte) ((secondsSinceEpoch >> 16) & 0xff),
(byte) ((secondsSinceEpoch >> 8) & 0xff),
(byte) (secondsSinceEpoch & 0xff),
(byte) ((fractionOfSecond >> 16) & 0xff),
(byte) ((fractionOfSecond >> 8) & 0xff),
(byte) (fractionOfSecond & 0xff),
(byte) timeQuality
};
}
public byte[] getValue() {
return value;
}
public void setValue(byte[] value) {
if (value == null) {
this.value = new byte[8];
}
this.value = value;
}
/**
* The value TRUE of the attribute LeapSecondsKnown shall indicate that the value for
* SecondSinceEpoch takes into account all leap seconds occurred. If it is FALSE then the value
* does not take into account the leap seconds that occurred before the initialization of the time
* source of the device.
*
* @return TRUE of the attribute LeapSecondsKnown shall indicate that the value for
* SecondSinceEpoch takes into account all leap seconds occurred
*/
public boolean getLeapSecondsKnown() {
return ((value[7] & 0x80) != 0);
}
/**
* The attribute clockFailure shall indicate that the time source of the sending device is
* unreliable. The value of the TimeStamp shall be ignored.
*
* @return true if the time source of the sending device is unreliable
*/
public boolean getClockFailure() {
return ((value[7] & 0x40) != 0);
}
/**
* The attribute clockNotSynchronized shall indicate that the time source of the sending device is
* not synchronized with the external UTC time.
*
* @return true if the time source of the sending device is not synchronized
*/
public boolean getClockNotSynchronized() {
return ((value[7] & 0x20) != 0);
}
/**
* The attribute TimeAccuracy shall represent the time accuracy class of the time source of the
* sending device relative to the external UTC time. The timeAccuracy classes shall represent the
* number of significant bits in the FractionOfSecond
*
* <p>If the time is set via Java {@link Date} objects, the accuracy is 1 ms, that is a
* timeAccuracy value of 10.
*
* @return the time accuracy
*/
public int getTimeAccuracy() {
return ((value[7] & 0x1f));
}
/**
* Sets Timestamp the empty byte array (indicating an invalid Timestamp)
*/
@Override
public void setDefault() {
value = new byte[8];
}
/**
* Sets Timestamp to current time
*/
public void setCurrentTime() {
setInstant(Instant.now());
}
@Override
public BdaTimestamp copy() {
BdaTimestamp copy = new BdaTimestamp(objectReference, fc, sAddr, dchg, dupd);
byte[] valueCopy = new byte[value.length];
System.arraycopy(value, 0, valueCopy, 0, value.length);
copy.setValue(valueCopy);
if (mirror == null) {
copy.mirror = this;
} else {
copy.mirror = mirror;
}
return copy;
}
@Override
Data getMmsDataObj() {
Data data = new Data();
data.setUtcTime(new UtcTime(value));
return data;
}
@Override
void setValueFromMmsDataObj(Data data) throws ServiceError {
if (data.getUtcTime() == null) {
throw new ServiceError(ServiceError.TYPE_CONFLICT, "expected type: utc_time/timestamp");
}
value = data.getUtcTime().value;
}
@Override
TypeDescription getMmsTypeSpec() {
TypeDescription typeDescription = new TypeDescription();
typeDescription.setUtcTime(new BerNull());
return typeDescription;
}
@Override
public String toString() {
return getReference().toString() + ": " + getInstant();
}
@Override
public String getValueString() {
return getInstant().toString();
}
}

@ -0,0 +1,148 @@
package com.beanit.iec61850bean;
import java.util.Objects;
public class ConnectionParam {
private String iedName;
private String IP;
private String IP_SUBNET;
private String OSI_AP_Title;
private String OSI_AE_Qualifier;
private String OSI_PSEL;
private String OSI_SSEL;
private String OSI_TSEL;
private String IP_GATEWAY;
private String S_Profile;
private String MAC_Address;
public String getIedName() {
return iedName;
}
public void setIedName(String iedName) {
this.iedName = iedName;
}
public String getIP() {
return IP;
}
public void setIP(String IP) {
this.IP = IP;
}
public String getIP_SUBNET() {
return IP_SUBNET;
}
public void setIP_SUBNET(String IP_SUBNET) {
this.IP_SUBNET = IP_SUBNET;
}
public String getOSI_AP_Title() {
return OSI_AP_Title;
}
public void setOSI_AP_Title(String OSI_AP_Title) {
this.OSI_AP_Title = OSI_AP_Title;
}
public String getOSI_AE_Qualifier() {
return OSI_AE_Qualifier;
}
public void setOSI_AE_Qualifier(String OSI_AE_Qualifier) {
this.OSI_AE_Qualifier = OSI_AE_Qualifier;
}
public String getOSI_PSEL() {
return OSI_PSEL;
}
public void setOSI_PSEL(String OSI_PSEL) {
this.OSI_PSEL = OSI_PSEL;
}
public String getOSI_SSEL() {
return OSI_SSEL;
}
public void setOSI_SSEL(String OSI_SSEL) {
this.OSI_SSEL = OSI_SSEL;
}
public String getOSI_TSEL() {
return OSI_TSEL;
}
public void setOSI_TSEL(String OSI_TSEL) {
this.OSI_TSEL = OSI_TSEL;
}
public String getIP_GATEWAY() {
return IP_GATEWAY;
}
public void setIP_GATEWAY(String IP_GATEWAY) {
this.IP_GATEWAY = IP_GATEWAY;
}
public String getS_Profile() {
return S_Profile;
}
public void setS_Profile(String s_Profile) {
S_Profile = s_Profile;
}
public String getMAC_Address() {
return MAC_Address;
}
public void setMAC_Address(String MAC_Address) {
this.MAC_Address = MAC_Address;
}
@Override
public String toString() {
return "iedName = " + iedName + '\n' +
"IP = " + IP + '\n' +
"IP_SUBNET = " + IP_SUBNET + '\n' +
"OSI_AP_Title = " + OSI_AP_Title + '\n' +
"OSI_AE_Qualifier = " + OSI_AE_Qualifier + '\n' +
"OSI_PSEL = " + OSI_PSEL + '\n' +
"OSI_SSEL = " + OSI_SSEL + '\n' +
"OSI_TSEL = " + OSI_TSEL + '\n' +
"IP_GATEWAY = " + IP_GATEWAY + '\n' +
"S_Profile = " + S_Profile + '\n' +
"MAC-Address = " + MAC_Address
;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConnectionParam that = (ConnectionParam) o;
return iedName.equals(that.iedName) &&
IP.equals(that.IP) &&
Objects.equals(IP_SUBNET, that.IP_SUBNET) &&
Objects.equals(OSI_AP_Title, that.OSI_AP_Title) &&
Objects.equals(OSI_AE_Qualifier, that.OSI_AE_Qualifier) &&
Objects.equals(OSI_PSEL, that.OSI_PSEL) &&
Objects.equals(OSI_SSEL, that.OSI_SSEL) &&
Objects.equals(OSI_TSEL, that.OSI_TSEL) &&
Objects.equals(IP_GATEWAY, that.IP_GATEWAY) &&
Objects.equals(S_Profile, that.S_Profile) &&
Objects.equals(MAC_Address, that.MAC_Address);
}
@Override
public int hashCode() {
return Objects.hash(iedName, IP, IP_SUBNET, OSI_AP_Title, OSI_AE_Qualifier, OSI_PSEL, OSI_SSEL,
OSI_TSEL, IP_GATEWAY, S_Profile, MAC_Address);
}
}

@ -14,6 +14,7 @@
package com.beanit.iec61850bean;
import com.beanit.iec61850bean.internal.mms.asn1.Data;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -30,66 +31,89 @@ import java.util.List;
*/
public class FcDataObject extends FcModelNode {
public FcDataObject(ObjectReference objectReference, Fc fc, List<FcModelNode> children) {
private final List<FcModelNode> fcModelNodes;
private String doType;
private String cdc;
this.children = new LinkedHashMap<>((int) ((children.size() / 0.75) + 1));
this.objectReference = objectReference;
for (ModelNode child : children) {
this.children.put(child.getReference().getName(), child);
child.setParent(this);
}
this.fc = fc;
}
@Override
public FcDataObject copy() {
List<FcModelNode> childCopies = new ArrayList<>(children.size());
for (ModelNode childNode : children.values()) {
childCopies.add((FcModelNode) childNode.copy());
public FcDataObject(ObjectReference objectReference, Fc fc, List<FcModelNode> children) {
this.fcModelNodes = children;
super.setDataAttributes(children);
this.children = new LinkedHashMap<>((int) ((children.size() / 0.75) + 1));
this.objectReference = objectReference;
for (ModelNode child : children) {
this.children.put(child.getReference().getName(), child);
child.setParent(this);
}
this.fc = fc;
}
return new FcDataObject(objectReference, fc, childCopies);
}
@Override
Data getMmsDataObj() {
Data.Structure dataStructure = new Data.Structure();
List<Data> seq = dataStructure.getData();
for (ModelNode modelNode : getChildren()) {
Data child = modelNode.getMmsDataObj();
if (child == null) {
throw new IllegalArgumentException(
"Unable to convert Child: " + modelNode.objectReference + " to MMS Data Object.");
}
seq.add(child);
@Override
public FcDataObject copy() {
List<FcModelNode> childCopies = new ArrayList<>(children.size());
for (ModelNode childNode : children.values()) {
childCopies.add((FcModelNode) childNode.copy());
}
return new FcDataObject(objectReference, fc, childCopies);
}
if (seq.size() == 0) {
throw new IllegalArgumentException(
"Converting ModelNode: "
+ objectReference
+ " to MMS Data Object resulted in Sequence of size zero.");
@Override
Data getMmsDataObj() {
Data.Structure dataStructure = new Data.Structure();
List<Data> seq = dataStructure.getData();
for (ModelNode modelNode : getChildren()) {
Data child = modelNode.getMmsDataObj();
if (child == null) {
throw new IllegalArgumentException(
"Unable to convert Child: " + modelNode.objectReference + " to MMS Data Object.");
}
seq.add(child);
}
if (seq.size() == 0) {
throw new IllegalArgumentException(
"Converting ModelNode: "
+ objectReference
+ " to MMS Data Object resulted in Sequence of size zero.");
}
Data data = new Data();
data.setStructure(dataStructure);
return data;
}
Data data = new Data();
data.setStructure(dataStructure);
@Override
void setValueFromMmsDataObj(Data data) throws ServiceError {
if (data.getStructure() == null) {
throw new ServiceError(ServiceError.TYPE_CONFLICT, "expected type: structure");
}
if (data.getStructure().getData().size() != children.size()) {
throw new ServiceError(
ServiceError.TYPE_CONFLICT,
"expected type: structure with " + children.size() + " elements");
}
Iterator<Data> iterator = data.getStructure().getData().iterator();
for (ModelNode child : children.values()) {
child.setValueFromMmsDataObj(iterator.next());
}
}
return data;
}
public String getDoType() {
return doType;
}
@Override
void setValueFromMmsDataObj(Data data) throws ServiceError {
if (data.getStructure() == null) {
throw new ServiceError(ServiceError.TYPE_CONFLICT, "expected type: structure");
public void setDoType(String doType) {
this.doType = doType;
}
if (data.getStructure().getData().size() != children.size()) {
throw new ServiceError(
ServiceError.TYPE_CONFLICT,
"expected type: structure with " + children.size() + " elements");
public String getCdc() {
return cdc;
}
Iterator<Data> iterator = data.getStructure().getData().iterator();
for (ModelNode child : children.values()) {
child.setValueFromMmsDataObj(iterator.next());
public void setCdc(String cdc) {
this.cdc = cdc;
}
}
}

@ -13,240 +13,373 @@
*/
package com.beanit.iec61850bean;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccess;
import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccessSelection;
import com.beanit.iec61850bean.internal.mms.asn1.*;
import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccessSelection.SelectAccess;
import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccessSelection.SelectAccess.Component;
import com.beanit.iec61850bean.internal.mms.asn1.BasicIdentifier;
import com.beanit.iec61850bean.internal.mms.asn1.Identifier;
import com.beanit.iec61850bean.internal.mms.asn1.ObjectName;
import com.beanit.iec61850bean.internal.mms.asn1.Unsigned32;
import com.beanit.iec61850bean.internal.mms.asn1.VariableDefs;
import com.beanit.iec61850bean.internal.mms.asn1.VariableSpecification;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import static java.nio.charset.StandardCharsets.UTF_8;
public abstract class FcModelNode extends ModelNode {
Fc fc;
private VariableDefs.SEQUENCE variableDef = null;
private ServerAssociation selected = null;
private TimerTask task = null;
Fc fc;
private VariableDefs.SEQUENCE variableDef = null;
private ServerAssociation selected = null;
private TimerTask task = null;
private String daType;
private BdaType basicType = null;
private String sAddr;
private String daiVal;
private boolean dchg;
private boolean dupd;
private boolean qchg;
private String bType;
private List<FcModelNode> bdas;
private short valueShort;
private byte[] valueBytes;
private byte valueByte;
private boolean valueBoolean;
private int valueInt;
private long valueLong;
public Fc getFc() {
return fc;
}
public Fc getFc() {
return fc;
}
boolean select(ServerAssociation association, Timer timer) {
if (selected != null) {
if (selected != association) {
return false;
}
} else {
selected = association;
association.selects.add(this);
}
boolean select(ServerAssociation association, Timer timer) {
if (selected != null) {
if (selected != association) {
return false;
}
} else {
selected = association;
association.selects.add(this);
}
ModelNode sboTimeoutNode =
association.serverModel.findModelNode(objectReference, Fc.CF).getChild("sboTimeout");
ModelNode sboTimeoutNode =
association.serverModel.findModelNode(objectReference, Fc.CF).getChild("sboTimeout");
if (sboTimeoutNode == null) {
return true;
}
if (sboTimeoutNode == null) {
return true;
}
long sboTimeout = ((BdaInt32U) sboTimeoutNode).getValue();
long sboTimeout = ((BdaInt32U) sboTimeoutNode).getValue();
if (sboTimeout == 0) {
return true;
}
if (sboTimeout == 0) {
return true;
}
class SelectResetTask extends TimerTask {
ServerAssociation association;
SelectResetTask(ServerAssociation association) {
this.association = association;
}
@Override
public void run() {
synchronized (association.serverModel) {
if (task == this) {
task = null;
deselectAndRemove(association);
}
}
}
}
class SelectResetTask extends TimerTask {
ServerAssociation association;
if (task != null) {
task.cancel();
}
SelectResetTask(ServerAssociation association) {
this.association = association;
}
task = new SelectResetTask(association);
timer.schedule(task, sboTimeout);
return true;
}
@Override
public void run() {
synchronized (association.serverModel) {
if (task == this) {
void deselectAndRemove(ServerAssociation association) {
selected = null;
if (task != null) {
task.cancel();
task = null;
deselectAndRemove(association);
}
}
}
association.selects.remove(this);
}
if (task != null) {
task.cancel();
void deselect() {
selected = null;
if (task != null) {
task.cancel();
task = null;
}
}
task = new SelectResetTask(association);
timer.schedule(task, sboTimeout);
return true;
}
void deselectAndRemove(ServerAssociation association) {
selected = null;
if (task != null) {
task.cancel();
task = null;
boolean isSelected() {
return selected != null;
}
association.selects.remove(this);
}
void deselect() {
selected = null;
if (task != null) {
task.cancel();
task = null;
boolean isSelectedBy(ServerAssociation association) {
return selected == association;
}
}
boolean isSelected() {
return selected != null;
}
VariableDefs.SEQUENCE getMmsVariableDef() {
if (variableDef != null) {
return variableDef;
}
boolean isSelectedBy(ServerAssociation association) {
return selected == association;
}
AlternateAccess alternateAccess = null;
VariableDefs.SEQUENCE getMmsVariableDef() {
StringBuilder preArrayIndexItemId = new StringBuilder(objectReference.get(1));
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(fc);
if (variableDef != null) {
return variableDef;
}
int arrayIndexPosition = objectReference.getArrayIndexPosition();
if (arrayIndexPosition != -1) {
AlternateAccess alternateAccess = null;
for (int i = 2; i < arrayIndexPosition; i++) {
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(objectReference.get(i));
}
StringBuilder preArrayIndexItemId = new StringBuilder(objectReference.get(1));
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(fc);
alternateAccess = new AlternateAccess();
List<AlternateAccess.CHOICE> subSeqOfAlternateAccess = alternateAccess.getCHOICE();
Unsigned32 indexBerInteger =
new Unsigned32(Integer.parseInt(objectReference.get(arrayIndexPosition)));
int arrayIndexPosition = objectReference.getArrayIndexPosition();
if (arrayIndexPosition != -1) {
if (arrayIndexPosition < (objectReference.size() - 1)) {
// this reference points to a sub-node of an array element
for (int i = 2; i < arrayIndexPosition; i++) {
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(objectReference.get(i));
}
StringBuilder postArrayIndexItemId =
new StringBuilder(objectReference.get(arrayIndexPosition + 1));
for (int i = (arrayIndexPosition + 2); i < objectReference.size(); i++) {
postArrayIndexItemId.append("$");
postArrayIndexItemId.append(objectReference.get(i));
}
BasicIdentifier subIndexReference =
new BasicIdentifier(postArrayIndexItemId.toString().getBytes(UTF_8));
AlternateAccessSelection.SelectAccess subIndexReferenceSelectAccess =
new AlternateAccessSelection.SelectAccess();
Component component = new Component();
component.setBasic(subIndexReference);
subIndexReferenceSelectAccess.setComponent(component);
AlternateAccessSelection subIndexReferenceAlternateAccessSelection =
new AlternateAccessSelection();
subIndexReferenceAlternateAccessSelection.setSelectAccess(subIndexReferenceSelectAccess);
AlternateAccess.CHOICE subIndexReferenceAlternateAccessSubChoice =
new AlternateAccess.CHOICE();
subIndexReferenceAlternateAccessSubChoice.setUnnamed(
subIndexReferenceAlternateAccessSelection);
AlternateAccess subIndexReferenceAlternateAccess = new AlternateAccess();
List<AlternateAccess.CHOICE> subIndexReferenceAlternateAccessSubSeqOf =
subIndexReferenceAlternateAccess.getCHOICE();
subIndexReferenceAlternateAccessSubSeqOf.add(subIndexReferenceAlternateAccessSubChoice);
// set array index:
AlternateAccessSelection.SelectAlternateAccess.AccessSelection indexAccessSelectionChoice =
new AlternateAccessSelection.SelectAlternateAccess.AccessSelection();
indexAccessSelectionChoice.setIndex(indexBerInteger);
AlternateAccessSelection.SelectAlternateAccess indexAndLowerReferenceSelectAlternateAccess =
new AlternateAccessSelection.SelectAlternateAccess();
indexAndLowerReferenceSelectAlternateAccess.setAccessSelection(indexAccessSelectionChoice);
indexAndLowerReferenceSelectAlternateAccess.setAlternateAccess(
subIndexReferenceAlternateAccess);
AlternateAccessSelection indexAndLowerReferenceAlternateAccessSelection =
new AlternateAccessSelection();
indexAndLowerReferenceAlternateAccessSelection.setSelectAlternateAccess(
indexAndLowerReferenceSelectAlternateAccess);
AlternateAccess.CHOICE indexAndLowerReferenceAlternateAccessChoice =
new AlternateAccess.CHOICE();
indexAndLowerReferenceAlternateAccessChoice.setUnnamed(
indexAndLowerReferenceAlternateAccessSelection);
subSeqOfAlternateAccess.add(indexAndLowerReferenceAlternateAccessChoice);
} else {
SelectAccess selectAccess = new SelectAccess();
selectAccess.setIndex(indexBerInteger);
AlternateAccessSelection alternateAccessSelection = new AlternateAccessSelection();
alternateAccessSelection.setSelectAccess(selectAccess);
AlternateAccess.CHOICE alternateAccessChoice = new AlternateAccess.CHOICE();
alternateAccessChoice.setUnnamed(alternateAccessSelection);
subSeqOfAlternateAccess.add(alternateAccessChoice);
}
alternateAccess = new AlternateAccess();
List<AlternateAccess.CHOICE> subSeqOfAlternateAccess = alternateAccess.getCHOICE();
Unsigned32 indexBerInteger =
new Unsigned32(Integer.parseInt(objectReference.get(arrayIndexPosition)));
} else {
if (arrayIndexPosition < (objectReference.size() - 1)) {
// this reference points to a sub-node of an array element
for (int i = 2; i < objectReference.size(); i++) {
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(objectReference.get(i));
}
}
ObjectName.DomainSpecific domainSpecificObjectName = new ObjectName.DomainSpecific();
domainSpecificObjectName.setDomainID(new Identifier(objectReference.get(0).getBytes(UTF_8)));
domainSpecificObjectName.setItemID(
new Identifier(preArrayIndexItemId.toString().getBytes(UTF_8)));
ObjectName objectName = new ObjectName();
objectName.setDomainSpecific(domainSpecificObjectName);
StringBuilder postArrayIndexItemId =
new StringBuilder(objectReference.get(arrayIndexPosition + 1));
VariableSpecification varSpec = new VariableSpecification();
varSpec.setName(objectName);
variableDef = new VariableDefs.SEQUENCE();
variableDef.setAlternateAccess(alternateAccess);
variableDef.setVariableSpecification(varSpec);
return variableDef;
}
for (int i = (arrayIndexPosition + 2); i < objectReference.size(); i++) {
postArrayIndexItemId.append("$");
postArrayIndexItemId.append(objectReference.get(i));
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getReference().toString()).append(" [").append(fc).append("]");
for (ModelNode childNode : children.values()) {
sb.append("\n");
sb.append(childNode.toString());
}
return sb.toString();
}
BasicIdentifier subIndexReference =
new BasicIdentifier(postArrayIndexItemId.toString().getBytes(UTF_8));
public String getDaType() {
return daType;
}
AlternateAccessSelection.SelectAccess subIndexReferenceSelectAccess =
new AlternateAccessSelection.SelectAccess();
Component component = new Component();
component.setBasic(subIndexReference);
subIndexReferenceSelectAccess.setComponent(component);
public void setDaType(String daType) {
this.daType = daType;
}
public BdaType getBasicType() {
return basicType;
}
public void setBasicType(BdaType basicType) {
this.basicType = basicType;
}
public String getsAddr() {
return sAddr;
}
public void setsAddr(String sAddr) {
this.sAddr = sAddr;
}
public String getDaiVal() {
return daiVal;
}
public void setDaiVal(String daiVal) {
this.daiVal = daiVal;
}
AlternateAccessSelection subIndexReferenceAlternateAccessSelection =
new AlternateAccessSelection();
subIndexReferenceAlternateAccessSelection.setSelectAccess(subIndexReferenceSelectAccess);
public boolean isDchg() {
return dchg;
}
AlternateAccess.CHOICE subIndexReferenceAlternateAccessSubChoice =
new AlternateAccess.CHOICE();
subIndexReferenceAlternateAccessSubChoice.setUnnamed(
subIndexReferenceAlternateAccessSelection);
public void setDchg(boolean dchg) {
this.dchg = dchg;
}
AlternateAccess subIndexReferenceAlternateAccess = new AlternateAccess();
public boolean isDupd() {
return dupd;
}
List<AlternateAccess.CHOICE> subIndexReferenceAlternateAccessSubSeqOf =
subIndexReferenceAlternateAccess.getCHOICE();
subIndexReferenceAlternateAccessSubSeqOf.add(subIndexReferenceAlternateAccessSubChoice);
public void setDupd(boolean dupd) {
this.dupd = dupd;
}
// set array index:
public boolean isQchg() {
return qchg;
}
AlternateAccessSelection.SelectAlternateAccess.AccessSelection indexAccessSelectionChoice =
new AlternateAccessSelection.SelectAlternateAccess.AccessSelection();
indexAccessSelectionChoice.setIndex(indexBerInteger);
public void setQchg(boolean qchg) {
this.qchg = qchg;
}
AlternateAccessSelection.SelectAlternateAccess indexAndLowerReferenceSelectAlternateAccess =
new AlternateAccessSelection.SelectAlternateAccess();
indexAndLowerReferenceSelectAlternateAccess.setAccessSelection(indexAccessSelectionChoice);
indexAndLowerReferenceSelectAlternateAccess.setAlternateAccess(
subIndexReferenceAlternateAccess);
public String getbType() {
return bType;
}
AlternateAccessSelection indexAndLowerReferenceAlternateAccessSelection =
new AlternateAccessSelection();
indexAndLowerReferenceAlternateAccessSelection.setSelectAlternateAccess(
indexAndLowerReferenceSelectAlternateAccess);
public void setbType(String bType) {
this.bType = bType;
}
AlternateAccess.CHOICE indexAndLowerReferenceAlternateAccessChoice =
new AlternateAccess.CHOICE();
indexAndLowerReferenceAlternateAccessChoice.setUnnamed(
indexAndLowerReferenceAlternateAccessSelection);
public List<FcModelNode> getDataAttributes() {
return bdas;
}
subSeqOfAlternateAccess.add(indexAndLowerReferenceAlternateAccessChoice);
public FcModelNode setDataAttributes(List<FcModelNode> bdas) {
this.bdas = bdas;
return this;
}
} else {
SelectAccess selectAccess = new SelectAccess();
selectAccess.setIndex(indexBerInteger);
public short getValueShort() {
return valueShort;
}
AlternateAccessSelection alternateAccessSelection = new AlternateAccessSelection();
alternateAccessSelection.setSelectAccess(selectAccess);
public void setValueShort(short valueShort) {
this.valueShort = valueShort;
}
AlternateAccess.CHOICE alternateAccessChoice = new AlternateAccess.CHOICE();
alternateAccessChoice.setUnnamed(alternateAccessSelection);
public byte[] getValueBytes() {
return valueBytes;
}
subSeqOfAlternateAccess.add(alternateAccessChoice);
}
public void setValueBytes(byte[] valueBytes) {
this.valueBytes = valueBytes;
}
} else {
public byte getValueByte() {
return valueByte;
}
for (int i = 2; i < objectReference.size(); i++) {
preArrayIndexItemId.append("$");
preArrayIndexItemId.append(objectReference.get(i));
}
public void setValueByte(byte valueByte) {
this.valueByte = valueByte;
}
ObjectName.DomainSpecific domainSpecificObjectName = new ObjectName.DomainSpecific();
domainSpecificObjectName.setDomainID(new Identifier(objectReference.get(0).getBytes(UTF_8)));
domainSpecificObjectName.setItemID(
new Identifier(preArrayIndexItemId.toString().getBytes(UTF_8)));
public boolean isValueBoolean() {
return valueBoolean;
}
ObjectName objectName = new ObjectName();
objectName.setDomainSpecific(domainSpecificObjectName);
public void setValueBoolean(boolean valueBoolean) {
this.valueBoolean = valueBoolean;
}
VariableSpecification varSpec = new VariableSpecification();
varSpec.setName(objectName);
public int getValueInt() {
return valueInt;
}
variableDef = new VariableDefs.SEQUENCE();
variableDef.setAlternateAccess(alternateAccess);
variableDef.setVariableSpecification(varSpec);
public void setValueInt(int valueInt) {
this.valueInt = valueInt;
}
return variableDef;
}
public long getValueLong() {
return valueLong;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getReference().toString()).append(" [").append(fc).append("]");
for (ModelNode childNode : children.values()) {
sb.append("\n");
sb.append(childNode.toString());
public void setValueLong(long valueLong) {
this.valueLong = valueLong;
}
return sb.toString();
}
}

@ -19,7 +19,11 @@ import java.util.List;
public final class LogicalDevice extends ModelNode {
private final List<LogicalNode> logicalNodes;
private String ldInst;
public LogicalDevice(ObjectReference objectReference, List<LogicalNode> logicalNodes) {
this.logicalNodes = logicalNodes;
children = new LinkedHashMap<>((int) ((logicalNodes.size() / 0.75) + 1));
this.objectReference = objectReference;
for (LogicalNode logicalNode : logicalNodes) {
@ -36,4 +40,16 @@ public final class LogicalDevice extends ModelNode {
}
return new LogicalDevice(objectReference, childCopies);
}
public List<LogicalNode> getLogicalNodes() {
return logicalNodes;
}
public String getLdInst() {
return ldInst;
}
public void setLdInst(String ldInst) {
this.ldInst = ldInst;
}
}

@ -28,7 +28,14 @@ public final class LogicalNode extends ModelNode {
private final Map<String, Urcb> urcbs = new HashMap<>();
private final Map<String, Brcb> brcbs = new HashMap<>();
private final List<FcDataObject> dataObjects;
private String prefix;
private String lnClass;
private String lnInst;
private String lnType;
public LogicalNode(ObjectReference objectReference, List<FcDataObject> fcDataObjects) {
this.dataObjects = fcDataObjects;
children = new LinkedHashMap<>();
for (Fc fc : Fc.values()) {
this.fcDataObjects.put(fc, new LinkedHashMap<String, FcDataObject>());
@ -59,8 +66,7 @@ public final class LogicalNode extends ModelNode {
dataObjectsCopy.add((FcDataObject) obj.copy());
}
LogicalNode copy = new LogicalNode(objectReference, dataObjectsCopy);
return copy;
return new LogicalNode(objectReference, dataObjectsCopy);
}
public List<FcDataObject> getChildren(Fc fc) {
@ -134,4 +140,36 @@ public final class LogicalNode extends ModelNode {
}
return sb.toString();
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getLnClass() {
return lnClass;
}
public void setLnClass(String lnClass) {
this.lnClass = lnClass;
}
public String getLnInst() {
return lnInst;
}
public void setLnInst(String lnInst) {
this.lnInst = lnInst;
}
public String getLnType() {
return lnType;
}
public void setLnType(String lnType) {
this.lnType = lnType;
}
}

File diff suppressed because it is too large Load Diff

@ -17,384 +17,488 @@ import com.beanit.iec61850bean.internal.mms.asn1.AlternateAccessSelection;
import com.beanit.iec61850bean.internal.mms.asn1.ObjectName;
import com.beanit.iec61850bean.internal.mms.asn1.ObjectName.DomainSpecific;
import com.beanit.iec61850bean.internal.mms.asn1.VariableDefs;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public final class ServerModel extends ModelNode {
private final Map<String, DataSet> dataSets = new LinkedHashMap<>();
private final Map<String, DataSet> dataSets = new LinkedHashMap<>();
private final Map<String, Urcb> urcbs = new HashMap<>();
private final Map<String, Brcb> brcbs = new HashMap<>();
private ConnectionParam connectionParam;
private String iedName;
private String iedManufacturer;
private List<String> ldsInsts;
private List<String> ldsRefs;
private List<String> lnsRefs;
private Map<String, Set<String>> lns;
private HashSet<String> lnS;
private Map<String, String> descriptions;
private Map<String,String> dAIDescriptions;
private Map<String, String> dos;
private List<LogicalDevice> logicalDevices;
public ServerModel(List<LogicalDevice> logicalDevices, Collection<DataSet> dataSets) {
children = new LinkedHashMap<>();
objectReference = null;
for (LogicalDevice logicalDevice : logicalDevices) {
children.put(logicalDevice.getReference().getName(), logicalDevice);
logicalDevice.setParent(this);
}
if (dataSets != null) {
addDataSets(dataSets);
}
for (LogicalDevice ld : logicalDevices) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcbs.put(urcb.getReference().toString(), urcb);
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcbs.put(brcb.getReference().toString(), brcb);
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
}
}
}
}
private final Map<String, Urcb> urcbs = new HashMap<>();
private final Map<String, Brcb> brcbs = new HashMap<>();
@Override
public ServerModel copy() {
List<LogicalDevice> childCopies = new ArrayList<>(children.size());
for (ModelNode childNode : children.values()) {
childCopies.add((LogicalDevice) childNode.copy());
}
List<DataSet> dataSetCopies = new ArrayList<>(dataSets.size());
for (DataSet dataSet : dataSets.values()) {
dataSetCopies.add(dataSet);
}
return new ServerModel(childCopies, dataSetCopies);
}
/**
* Get the data set with the given reference. Return null if none is found.
*
* @param reference the reference of the requested data set.
* @return the data set with the given reference.
*/
public DataSet getDataSet(String reference) {
return dataSets.get(reference);
}
void addDataSet(DataSet dataSet) {
dataSets.put(dataSet.getReferenceStr().replace('$', '.'), dataSet);
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
}
}
}
}
void addDataSets(Collection<DataSet> dataSets) {
for (DataSet dataSet : dataSets) {
addDataSet(dataSet);
}
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
}
}
}
}
public ServerModel(List<LogicalDevice> logicalDevices, Collection<DataSet> dataSets) {
children = new LinkedHashMap<>();
objectReference = null;
for (LogicalDevice logicalDevice : logicalDevices) {
children.put(logicalDevice.getReference().getName(), logicalDevice);
logicalDevice.setParent(this);
List<String> getDataSetNames(String ldName) {
// TODO make thread save
List<String> dataSetNames = new ArrayList<>();
for (String dataSetRef : dataSets.keySet()) {
if (dataSetRef.startsWith(ldName)) {
dataSetNames.add(dataSetRef.substring(dataSetRef.indexOf('/') + 1).replace('.', '$'));
}
}
return dataSetNames;
}
if (dataSets != null) {
addDataSets(dataSets);
/**
* Get a collection of all data sets that exist in this model.
*
* @return a collection of all data sets
*/
public Collection<DataSet> getDataSets() {
return dataSets.values();
}
for (LogicalDevice ld : logicalDevices) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcbs.put(urcb.getReference().toString(), urcb);
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
/**
* @param dataSetReference the data set reference
* @return returns the DataSet that was removed, null if no DataSet with the given reference was
* found or the data set is not deletable.
*/
DataSet removeDataSet(String dataSetReference) {
DataSet dataSet = dataSets.get(dataSetReference);
if (dataSet == null || !dataSet.isDeletable()) {
return null;
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcbs.put(brcb.getReference().toString(), brcb);
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
DataSet removedDataSet = dataSets.remove(dataSetReference);
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
}
}
}
}
return removedDataSet;
}
void addUrcb(Urcb urcb) {
urcbs.put(urcb.getReference().getName(), urcb);
}
}
@Override
public ServerModel copy() {
List<LogicalDevice> childCopies = new ArrayList<>(children.size());
for (ModelNode childNode : children.values()) {
childCopies.add((LogicalDevice) childNode.copy());
/**
* Get the unbuffered report control block (URCB) with the given reference.
*
* @param reference the reference of the requested URCB.
* @return the reference to the requested URCB or null if none with the given reference is found.
*/
public Urcb getUrcb(String reference) {
return urcbs.get(reference);
}
List<DataSet> dataSetCopies = new ArrayList<>(dataSets.size());
for (DataSet dataSet : dataSets.values()) {
dataSetCopies.add(dataSet);
/**
* Get a collection of all unbuffered report control blocks (URCB) that exist in this model.
*
* @return a collection of all unbuffered report control blocks (URCB)
*/
public Collection<Urcb> getUrcbs() {
return urcbs.values();
}
return new ServerModel(childCopies, dataSetCopies);
}
/**
* Get the buffered report control block (BRCB) with the given reference.
*
* @param reference the reference of the requested BRCB.
* @return the reference to the requested BRCB or null if none with the given reference is found.
*/
public Brcb getBrcb(String reference) {
return brcbs.get(reference);
}
/**
* Get the data set with the given reference. Return null if none is found.
*
* @param reference the reference of the requested data set.
* @return the data set with the given reference.
*/
public DataSet getDataSet(String reference) {
return dataSets.get(reference);
}
/**
* Get a collection of all buffered report control blocks (BRCB) that exist in this model.
*
* @return a collection of all buffered report control blocks (BRCB)
*/
public Collection<Brcb> getBrcbs() {
return brcbs.values();
}
void addDataSet(DataSet dataSet) {
dataSets.put(dataSet.getReferenceStr().replace('$', '.'), dataSet);
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (ModelNode logicalDevice : children.values()) {
sb.append(logicalDevice.toString());
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
sb.append("\n\n\n---------------------\nURCBs:");
for (Urcb urcb : getUrcbs()) {
sb.append("\n\n").append(urcb);
}
}
sb.append("\n\n\n---------------------\nBRCBs:");
for (Brcb brcb : getBrcbs()) {
sb.append("\n\n").append(brcb);
}
sb.append("\n\n\n---------------------\nData sets:");
for (DataSet dataSet : getDataSets()) {
sb.append("\n\n").append(dataSet);
}
return sb.toString();
}
/**
* Searches and returns the model node with the given object reference and FC. If searching for
* Logical Devices and Logical Nodes the given fc parameter may be <code>null</code>.
*
* @param objectReference the object reference of the node that is being searched for. It has a
* syntax like "ldname/ln.do....".
* @param fc the functional constraint of the requested model node. May be null for Logical Device
* and Logical Node references.
* @return the model node if it was found or null otherwise
*/
public ModelNode findModelNode(ObjectReference objectReference, Fc fc) {
ModelNode currentNode = this;
Iterator<String> searchedNodeReferenceIterator = objectReference.iterator();
while (searchedNodeReferenceIterator.hasNext()) {
currentNode = currentNode.getChild(searchedNodeReferenceIterator.next(), fc);
if (currentNode == null) {
return null;
}
}
return currentNode;
}
}
void addDataSets(Collection<DataSet> dataSets) {
for (DataSet dataSet : dataSets) {
addDataSet(dataSet);
/**
* Searches and returns the model node with the given object reference and FC. If searching for
* Logical Devices and Logical Nodes the given fc parameter may be <code>null</code>.
*
* @param objectReference the object reference of the node that is being searched for. It has a
* syntax like "ldname/ln.do....".
* @param fc the functional constraint of the requested model node. May be null for Logical Device
* and Logical Node references.
* @return the model node if it was found or null otherwise
*/
public ModelNode findModelNode(String objectReference, Fc fc) {
return findModelNode(new ObjectReference(objectReference), fc);
}
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
/**
* Returns the subModelNode that is referenced by the given VariableDef. Return null in case the
* referenced ModelNode is not found.
*
* @param variableDef the variableDef
* @return the subModelNode that is referenced by the given VariableDef
* @throws ServiceError if an error occurs
*/
FcModelNode getNodeFromVariableDef(VariableDefs.SEQUENCE variableDef) throws ServiceError {
ObjectName objectName = variableDef.getVariableSpecification().getName();
if (objectName == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"name in objectName is not selected");
}
DomainSpecific domainSpecific = objectName.getDomainSpecific();
if (domainSpecific == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"domain_specific in name is not selected");
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
ModelNode modelNode = getChild(domainSpecific.getDomainID().toString());
if (modelNode == null) {
return null;
}
String mmsItemId = domainSpecific.getItemID().toString();
int index1 = mmsItemId.indexOf('$');
if (index1 == -1) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"invalid mms item id: " + domainSpecific.getItemID());
}
}
}
}
List<String> getDataSetNames(String ldName) {
// TODO make thread save
List<String> dataSetNames = new ArrayList<>();
for (String dataSetRef : dataSets.keySet()) {
if (dataSetRef.startsWith(ldName)) {
dataSetNames.add(dataSetRef.substring(dataSetRef.indexOf('/') + 1).replace('.', '$'));
}
}
return dataSetNames;
}
/**
* Get a collection of all data sets that exist in this model.
*
* @return a collection of all data sets
*/
public Collection<DataSet> getDataSets() {
return dataSets.values();
}
/**
* @param dataSetReference the data set reference
* @return returns the DataSet that was removed, null if no DataSet with the given reference was
* found or the data set is not deletable.
*/
DataSet removeDataSet(String dataSetReference) {
DataSet dataSet = dataSets.get(dataSetReference);
if (dataSet == null || !dataSet.isDeletable()) {
return null;
}
DataSet removedDataSet = dataSets.remove(dataSetReference);
for (ModelNode ld : children.values()) {
for (ModelNode ln : ld.getChildren()) {
for (Urcb urcb : ((LogicalNode) ln).getUrcbs()) {
urcb.dataSet = getDataSet(urcb.getDatSet().getStringValue().replace('$', '.'));
LogicalNode ln = (LogicalNode) modelNode.getChild(mmsItemId.substring(0, index1));
if (ln == null) {
return null;
}
for (Brcb brcb : ((LogicalNode) ln).getBrcbs()) {
brcb.dataSet = getDataSet(brcb.getDatSet().getStringValue().replace('$', '.'));
int index2 = mmsItemId.indexOf('$', index1 + 1);
if (index2 == -1) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT, "invalid mms item id");
}
}
}
return removedDataSet;
}
void addUrcb(Urcb urcb) {
urcbs.put(urcb.getReference().getName(), urcb);
}
/**
* Get the unbuffered report control block (URCB) with the given reference.
*
* @param reference the reference of the requested URCB.
* @return the reference to the requested URCB or null if none with the given reference is found.
*/
public Urcb getUrcb(String reference) {
return urcbs.get(reference);
}
/**
* Get a collection of all unbuffered report control blocks (URCB) that exist in this model.
*
* @return a collection of all unbuffered report control blocks (URCB)
*/
public Collection<Urcb> getUrcbs() {
return urcbs.values();
}
/**
* Get the buffered report control block (BRCB) with the given reference.
*
* @param reference the reference of the requested BRCB.
* @return the reference to the requested BRCB or null if none with the given reference is found.
*/
public Brcb getBrcb(String reference) {
return brcbs.get(reference);
}
/**
* Get a collection of all buffered report control blocks (BRCB) that exist in this model.
*
* @return a collection of all buffered report control blocks (BRCB)
*/
public Collection<Brcb> getBrcbs() {
return brcbs.values();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (ModelNode logicalDevice : children.values()) {
sb.append(logicalDevice.toString());
}
sb.append("\n\n\n---------------------\nURCBs:");
for (Urcb urcb : getUrcbs()) {
sb.append("\n\n").append(urcb);
}
sb.append("\n\n\n---------------------\nBRCBs:");
for (Brcb brcb : getBrcbs()) {
sb.append("\n\n").append(brcb);
}
sb.append("\n\n\n---------------------\nData sets:");
for (DataSet dataSet : getDataSets()) {
sb.append("\n\n").append(dataSet);
}
return sb.toString();
}
/**
* Searches and returns the model node with the given object reference and FC. If searching for
* Logical Devices and Logical Nodes the given fc parameter may be <code>null</code>.
*
* @param objectReference the object reference of the node that is being searched for. It has a
* syntax like "ldname/ln.do....".
* @param fc the functional constraint of the requested model node. May be null for Logical Device
* and Logical Node references.
* @return the model node if it was found or null otherwise
*/
public ModelNode findModelNode(ObjectReference objectReference, Fc fc) {
ModelNode currentNode = this;
Iterator<String> searchedNodeReferenceIterator = objectReference.iterator();
Fc fc = Fc.fromString(mmsItemId.substring(index1 + 1, index2));
while (searchedNodeReferenceIterator.hasNext()) {
currentNode = currentNode.getChild(searchedNodeReferenceIterator.next(), fc);
if (currentNode == null) {
return null;
}
}
return currentNode;
}
if (fc == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"unknown functional constraint: " + mmsItemId.substring(index1 + 1, index2));
}
/**
* Searches and returns the model node with the given object reference and FC. If searching for
* Logical Devices and Logical Nodes the given fc parameter may be <code>null</code>.
*
* @param objectReference the object reference of the node that is being searched for. It has a
* syntax like "ldname/ln.do....".
* @param fc the functional constraint of the requested model node. May be null for Logical Device
* and Logical Node references.
* @return the model node if it was found or null otherwise
*/
public ModelNode findModelNode(String objectReference, Fc fc) {
return findModelNode(new ObjectReference(objectReference), fc);
}
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
if (index2 == -1) {
if (fc == Fc.RP) {
return ln.getUrcb(mmsItemId.substring(index1 + 1));
}
if (fc == Fc.BR) {
return ln.getBrcb(mmsItemId.substring(index1 + 1));
}
return (FcModelNode) ln.getChild(mmsItemId.substring(index1 + 1), fc);
}
if (fc == Fc.RP) {
modelNode = ln.getUrcb(mmsItemId.substring(index1 + 1, index2));
} else if (fc == Fc.BR) {
modelNode = ln.getBrcb(mmsItemId.substring(index1 + 1, index2));
} else {
modelNode = ln.getChild(mmsItemId.substring(index1 + 1, index2), fc);
}
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
while (index2 != -1) {
modelNode = modelNode.getChild(mmsItemId.substring(index1 + 1, index2));
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
}
/**
* Returns the subModelNode that is referenced by the given VariableDef. Return null in case the
* referenced ModelNode is not found.
*
* @param variableDef the variableDef
* @return the subModelNode that is referenced by the given VariableDef
* @throws ServiceError if an error occurs
*/
FcModelNode getNodeFromVariableDef(VariableDefs.SEQUENCE variableDef) throws ServiceError {
modelNode = modelNode.getChild(mmsItemId.substring(index1 + 1));
ObjectName objectName = variableDef.getVariableSpecification().getName();
if (variableDef.getAlternateAccess() == null) {
// no array is in this node path
return (FcModelNode) modelNode;
}
if (objectName == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"name in objectName is not selected");
AlternateAccessSelection altAccIt =
variableDef.getAlternateAccess().getCHOICE().get(0).getUnnamed();
if (altAccIt.getSelectAlternateAccess() != null) {
// path to node below an array element
modelNode =
((Array) modelNode)
.getChild(
altAccIt.getSelectAlternateAccess().getAccessSelection().getIndex().intValue());
String mmsSubArrayItemId =
altAccIt
.getSelectAlternateAccess()
.getAlternateAccess()
.getCHOICE()
.get(0)
.getUnnamed()
.getSelectAccess()
.getComponent()
.getBasic()
.toString();
index1 = -1;
index2 = mmsSubArrayItemId.indexOf('$');
while (index2 != -1) {
modelNode = modelNode.getChild(mmsSubArrayItemId.substring(index1 + 1, index2));
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
}
return (FcModelNode) modelNode.getChild(mmsSubArrayItemId.substring(index1 + 1));
} else {
// path to an array element
return (FcModelNode)
((Array) modelNode).getChild(altAccIt.getSelectAccess().getIndex().intValue());
}
}
DomainSpecific domainSpecific = objectName.getDomainSpecific();
public ConnectionParam getConnectionParam() {
return connectionParam;
}
if (domainSpecific == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"domain_specific in name is not selected");
public void setConnectionParam(ConnectionParam connectionParam) {
this.connectionParam = connectionParam;
}
ModelNode modelNode = getChild(domainSpecific.getDomainID().toString());
public String getIedName() {
return iedName;
}
if (modelNode == null) {
return null;
public void setIedName(String iedName) {
this.iedName = iedName;
}
String mmsItemId = domainSpecific.getItemID().toString();
int index1 = mmsItemId.indexOf('$');
public String getIedManufacturer() {
return iedManufacturer;
}
if (index1 == -1) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"invalid mms item id: " + domainSpecific.getItemID());
public void setIedManufacturer(String iedManufacturer) {
this.iedManufacturer = iedManufacturer;
}
LogicalNode ln = (LogicalNode) modelNode.getChild(mmsItemId.substring(0, index1));
public List<String> getLdsInsts() {
return ldsInsts;
}
if (ln == null) {
return null;
public void setLdsInsts(List<String> ldsInsts) {
this.ldsInsts = ldsInsts;
}
int index2 = mmsItemId.indexOf('$', index1 + 1);
public List<String> getLdsRefs() {
return ldsRefs;
}
if (index2 == -1) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT, "invalid mms item id");
public void setLdsRefs(List<String> ldsRefs) {
this.ldsRefs = ldsRefs;
}
Fc fc = Fc.fromString(mmsItemId.substring(index1 + 1, index2));
public List<String> getLnsRefs() {
return lnsRefs;
}
if (fc == null) {
throw new ServiceError(
ServiceError.FAILED_DUE_TO_COMMUNICATIONS_CONSTRAINT,
"unknown functional constraint: " + mmsItemId.substring(index1 + 1, index2));
public void setLnsRefs(List<String> lnsRefs) {
this.lnsRefs = lnsRefs;
}
index1 = index2;
public Map<String, Set<String>> getLns() {
return lns;
}
index2 = mmsItemId.indexOf('$', index1 + 1);
public void setLns(Map<String, Set<String>> lns) {
this.lns = lns;
}
if (index2 == -1) {
if (fc == Fc.RP) {
return ln.getUrcb(mmsItemId.substring(index1 + 1));
}
if (fc == Fc.BR) {
return ln.getBrcb(mmsItemId.substring(index1 + 1));
}
return (FcModelNode) ln.getChild(mmsItemId.substring(index1 + 1), fc);
public HashSet<String> getLnS() {
return lnS;
}
if (fc == Fc.RP) {
modelNode = ln.getUrcb(mmsItemId.substring(index1 + 1, index2));
} else if (fc == Fc.BR) {
modelNode = ln.getBrcb(mmsItemId.substring(index1 + 1, index2));
} else {
modelNode = ln.getChild(mmsItemId.substring(index1 + 1, index2), fc);
public void setLnS(HashSet<String> lnS) {
this.lnS = lnS;
}
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
while (index2 != -1) {
modelNode = modelNode.getChild(mmsItemId.substring(index1 + 1, index2));
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
public Map<String, String> getDescriptions() {
return descriptions;
}
modelNode = modelNode.getChild(mmsItemId.substring(index1 + 1));
public void setDescriptions(Map<String, String> descriptions) {
this.descriptions = descriptions;
}
if (variableDef.getAlternateAccess() == null) {
// no array is in this node path
return (FcModelNode) modelNode;
public Map<String, String> getdAIDescriptions() {
return dAIDescriptions;
}
AlternateAccessSelection altAccIt =
variableDef.getAlternateAccess().getCHOICE().get(0).getUnnamed();
public void setdAIDescriptions(Map<String, String> dAIDescriptions) {
this.dAIDescriptions = dAIDescriptions;
}
if (altAccIt.getSelectAlternateAccess() != null) {
// path to node below an array element
modelNode =
((Array) modelNode)
.getChild(
altAccIt.getSelectAlternateAccess().getAccessSelection().getIndex().intValue());
public Map<String, String> getDos() {
return dos;
}
String mmsSubArrayItemId =
altAccIt
.getSelectAlternateAccess()
.getAlternateAccess()
.getCHOICE()
.get(0)
.getUnnamed()
.getSelectAccess()
.getComponent()
.getBasic()
.toString();
public void setDos(Map<String, String> dos) {
this.dos = dos;
}
index1 = -1;
index2 = mmsSubArrayItemId.indexOf('$');
while (index2 != -1) {
modelNode = modelNode.getChild(mmsSubArrayItemId.substring(index1 + 1, index2));
index1 = index2;
index2 = mmsItemId.indexOf('$', index1 + 1);
}
public List<LogicalDevice> getLogicalDevices() {
return logicalDevices;
}
return (FcModelNode) modelNode.getChild(mmsSubArrayItemId.substring(index1 + 1));
} else {
// path to an array element
return (FcModelNode)
((Array) modelNode).getChild(altAccIt.getSelectAccess().getIndex().intValue());
public void setLogicalDevices(List<LogicalDevice> logicalDevices) {
this.logicalDevices = logicalDevices;
}
}
}
}

@ -14,36 +14,45 @@
package com.beanit.iec61850bean.internal.scl;
import com.beanit.iec61850bean.SclParseException;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.List;
public final class DoType extends AbstractType {
// attributes not needed: cdc, iedType
// attributes not needed: cdc, iedType
public List<Da> das = new ArrayList<>();
public List<Sdo> sdos = new ArrayList<>();
public List<Da> das = new ArrayList<>();
public List<Sdo> sdos = new ArrayList<>();
public DoType(Node xmlNode) throws SclParseException {
private String cdc;
super(xmlNode);
public DoType(Node xmlNode) throws SclParseException {
if (xmlNode.getAttributes().getNamedItem("cdc") == null) {
throw new SclParseException("Required attribute \"cdc\" not found in DOType!");
}
super(xmlNode);
if (xmlNode.getAttributes().getNamedItem("cdc") == null) {
throw new SclParseException("Required attribute \"cdc\" not found in DOType!");
} else {
cdc = xmlNode.getAttributes().getNamedItem("cdc").getNodeValue();
}
NodeList elements = xmlNode.getChildNodes();
NodeList elements = xmlNode.getChildNodes();
for (int i = 0; i < elements.getLength(); i++) {
Node node = elements.item(i);
if (node.getNodeName().equals("SDO")) {
sdos.add(new Sdo(node));
}
if (node.getNodeName().equals("DA")) {
das.add(new Da(node));
}
}
}
for (int i = 0; i < elements.getLength(); i++) {
Node node = elements.item(i);
if (node.getNodeName().equals("SDO")) {
sdos.add(new Sdo(node));
}
if (node.getNodeName().equals("DA")) {
das.add(new Da(node));
}
public String getCdc() {
return cdc;
}
}
}

@ -14,32 +14,44 @@
package com.beanit.iec61850bean.internal.scl;
import com.beanit.iec61850bean.SclParseException;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.List;
public final class LnType extends AbstractType {
// attributes not needed: lnClass, iedType
// attributes not needed: lnClass, iedType
public List<Do> dos = new ArrayList<>();
private String lnClass;
public List<Do> dos = new ArrayList<>();
public LnType(Node xmlNode) throws SclParseException {
public LnType(Node xmlNode) throws SclParseException {
super(xmlNode);
super(xmlNode);
if (xmlNode.getAttributes().getNamedItem("lnClass") == null) {
throw new SclParseException("Required attribute \"lnClass\" not found in LNType!");
} else {
lnClass = xmlNode.getAttributes().getNamedItem("lnClass").getNodeValue();
}
if (xmlNode.getAttributes().getNamedItem("lnClass") == null) {
throw new SclParseException("Required attribute \"lnClass\" not found in LNType!");
NodeList elements = xmlNode.getChildNodes();
for (int i = 0; i < elements.getLength(); i++) {
Node node = elements.item(i);
if (node.getNodeName().equals("DO")) {
dos.add(new Do(node));
}
}
}
NodeList elements = xmlNode.getChildNodes();
public String getLnClass() {
return lnClass;
}
for (int i = 0; i < elements.getLength(); i++) {
Node node = elements.item(i);
if (node.getNodeName().equals("DO")) {
dos.add(new Do(node));
}
public void setLnClass(String lnClass) {
this.lnClass = lnClass;
}
}
}

Loading…
Cancel
Save