use of org.opensmartgridplatform.dlms.DlmsPushNotification in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoderTest method decodeSmr5AlarmsWithAlarmRegister.
@Test
public void decodeSmr5AlarmsWithAlarmRegister() throws UnrecognizedMessageDataException {
// SETUP
this.decoder = new DlmsPushNotificationDecoder();
final ByteBuf buffer = mock(ByteBuf.class);
// Create alarm register with 4 alarms: replace battery, 2 mbus alarms
// and phase outage detected (new in SMR5.1)
final byte[] alarmRegister = new byte[] { 0x10, 0x18, 0x00, 0x02 };
this.setupSmr5BufferWithAlarm(buffer, IDENTIFIER, ALARM_OBISCODE_BYTES, alarmRegister);
// CALL
final List<Object> out = new ArrayList<>();
this.decoder.decode(this.ctx, buffer, out);
final Object pushNotificationObject = out.get(0);
// VERIFY
assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(PUSH_ALARM_TRIGGER);
final Set<AlarmTypeDto> alarms = dlmsPushNotification.getAlarms();
assertThat(alarms.size()).isEqualTo(4);
assertThat(alarms.contains(REPLACE_BATTERY)).isTrue();
assertThat(alarms.contains(COMMUNICATION_ERROR_M_BUS_CHANNEL_4)).isTrue();
assertThat(alarms.contains(FRAUD_ATTEMPT_M_BUS_CHANNEL_1)).isTrue();
assertThat(alarms.contains(PHASE_OUTAGE_DETECTED_L1)).isTrue();
this.verifySmr5BufferCallsWithAlarm(buffer, alarmRegister);
// Verify the addressing bytes, the 0x0F for data-notification and the
// invoke-id bytes were skipped
verify(buffer, times(1)).skipBytes(SMR5_NUMBER_OF_BYTES_FOR_ADDRESSING + 1 + SMR5_NUMBER_OF_BYTES_FOR_INVOKE_ID);
}
use of org.opensmartgridplatform.dlms.DlmsPushNotification in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoderTest method decodeSmr5AlarmsWithLogicalName.
private void decodeSmr5AlarmsWithLogicalName(final byte[] logicalName, final String expecterTriggerType, final boolean withDateTime) throws UnrecognizedMessageDataException {
// SETUP
this.decoder = new DlmsPushNotificationDecoder();
final ByteBuf buffer = mock(ByteBuf.class);
this.setupSmr5Buffer(buffer, IDENTIFIER, logicalName, withDateTime);
// CALL
final List<Object> out = new ArrayList<>();
this.decoder.decode(this.ctx, buffer, out);
final Object pushNotificationObject = out.get(0);
// VERIFY
assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(expecterTriggerType);
assertThat(dlmsPushNotification.getAlarms().isEmpty()).isTrue();
this.verifySmr5BufferCalls(buffer);
// Verify the addressing bytes, the 0x0F for data-notification and the
// invoke-id bytes were skipped
verify(buffer, times(1)).skipBytes(SMR5_NUMBER_OF_BYTES_FOR_ADDRESSING + 1 + SMR5_NUMBER_OF_BYTES_FOR_INVOKE_ID);
if (withDateTime) {
// Verify the date-time bytes were skipped
verify(buffer, times(1)).skipBytes(SMR5_NUMBER_OF_BYTES_FOR_DATETIME);
}
}
use of org.opensmartgridplatform.dlms.DlmsPushNotification in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoder method decode.
/**
* Decoded the alarm bytes in the buffer. Could be either a DSMR4 or SMR5 alarm. If there are not
* enough bytes while decoding, the ReplayingDecoder rewinds and tries the decoding again when
* there are more bytes received.
*
* @param ctx the context from the ReplayingDecoder. Not used in decoding the alarm.
* @param in the bytes of the alarm.
* @param out decoded list of objects
* @throws UnrecognizedMessageDataException
*/
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws UnrecognizedMessageDataException {
/**
* DSMR4 alarm examples (in HEX bytes):
*
* <p>45 58 58 58 58 31 32 33 34 35 36 37 38 39 30 31 32 // Equipment id EXXXX123456789012 2C //
* Comma 00 00 0F 00 04 FF // Logical name 0.0.15.0.4.255
*
* <p>45 58 58 58 58 31 32 33 34 35 36 37 38 39 30 31 32 // Equipment id EXXXX123456789012 2C //
* Comma 00 00 00 02 // Alarm register, with Replace battery set
*
* <p>SMR5 alarm examples (in HEX bytes):
*
* <p>0F // Data-notification 00 00 00 01 // Long-invoke-id-and-priority (can be ignored) 00 //
* Date-time (empty) 02 02 // Structure with 2 elements 09 11 45 58 58 58 58 31 32 33 34 35 36
* 37 38 39 30 31 32 // Equipment id EXXXX123456789012 09 06 00 00 19 09 00 FF // Logical name:
* Push setup schedule
*
* <p>0F // Data-notification 00 00 00 01 // Long-invoke-id-and-priority (can be ignored) 00 //
* Date-time (empty) 02 03 // Structure with 3 elements 09 11 45 58 58 58 58 31 32 33 34 35 36
* 37 38 39 30 31 32 // Equipment id EXXXX123456789012 09 06 00 01 19 09 00 FF // Logical name:
* Push setup alarms 06 00 00 00 02 // Alarm register, with Replace battery set
*
* <p>Notes: - For SMR5 alarms, we get 8 additional addressing bytes in front of the alarm.
* These bytes can be ignored here. - To check if the alarm is in DSMR4 or SMR5 format, check
* the 9th byte (at index 8). If it is 0F, then it is SMR5, otherwise it is DSMR4, because the
* 9th byte in DSMR4 is in the identifier and this should be a number or a character, so it
* can't be ASCII code 0F.
*/
final DlmsPushNotification pushNotification;
// Determine whether the alarm is in DSMR4 or SMR5 format.
final boolean smr5alarm = in.getByte(8) == 0x0F;
LOGGER.info("Decoding state: {}, SMR5 alarm: {}", this.state(), smr5alarm);
if (smr5alarm) {
final Smr5AlarmDecoder alarmDecoder = new Smr5AlarmDecoder();
pushNotification = alarmDecoder.decodeSmr5alarm(in);
} else {
final Dsmr4AlarmDecoder alarmDecoder = new Dsmr4AlarmDecoder();
pushNotification = alarmDecoder.decodeDsmr4alarm(in);
}
LOGGER.info("Decoded push notification: {}", pushNotification);
out.add(pushNotification);
}
use of org.opensmartgridplatform.dlms.DlmsPushNotification in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoderTest method decodeDsmr4AlarmsWithAlarmRegister.
@Test
public void decodeDsmr4AlarmsWithAlarmRegister() throws UnrecognizedMessageDataException {
// SETUP
this.decoder = new DlmsPushNotificationDecoder();
final ByteBuf buffer = mock(ByteBuf.class);
// Create alarm register with 3 alarms: replace battery and 2 mbus
// alarms
final byte[] alarmRegister = new byte[] { 0x00, 0x18, 0x00, 0x02 };
final byte[] bytes = this.setupDsmr4Buffer(buffer, IDENTIFIER, alarmRegister);
// CALL
final List<Object> out = new ArrayList<>();
this.decoder.decode(this.ctx, buffer, out);
final Object pushNotificationObject = out.get(0);
// VERIFY
assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(PUSH_ALARM_TRIGGER);
assertThat(dlmsPushNotification.toByteArray()).isEqualTo(bytes);
final Set<AlarmTypeDto> alarms = dlmsPushNotification.getAlarms();
assertThat(alarms.size()).isEqualTo(3);
assertThat(alarms.contains(REPLACE_BATTERY)).isTrue();
assertThat(alarms.contains(COMMUNICATION_ERROR_M_BUS_CHANNEL_4)).isTrue();
assertThat(alarms.contains(FRAUD_ATTEMPT_M_BUS_CHANNEL_1)).isTrue();
this.verifyDsmr4BufferCalls(buffer, alarmRegister);
}
use of org.opensmartgridplatform.dlms.DlmsPushNotification in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoderTest method decodeDsmr4AlarmsWithLogicalName.
private void decodeDsmr4AlarmsWithLogicalName(final byte[] logicalName, final String expecterTriggerType) throws UnrecognizedMessageDataException {
// SETUP
this.decoder = new DlmsPushNotificationDecoder();
final ByteBuf buffer = mock(ByteBuf.class);
final byte[] bytes = this.setupDsmr4Buffer(buffer, IDENTIFIER, logicalName);
// CALL
final List<Object> out = new ArrayList<>();
this.decoder.decode(this.ctx, buffer, out);
final Object pushNotificationObject = out.get(0);
// VERIFY
assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(expecterTriggerType);
assertThat(dlmsPushNotification.getAlarms().isEmpty()).isTrue();
assertThat(dlmsPushNotification.toByteArray()).isEqualTo(bytes);
this.verifyDsmr4BufferCalls(buffer, logicalName);
}
Aggregations