Search in sources :

Example 1 with InstructionStatus

use of net.solarnetwork.domain.InstructionStatus in project solarnetwork-node by SolarNetwork.

the class OutstationService method operateBinaryControl.

private InstructionStatus operateBinaryControl(ControlRelayOutputBlock command, int index, OperateType opType, ControlConfig config) {
    final InstructionExecutionService service = OptionalService.service(instructionExecutionService);
    Instruction instr = null;
    switch(command.function) {
        case LATCH_ON:
            instr = InstructionUtils.createSetControlValueLocalInstruction(config.getControlId(), Boolean.TRUE);
            break;
        case LATCH_OFF:
            instr = InstructionUtils.createSetControlValueLocalInstruction(config.getControlId(), Boolean.FALSE);
            break;
        default:
    }
    InstructionStatus result = null;
    if (service != null) {
        try {
            if (instr != null) {
                result = service.executeInstruction(instr);
            } else {
                result = InstructionUtils.createStatus(instr, InstructionState.Declined);
            }
        } finally {
            log.info("DNP3 outstation [{}] CROB operation request {} on {}[{}] control [{}] result: {}", getUid(), command.function, config.getType(), index, config.getControlId(), result);
        }
    }
    return result;
}
Also used : InstructionExecutionService(net.solarnetwork.node.reactor.InstructionExecutionService) InstructionStatus(net.solarnetwork.domain.InstructionStatus) InstructionUtils.createSetControlValueLocalInstruction(net.solarnetwork.node.reactor.InstructionUtils.createSetControlValueLocalInstruction) Instruction(net.solarnetwork.node.reactor.Instruction)

Example 2 with InstructionStatus

use of net.solarnetwork.domain.InstructionStatus in project solarnetwork-node by SolarNetwork.

the class OutstationService method operateAnalogControl.

private InstructionStatus operateAnalogControl(Object command, int index, String opDescription, ControlConfig config, Number value) {
    final InstructionExecutionService service = service(instructionExecutionService);
    Instruction instr = createSetControlValueLocalInstruction(config.getControlId(), value.toString());
    InstructionStatus result = null;
    try {
        if (service != null) {
            result = service.executeInstruction(instr);
        } else {
            result = InstructionUtils.createStatus(instr, InstructionState.Declined);
        }
    } finally {
        log.info("DNP3 outstation [{}] analog operation request {} on {}[{}] control [{}] result: {}", getUid(), opDescription, config.getType(), index, config.getControlId(), result);
    }
    return result;
}
Also used : InstructionExecutionService(net.solarnetwork.node.reactor.InstructionExecutionService) InstructionStatus(net.solarnetwork.domain.InstructionStatus) InstructionUtils.createSetControlValueLocalInstruction(net.solarnetwork.node.reactor.InstructionUtils.createSetControlValueLocalInstruction) Instruction(net.solarnetwork.node.reactor.Instruction)

Example 3 with InstructionStatus

use of net.solarnetwork.domain.InstructionStatus in project solarnetwork-node by SolarNetwork.

the class MotionCameraControlTests method signalInstruction_snapshotDefaultCamera.

@Test
public void signalInstruction_snapshotDefaultCamera() throws Exception {
    // GIVEN
    TestHttpHandler handler = new TestHttpHandler() {

        @Override
        protected boolean handleInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
            assertThat("Snapshot request method", request.getMethod(), equalTo("GET"));
            assertThat("Snapshot Request path", request.getPathInfo(), equalTo("/1/action/snapshot"));
            respondWithText(response, "OK");
            response.flushBuffer();
            return true;
        }
    };
    getHttpServer().addHandler(handler);
    // WHEN
    Instruction signal = InstructionUtils.createLocalInstruction(InstructionHandler.TOPIC_SIGNAL, controlId, MotionCameraControl.SIGNAL_SNAPSHOT);
    InstructionStatus result = control.processInstruction(signal);
    // THEN
    assertThat("HTTP method called", handler.isHandled(), equalTo(true));
    assertThat("Snapshot instruction completed", result.getInstructionState(), equalTo(InstructionState.Completed));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InstructionStatus(net.solarnetwork.domain.InstructionStatus) HttpServletResponse(javax.servlet.http.HttpServletResponse) Instruction(net.solarnetwork.node.reactor.Instruction) Test(org.junit.Test)

