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;
}
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;
}
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));
}
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));
}
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));
}
Aggregations