use of org.apache.plc4x.java.ads.api.generic.types.AmsNetId in project plc4x by apache.
the class Plc4x2AdsProtocolTest method setUp.
@Before
public void setUp() {
AmsNetId targetAmsNetId = AmsNetId.of("1.2.3.4.5.6");
AmsPort targetAmsPort = AmsPort.of(7);
AmsNetId sourceAmsNetId = AmsNetId.of("8.9.10.11.12.13");
AmsPort sourceAmsPort = AmsPort.of(14);
SUT = new Plc4x2AdsProtocol(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, new ConcurrentHashMap<>());
}
use of org.apache.plc4x.java.ads.api.generic.types.AmsNetId in project plc4x by apache.
the class ADSProtocolBenchmark method buildAdsReadRequest.
private static AdsReadRequest buildAdsReadRequest() {
AmsNetId targetAmsNetId = AmsNetId.of("1.2.3.4.5.6");
AmsPort targetAmsPort = AmsPort.of(7);
AmsNetId sourceAmsNetId = AmsNetId.of("8.9.10.11.12.13");
AmsPort sourceAmsPort = AmsPort.of(14);
Invoke invokeId = Invoke.of(15);
return AdsReadRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, IndexGroup.of(1), IndexOffset.of(1), Length.of(1));
}
use of org.apache.plc4x.java.ads.api.generic.types.AmsNetId in project plc4x by apache.
the class ADSProtocolBenchmark method buildADSReadResponse.
private static byte[] buildADSReadResponse() {
AmsNetId targetAmsNetId = AmsNetId.of("1.2.3.4.5.6");
AmsPort targetAmsPort = AmsPort.of(7);
AmsNetId sourceAmsNetId = AmsNetId.of("8.9.10.11.12.13");
AmsPort sourceAmsPort = AmsPort.of(14);
Invoke invokeId = Invoke.of(15);
Result result = Result.of(AdsReturnCode.ADS_CODE_0);
Data data = Data.of("Hello World!".getBytes());
return AdsReadResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, result, data).getBytes();
}
use of org.apache.plc4x.java.ads.api.generic.types.AmsNetId in project plc4x by apache.
the class AbstractProtocolTest method amsPacketStream.
public static Stream<AmsPacket> amsPacketStream() {
AmsNetId targetAmsNetId = AmsNetId.of("1.2.3.4.5.6");
AmsPort targetAmsPort = AmsPort.of(7);
AmsNetId sourceAmsNetId = AmsNetId.of("8.9.10.11.12.13");
AmsPort sourceAmsPort = AmsPort.of(14);
Invoke invokeId = Invoke.of(15);
Data data = Data.of("Hello World!".getBytes());
return Stream.of(AdsAddDeviceNotificationRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, IndexGroup.of(1), IndexOffset.of(1), Length.of(1), TransmissionMode.of(1), MaxDelay.of(1), CycleTime.of(1)), AdsAddDeviceNotificationResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), NotificationHandle.of(0)), AdsDeleteDeviceNotificationRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, NotificationHandle.of(0)), AdsDeleteDeviceNotificationResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0)), AdsDeviceNotificationRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Stamps.of(1), Collections.singletonList(// Nano times need to be offset by (1.1.1970 - 1.1.1601) years in nanos
AdsStampHeader.of(TimeStamp.of(new Date()), Collections.singletonList(AdsNotificationSample.of(NotificationHandle.of(0), data))))), AdsReadDeviceInfoRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId), AdsReadDeviceInfoResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), MajorVersion.of((byte) 1), MinorVersion.of((byte) 2), Version.of(3), Device.of("Random DeviceId")), AdsReadRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, IndexGroup.of(0), IndexOffset.NONE, Length.of(1)), AdsReadResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), data), AdsReadStateRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId), AdsReadStateResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), AdsState.of(0), DeviceState.of(0)), AdsReadWriteRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, IndexGroup.of(0), IndexOffset.NONE, ReadLength.of(data.getCalculatedLength()), data), AdsReadWriteResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), data), AdsWriteControlRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, AdsState.of(0xaffe), DeviceState.of(0xaffe), data), AdsWriteControlResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0)), AdsWriteRequest.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, IndexGroup.of(0), IndexOffset.NONE, data), AdsWriteResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0)));
}
use of org.apache.plc4x.java.ads.api.generic.types.AmsNetId in project plc4x by apache.
the class Plc4x2AdsProtocolTest method data.
@Parameterized.Parameters(name = "{index} Type:{0} {3} {5}")
public static Collection<Object[]> data() {
AmsNetId targetAmsNetId = AmsNetId.of("1.2.3.4.5.6");
AmsPort targetAmsPort = AmsPort.of(7);
AmsNetId sourceAmsNetId = AmsNetId.of("8.9.10.11.12.13");
AmsPort sourceAmsPort = AmsPort.of(14);
Invoke invokeId = Invoke.of(2);
return streamOfLittleEndianDataTypePairs().filter(o -> o.getDataTypeClass() != LocalDateTime.class).filter(o -> o.getDataTypeClass() != Byte[].class).filter(o -> o.getDataTypeClass() != byte[].class).map(Plc4x2AdsProtocolTest::mapToAdsDataType).map(pair -> Stream.of(ImmutablePair.of(new PlcRequestContainer<>((InternalPlcRequest) // TODO: remove null
new DefaultPlcWriteRequest.Builder(null, new AdsPlcFieldHandler()).addItem(RandomStringUtils.randomAscii(10), "1/1:" + pair.adsDataType.name(), pair.getValue()).build(), new CompletableFuture<>()), AdsWriteResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0))), ImmutablePair.of(new PlcRequestContainer<>((InternalPlcRequest) // TODO: remove null
new DefaultPlcReadRequest.Builder(null, new AdsPlcFieldHandler()).addItem(RandomStringUtils.randomAscii(10), "1/1:" + pair.adsDataType.name()).build(), new CompletableFuture<>()), AdsReadResponse.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, invokeId, Result.of(0), Data.of(pair.getByteRepresentation()))))).flatMap(stream -> stream).map(pair -> new Object[] { "???", pair.left, pair.left.getResponseFuture(), pair.left.getRequest().getClass().getSimpleName(), pair.right, pair.right.getClass().getSimpleName() }).collect(Collectors.toList());
}
Aggregations