Search in sources :

Example 1 with ChannelAddress

use of org.openmuc.framework.driver.iec60870.settings.ChannelAddress in project OpenMUC by isc-konstanz.

the class Iec60870Connection method write.

@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws ConnectionException {
    for (ChannelValueContainer channelValueContainer : containers) {
        ChannelAddress channelAddress;
        try {
            channelAddress = new ChannelAddress(channelValueContainer.getChannelAddress());
            Record record = new Record(channelValueContainer.getValue(), System.currentTimeMillis(), Flag.VALID);
            Iec60870DataHandling.writeSingleCommand(record, channelAddress, clientConnection);
            channelValueContainer.setFlag(Flag.VALID);
        } catch (ArgumentSyntaxException e) {
            channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID);
            logger.error(e.getMessage());
            throw new UnsupportedOperationException(e);
        } catch (IOException e) {
            channelValueContainer.setFlag(Flag.CONNECTION_EXCEPTION);
            throw new ConnectionException(e);
        } catch (TypeConversionException e) {
            channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_VALUE_TYPE_CONVERSION_EXCEPTION);
            logger.error(e.getMessage());
        } catch (UnsupportedOperationException e) {
            channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID);
            logger.error(e.getMessage());
            throw e;
        }
    }
    return null;
}
Also used : TypeConversionException(org.openmuc.framework.data.TypeConversionException) ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 2 with ChannelAddress

use of org.openmuc.framework.driver.iec60870.settings.ChannelAddress in project OpenMUC by isc-konstanz.

the class Iec60870ReadListener method newASdu.

@Override
public synchronized void newASdu(ASdu aSdu) {
    logger.debug("Got new ASdu");
    if (logger.isTraceEnabled()) {
        logger.trace(aSdu.toString());
    }
    long timestamp = System.currentTimeMillis();
    if (!aSdu.isTestFrame()) {
        Set<String> keySet = channelAddressMap.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            String channelId = iterator.next();
            ChannelAddress channelAddress = channelAddressMap.get(channelId);
            if (aSdu.getCommonAddress() == channelAddress.commonAddress() && aSdu.getTypeIdentification().getId() == channelAddress.typeId()) {
                processRecords(aSdu, timestamp, channelId, channelAddress);
            }
        }
        isReadyReading = true;
    }
}
Also used : ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress)

Example 3 with ChannelAddress

use of org.openmuc.framework.driver.iec60870.settings.ChannelAddress in project OpenMUC by isc-konstanz.

the class Iec60870ReadListener method setContainer.

synchronized void setContainer(List<ChannelRecordContainer> containers) {
    this.containers = containers;
    Iterator<ChannelRecordContainer> containerIterator = containers.iterator();
    while (containerIterator.hasNext()) {
        ChannelRecordContainer channelRecordContainer = containerIterator.next();
        try {
            ChannelAddress channelAddress = new ChannelAddress(channelRecordContainer.getChannelAddress());
            channelAddressMap.put(channelRecordContainer.getChannel().getId(), channelAddress);
        } catch (ArgumentSyntaxException e) {
            logger.error("ChannelId: " + channelRecordContainer.getChannel().getId() + "; Message: " + e.getMessage());
        }
    }
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 4 with ChannelAddress

use of org.openmuc.framework.driver.iec60870.settings.ChannelAddress in project OpenMUC by isc-konstanz.

the class Iec60870Listener method newASdu.

@Override
public synchronized void newASdu(ASdu aSdu) {
    logger.debug("Got new ASdu");
    if (logger.isTraceEnabled()) {
        logger.trace(aSdu.toString());
    }
    if (listener != null) {
        long timestamp = System.currentTimeMillis();
        if (!aSdu.isTestFrame()) {
            Iterator<ChannelAddress> channelAddressIterator = channelAddresses.iterator();
            int i = 0;
            while (channelAddressIterator.hasNext()) {
                ChannelAddress channelAddress = channelAddressIterator.next();
                if (aSdu.getCommonAddress() == channelAddress.commonAddress() && aSdu.getTypeIdentification().getId() == channelAddress.typeId()) {
                    processRecords(aSdu, timestamp, i, channelAddress);
                }
                ++i;
            }
        }
    } else {
        logger.warn("Listener object is null.");
    }
}
Also used : ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress)

Example 5 with ChannelAddress

use of org.openmuc.framework.driver.iec60870.settings.ChannelAddress in project OpenMUC by isc-konstanz.

the class Iec60870Listener method registerOpenMucListener.

public synchronized void registerOpenMucListener(List<ChannelRecordContainer> containers, RecordsReceivedListener listener, String driverId, Connection connection) throws ConnectionException {
    this.containers = containers;
    this.listener = listener;
    this.driverId = driverId;
    this.connection = connection;
    Iterator<ChannelRecordContainer> containerIterator = containers.iterator();
    while (containerIterator.hasNext()) {
        ChannelRecordContainer channelRecordContainer = containerIterator.next();
        try {
            ChannelAddress channelAddress = new ChannelAddress(channelRecordContainer.getChannelAddress());
            channelAddresses.add(channelAddress);
        } catch (ArgumentSyntaxException e) {
            logger.error("ChannelId: " + channelRecordContainer.getChannel().getId() + "; Message: " + e.getMessage());
        }
    }
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Aggregations

ChannelAddress (org.openmuc.framework.driver.iec60870.settings.ChannelAddress)5 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)3 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 IOException (java.io.IOException)1 Record (org.openmuc.framework.data.Record)1 TypeConversionException (org.openmuc.framework.data.TypeConversionException)1 ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1