Example 4 with InstructionStatus

use of net.solarnetwork.domain.InstructionStatus in project solarnetwork-node by SolarNetwork.

the class MotionCameraControlTests method signalInstruction_snapshotCameraNotFound.

@Test
public void signalInstruction_snapshotCameraNotFound() throws Exception {
    // GIVEN
    TestHttpHandler handler = new TestHttpHandler() {

        @Override
        protected boolean handleInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
            assertThat("Snapshot request method", request.getMethod(), equalTo("GET"));
            assertThat("Snapshot Request path", request.getPathInfo(), equalTo("/2/action/snapshot"));
            response.setStatus(404);
            response.flushBuffer();
            return true;
        }
    };
    getHttpServer().addHandler(handler);
    // WHEN
    Map<String, String> signalParams = new HashMap<>(2);
    signalParams.put(controlId, MotionCameraControl.SIGNAL_SNAPSHOT);
    signalParams.put(MotionCameraControl.CAMERA_ID_PARAM, "2");
    Instruction signal = InstructionUtils.createLocalInstruction(InstructionHandler.TOPIC_SIGNAL, signalParams);
    InstructionStatus result = control.processInstruction(signal);
    // THEN
    assertThat("HTTP method called", handler.isHandled(), equalTo(true));
    assertThat("Snapshot instruction for unknown camaera declined", result.getInstructionState(), equalTo(InstructionState.Declined));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InstructionStatus(net.solarnetwork.domain.InstructionStatus) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) Instruction(net.solarnetwork.node.reactor.Instruction) Test(org.junit.Test)

Example 5 with InstructionStatus

use of net.solarnetwork.domain.InstructionStatus in project solarnetwork-node by SolarNetwork.

the class MotionCameraControlTests method signalInstruction_snapshotSpecificCamera.

@Test
public void signalInstruction_snapshotSpecificCamera() throws Exception {
    // GIVEN
    TestHttpHandler handler = new TestHttpHandler() {

        @Override
        protected boolean handleInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
            assertThat("Snapshot request method", request.getMethod(), equalTo("GET"));
            assertThat("Snapshot Request path", request.getPathInfo(), equalTo("/2/action/snapshot"));
            respondWithText(response, "OK");
            response.flushBuffer();
            return true;
        }
    };
    getHttpServer().addHandler(handler);
    // WHEN
    Map<String, String> signalParams = new HashMap<>(2);
    signalParams.put(controlId, MotionCameraControl.SIGNAL_SNAPSHOT);
    signalParams.put(MotionCameraControl.CAMERA_ID_PARAM, "2");
    Instruction signal = InstructionUtils.createLocalInstruction(InstructionHandler.TOPIC_SIGNAL, signalParams);
    InstructionStatus result = control.processInstruction(signal);
    // THEN
    assertThat("HTTP method called", handler.isHandled(), equalTo(true));
    assertThat("Snapshot instruction completed", result.getInstructionState(), equalTo(InstructionState.Completed));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InstructionStatus(net.solarnetwork.domain.InstructionStatus) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) Instruction(net.solarnetwork.node.reactor.Instruction) Test(org.junit.Test)

Aggregations

InstructionStatus (net.solarnetwork.domain.InstructionStatus)5 Instruction (net.solarnetwork.node.reactor.Instruction)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 InstructionExecutionService (net.solarnetwork.node.reactor.InstructionExecutionService)2 InstructionUtils.createSetControlValueLocalInstruction (net.solarnetwork.node.reactor.InstructionUtils.createSetControlValueLocalInstruction)2