use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsHelper method buildWindowElementFromDataObjects.
private WindowElementDto buildWindowElementFromDataObjects(final List<DataObject> elements, final String description) throws ProtocolAdapterException {
if (elements.size() != 2) {
LOGGER.error("Unexpected number of ResultData elements for WindowElement value: {}", elements.size());
throw new ProtocolAdapterException("Expected list for WindowElement to contain 2 elements, got: " + elements.size());
}
final CosemDateTimeDto startTime = this.readDateTime(elements.get(0), "Start Time from " + description);
final CosemDateTimeDto endTime = this.readDateTime(elements.get(1), "End Time from " + description);
return new WindowElementDto(startTime, endTime);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readTransportServiceType.
public TransportServiceTypeDto readTransportServiceType(final DataObject resultData, final String description) throws ProtocolAdapterException {
final Number number = this.readNumber(resultData, description, "Enum");
if (number == null) {
return null;
}
final int enumValue = number.intValue();
final TransportServiceTypeDto transportService = this.getTransportServiceTypeForEnumValue(enumValue);
if (transportService == null) {
LOGGER.error("Unexpected Enum value for TransportServiceType: {}", enumValue);
throw new ProtocolAdapterException("Unknown Enum value for TransportServiceType: " + enumValue);
}
return transportService;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsHelper method getWithList.
public List<GetResult> getWithList(final DlmsConnectionManager conn, final DlmsDevice device, final AttributeAddress... params) throws ProtocolAdapterException {
try {
if (device.isWithListSupported()) {
// Getting a too large list of attribute addresses in one get
// from the DlmsConnection
// might result in a SCOPE_OF_ACCESS_VIOLATED error
final List<GetResult> getResults = new ArrayList<>();
final List<AttributeAddress[]> maximizedSubsetsOfParams = this.getMaximizedSubsetsOfParams(params);
for (final AttributeAddress[] maximizedSubsetOfParams : maximizedSubsetsOfParams) {
getResults.addAll(conn.getConnection().get(Arrays.asList(maximizedSubsetOfParams)));
}
return getResults;
} else {
return this.getWithListWorkaround(conn, params);
}
} catch (final IOException | NullPointerException e) {
// JDlmsException).
throw new ConnectionException("Connection error retrieving values with-list for device: " + device.getDeviceIdentification(), e);
} catch (final Exception e) {
throw new ProtocolAdapterException("Error retrieving values with-list for device: " + device.getDeviceIdentification() + ", with-list: " + (device.isWithListSupported() ? "supported" : "not supported"), e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readMessageType.
public MessageTypeDto readMessageType(final DataObject resultData, final String description) throws ProtocolAdapterException {
final Number number = this.readNumber(resultData, description, "Enum");
if (number == null) {
return null;
}
final MessageTypeDto message;
final int enumValue = number.intValue();
switch(enumValue) {
case 0:
message = MessageTypeDto.A_XDR_ENCODED_X_DLMS_APDU;
break;
case 1:
message = MessageTypeDto.XML_ENCODED_X_DLMS_APDU;
break;
default:
if (enumValue < 128 || enumValue > 255) {
LOGGER.error("Unexpected Enum value for MessageType: {}", enumValue);
throw new ProtocolAdapterException("Unknown Enum value for MessageType: " + enumValue);
}
message = MessageTypeDto.MANUFACTURER_SPECIFIC;
}
return message;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsHelper method checkResultCode.
private void checkResultCode(final GetResult getResult, final String description) throws ProtocolAdapterException {
final AccessResultCode resultCode = getResult.getResultCode();
LOGGER.debug("{} - AccessResultCode: {}", description, resultCode);
if (resultCode != AccessResultCode.SUCCESS) {
throw new ProtocolAdapterException("No success retrieving " + description + ": AccessResultCode = " + resultCode);
}
}
Aggregations