Search in sources :

Example 1 with PlcSTRING

use of org.apache.plc4x.java.spi.values.PlcSTRING in project plc4x by apache.

the class ConnectedEntityTest method setUp.

@BeforeEach
void setUp() throws Exception {
    driverManager = new PlcDriverManager();
    connection = (MockConnection) driverManager.getConnection("mock:cached");
    when(mockDevice.read(any())).thenReturn(new ResponseItem<>(PlcResponseCode.OK, new PlcSTRING("hallo")));
    connection.setDevice(mockDevice);
    entityManager = new PlcEntityManager(driverManager);
}
Also used : PlcSTRING(org.apache.plc4x.java.spi.values.PlcSTRING) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with PlcSTRING

use of org.apache.plc4x.java.spi.values.PlcSTRING in project plc4x by apache.

the class ScraperTaskTest method scrape.

@Test
public void scrape() throws PlcConnectionException {
    PlcDriverManager driverManager = new PlcDriverManager();
    MockConnection connection = (MockConnection) driverManager.getConnection("mock:scraper");
    connection.setDevice(mockDevice);
    when(mockDevice.read(any())).thenReturn(new ResponseItem<>(PlcResponseCode.OK, new PlcSTRING("hallo")));
    ScraperTask scraperTask = new ScraperTaskImpl(driverManager, "job1", "m1", "mock:scraper", Collections.singletonMap("a", "b"), 1_000, ForkJoinPool.commonPool(), (j, a, m) -> {
    });
    scraperTask.run();
}
Also used : PlcSTRING(org.apache.plc4x.java.spi.values.PlcSTRING) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) MockConnection(org.apache.plc4x.java.mock.connection.MockConnection) Test(org.junit.jupiter.api.Test)

Example 3 with PlcSTRING

use of org.apache.plc4x.java.spi.values.PlcSTRING in project plc4x by apache.

the class KnxNetIpProtocolLogic method processCemiData.

protected void processCemiData(KnxAddress sourceAddress, byte[] destinationGroupAddress, byte firstByte, byte[] restBytes) throws ParseException {
    // The first byte is actually just 6 bit long, but we'll treat it as a full one.
    // So here we create a byte array containing the first and all the following bytes.
    byte[] payload = new byte[1 + restBytes.length];
    payload[0] = firstByte;
    System.arraycopy(restBytes, 0, payload, 1, restBytes.length);
    // Decode the group address depending on the project settings.
    ReadBuffer addressBuffer = new ReadBufferByteBased(destinationGroupAddress);
    final KnxGroupAddress knxGroupAddress = KnxGroupAddress.staticParse(addressBuffer, knxNetIpDriverContext.getGroupAddressType());
    final String destinationAddress = toString(knxGroupAddress);
    // If there is an ETS model provided, continue decoding the payload.
    if (knxNetIpDriverContext.getEtsModel() != null) {
        final EtsModel etsModel = knxNetIpDriverContext.getEtsModel();
        final GroupAddress groupAddress = etsModel.getGroupAddresses().get(destinationAddress);
        final String areaName = etsModel.getTopologyName(destinationAddress.substring(0, destinationAddress.indexOf('/')));
        final String lineName = etsModel.getTopologyName(destinationAddress.substring(0, destinationAddress.indexOf('/', destinationAddress.indexOf('/') + 1)));
        if ((groupAddress != null) && (groupAddress.getType() != null)) {
            LOGGER.trace(String.format("Message from: '%s' to: '%s'", toString(sourceAddress), destinationAddress));
            // Parse the payload depending on the type of the group-address.
            ReadBuffer rawDataReader = new ReadBufferByteBased(payload);
            final PlcValue value = KnxDatapoint.staticParse(rawDataReader, groupAddress.getType());
            // Assemble the plc4x return data-structure.
            Map<String, PlcValue> dataPointMap = new HashMap<>();
            dataPointMap.put("sourceAddress", new PlcSTRING(toString(sourceAddress)));
            dataPointMap.put("targetAddress", new PlcSTRING(groupAddress.getGroupAddress()));
            if (groupAddress.getFunction() != null) {
                dataPointMap.put("location", new PlcSTRING(groupAddress.getFunction().getSpaceName()));
                dataPointMap.put("function", new PlcSTRING(groupAddress.getFunction().getName()));
            } else {
                dataPointMap.put("location", null);
                dataPointMap.put("function", null);
            }
            if (areaName != null) {
                dataPointMap.put("area", new PlcSTRING(areaName));
            }
            if (lineName != null) {
                dataPointMap.put("line", new PlcSTRING(lineName));
            }
            dataPointMap.put("description", new PlcSTRING(groupAddress.getName()));
            dataPointMap.put("unitOfMeasurement", new PlcSTRING(groupAddress.getType().getName()));
            dataPointMap.put("value", value);
            final PlcStruct dataPoint = new PlcStruct(dataPointMap);
            // Send the data-structure.
            publishEvent(groupAddress, dataPoint);
        } else {
            LOGGER.warn(String.format("Message from: '%s' to unknown group address: '%s'%n payload: '%s'", toString(sourceAddress), destinationAddress, Hex.encodeHexString(payload)));
        }
    } else // Else just output the raw payload.
    {
        LOGGER.info(String.format("Raw Message: '%s' to: '%s'%n payload: '%s'", KnxNetIpProtocolLogic.toString(sourceAddress), destinationAddress, Hex.encodeHexString(payload)));
    }
}
Also used : KnxGroupAddress(org.apache.plc4x.java.knxnetip.readwrite.KnxGroupAddress) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EtsModel(org.apache.plc4x.java.knxnetip.ets.model.EtsModel) PlcStruct(org.apache.plc4x.java.spi.values.PlcStruct) GroupAddress(org.apache.plc4x.java.knxnetip.ets.model.GroupAddress) KnxGroupAddress(org.apache.plc4x.java.knxnetip.readwrite.KnxGroupAddress) PlcSTRING(org.apache.plc4x.java.spi.values.PlcSTRING)

Aggregations

PlcSTRING (org.apache.plc4x.java.spi.values.PlcSTRING)3 PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EtsModel (org.apache.plc4x.java.knxnetip.ets.model.EtsModel)1 GroupAddress (org.apache.plc4x.java.knxnetip.ets.model.GroupAddress)1 KnxGroupAddress (org.apache.plc4x.java.knxnetip.readwrite.KnxGroupAddress)1 MockConnection (org.apache.plc4x.java.mock.connection.MockConnection)1 PlcStruct (org.apache.plc4x.java.spi.values.PlcStruct)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1