Search in sources :

Example 1 with ControlRelayOutputBlock

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

the class OutstationServceTests method handleCROBMissingIndex.

@Test
public void handleCROBMissingIndex() {
    // given
    TestOutstationService service = createOutstationService();
    final String controlId = "/foo/switch";
    ControlConfig cConfig = new ControlConfig(null, controlId, ControlType.Binary);
    service.setControlConfigs(new ControlConfig[] { cConfig });
    // when
    replayAll();
    ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 0, 0, CommandStatus.SUCCESS);
    CommandStatus status = service.getCommandHandler().operateCROB(crob, 123123123, OperateType.DirectOperate);
    // then
    assertThat("Command rejected because control index out of range", status, equalTo(CommandStatus.NOT_AUTHORIZED));
}
Also used : ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock) CommandStatus(com.automatak.dnp3.enums.CommandStatus) Test(org.junit.Test)

Example 2 with ControlRelayOutputBlock

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

the class OutstationServceTests method handleCROBLatchOff.

@Test
public void handleCROBLatchOff() {
    // given
    TestOutstationService service = createOutstationService();
    final String controlId = "/foo/switch";
    ControlConfig cConfig = new ControlConfig(null, controlId, ControlType.Binary);
    service.setControlConfigs(new ControlConfig[] { cConfig });
    Capture<Instruction> instrCaptor = Capture.newInstance();
    expect(instructionService.executeInstruction(capture(instrCaptor))).andAnswer(new IAnswer<InstructionStatus>() {

        @Override
        public InstructionStatus answer() throws Throwable {
            return createStatus(instrCaptor.getValue(), Completed);
        }
    });
    // when
    replayAll();
    ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_OFF, (short) 1, 0, 0, CommandStatus.SUCCESS);
    CommandStatus status = service.getCommandHandler().operateCROB(crob, 0, OperateType.DirectOperate);
    // then
    assertThat("Command OK", status, equalTo(CommandStatus.SUCCESS));
    Instruction instr = instrCaptor.getValue();
    assertThat("Instruction", instr.getTopic(), equalTo(InstructionHandler.TOPIC_SET_CONTROL_PARAMETER));
    assertThat("Control ID param", instr.getParameterValue(controlId), equalTo(Boolean.FALSE.toString()));
}
Also used : ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock) CommandStatus(com.automatak.dnp3.enums.CommandStatus) Instruction(net.solarnetwork.node.reactor.Instruction) Test(org.junit.Test)

Example 3 with ControlRelayOutputBlock

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

the class OutstationServceTests method handleCROBLatchOn.

@Test
public void handleCROBLatchOn() {
    // GIVEN
    TestOutstationService service = createOutstationService();
    final String controlId = "/foo/switch";
    ControlConfig cConfig = new ControlConfig(null, controlId, ControlType.Binary);
    service.setControlConfigs(new ControlConfig[] { cConfig });
    Capture<Instruction> instrCaptor = Capture.newInstance();
    expect(instructionService.executeInstruction(capture(instrCaptor))).andAnswer(new IAnswer<InstructionStatus>() {

        @Override
        public InstructionStatus answer() throws Throwable {
            return createStatus(instrCaptor.getValue(), Completed);
        }
    });
    // WHEN
    replayAll();
    ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 0, 0, CommandStatus.SUCCESS);
    CommandStatus status = service.getCommandHandler().operateCROB(crob, 0, OperateType.DirectOperate);
    // THEN
    assertThat("Command OK", status, equalTo(CommandStatus.SUCCESS));
    Instruction instr = instrCaptor.getValue();
    assertThat("Instruction", instr.getTopic(), equalTo(InstructionHandler.TOPIC_SET_CONTROL_PARAMETER));
    assertThat("Control ID param", instr.getParameterValue(controlId), equalTo(Boolean.TRUE.toString()));
}
Also used : ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock) CommandStatus(com.automatak.dnp3.enums.CommandStatus) Instruction(net.solarnetwork.node.reactor.Instruction) Test(org.junit.Test)

Example 4 with ControlRelayOutputBlock

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

the class OutstationServceTests method handleCROBLatchOnWithTaskExecutor.

