use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method setUp.
@BeforeEach
public void setUp() {
this.setParametersReceived = new ArrayList<>();
this.device = new DlmsDevice("SuperAwesomeHeroicRockstarDevice");
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
final DlmsObjectConfigConfiguration dlmsObjectConfigConfiguration = new DlmsObjectConfigConfiguration();
final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(new DlmsHelper(), dlmsObjectConfigConfiguration.getDlmsObjectConfigs()) {
@Override
public Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type, final Integer channel) {
switch(type) {
case ALARM_FILTER_1:
return Optional.of(new AttributeAddress(40, "0.0.97.98.10.255", 2));
case ALARM_FILTER_2:
return Optional.of(new AttributeAddress(40, "0.0.97.98.11.255", 2));
}
return Optional.empty();
}
};
this.executor = new SetAlarmNotificationsCommandExecutor(dlmsObjectConfigService);
final DlmsConnectionStub conn = new DlmsConnectionStub() {
@Override
public AccessResultCode set(final SetParameter setParameter) {
SetAlarmNotificationsCommandExecutorTest.this.setParametersReceived.add(setParameter);
return AccessResultCode.SUCCESS;
}
};
// Set the return value to 10 (0b1010):
// REPLACE_BATTERY enabled, AUXILIARY_EVENT enabled.
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.10.255", 2), DataObject.newInteger32Data(10));
conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0));
this.connMgr = new DlmsConnectionManagerStub(conn);
}
use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.
the class GetAllAttributeValuesCommandExecutor method execute.
@Override
public String execute(final DlmsConnectionManager conn, final DlmsDevice device, final DataObject object, final MessageMetadata messageMetadata) throws OsgpException {
final AttributeAddress attributeAddress = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
LOGGER.debug("Retrieving all attribute values for class id: {}, obis code: {}, attribute id: {}", CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
final DataObject objectList = this.dlmsHelper.getAttributeValue(conn, attributeAddress);
if (!objectList.isComplex()) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final List<DataObject> objectListElements = objectList.getValue();
final List<ClassIdObisAttr> allObisCodes = this.getAllObisCodes(objectListElements);
this.logAllObisCodes(allObisCodes);
try {
final String output = this.createOutput(conn, allObisCodes);
LOGGER.debug("Total output is: {}", output);
return output;
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.
the class GetAllAttributeValuesCommandExecutor method getAllDataFromAttribute.
private String getAllDataFromAttribute(final DlmsConnectionManager conn, final int classNumber, final DataObject obisCode, final int attributeValue) throws ProtocolAdapterException, IOException {
if (!obisCode.isByteArray()) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final byte[] obisCodeByteArray = obisCode.getValue();
if (obisCodeByteArray.length != OBIS_CODE_BYTE_ARRAY_LENGTH) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final AttributeAddress attributeAddress = new AttributeAddress(classNumber, new ObisCode(obisCodeByteArray), attributeValue);
conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
LOGGER.debug("Retrieving configuration objects data for class id: {}, obis code: {}, attribute id: {}", classNumber, obisCodeByteArray, attributeValue);
final GetResult getResult = conn.getConnection().get(attributeAddress);
LOGGER.debug("ResultCode: {}", getResult.getResultCode());
return this.dlmsHelper.getDebugInfo(getResult.getResultData());
}
use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method createAttributeAddresses.
private AttributeAddress[] createAttributeAddresses(final DlmsObject dlmsObject) {
final int classId = dlmsObject.getClassId();
final ObisCode obisCode = dlmsObject.getObisCode();
return new AttributeAddress[] { new AttributeAddress(classId, obisCode, OPERATOR.attributeId()), new AttributeAddress(classId, obisCode, MODEM_REGISTRATION_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CIRCUIT_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, PACKET_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CELL_INFO.attributeId()), new AttributeAddress(classId, obisCode, ADJACENT_CELLS.attributeId()) // Reading of capture_time is disabled for now, because the jDLMS library appears to handle
// the COSEM date-time in the response incorrectly. Also see comment in getCaptureTime.
// new AttributeAddress(classId, obisCode, CAPTURE_TIME.attributeId())
};
}
use of org.openmuc.jdlms.AttributeAddress in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method execute.
@Override
public GetGsmDiagnosticResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetGsmDiagnosticRequestDto getGsmDiagnosticQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DlmsObject dlmsObject = this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(device, DlmsObjectType.GSM_DIAGNOSTIC);
final AttributeAddress[] addresses = this.createAttributeAddresses(dlmsObject);
final String addressesDescriptions = JdlmsObjectToStringUtil.describeAttributes(addresses);
conn.getDlmsMessageListener().setDescription("Get GsmDiagnostic, retrieve attributes: " + addressesDescriptions);
LOGGER.info("Get GsmDiagnostic, retrieve attributes: {}", addressesDescriptions);
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "Get GsmDiagnostic", addresses);
LOGGER.info("GetResultList: {}", describeGetResults(getResultList));
if (!getResultList.stream().allMatch(result -> result.getResultCode() == AccessResultCode.SUCCESS)) {
throw new ProtocolAdapterException("Get gsm diagnostic failed for " + device.getDeviceId());
}
return this.createGetGsmDiagnosticResponse(getResultList);
}
Aggregations