Search in sources :

Example 1 with ServerModel

use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.

the class Iec61850ConnectionTest method testWrite.

@Test
public void testWrite() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
    System.out.println("Attempting to connect to server " + host + " on port " + port);
    clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
    ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
    clientAssociation.setServerModel(serverModel);
    getAllBdas(serverModel, clientAssociation);
    // ------------SCAN FOR CHANNELS-------------------
    Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
    List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
    // ----------WRITE-----------------
    List<ChannelValueContainer> testChannelValueContainers = new ArrayList<>();
    byte[] newValue = { 0x44 };
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(14).getChannelAddress(), new ByteArrayValue(newValue)));
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(25).getChannelAddress(), new FloatValue((float) 12.5)));
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(24).getChannelAddress(), new BooleanValue(true)));
    testIec61850Connection.write(testChannelValueContainers, null);
    // Create record container to read the changes made by "write"
    List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
    for (int i = 0; i < 34; i++) {
        testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
    }
    testIec61850Connection.read(testRecordContainers, null, "");
    Assert.assertEquals("[68]", testRecordContainers.get(14).getRecord().getValue().toString());
    Assert.assertEquals("12.5", testRecordContainers.get(25).getRecord().getValue().toString());
    Assert.assertEquals("true", testRecordContainers.get(24).getRecord().getValue().toString());
}
Also used : ArrayList(java.util.ArrayList) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ServerModel(com.beanit.iec61850bean.ServerModel) BooleanValue(org.openmuc.framework.data.BooleanValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) FloatValue(org.openmuc.framework.data.FloatValue) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) Test(org.junit.jupiter.api.Test)

Example 2 with ServerModel

use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.

the class Iec61850ConnectionTest method testScanForChannels.

@Test
public void testScanForChannels() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
    System.out.println("Attempting to connect to server " + host + " on port " + port);
    clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
    ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
    clientAssociation.setServerModel(serverModel);
    getAllBdas(serverModel, clientAssociation);
    Iec61850Connection testConnection = new Iec61850Connection(clientAssociation, serverModel);
    List<ChannelScanInfo> testChannelScanList = testConnection.scanForChannels("");
    for (int i = 14; i < 23; i++) {
        System.out.print(testChannelScanList.get(i).getChannelAddress() + "\n");
        Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(i).getValueType().toString());
    }
    Assert.assertEquals("LONG", testChannelScanList.get(23).getValueType().toString());
    Assert.assertEquals("BOOLEAN", testChannelScanList.get(24).getValueType().toString());
    Assert.assertEquals("FLOAT", testChannelScanList.get(25).getValueType().toString());
    Assert.assertEquals("DOUBLE", testChannelScanList.get(26).getValueType().toString());
    Assert.assertEquals("BYTE", testChannelScanList.get(27).getValueType().toString());
    Assert.assertEquals("SHORT", testChannelScanList.get(28).getValueType().toString());
    Assert.assertEquals("SHORT", testChannelScanList.get(29).getValueType().toString());
    Assert.assertEquals("INTEGER", testChannelScanList.get(30).getValueType().toString());
    Assert.assertEquals("INTEGER", testChannelScanList.get(31).getValueType().toString());
    Assert.assertEquals("LONG", testChannelScanList.get(32).getValueType().toString());
    Assert.assertEquals("LONG", testChannelScanList.get(33).getValueType().toString());
    Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(34).getValueType().toString());
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ServerModel(com.beanit.iec61850bean.ServerModel) Test(org.junit.jupiter.api.Test)

Example 3 with ServerModel

use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.

the class Iec61850ConnectionTest method testRead.

@Test
public void testRead() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
    System.out.println("Attempting to connect to server " + host + " on port " + port);
    clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
    ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
    clientAssociation.setServerModel(serverModel);
    getAllBdas(serverModel, clientAssociation);
    // ------------SCAN FOR CHANNELS-------------------
    Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
    List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
    List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
    for (int i = 14; i < 34; i++) {
        testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
    }
    // ----------READ-------------------
    testIec61850Connection.read(testRecordContainers, null, "");
    System.out.print("recordContainer:" + testRecordContainers.get(0).getRecord() + "\n");
    Assert.assertEquals("[64]", testRecordContainers.get(0).getRecord().getValue().toString());
    System.out.print("recordContainer:" + testRecordContainers.get(0).getRecord() + "\n");
    Assert.assertEquals("[64]", testRecordContainers.get(0).getRecord().getValue().toString());
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ServerModel(com.beanit.iec61850bean.ServerModel) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with ServerModel

use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.

the class Iec61850Driver method connect.

@Override
public Connection connect(String deviceAddress, String settings) throws ArgumentSyntaxException, ConnectionException {
    DeviceAddress deviceAdress = new DeviceAddress(deviceAddress);
    DeviceSettings deviceSettings = new DeviceSettings(settings);
    ClientSap clientSap = new ClientSap();
    clientSap.setTSelLocal(deviceSettings.getTSelLocal());
    clientSap.setTSelLocal(deviceSettings.getTSelRemote());
    ClientAssociation clientAssociation;
    try {
        clientAssociation = clientSap.associate(deviceAdress.getAdress(), deviceAdress.getRemotePort(), deviceSettings.getAuthentication(), null);
    } catch (IOException e) {
        throw new ConnectionException(e);
    }
    ServerModel serverModel;
    try {
        serverModel = clientAssociation.retrieveModel();
    } catch (ServiceError e) {
        clientAssociation.close();
        throw new ConnectionException("Service error retrieving server model" + e.getMessage(), e);
    } catch (IOException e) {
        clientAssociation.close();
        throw new ConnectionException("IOException retrieving server model: " + e.getMessage(), e);
    }
    return new Iec61850Connection(clientAssociation, serverModel);
}
Also used : ServiceError(com.beanit.iec61850bean.ServiceError) ClientSap(com.beanit.iec61850bean.ClientSap) ServerModel(com.beanit.iec61850bean.ServerModel) ClientAssociation(com.beanit.iec61850bean.ClientAssociation) IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Aggregations

ServerModel (com.beanit.iec61850bean.ServerModel)4 Test (org.junit.jupiter.api.Test)3 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)3 ArrayList (java.util.ArrayList)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 ClientAssociation (com.beanit.iec61850bean.ClientAssociation)1 ClientSap (com.beanit.iec61850bean.ClientSap)1 ServiceError (com.beanit.iec61850bean.ServiceError)1 IOException (java.io.IOException)1 BooleanValue (org.openmuc.framework.data.BooleanValue)1 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)1 FloatValue (org.openmuc.framework.data.FloatValue)1 ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1