use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method anSsldOslpDevice.
@Given("^an ssld oslp device$")
public void anSsldOslpDevice(final Map<String, String> settings) {
// First create the device itself in the OSGP core database
this.ssldDeviceSteps.anSsldDevice(settings);
// Now create the OSLP device in the OSLP database
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final OslpDevice device = new OslpDevice(getString(settings, PlatformKeys.KEY_DEVICE_UID, DEFAULT_DEVICE_UID), deviceIdentification, getString(settings, PlatformKeys.KEY_DEVICE_TYPE, PlatformDefaults.DEFAULT_DEVICE_TYPE));
device.setSequenceNumber(0);
device.setRandomDevice(0);
device.setRandomPlatform(0);
device.updatePublicKey(DEVICE_PUBLIC_KEY);
this.oslpDeviceRepository.save(device);
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theSsldOslpDeviceContains.
@Then("^the ssld oslp device contains$")
public void theSsldOslpDeviceContains(final Map<String, String> expectedEntity) {
Wait.until(() -> {
final OslpDevice entity = this.oslpDeviceRepository.findByDeviceIdentification(getString(expectedEntity, PlatformKeys.KEY_DEVICE_IDENTIFICATION));
assertThat(entity.getDeviceType()).isEqualTo(getString(expectedEntity, PlatformKeys.KEY_DEVICE_TYPE));
assertThat(entity.getDeviceUid()).isEqualTo(getString(expectedEntity, PlatformKeys.KEY_DEVICE_UID));
});
this.ssldDeviceSteps.theSsldDeviceContains(expectedEntity);
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpChannelHandlerServer method handleRegisterDeviceRequest.
private Oslp.Message handleRegisterDeviceRequest(final byte[] deviceUid, final byte[] sequenceNumber, final Oslp.RegisterDeviceRequest registerRequest) throws UnknownHostException {
final String deviceIdentification = registerRequest.getDeviceIdentification();
final String deviceType = registerRequest.getDeviceType().toString();
final boolean hasSchedule = registerRequest.getHasSchedule();
final InetAddress inetAddress = this.getInetAddress(registerRequest, deviceIdentification);
// Send message to OSGP-CORE to save IP Address, device type and has
// schedule values in OSGP-CORE database.
this.deviceRegistrationService.sendDeviceRegisterRequest(inetAddress, deviceType, hasSchedule, deviceIdentification);
OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(registerRequest.getDeviceIdentification());
// Save the security related values in the OSLP database.
oslpDevice.updateRegistrationData(deviceUid, registerRequest.getDeviceType().toString(), registerRequest.getRandomDevice());
oslpDevice.setSequenceNumber(SequenceNumberUtils.convertByteArrayToInteger(sequenceNumber));
oslpDevice = this.oslpDeviceSettingsService.updateDevice(oslpDevice);
// Return current date and time in UTC so the device can sync the clock.
final Oslp.RegisterDeviceResponse.Builder responseBuilder = Oslp.RegisterDeviceResponse.newBuilder().setStatus(Oslp.Status.OK).setCurrentTime(Instant.now().toString(format)).setRandomDevice(registerRequest.getRandomDevice()).setRandomPlatform(oslpDevice.getRandomPlatform());
// Return local time zone information of the platform. Devices can use
// this to convert UTC times to local times.
final LocationInfo.Builder locationInfo = LocationInfo.newBuilder();
locationInfo.setTimeOffset(this.timeZoneOffsetMinutes);
// Get the GPS values from OSGP-CORE database.
final GpsCoordinatesDto gpsCoordinates = this.deviceDataService.getGpsCoordinatesForDevice(deviceIdentification);
if (gpsCoordinates != null && gpsCoordinates.getLatitude() != null && gpsCoordinates.getLongitude() != null) {
// Add GPS information when available in meta data.
locationInfo.setLatitude(this.convertGpsCoordinateFromFloatToInt(gpsCoordinates.getLatitude())).setLongitude(this.convertGpsCoordinateFromFloatToInt(gpsCoordinates.getLongitude()));
} else {
// Otherwise use default GPS information.
locationInfo.setLatitude(this.convertGpsCoordinateFromFloatToInt(this.defaultLatitude)).setLongitude(this.convertGpsCoordinateFromFloatToInt(this.defaultLongitude));
}
responseBuilder.setLocationInfo(locationInfo);
return Oslp.Message.newBuilder().setRegisterDeviceResponse(responseBuilder.build()).build();
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceService method buildAndSignEnvelope.
private void buildAndSignEnvelope(final DeviceRequest deviceRequest, final Oslp.Message payloadMessage, final Serializable extraData) {
final String deviceIdentification = deviceRequest.getDeviceIdentification();
final String organisationIdentification = deviceRequest.getOrganisationIdentification();
final String correlationUid = deviceRequest.getCorrelationUid();
final String ipAddress = deviceRequest.getIpAddress();
final String domain = deviceRequest.getDomain();
final String domainVersion = deviceRequest.getDomainVersion();
final String messageType = deviceRequest.getMessageType();
final int messagePriority = deviceRequest.getMessagePriority();
final int retryCount = deviceRequest.getRetryCount();
final boolean isScheduled = deviceRequest.isScheduled();
// Get some values from the database.
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
if (oslpDevice == null) {
LOGGER.error("Unable to find OSLP device: {}", deviceIdentification);
return;
}
final byte[] deviceId = Base64.decodeBase64(oslpDevice.getDeviceUid());
final byte[] sequenceNumber = SequenceNumberUtils.convertIntegerToByteArray(oslpDevice.getSequenceNumber());
this.oslpSigningService.buildAndSignEnvelope(organisationIdentification, deviceIdentification, correlationUid, deviceId, sequenceNumber, ipAddress, domain, domainVersion, messageType, messagePriority, retryCount, isScheduled, payloadMessage, extraData);
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceService method updateSequenceNumber.
private void updateSequenceNumber(final String deviceIdentification, final OslpEnvelope oslpResponse) {
final Integer sequenceNumber = SequenceNumberUtils.convertByteArrayToInteger(oslpResponse.getSequenceNumber());
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
oslpDevice.setSequenceNumber(sequenceNumber);
this.oslpDeviceSettingsService.updateDeviceAndForceSave(oslpDevice);
}
Aggregations