@ -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 ! = nul l) {
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 ( ) ;
}
}