use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.
the class CosemObjectAccessor method writeAttribute.
public void writeAttribute(final AttributeClass attributeClass, final DataObject data) throws ProtocolAdapterException {
final AttributeAddress attributeAddress = this.createAttributeAddress(attributeClass);
final SetParameter setParameter = new SetParameter(attributeAddress, data);
final AccessResultCode accessResultCode;
try {
accessResultCode = this.connector.getConnection().set(setParameter);
} catch (final IOException e) {
throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_WRITING_ATTRIBUTE, attributeClass, this.classId, this.obisCode), e);
}
if (accessResultCode != AccessResultCode.SUCCESS) {
throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_ACCESS_RESULT_NOT_SUCCESS, accessResultCode.name(), attributeClass, this.classId, this.obisCode));
}
}
use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.
the class DlmsHelper method checkResultCode.
private void checkResultCode(final GetResult getResult, final String description) throws ProtocolAdapterException {
final AccessResultCode resultCode = getResult.getResultCode();
LOGGER.debug("{} - AccessResultCode: {}", description, resultCode);
if (resultCode != AccessResultCode.SUCCESS) {
throw new ProtocolAdapterException("No success retrieving " + description + ": AccessResultCode = " + resultCode);
}
}
use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.
the class DlmsHelper method getAttributeValue.
/**
* Gets a single result from a meter, and returns the result data if retrieval was successful
* (resultCode of the GetResult equals AccessResultCode.SUCCESS).
*
* @return a result from trying to retrieve the value for the attribute identified by {@code
* attributeAddress}.
*/
public DataObject getAttributeValue(final DlmsConnectionManager conn, final AttributeAddress attributeAddress) throws FunctionalException {
Objects.requireNonNull(conn, "conn must not be null");
Objects.requireNonNull(attributeAddress, "attributeAddress must not be null");
try {
final GetResult getResult = conn.getConnection().get(attributeAddress);
final AccessResultCode resultCode = getResult.getResultCode();
if (AccessResultCode.SUCCESS == resultCode) {
return getResult.getResultData();
}
final String errorMessage = String.format("Retrieving attribute value for { %d, %s, %d }. Result: resultCode(%d), with data: %s", attributeAddress.getClassId(), attributeAddress.getInstanceId().asShortObisCodeString(), attributeAddress.getId(), resultCode.getCode(), this.getDebugInfo(getResult.getResultData()));
LOGGER.error(errorMessage);
throw new FunctionalException(FunctionalExceptionType.ERROR_RETRIEVING_ATTRIBUTE_VALUE, ComponentType.PROTOCOL_DLMS, new OsgpException(ComponentType.PROTOCOL_DLMS, errorMessage));
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.
the class SetPushSetupAlarmCommandExecutor method setSendDestinationAndMethod.
private AccessResultCode setSendDestinationAndMethod(final DlmsConnectionManager conn, final PushSetupAlarmDto pushSetupAlarm, final DlmsDevice device) throws ProtocolAdapterException {
LOGGER.info("Setting Send destination and method of Push Setup Alarm: {}", pushSetupAlarm.getSendDestinationAndMethod());
final SetParameter setParameterSendDestinationAndMethod = this.getSetParameterSendDestinationAndMethod(pushSetupAlarm, device);
final AccessResultCode resultCode = this.doSetRequest("PushSetupAlarm, Send destination and method", conn, setParameterSendDestinationAndMethod);
if (resultCode != null) {
return resultCode;
} else {
throw new ProtocolAdapterException("Error setting Alarm push setup data (destination and method.");
}
}
use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.
the class SetPushSetupAlarmCommandExecutor method setPushObjectList.
private AccessResultCode setPushObjectList(final DlmsConnectionManager conn, final PushSetupAlarmDto pushSetupAlarm) throws ProtocolAdapterException {
LOGGER.info("Setting Push Object List of Push Setup Alarm: {}", pushSetupAlarm.getPushObjectList());
// Before setting the push object list, verify if the objects in the list are really present in
// the meter
this.verifyPushObjects(pushSetupAlarm.getPushObjectList(), conn);
final SetParameter setParameterPushObjectList = this.getSetParameterPushObjectList(pushSetupAlarm);
final AccessResultCode resultCode = this.doSetRequest("PushSetupAlarm, push object list", conn, setParameterPushObjectList);
if (resultCode != null) {
return resultCode;
} else {
throw new ProtocolAdapterException("Error setting Alarm push setup data (push object list).");
}
}
Aggregations