use of org.opensmartgridplatform.webdevicesimulator.domain.entities.Device in project open-smart-grid-platform by OSGP.
the class AutonomousDeviceRegister method run.
@Override
public void run() {
if (this.deviceManagementService.getDevRegistration()) {
LOGGER.info("Registering devices");
final List<Device> devices = this.deviceRepository.findAll();
for (final Device device : devices) {
LOGGER.info("Autonomous device register for : {}: {} ", device.getId(), device.getDeviceIdentification());
this.registerDevice.sendRegisterDeviceCommand(device.getId(), false);
LOGGER.info("Autonomous device register confirmation for : {}: {} ", device.getId(), device.getDeviceIdentification());
this.registerDevice.sendConfirmDeviceRegistrationCommand(device.getId());
}
}
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.Device in project open-smart-grid-platform by OSGP.
the class TariffSwitchingLow method run.
@Override
public void run() {
if (Boolean.TRUE.equals(this.deviceManagementService.getTariffSwitching())) {
LOGGER.info("traiff Switching off for devices");
final List<Device> devices = this.deviceRepository.findAll();
for (final Device device : devices) {
LOGGER.info("Tariff switching for : {}: {} ", device.getId(), device.getDeviceIdentification());
// Switching off Tariff
this.switchingServices.tariffSwitchLow(device.getId());
// Send EventNotifications for TariffSwitching Off
LOGGER.info("Sending TARIFF_EVENTS_TARIFF_OFF event for device : {}: {} ", device.getId(), device.getDeviceIdentification());
this.registerDevice.sendEventNotificationCommand(device.getId(), Oslp.Event.TARIFF_EVENTS_TARIFF_OFF_VALUE, "TARIFF_EVENTS_TARIFF_OFF event occurred on Tariff Switching low ", 1);
}
}
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.Device in project open-smart-grid-platform by OSGP.
the class RegisterDevice method sendRegisterDeviceCommand.
public DeviceMessageStatus sendRegisterDeviceCommand(final long deviceId, final Boolean hasSchedule) {
// Find device.
final Device device = this.deviceManagementService.findDevice(deviceId);
if (device == null) {
// Set the DeviceMessageStatus NOT_FOUND as the Device is not found.
return DeviceMessageStatus.NOT_FOUND;
}
this.errorMessage = "";
try {
// Generate random sequence number and random device number.
final Integer sequenceNumber = device.doGenerateRandomNumber();
final Integer randomDevice = device.doGenerateRandomNumber();
// Create registration message.
final OslpEnvelope oslpRequest = this.createEnvelopeBuilder(device.getDeviceUid(), sequenceNumber).withPayloadMessage(Message.newBuilder().setRegisterDeviceRequest(Oslp.RegisterDeviceRequest.newBuilder().setDeviceIdentification(device.getDeviceIdentification()).setIpAddress(ByteString.copyFrom(InetAddress.getByName(device.getIpAddress()).getAddress())).setDeviceType(device.getDeviceType().isEmpty() ? DeviceType.PSLD : DeviceType.valueOf(device.getDeviceType())).setHasSchedule(hasSchedule).setRandomDevice(randomDevice)).build()).build();
// Write outgoing request to log.
this.writeOslpLogItem(oslpRequest, device, false);
final OslpEnvelope response = this.sendRequest(device, oslpRequest);
// Write incoming response to log.
this.writeOslpLogItem(response, device, true);
this.currentTime = response.getPayloadMessage().getRegisterDeviceResponse().getCurrentTime();
// Get the sequence number from the response envelope and check it.
this.checkSequenceNumber(response.getSequenceNumber(), sequenceNumber);
// Get the two random numbers and check them both.
this.checkRandomDeviceAndRandomPlatform(randomDevice, response.getPayloadMessage().getRegisterDeviceResponse().getRandomDevice(), response.getPayloadMessage().getRegisterDeviceResponse().getRandomPlatform());
// Set the sequence number and persist it.
device.setSequenceNumber(sequenceNumber);
// Get the two random numbers and persist them both.
device.setRandomDevice(response.getPayloadMessage().getRegisterDeviceResponse().getRandomDevice());
device.setRandomPlatform(response.getPayloadMessage().getRegisterDeviceResponse().getRandomPlatform());
// Save the entity.
this.deviceManagementService.updateDevice(device);
// Set the DeviceMessageStatus OK as the registration is successful.
return DeviceMessageStatus.OK;
} catch (final UnknownHostException ex) {
LOGGER.error("incorrect IP address format", ex);
} catch (final Exception e) {
LOGGER.error("register device exception", e);
this.errorMessage = e.getMessage();
// successful.
return DeviceMessageStatus.FAILURE;
}
return DeviceMessageStatus.NOT_FOUND;
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementController method sendEventNotificationCommandAll.
@PostMapping(value = COMMAND_SENDNOTIFICATION_URL)
@ResponseBody
public String sendEventNotificationCommandAll(@RequestBody final SendEventNotificationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendEventNotificationCommand(request.getDeviceId(), request.getEvent(), request.getDescription(), request.getIndex(), request.getHasTimestamp());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_EVENTNOTIFICATION_SENT, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementController method sendConfirmDeviceRegistrationCommand.
@PostMapping(value = COMMAND_REGISTER_CONFIRM_URL)
@ResponseBody
public String sendConfirmDeviceRegistrationCommand(@RequestBody final ConfirmDeviceRegistrationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendConfirmDeviceRegistrationCommand(request.getDeviceId());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_REGISTERED_CONFIRM, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
Aggregations