Search in sources :

Example 1 with AmsPort

use of org.apache.plc4x.java.ads.api.generic.types.AmsPort 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<>());
}
Also used : AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Before(org.junit.Before)

Example 2 with AmsPort

use of org.apache.plc4x.java.ads.api.generic.types.AmsPort 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));
}
Also used : AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke)

Example 3 with AmsPort

use of org.apache.plc4x.java.ads.api.generic.types.AmsPort 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();
}
Also used : AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke)

Example 4 with AmsPort

use of org.apache.plc4x.java.ads.api.generic.types.AmsPort 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)));
}
Also used : AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) Date(java.util.Date) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke)

Example 5 with AmsPort

use of org.apache.plc4x.java.ads.api.generic.types.AmsPort 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());
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) AdsReadResponse(org.apache.plc4x.java.ads.api.commands.AdsReadResponse) java.util(java.util) Assume.assumeThat(org.junit.Assume.assumeThat) AdsWriteRequest(org.apache.plc4x.java.ads.api.commands.AdsWriteRequest) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) Data(org.apache.plc4x.java.ads.api.commands.types.Data) AdsWriteResponse(org.apache.plc4x.java.ads.api.commands.AdsWriteResponse) LocalTime(java.time.LocalTime) AmsHeader(org.apache.plc4x.java.ads.api.generic.AmsHeader) AdsPlcFieldHandler(org.apache.plc4x.java.ads.model.AdsPlcFieldHandler) BigInteger(java.math.BigInteger) ExpectedException(org.junit.rules.ExpectedException) AdsDataType(org.apache.plc4x.java.ads.model.AdsDataType) Parameterized(org.junit.runners.Parameterized) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke) Before(org.junit.Before) Result(org.apache.plc4x.java.ads.api.commands.types.Result) AmsPacket(org.apache.plc4x.java.ads.api.generic.AmsPacket) Logger(org.slf4j.Logger) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) org.apache.plc4x.java.spi.messages(org.apache.plc4x.java.spi.messages) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Ignore(org.junit.Ignore) Modifier(java.lang.reflect.Modifier) LocalDate(java.time.LocalDate) AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) AdsPlcFieldHandler(org.apache.plc4x.java.ads.model.AdsPlcFieldHandler) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke)

Aggregations

AmsNetId (org.apache.plc4x.java.ads.api.generic.types.AmsNetId)7 AmsPort (org.apache.plc4x.java.ads.api.generic.types.AmsPort)7 Invoke (org.apache.plc4x.java.ads.api.generic.types.Invoke)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Before (org.junit.Before)2 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 java.util (java.util)1 Date (java.util.Date)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1