use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DomainHelperService method getDeviceIpAddressFromSessionProvider.
public String getDeviceIpAddressFromSessionProvider(final DlmsDevice dlmsDevice) throws OsgpException {
final SessionProvider sessionProvider = this.sessionProviderService.getSessionProvider(dlmsDevice.getCommunicationProvider());
String deviceIpAddress;
try {
deviceIpAddress = sessionProvider.getIpAddress(dlmsDevice.getIccId());
if (deviceIpAddress != null) {
return deviceIpAddress;
}
// If the result is null then the meter is not in session (not
// awake).
// So wake up the meter and start polling for the session
this.jasperWirelessSmsClient.sendWakeUpSMS(dlmsDevice.getIccId());
deviceIpAddress = this.pollForSession(sessionProvider, dlmsDevice);
} catch (final SessionProviderException e) {
LOGGER.error("IccId is probably not supported in this session provider", e);
throw new FunctionalException(FunctionalExceptionType.INVALID_ICCID, ComponentType.PROTOCOL_DLMS, e);
}
if ((deviceIpAddress == null) || "".equals(deviceIpAddress)) {
throw new ProtocolAdapterException("Session provider: " + dlmsDevice.getCommunicationProvider() + " did not return an IP address for device: " + dlmsDevice.getDeviceIdentification() + " and iccId: " + dlmsDevice.getIccId());
}
return deviceIpAddress;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class ClearMBusStatusOnAllChannelsCommandExecutor method clearStatusMaskForChannel.
private void clearStatusMaskForChannel(final DlmsConnectionManager conn, final int channel, final DlmsDevice device) throws IOException, ProtocolAdapterException {
final AttributeAddress readMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.READ_MBUS_STATUS, channel);
final AttributeAddress clearMBusStatusAttributeAddress = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLEAR_MBUS_STATUS, channel);
final AttributeAddress clientSetupMbus = this.dlmsObjectConfigService.getAttributeAddress(device, DlmsObjectType.CLIENT_SETUP_MBUS, channel);
final long statusMask = this.readStatus(conn, channel, readMBusStatusAttributeAddress);
if (statusMask == 0L) {
return;
}
final AccessResultCode resultCode = this.setClearStatusMask(statusMask, conn, channel, clearMBusStatusAttributeAddress);
if (resultCode != AccessResultCode.SUCCESS) {
throw new ProtocolAdapterException("Unable to set clear status mask for M-Bus channel " + channel + ", AccessResultCode=" + resultCode + ".");
}
final MethodResult methodResult = this.resetAlarm(conn, channel, clientSetupMbus.getInstanceId());
if (methodResult.getResultCode() != MethodResultCode.SUCCESS) {
throw new ProtocolAdapterException("Call for RESET_ALARM was unsuccessful for M-Bus channel " + channel + ", MethodResultCode=" + methodResult.getResultCode() + ".");
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutor method retrieveCurrentAlarmNotifications.
private AlarmNotificationsDto retrieveCurrentAlarmNotifications(final DlmsConnectionManager conn, final AttributeAddress alarmFilterValue, final DlmsObjectType alarmRegisterDlmsObjectType) throws IOException, ProtocolAdapterException {
conn.getDlmsMessageListener().setDescription("SetAlarmNotifications retrieve current value, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(alarmFilterValue));
LOGGER.info("Retrieving current alarm filter by issuing get request for for address: {}", alarmFilterValue);
final GetResult getResult = conn.getConnection().get(alarmFilterValue);
if (getResult == null) {
throw new ProtocolAdapterException("No GetResult received while retrieving current alarm filter.");
}
return this.alarmNotifications(getResult.getResultData(), alarmRegisterDlmsObjectType);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4 method getConfigurationObject.
private ConfigurationObjectDto getConfigurationObject(final List<DataObject> elements) throws ProtocolAdapterException {
final Optional<GprsOperationModeTypeDto> gprsMode = this.getGprsOperationMode(elements.get(INDEX_OF_GPRS_OPERATION_MODE));
final ConfigurationFlagsDto flags = this.getConfigurationFlags(elements.get(INDEX_OF_CONFIGURATION_FLAGS));
return gprsMode.map(c -> new ConfigurationObjectDto(c, flags)).orElseGet(() -> new ConfigurationObjectDto(flags));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException 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;
}
Aggregations