use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class SetSpecialDaysCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final List<SpecialDayDto> specialDays, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final StringBuilder specialDayData = new StringBuilder();
final List<DataObject> specialDayEntries = new ArrayList<>();
int i = 0;
for (final SpecialDayDto specialDay : specialDays) {
specialDayData.append(", ").append(specialDay.getDayId()).append(" => ").append(specialDay.getSpecialDayDate());
final List<DataObject> specDayEntry = new ArrayList<>();
specDayEntry.add(DataObject.newUInteger16Data(i));
specDayEntry.add(this.dlmsHelper.asDataObject(specialDay.getSpecialDayDate()));
specDayEntry.add(DataObject.newUInteger8Data((short) specialDay.getDayId()));
final DataObject dayStruct = DataObject.newStructureData(specDayEntry);
specialDayEntries.add(dayStruct);
i += 1;
}
final AttributeAddress specialDaysTableEntries = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
final DataObject entries = DataObject.newArrayData(specialDayEntries);
final SetParameter request = new SetParameter(specialDaysTableEntries, entries);
final String specialDayValues;
if (specialDayData.length() == 0) {
specialDayValues = "";
} else {
specialDayValues = ", values [" + specialDayData.substring(2) + "]";
}
conn.getDlmsMessageListener().setDescription("SetSpecialDays" + specialDayValues + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(specialDaysTableEntries));
try {
return conn.getConnection().set(request);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class SynchronizeTimeCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final SynchronizeTimeRequestDto synchronizeTimeRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DateTime dt = DateTime.now();
final DataObject time = this.dlmsHelper.asDataObject(dt, synchronizeTimeRequestDto.getDeviation(), synchronizeTimeRequestDto.isDst());
final SetParameter setParameter = new SetParameter(ATTRIBUTE_TIME, time);
conn.getDlmsMessageListener().setDescription("SynchronizeTime to " + dt + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(ATTRIBUTE_TIME));
try {
return conn.getConnection().set(setParameter);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getAccessDescription.
private SelectiveAccessDescription getAccessDescription(final AddressRequest addressRequest, final List<DlmsCaptureObject> selectedObjects) {
final DlmsObject object = addressRequest.getDlmsObject();
final DateTime from = addressRequest.getFrom();
final DateTime to = addressRequest.getTo();
if (!(object instanceof DlmsProfile) || from == null || to == null) {
return null;
} else {
final int accessSelector = 1;
final DataObject selectedValues = this.getSelectedValues(addressRequest, selectedObjects);
final DataObject accessParameter = this.dlmsHelper.getAccessSelectionTimeRangeParameter(from, to, selectedValues);
return new SelectiveAccessDescription(accessSelector, accessParameter);
}
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getSelectedValues.
private DataObject getSelectedValues(final AddressRequest addressRequest, final List<DlmsCaptureObject> selectedObjects) {
List<DataObject> objectDefinitions = new ArrayList<>();
final DlmsObject object = addressRequest.getDlmsObject();
final Protocol protocol = Protocol.forDevice(addressRequest.getDevice());
if (object instanceof DlmsProfile && ((DlmsProfile) object).getCaptureObjects() != null) {
final DlmsProfile profile = (DlmsProfile) object;
objectDefinitions = this.getObjectDefinitions(addressRequest.getChannel(), addressRequest.getFilterMedium(), protocol, profile, selectedObjects);
}
return DataObject.newArrayData(objectDefinitions);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutor method writeRandomisationSettings.
private void writeRandomisationSettings(final DlmsConnectionManager conn, final DlmsDevice device, final int randomisationStartWindow, final int multiplicationFactor, final int numberOfRetries) throws ProtocolAdapterException {
final AttributeAddress randomisationSettingsAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.RANDOMISATION_SETTINGS, null);
final DataObject randomisationStartWindowObject = DataObject.newUInteger32Data(randomisationStartWindow);
final DataObject multiplicationFactorObject = DataObject.newUInteger16Data(multiplicationFactor);
final DataObject numberOfRetriesObject = DataObject.newUInteger16Data(numberOfRetries);
final DataObject randomisationSettingsObject = DataObject.newStructureData(randomisationStartWindowObject, multiplicationFactorObject, numberOfRetriesObject);
final SetParameter setRandomisationSettings = new SetParameter(randomisationSettingsAddress, randomisationSettingsObject);
this.writeAttribute(conn, setRandomisationSettings);
}
Aggregations