use of org.openmuc.jdlms.MethodResult in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutor method clearStatusMaskForChannel.
private void clearStatusMaskForChannel(final DlmsConnectionManager conn, final int channel, final DlmsDevice device) throws IOException, ProtocolAdapterException {
final AttributeAddress readMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.READ_MBUS_STATUS, channel);
final AttributeAddress clearMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLEAR_MBUS_STATUS, channel);
final AttributeAddress clientSetupMbus = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLIENT_SETUP_MBUS, channel);
final long statusMask = this.readStatus(conn, channel, readMBusStatusAttributeAddress);
if (statusMask == 0L) {
return;
}
final AccessResultCode resultCode = this.setClearStatusMask(statusMask, conn, channel, clearMBusStatusAttributeAddress);
if (resultCode != AccessResultCode.SUCCESS) {
throw new ProtocolAdapterException("Unable to set clear status mask for M-Bus channel " + channel + ", AccessResultCode=" + resultCode + ".");
}
final MethodResult methodResult = this.resetAlarm(conn, channel, clientSetupMbus.getInstanceId());
if (methodResult.getResultCode() != MethodResultCode.SUCCESS) {
throw new ProtocolAdapterException("Call for RESET_ALARM was unsuccessful for M-Bus channel " + channel + ", MethodResultCode=" + methodResult.getResultCode() + ".");
}
}
use of org.openmuc.jdlms.MethodResult in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandActivationExecutor method execute.
@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void v, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
LOGGER.info("ACTIVATING PASSIVE CALENDAR");
final MethodParameter method = new MethodParameter(CLASS_ID, OBIS_CODE, METHOD_ID_ACTIVATE_PASSIVE_CALENDAR, DataObject.newInteger32Data(0));
conn.getDlmsMessageListener().setDescription("SetActivityCalendarActivation, call method: " + JdlmsObjectToStringUtil.describeMethod(method));
final MethodResult methodResultCode;
try {
methodResultCode = conn.getConnection().action(method);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (!MethodResultCode.SUCCESS.equals(methodResultCode.getResultCode())) {
throw new ProtocolAdapterException("Activating the activity calendar failed. MethodResult is: " + methodResultCode.getResultCode() + " ClassId: " + CLASS_ID + " obisCode: " + OBIS_CODE + " method id: " + METHOD_ID_ACTIVATE_PASSIVE_CALENDAR);
}
return MethodResultCode.SUCCESS;
}
use of org.openmuc.jdlms.MethodResult 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.MethodResult in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareCommandExecutorIntegrationTest method setUp.
@BeforeEach
void setUp() {
this.connectionStub = new DlmsConnectionStub();
this.connectionManagerStub = new DlmsConnectionManagerStub(this.connectionStub);
this.connectionStub.setDefaultReturnValue(DataObject.newArrayData(Collections.emptyList()));
this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_ENABLED), DataObject.newBoolData(true));
this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_STATUS), DataObject.newInteger32Data(1), 5);
this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_TRANSFER_STATUS), DataObject.newInteger32Data(6));
this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_BLOCK_SIZE), DataObject.newUInteger32Data(100));
this.connectionStub.addReturnValue(this.createAttributeAddressForImageTransfer(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER), DataObject.newUInteger32Data(100));
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final MethodResult methodResult = mock(MethodResult.class);
when(methodResult.getResultCode()).thenReturn(MethodResultCode.SUCCESS);
final ImageTransferProperties imageTransferProperties = new ImageTransfer.ImageTransferProperties();
imageTransferProperties.setVerificationStatusCheckInterval(this.verificationStatusCheckInterval);
imageTransferProperties.setVerificationStatusCheckTimeout(this.verificationStatusCheckTimeout);
imageTransferProperties.setInitiationStatusCheckInterval(this.initiationStatusCheckInterval);
imageTransferProperties.setInitiationStatusCheckTimeout(this.initiationStatusCheckTimeout);
this.connectionStub.setDefaultMethodResult(methodResult);
this.commandExecutor = new UpdateFirmwareCommandExecutor(this.dlmsDeviceRepository, this.firmwareFileCachingRepository, this.firmwareImageIdentifierCachingRepository, this.macGenerationService, imageTransferProperties);
}
Aggregations