use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutorTest method init.
@BeforeEach
public void init() throws ProtocolAdapterException, IOException {
// SETUP
final Protocol smr51 = Protocol.SMR_5_1;
this.device = this.createDlmsDevice(smr51);
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final AttributeAddress address = new AttributeAddress(1, new ObisCode("0.1.94.31.12.255"), 1);
this.dataDto = new SetRandomisationSettingsRequestDataDto(0, 1, 1, 1);
final ConfigurationFlagsDto currentConfigurationFlagsDto = new ConfigurationFlagsDto(this.getFlags());
final ConfigurationObjectDto currentConfigurationObjectDto = new ConfigurationObjectDto(currentConfigurationFlagsDto);
when(this.protocolServiceLookup.lookupGetService(smr51)).thenReturn(this.getConfigurationObjectService);
when(this.protocolServiceLookup.lookupSetService(smr51)).thenReturn(this.setConfigurationObjectService);
when(this.getConfigurationObjectService.getConfigurationObject(this.dlmsConnectionManager)).thenReturn(currentConfigurationObjectDto);
when(this.setConfigurationObjectService.setConfigurationObject(any(DlmsConnectionManager.class), any(ConfigurationObjectDto.class), any(ConfigurationObjectDto.class))).thenReturn(AccessResultCode.SUCCESS);
when(this.dlmsObjectConfigService.getAttributeAddress(this.device, DlmsObjectType.RANDOMISATION_SETTINGS, null)).thenReturn(address);
when(this.dlmsConnectionManager.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method execute.
@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final GMeterInfoDto gMeterInfo, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
try {
LOGGER.debug("SetEncryptionKeyExchangeOnGMeterCommandExecutor.execute called");
final String mbusDeviceIdentification = gMeterInfo.getDeviceIdentification();
final int channel = gMeterInfo.getChannel();
final ObisCode obisCode = OBIS_HASHMAP.get(channel);
final byte[] gMeterEncryptionKey = this.secretManagementService.generate128BitsKeyAndStoreAsNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
MethodResult methodResultCode = this.transferKey(conn, mbusDeviceIdentification, channel, gMeterEncryptionKey, messageMetadata);
this.checkMethodResultCode(methodResultCode, "M-Bus Setup transfer_key", obisCode);
methodResultCode = this.setEncryptionKey(conn, channel, gMeterEncryptionKey);
this.checkMethodResultCode(methodResultCode, "M-Bus Setup set_encryption_key", obisCode);
this.secretManagementService.activateNewKey(messageMetadata, mbusDeviceIdentification, G_METER_ENCRYPTION);
return MethodResultCode.SUCCESS;
} catch (final IOException e) {
throw new ConnectionException(e);
} catch (final EncrypterException e) {
throw new ProtocolAdapterException("Unexpected exception during decryption of security keys, reason = " + e.getMessage(), e);
}
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class GetAllAttributeValuesCommandExecutor method getAllDataFromAttribute.
private String getAllDataFromAttribute(final DlmsConnectionManager conn, final int classNumber, final DataObject obisCode, final int attributeValue) throws ProtocolAdapterException, IOException {
if (!obisCode.isByteArray()) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final byte[] obisCodeByteArray = obisCode.getValue();
if (obisCodeByteArray.length != OBIS_CODE_BYTE_ARRAY_LENGTH) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final AttributeAddress attributeAddress = new AttributeAddress(classNumber, new ObisCode(obisCodeByteArray), attributeValue);
conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
LOGGER.debug("Retrieving configuration objects data for class id: {}, obis code: {}, attribute id: {}", classNumber, obisCodeByteArray, attributeValue);
final GetResult getResult = conn.getConnection().get(attributeAddress);
LOGGER.debug("ResultCode: {}", getResult.getResultCode());
return this.dlmsHelper.getDebugInfo(getResult.getResultData());
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method createAttributeAddresses.
private AttributeAddress[] createAttributeAddresses(final DlmsObject dlmsObject) {
final int classId = dlmsObject.getClassId();
final ObisCode obisCode = dlmsObject.getObisCode();
return new AttributeAddress[] { new AttributeAddress(classId, obisCode, OPERATOR.attributeId()), new AttributeAddress(classId, obisCode, MODEM_REGISTRATION_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CIRCUIT_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, PACKET_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CELL_INFO.attributeId()), new AttributeAddress(classId, obisCode, ADJACENT_CELLS.attributeId()) // Reading of capture_time is disabled for now, because the jDLMS library appears to handle
// the COSEM date-time in the response incorrectly. Also see comment in getCaptureTime.
// new AttributeAddress(classId, obisCode, CAPTURE_TIME.attributeId())
};
}
use of org.openmuc.jdlms.ObisCode in project open-smart-grid-platform by OSGP.
the class GetOutagesCommandExecutor method execute.
@Override
public List<OutageDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetOutagesRequestDto getOutagesRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final AttributeAddress eventLogBuffer = new AttributeAddress(CLASS_ID, new ObisCode(OBIS_CODE), ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("RetrieveOutages, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
final GetResult getResult;
try {
getResult = conn.getConnection().get(eventLogBuffer);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving event register POWER_FAILURE_EVENT_LOG");
}
if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
log.info("Result of getting events for POWER_FAILURE_EVENT_LOG is {}", getResult.getResultCode());
throw new ProtocolAdapterException("Getting the outages from POWER_FAILURE_EVENT_LOG from the meter resulted in: " + getResult.getResultCode());
}
final DataObject resultData = getResult.getResultData();
return this.dataObjectToOutageListConverter.convert(resultData);
}
Aggregations