use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class AbstractCommandExecutor method getValidatedResultData.
/**
* Retrieves connection, gets result data and validates it before returning.
*
* @param conn holds connection
* @param getParameter for attribute to retrieve result data from
* @return dataObject
*/
public DataObject getValidatedResultData(final DlmsConnectionManager conn, final AttributeAddress getParameter) throws ProtocolAdapterException {
final GetResult getResult;
try {
getResult = conn.getConnection().get(getParameter);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving M-Bus encryption key status.");
}
final DataObject dataObject = getResult.getResultData();
if (!dataObject.isNumber()) {
throw new ProtocolAdapterException("Received unexpected result data.");
}
return dataObject;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class ClearAlarmRegisterCommandExecutor method executeForAlarmRegister.
public AccessResultCode executeForAlarmRegister(final DlmsConnectionManager conn, final AttributeAddress alarmRegisterAttributeAddress) {
log.info("Clear alarm register {}", JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
final DataObject data = DataObject.newUInteger32Data(ALARM_CODE);
final SetParameter setParameter = new SetParameter(alarmRegisterAttributeAddress, data);
conn.getDlmsMessageListener().setDescription("ClearAlarmRegister, with alarm code = " + ALARM_CODE + JdlmsObjectToStringUtil.describeAttributes(alarmRegisterAttributeAddress));
try {
return conn.getConnection().set(setParameter);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandActivationExecutor method execute.
@Override
public MethodResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void v, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
LOGGER.info("ACTIVATING PASSIVE CALENDAR");
final MethodParameter method = new MethodParameter(CLASS_ID, OBIS_CODE, METHOD_ID_ACTIVATE_PASSIVE_CALENDAR, DataObject.newInteger32Data(0));
conn.getDlmsMessageListener().setDescription("SetActivityCalendarActivation, call method: " + JdlmsObjectToStringUtil.describeMethod(method));
final MethodResult methodResultCode;
try {
methodResultCode = conn.getConnection().action(method);
} catch (final IOException e) {
throw new ConnectionException(e);
}
if (!MethodResultCode.SUCCESS.equals(methodResultCode.getResultCode())) {
throw new ProtocolAdapterException("Activating the activity calendar failed. MethodResult is: " + methodResultCode.getResultCode() + " ClassId: " + CLASS_ID + " obisCode: " + OBIS_CODE + " method id: " + METHOD_ID_ACTIVATE_PASSIVE_CALENDAR);
}
return MethodResultCode.SUCCESS;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException 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.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException 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);
}
}
Aggregations