use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class ClearAlarmRegisterCommandExecutorTest method assertForOneRegister.
void assertForOneRegister(final String protocol, final String protocolVersion) throws ProtocolAdapterException, IOException {
final DlmsDevice dlmsDevice = new DlmsDevice(protocol + " " + protocolVersion + " device");
dlmsDevice.setProtocol(protocol, protocolVersion);
when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice, DlmsObjectType.ALARM_REGISTER_1, null)).thenReturn(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_ALARM_REGISTER_1, DataAttribute.VALUE.attributeId()));
when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.SUCCESS);
this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
assertThat(this.setParameterArgumentCaptor.getAllValues()).hasSize(1);
final SetParameter setParameter = this.setParameterArgumentCaptor.getAllValues().get(0);
assertThat(((Number) setParameter.getData().getValue()).longValue()).isEqualTo(ALARM_CODE);
final AttributeAddress attributeAddress = setParameter.getAttributeAddress();
assertThat(attributeAddress.getInstanceId().asDecimalString()).isEqualTo(OBIS_CODE_ALARM_REGISTER_1);
assertThat(attributeAddress.getClassId()).isEqualTo(CLASS_ID_CLEAR_ALARM_REGISTER);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectCommandExecutorDsmr4IT method execute.
@Test
public void execute() throws IOException, ProtocolAdapterException {
// SETUP
// configurationToSet: 0111-----1------
final GprsOperationModeTypeDto gprsModeToSet = GprsOperationModeTypeDto.TRIGGERED;
final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsModeToSet, this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, false), this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.DYNAMIC_MBUS_ADDRESS, true), this.createFlagDto(ConfigurationFlagTypeDto.PO_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, true));
// flagsOnDevice: 1000101010000000
final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, ConfigurationFlagTypeDto.HLS_3_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_4_ON_PO_ENABLE);
// result of merging configurationToSet and flagsOnDevice
final byte firstExpectedByte = this.asByte("01111010");
final byte secondExpectedByte = this.asByte("11000000");
final GprsOperationModeTypeDto gprsModeOnDevice = GprsOperationModeTypeDto.ALWAYS_ON;
final DataObject deviceData = this.createStructureData(flagsOnDevice, gprsModeOnDevice);
when(this.getResult.getResultData()).thenReturn(deviceData);
final DlmsDevice device = new DlmsDevice();
device.setProtocol(Protocol.DSMR_4_2_2);
// CALL
final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
// VERIFY
assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
final List<DataObject> elements = this.captureSetParameterStructureData();
final Number gprsOperationMode = elements.get(INDEX_OF_GPRS_OPERATION_MODE).getValue();
assertThat(gprsOperationMode).isEqualTo(gprsModeToSet.getNumber());
final BitString configurationFlags = elements.get(INDEX_OF_CONFIGURATION_FLAGS).getValue();
final byte[] flagsSentToDevice = configurationFlags.getBitString();
assertThat(flagsSentToDevice[0]).isEqualTo(firstExpectedByte);
assertThat(flagsSentToDevice[1]).isEqualTo(secondExpectedByte);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method createDlmsDevice.
private DlmsDevice createDlmsDevice(final Protocol protocol) {
final DlmsDevice device = new DlmsDevice();
device.setProtocol(protocol);
device.setSelectiveAccessSupported(true);
return device;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectCommandExecutorTest method execute.
@Test
public void execute() throws ProtocolAdapterException {
// SETUP
final DlmsDevice device = new DlmsDevice();
final Protocol protocol = Protocol.DSMR_4_2_2;
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
device.setProtocol(protocol);
when(this.protocolServiceLookup.lookupGetService(protocol)).thenReturn(this.getService);
when(this.getService.getConfigurationObject(this.conn)).thenReturn(this.configurationOnDevice);
when(this.protocolServiceLookup.lookupSetService(protocol)).thenReturn(this.setService);
final AccessResultCode accessResultCode = AccessResultCode.SUCCESS;
when(this.setService.setConfigurationObject(this.conn, this.configurationToSet, this.configurationOnDevice)).thenReturn(accessResultCode);
// CALL
final AccessResultCode result = this.instance.execute(this.conn, device, this.configurationToSet, messageMetadata);
// VERIFY
assertThat(result).isSameAs(accessResultCode);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutorIntegrationTest method testExecute.
private void testExecute(final Protocol protocol, final CommunicationMethod method, final boolean expectObjectNotFound) throws Exception {
// SETUP
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
// Reset stub
this.connectionStub.clearRequestedAttributeAddresses();
// Create device with requested protocol version and communication method
final DlmsDevice device = this.createDlmsDevice(protocol, method);
// Create request object
final GetGsmDiagnosticRequestDto request = new GetGsmDiagnosticRequestDto();
// Get expected addresses
final AttributeAddress expectedAddressOperator = this.createAttributeAddress(method, 2);
final AttributeAddress expectedAddressRegistrationStatus = this.createAttributeAddress(method, 3);
final AttributeAddress expectedAddressCsStatus = this.createAttributeAddress(method, 4);
final AttributeAddress expectedAddressPsStatus = this.createAttributeAddress(method, 5);
final AttributeAddress expectedAddressCellInfo = this.createAttributeAddress(method, 6);
final AttributeAddress expectedAddressAdjacentCells = this.createAttributeAddress(method, 7);
final AttributeAddress expectedAddressCaptureTime = this.createAttributeAddress(method, 8);
// Reading of capture_time is disabled for now, therefore only 6 addresses expected
final int expectedTotalNumberOfAttributeAddresses = 6;
// Set responses in stub
this.setResponseForOperator(expectedAddressOperator);
this.setResponseForRegistrationStatus(expectedAddressRegistrationStatus);
this.setResponseForCsStatus(expectedAddressCsStatus);
this.setResponseForPsStatus(expectedAddressPsStatus);
this.setResponseForCellInfo(expectedAddressCellInfo);
this.setResponseForAdjacentCells(expectedAddressAdjacentCells);
this.setResponseForCaptureTime(expectedAddressCaptureTime);
// CALL
GetGsmDiagnosticResponseDto response = null;
try {
response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
} catch (final ProtocolAdapterException e) {
if (expectObjectNotFound) {
assertThat(e.getMessage()).isEqualTo("Did not find GSM_DIAGNOSTIC object with communication method " + method.getMethodName() + " for device 6789012");
return;
} else {
fail("Unexpected ProtocolAdapterException: " + e.getMessage());
}
}
// VERIFY
// Get resulting requests from connection stub
final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
assertThat(requestedAttributeAddresses.size()).isEqualTo(expectedTotalNumberOfAttributeAddresses);
// Check response
assertThat(response).isNotNull();
assertThat(response).isNotNull();
assertThat(response.getOperator()).isEqualTo("Operator");
assertThat(response.getModemRegistrationStatus()).isEqualTo(ModemRegistrationStatusDto.REGISTERED_ROAMING);
assertThat(response.getCircuitSwitchedStatus()).isEqualTo(CircuitSwitchedStatusDto.INACTIVE);
assertThat(response.getPacketSwitchedStatus()).isEqualTo(PacketSwitchedStatusDto.CDMA);
final CellInfoDto cellInfo = response.getCellInfo();
assertThat(cellInfo.getCellId()).isEqualTo(93L);
assertThat(cellInfo.getLocationId()).isEqualTo(2232);
assertThat(cellInfo.getSignalQuality()).isEqualTo(SignalQualityDto.MINUS_87_DBM);
assertThat(cellInfo.getBitErrorRate()).isEqualTo(BitErrorRateDto.RXQUAL_6);
assertThat(cellInfo.getMobileCountryCode()).isEqualTo(204);
assertThat(cellInfo.getMobileNetworkCode()).isEqualTo(66);
assertThat(cellInfo.getChannelNumber()).isEqualTo(107);
final List<AdjacentCellInfoDto> adjacentCells = response.getAdjacentCells();
assertThat(adjacentCells.size()).isEqualTo(3);
assertThat(adjacentCells.get(0).getCellId()).isEqualTo(85L);
assertThat(adjacentCells.get(0).getSignalQuality()).isEqualTo(SignalQualityDto.MINUS_65_DBM);
// Reading of capture_time is disabled, so don't check the capture time
// assertThat(response.getCaptureTime())
// .isEqualTo(new DateTime(2021, 4, 1, 9, 28, DateTimeZone.UTC).toDate());
}
Aggregations