@Test
public void handleCROBLatchOnWithTaskExecutor() throws InterruptedException {
    // given
    TestOutstationService service = createOutstationService();
    CapturingExecutorService executor = new CapturingExecutorService(newSingleThreadExecutor());
    service.setTaskExecutor(new TaskExecutorAdapter(executor));
    final String controlId = "/foo/switch";
    ControlConfig cConfig = new ControlConfig(null, controlId, ControlType.Binary);
    service.setControlConfigs(new ControlConfig[] { cConfig });
    Capture<Instruction> instrCaptor = Capture.newInstance();
    expect(instructionService.executeInstruction(capture(instrCaptor))).andAnswer(new IAnswer<InstructionStatus>() {

        @Override
        public InstructionStatus answer() throws Throwable {
            return createStatus(instrCaptor.getValue(), Completed);
        }
    });
    // when
    replayAll();
    ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 0, 0, CommandStatus.SUCCESS);
    CommandStatus status = service.getCommandHandler().operateCROB(crob, 0, OperateType.DirectOperate);
    // wait for bg task
    executor.shutdown();
    executor.awaitTermination(2, TimeUnit.SECONDS);
    // then
    assertThat("Command OK", status, equalTo(CommandStatus.SUCCESS));
    Instruction instr = instrCaptor.getValue();
    assertThat("Instruction", instr.getTopic(), equalTo(InstructionHandler.TOPIC_SET_CONTROL_PARAMETER));
    assertThat("Control ID param", instr.getParameterValue(controlId), equalTo(Boolean.TRUE.toString()));
    assertThat("Instruction handled in background", executor.getCapturedFutures(), hasSize(1));
}
Also used : ControlConfig(net.solarnetwork.node.io.dnp3.domain.ControlConfig) InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) CapturingExecutorService(net.solarnetwork.node.test.CapturingExecutorService) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock) Instruction(net.solarnetwork.node.reactor.Instruction) TaskExecutorAdapter(org.springframework.core.task.support.TaskExecutorAdapter) CommandStatus(com.automatak.dnp3.enums.CommandStatus) Test(org.junit.Test)

Example 5 with ControlRelayOutputBlock

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

the class MasterDemo method run.

static void run(DNP3Manager manager) throws Exception {
    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPClient("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ChannelRetry.getDefault(), "127.0.0.1", "0.0.0.0", 20000, new Slf4jChannelListener());
    // You can modify the defaults to change the way the master behaves
    MasterStackConfig config = new MasterStackConfig();
    // Create a master instance, pass in a simple singleton to print received values to the console
    Master master = channel.addMaster("master", PrintingSOEHandler.getInstance(), DefaultMasterApplication.getInstance(), config);
    // do an integrity scan every 2 seconds
    // master.addPeriodicScan(Duration.ofSeconds(2), Header.getIntegrity());
    master.enable();
    // all this cruft just to read a line of text in Java. Oh the humanity.
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    while (true) {
        System.out.println("Enter something to issue a command or type <quit> to exit");
        String line = in.readLine();
        switch(line) {
            case ("quit"):
                return;
            case ("crob"):
                ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 100, 100, CommandStatus.SUCCESS);
                master.selectAndOperateCROB(crob, 0).thenAccept(// asynchronously print the result of the command operation
                (CommandTaskResult result) -> System.out.println(result));
                break;
            case ("scan"):
                master.scan(Header.getEventClasses());
                break;
            default:
                System.out.println("Unknown command: " + line);
                break;
        }
    }
}
Also used : MasterStackConfig(com.automatak.dnp3.MasterStackConfig) Master(com.automatak.dnp3.Master) Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) InputStreamReader(java.io.InputStreamReader) CommandTaskResult(com.automatak.dnp3.CommandTaskResult) Channel(com.automatak.dnp3.Channel) BufferedReader(java.io.BufferedReader) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock)

Aggregations

ControlRelayOutputBlock (com.automatak.dnp3.ControlRelayOutputBlock)5 CommandStatus (com.automatak.dnp3.enums.CommandStatus)4 ControlConfig (net.solarnetwork.node.io.dnp3.domain.ControlConfig)4 Test (org.junit.Test)4 Instruction (net.solarnetwork.node.reactor.Instruction)3 InstructionStatus (net.solarnetwork.node.reactor.InstructionStatus)3 Channel (com.automatak.dnp3.Channel)1 CommandTaskResult (com.automatak.dnp3.CommandTaskResult)1 Master (com.automatak.dnp3.Master)1 MasterStackConfig (com.automatak.dnp3.MasterStackConfig)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Slf4jChannelListener (net.solarnetwork.dnp3.util.Slf4jChannelListener)1 CapturingExecutorService (net.solarnetwork.node.test.CapturingExecutorService)1 TaskExecutorAdapter (org.springframework.core.task.support.TaskExecutorAdapter)1