use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActivityCalendarDto activityCalendar, final MessageMetadata messageMetadata) throws ProtocolAdapterException, FunctionalException {
LOGGER.debug("SetActivityCalendarCommandExecutor.execute {} called", activityCalendar.getCalendarName());
ActivityCalendarValidator.validate(activityCalendar);
final List<SeasonProfileDto> seasonProfileList = activityCalendar.getSeasonProfileList();
final Set<WeekProfileDto> weekProfileSet = this.getWeekProfileSet(seasonProfileList);
final Set<DayProfileDto> dayProfileSet = this.getDayProfileSet(weekProfileSet);
final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors("SetActivityCalendar").addExecutor(this.getCalendarNameExecutor(activityCalendar)).addExecutor(this.getSeasonProfileExecutor(seasonProfileList)).addExecutor(this.getWeekProfileTableExecutor(weekProfileSet)).addExecutor(this.getDayProfileTablePassiveExecutor(dayProfileSet));
conn.getDlmsMessageListener().setDescription("SetActivityCalendar for calendar " + activityCalendar.getCalendarName() + ", set attributes: " + dataObjectExecutors.describeAttributes());
dataObjectExecutors.execute(conn);
LOGGER.info("Finished setting the passive activity calendar");
// in the exception to throw
try {
this.setActivityCalendarCommandActivationExecutor.execute(conn, device, null, messageMetadata);
LOGGER.info("Finished activating the passive to the active activity calendar");
} catch (final ProtocolAdapterException e) {
final StringBuilder message = new StringBuilder();
for (final DataObjectAttrExecutor executor : dataObjectExecutors.getDataObjectAttrExecutorList()) {
message.append(executor.createRequestAndResultCodeInfo());
}
throw new ProtocolAdapterException(e.getMessage() + message, e);
}
return AccessResultCode.SUCCESS;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelper method writeUpdatedMbus.
protected ChannelElementValuesDto writeUpdatedMbus(final DlmsConnectionManager conn, final DlmsDevice device, final MbusChannelElementsDto requestDto, final short channel, final String executorName) throws ProtocolAdapterException {
final DlmsObject mbusClientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
final int classId = mbusClientSetupObject.getClassId();
final DataObject identificationNumberDataObject;
if (this.identificationNumberStoredAsBcdOnDevice(mbusClientSetupObject)) {
identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObjectInBcdRepresentation();
} else {
identificationNumberDataObject = IdentificationNumber.fromTextualRepresentation(requestDto.getMbusIdentificationNumber()).asDataObject();
}
final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors(executorName).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.IDENTIFICATION_NUMBER, identificationNumberDataObject, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.MANUFACTURER_ID, ManufacturerId.fromIdentification(requestDto.getMbusManufacturerIdentification()).asDataObject(), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.VERSION, DataObject.newUInteger8Data(requestDto.getMbusVersion()), obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.DEVICE_TYPE, DataObject.newUInteger8Data(requestDto.getMbusDeviceTypeIdentification()), obiscode, classId));
if (requestDto.getPrimaryAddress() != null) {
dataObjectExecutors.addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.PRIMARY_ADDRESS, DataObject.newUInteger8Data(requestDto.getPrimaryAddress()), obiscode, classId));
}
conn.getDlmsMessageListener().setDescription(String.format("Write updated MBus attributes to channel %d, set attributes: %s", channel, dataObjectExecutors.describeAttributes()));
dataObjectExecutors.execute(conn);
log.info("Finished coupling the mbus device to the gateway device");
return new ChannelElementValuesDto(channel, requestDto.getPrimaryAddress(), requestDto.getMbusIdentificationNumber(), requestDto.getMbusManufacturerIdentification(), requestDto.getMbusVersion(), requestDto.getMbusDeviceTypeIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelper method resetMBusClientAttributeValues.
protected void resetMBusClientAttributeValues(final DlmsConnectionManager conn, final DlmsDevice device, final short channel, final String executorName) throws ProtocolAdapterException {
final DlmsObject mbusClientSetupObject = this.dlmsObjectConfigService.getDlmsObject(device, DlmsObjectType.MBUS_CLIENT_SETUP);
final ObisCode obiscode = mbusClientSetupObject.getObisCodeWithChannel(channel);
final int classId = mbusClientSetupObject.getClassId();
final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors(executorName).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.IDENTIFICATION_NUMBER, UINT_32_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.MANUFACTURER_ID, UINT_16_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.VERSION, UINT_8_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.DEVICE_TYPE, UINT_8_ZERO, obiscode, classId)).addExecutor(this.getMbusAttributeExecutor(MbusClientAttribute.PRIMARY_ADDRESS, UINT_8_ZERO, obiscode, classId));
conn.getDlmsMessageListener().setDescription(String.format("Reset MBus attributes to channel %d", channel));
dataObjectExecutors.execute(conn);
}
Aggregations