use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method getCellInfo.
private CellInfoDto getCellInfo(final List<GetResult> getResultList) {
final GetResult result = getResultList.get(RESULT_CELL_INFO_INDEX);
if (result.getResultCode() != AccessResultCode.SUCCESS) {
return null;
}
final List<DataObject> cellInfoDataObjects = result.getResultData().getValue();
if (cellInfoDataObjects != null) {
return new CellInfoDto(cellInfoDataObjects.get(CELL_INFO_CELL_ID_INDEX).getValue(), cellInfoDataObjects.get(CELL_INFO_LOCATION_ID_INDEX).getValue(), SignalQualityDto.fromIndexValue((short) cellInfoDataObjects.get(CELL_INFO_SIGNAL_QUALITY_INDEX).getValue()), BitErrorRateDto.fromIndexValue((short) cellInfoDataObjects.get(CELL_INFO_BIT_ERROR_RATE_INDEX).getValue()), cellInfoDataObjects.get(CELL_INFO_MOBILE_COUNTRY_CODE_INDEX).getValue(), cellInfoDataObjects.get(CELL_INFO_MOBILE_NETWORK_CODE_INDEX).getValue(), cellInfoDataObjects.get(CELL_INFO_CHANNEL_NUMBER_INDEX).getValue());
} else {
return null;
}
}
use of org.openmuc.jdlms.GetResult 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);
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method getAdjacentCells.
private List<AdjacentCellInfoDto> getAdjacentCells(final List<GetResult> getResultList) {
final GetResult result = getResultList.get(RESULT_ADJACENT_CELLS_INDEX);
if (result.getResultCode() != AccessResultCode.SUCCESS) {
return Collections.emptyList();
}
final List<DataObject> adjacentCellsDataObjects = result.getResultData().getValue();
if (adjacentCellsDataObjects == null) {
return Collections.emptyList();
} else {
return adjacentCellsDataObjects.stream().map(cellInfo -> {
final List<DataObject> adjacentCell = cellInfo.getValue();
return new AdjacentCellInfoDto(adjacentCell.get(ADJACENT_CELLS_CELL_ID_INDEX).getValue(), SignalQualityDto.fromIndexValue((short) adjacentCell.get(ADJACENT_CELLS_SIGNAL_QUALITY_INDEX).getValue()));
}).collect(Collectors.toList());
}
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method getCaptureTime.
private Date getCaptureTime(final List<GetResult> getResultList) throws ProtocolAdapterException {
// createAttributeAddresses.
if (RESULT_CAPTURE_TIME_INDEX >= getResultList.size()) {
return null;
}
final GetResult result = getResultList.get(RESULT_CAPTURE_TIME_INDEX);
if (this.isResultSuccess(result)) {
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(result.getResultData(), "Clock from gsm diagnostic");
final Date captureTime;
if (cosemDateTime.isDateTimeSpecified()) {
captureTime = cosemDateTime.asDateTime().toDate();
} else {
throw new ProtocolAdapterException("Unexpected values in gsm diagnostic capture time");
}
return captureTime;
} else {
return null;
}
}
use of org.openmuc.jdlms.GetResult in project open-smart-grid-platform by OSGP.
the class GetOutagesCommandExecutor method execute.
@Override
public List<OutageDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetOutagesRequestDto getOutagesRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final AttributeAddress eventLogBuffer = new AttributeAddress(CLASS_ID, new ObisCode(OBIS_CODE), ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("RetrieveOutages, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(eventLogBuffer));
final GetResult getResult;
try {
getResult = conn.getConnection().get(eventLogBuffer);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving event register POWER_FAILURE_EVENT_LOG");
}
if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) {
log.info("Result of getting events for POWER_FAILURE_EVENT_LOG is {}", getResult.getResultCode());
throw new ProtocolAdapterException("Getting the outages from POWER_FAILURE_EVENT_LOG from the meter resulted in: " + getResult.getResultCode());
}
final DataObject resultData = getResult.getResultData();
return this.dataObjectToOutageListConverter.convert(resultData);
}
Aggregations