Search in sources :

Example 1 with Outstation

use of com.automatak.dnp3.Outstation in project solarnetwork-node by SolarNetwork.

the class OutstationDemo method run.

public static void run(DNP3Manager manager) throws Exception {
    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPServer("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ServerAcceptMode.CloseNew, "127.0.0.1", 20000, new Slf4jChannelListener());
    // Create the default outstation configuration
    OutstationStackConfig config = new OutstationStackConfig(DatabaseConfig.allValues(5), EventBufferConfig.allTypes(50));
    // Create an Outstation instance, pass in a simple a command handler that responds successfully to everything
    Outstation outstation = channel.addOutstation("outstation", SuccessCommandHandler.getInstance(), DefaultOutstationApplication.getInstance(), config);
    outstation.enable();
    // all this stuff just to read a line of text in Java. Oh the humanity.
    String line = "";
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    int i = 0;
    while (true) {
        System.out.println("Enter something to update a counter or type <quit> to exit");
        line = in.readLine();
        if (line.equals("quit"))
            break;
        else {
            OutstationChangeSet set = new OutstationChangeSet();
            set.update(new Counter(i, (byte) 0x01, 0), 0);
            outstation.apply(set);
            ++i;
        }
    }
}
Also used : Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) Outstation(com.automatak.dnp3.Outstation) Counter(com.automatak.dnp3.Counter) InputStreamReader(java.io.InputStreamReader) OutstationChangeSet(com.automatak.dnp3.OutstationChangeSet) Channel(com.automatak.dnp3.Channel) OutstationStackConfig(com.automatak.dnp3.OutstationStackConfig) BufferedReader(java.io.BufferedReader)

Example 2 with Outstation

use of com.automatak.dnp3.Outstation in project solarnetwork-node by SolarNetwork.

the class OutstationService method applyDatumCapturedUpdates.

private void applyDatumCapturedUpdates(Datum datum, Event event) {
    OutstationChangeSet changes = changeSetForDatumCapturedEvent(datum, event);
    if (changes == null) {
        return;
    }
    synchronized (this) {
        Outstation station = getOutstation();
        if (station != null) {
            log.info("Applying changes to DNP3 [{}]", getUid());
            station.apply(changes);
        }
    }
}
Also used : Outstation(com.automatak.dnp3.Outstation) OutstationChangeSet(com.automatak.dnp3.OutstationChangeSet)

Example 3 with Outstation

use of com.automatak.dnp3.Outstation in project solarnetwork-node by SolarNetwork.

the class OutstationService method createOutstation.

private Outstation createOutstation() {
    Channel channel = channel();
    if (channel == null) {
        log.info("DNP3 channel not available for outstation [{}]", getUid());
        return null;
    }
    log.info("Initializing DNP3 outstation [{}]", getUid());
    try {
        return channel.addOutstation(getUid(), commandHandler, app, createOutstationStackConfig());
    } catch (DNP3Exception e) {
        log.error("Error creating outstation application [{}]: {}", getUid(), e.getMessage(), e);
        return null;
    }
}
Also used : Channel(com.automatak.dnp3.Channel) DNP3Exception(com.automatak.dnp3.DNP3Exception)

Example 4 with Outstation

use of com.automatak.dnp3.Outstation in project solarnetwork-node by SolarNetwork.

the class OutstationService method createDatabaseConfig.

private DatabaseConfig createDatabaseConfig(Map<MeasurementType, List<MeasurementConfig>> configs, Map<ControlType, List<ControlConfig>> controlConfigs) {
    int analogCount = 0;
    int aoStatusCount = 0;
    int binaryCount = 0;
    int boStatusCount = 0;
    int counterCount = 0;
    int doubleBinaryCount = 0;
    int frozenCounterCount = 0;
    StringBuilder infoBuf = new StringBuilder();
    if (configs != null) {
        for (Map.Entry<MeasurementType, List<MeasurementConfig>> me : configs.entrySet()) {
            MeasurementType type = me.getKey();
            List<MeasurementConfig> list = me.getValue();
            if (type == null || list == null || list.isEmpty()) {
                continue;
            }
            switch(type) {
                case AnalogInput:
                    analogCount = list.size();
                    appendMeasurementInfos(infoBuf, type, list);
                    break;
                case AnalogOutputStatus:
                    aoStatusCount = list.size();
                    break;
                case BinaryInput:
                    binaryCount = list.size();
                    appendMeasurementInfos(infoBuf, type, list);
                    break;
                case BinaryOutputStatus:
                    boStatusCount = list.size();
                    break;
                case Counter:
                    counterCount = list.size();
                    appendMeasurementInfos(infoBuf, type, list);
                    break;
                case DoubleBitBinaryInput:
                    doubleBinaryCount = list.size();
                    appendMeasurementInfos(infoBuf, type, list);
                    break;
                case FrozenCounter:
                    frozenCounterCount = list.size();
                    appendMeasurementInfos(infoBuf, type, list);
                    break;
            }
        }
    }
    if (controlConfigs != null) {
        for (Map.Entry<ControlType, List<ControlConfig>> me : controlConfigs.entrySet()) {
            ControlType type = me.getKey();
            List<ControlConfig> list = me.getValue();
            if (type == null || list == null || list.isEmpty()) {
                continue;
            }
            switch(type) {
                case Analog:
                    appendControlInfos(infoBuf, type, list, aoStatusCount);
                    aoStatusCount += list.size();
                    break;
                case Binary:
                    appendControlInfos(infoBuf, type, list, boStatusCount);
                    boStatusCount += list.size();
                    break;
            }
        }
    }
    log.info("DNP3 outstation [{}] database configured with following registers:\n{}", getUid(), infoBuf);
    return new DatabaseConfig(binaryCount, doubleBinaryCount, analogCount, counterCount, frozenCounterCount, boStatusCount, aoStatusCount);
}
Also used : MeasurementConfig(net.solarnetwork.node.io.dnp3.domain.MeasurementConfig) ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) MeasurementType(net.solarnetwork.node.io.dnp3.domain.MeasurementType) List(java.util.List) ArrayList(java.util.ArrayList) ControlType(net.solarnetwork.node.io.dnp3.domain.ControlType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DatabaseConfig(com.automatak.dnp3.DatabaseConfig)

Aggregations

Channel (com.automatak.dnp3.Channel)2 Outstation (com.automatak.dnp3.Outstation)2 OutstationChangeSet (com.automatak.dnp3.OutstationChangeSet)2 Counter (com.automatak.dnp3.Counter)1 DNP3Exception (com.automatak.dnp3.DNP3Exception)1 DatabaseConfig (com.automatak.dnp3.DatabaseConfig)1 OutstationStackConfig (com.automatak.dnp3.OutstationStackConfig)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Slf4jChannelListener (net.solarnetwork.dnp3.util.Slf4jChannelListener)1 ControlConfig (net.solarnetwork.node.io.dnp3.domain.ControlConfig)1 ControlType (net.solarnetwork.node.io.dnp3.domain.ControlType)1 MeasurementConfig (net.solarnetwork.node.io.dnp3.domain.MeasurementConfig)1 MeasurementType (net.solarnetwork.node.io.dnp3.domain.MeasurementType)1