use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getGprsOperationMode.
private Optional<GprsOperationModeTypeDto> getGprsOperationMode(final DataObject gprsMode) throws ProtocolAdapterException {
if (gprsMode == null || !gprsMode.isNumber()) {
final String message = String.format("Expected ConfigurationObject gprsOperationMode as Number, but got: %s", gprsMode);
LOGGER.warn(message);
throw new ProtocolAdapterException(message);
}
final Number number = gprsMode.getValue();
return GprsOperationModeTypeDto.forNumber(number.intValue());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getConfigurationFlags.
private ConfigurationFlagsDto getConfigurationFlags(final DataObject flags) throws ProtocolAdapterException {
if (flags == null || !flags.isBitString()) {
final String message = String.format("Expected ConfigurationObject flags as BitString, but got: %s", flags);
LOGGER.warn(message);
throw new ProtocolAdapterException(message);
}
final BitString bitString = flags.getValue();
final byte[] flagBytes = bitString.getBitString();
final List<ConfigurationFlagDto> configurationFlags = this.toConfigurationFlags(flagBytes);
return new ConfigurationFlagsDto(configurationFlags);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.
@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
final DataObject resultData = result.getResultData();
if (resultData == null || !resultData.isComplex()) {
final String message = String.format("Expected ConfigurationObject ResultData as Complex, but got: %s", resultData);
LOGGER.warn(message);
throw new ProtocolAdapterException(message);
}
return this.getConfigurationObject(resultData);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.
private ConfigurationObjectDto getConfigurationObject(final DataObject resultData) throws ProtocolAdapterException {
LOGGER.info("ConfigurationObject ResultData: {}", this.dlmsHelper.getDebugInfo(resultData));
final List<DataObject> elements = resultData.getValue();
if (elements == null || elements.size() != NUMBER_OF_CONFIGURATION_OBJECT_ELEMENTS) {
final String message = String.format("Expected ConfigurationObject ResultData with %d elements, but got %s", NUMBER_OF_CONFIGURATION_OBJECT_ELEMENTS, elements == null ? "null" : elements.size());
LOGGER.warn(message);
throw new ProtocolAdapterException(message);
}
return this.getConfigurationObject(elements);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutorTest method testExecuteObjectNotFound.
@Test
void testExecuteObjectNotFound() throws ProtocolAdapterException {
when(this.dlmsObjectConfigService.getAttributeAddress(any(), any(), any())).thenThrow(new ProtocolAdapterException("Object not found"));
final DlmsDevice dlmsDevice = new DlmsDevice();
dlmsDevice.setProtocol("SMR", "5.0.0");
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
});
}
Aggregations