use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class SetPushSetupSmsCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final PushSetupSmsDto pushSetupSms, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final SetParameter setParameterSendDestinationAndMethod = this.getSetParameter(pushSetupSms);
final AccessResultCode resultCode = this.doSetRequest("PushSetupSms, Send destination and method", conn, setParameterSendDestinationAndMethod);
if (resultCode != null) {
return resultCode;
} else {
throw new ProtocolAdapterException("Error setting Sms push setup data.");
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetActualMeterReadsCommandExecutor method execute.
@Override
public MeterReadsResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
if (actualMeterReadsQuery != null && actualMeterReadsQuery.isMbusQuery()) {
throw new IllegalArgumentException("ActualMeterReadsQuery object for energy reads should not be about gas.");
}
conn.getDlmsMessageListener().setDescription("GetActualMeterReads retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_ADDRESSES));
LOGGER.info("Retrieving actual energy reads");
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads", ATTRIBUTE_ADDRESSES);
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(INDEX_TIME), "Actual Energy Reads Time");
final DateTime time = cosemDateTime.asDateTime();
if (time == null) {
throw new ProtocolAdapterException("Unexpected null/unspecified value for Actual Energy Reads Time");
}
final DlmsMeterValueDto activeEnergyImport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_SCALER_UNIT), "Actual Energy Reads +A");
final DlmsMeterValueDto activeEnergyExport = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_SCALER_UNIT), "Actual Energy Reads -A");
final DlmsMeterValueDto activeEnergyImportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads +A rate 1");
final DlmsMeterValueDto activeEnergyImportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_IMPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads +A rate 2");
final DlmsMeterValueDto activeEnergyExportRate1 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_1_SCALER_UNIT), "Actual Energy Reads -A rate 1");
final DlmsMeterValueDto activeEnergyExportRate2 = this.dlmsHelper.getScaledMeterValue(getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2), getResultList.get(INDEX_ACTIVE_ENERGY_EXPORT_RATE_2_SCALER_UNIT), "Actual Energy Reads -A rate 2");
return new MeterReadsResponseDto(time.toDate(), new ActiveEnergyValuesDto(activeEnergyImport, activeEnergyExport, activeEnergyImportRate1, activeEnergyImportRate2, activeEnergyExportRate1, activeEnergyExportRate2));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareCommandExecutor method getFirmwareFile.
private FirmwareFile getFirmwareFile(final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
log.debug("Getting firmware file from caching repository for firmware {}", updateFirmwareRequestDto.getFirmwareIdentification());
final byte[] firmwareFileByteArray = this.firmwareFileCachingRepository.retrieve(updateFirmwareRequestDto.getFirmwareIdentification());
if (firmwareFileByteArray == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_FIRMWARE_FILE_NOT_AVAILABLE);
}
final FirmwareFile firmwareFile = new FirmwareFile(firmwareFileByteArray);
if (firmwareFile.isMbusFirmware()) {
firmwareFile.checkLengths();
this.addMac(messageMetadata, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile);
}
return firmwareFile;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class ImageTransfer method imageTransferEnabled.
/**
* Check image transfer enabled value of the COSEM server.
*
* @return image transfer enabled
*/
public boolean imageTransferEnabled() throws ProtocolAdapterException {
this.connector.getDlmsMessageListener().setDescription("ImageTransfer read image_transfer_enabled, read attribute: " + JdlmsObjectToStringUtil.describeAttributes(this.imageTransferCosem.createAttributeAddress(ImageTransferAttribute.IMAGE_TRANSFER_ENABLED)));
final DataObject transferEnabled = this.imageTransferCosem.readAttribute(ImageTransferAttribute.IMAGE_TRANSFER_ENABLED);
if (transferEnabled == null || !transferEnabled.isBoolean()) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_TRANSFER_ENABLED_NOT_READ);
}
return (Boolean) transferEnabled.getValue();
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class ImageTransfer method activateImage.
/**
* The image is activated.
*/
public void activateImage() throws OsgpException {
final DataObject parameter = DataObject.newInteger8Data((byte) 0);
this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_ACTIVATE, parameter);
final MethodResultCode imageActivate = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_ACTIVATE, parameter);
if (imageActivate == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_ACTIVATE_NOT_CALLED);
}
}
Aggregations