Search in sources :

Example 1 with GattService

use of org.eclipse.vorto.mapping.engine.model.blegatt.GattService in project vorto by eclipse.

the class BinaryMappingTest method testMappingWithGattStructure.

@Test
public void testMappingWithGattStructure() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecGattConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    GattDevice gattDevice = new GattDevice();
    GattService gattService = new GattService();
    List<GattCharacteristic> characteristics = new ArrayList<GattCharacteristic>();
    byte[] dest = new byte[6];
    byte[] value = Conversion.intToByteArray(2000, 0, dest, 3, 3);
    characteristics.add(new GattCharacteristic("23-D1-13-EF-5F-78-23-15-DE-EF-12-12-0D-F0-00-00", value));
    gattService.setCharacteristics(characteristics);
    List<GattService> services = new ArrayList<GattService>();
    services.add(gattService);
    gattDevice.setModelNumber("23-23-23");
    gattDevice.setServices(services);
    gattDevice.setCharacteristics(characteristics);
    String json = new Gson().toJson(gattDevice);
    InfomodelValue mapped = mapper.mapSource(gson.fromJson(json, Object.class));
    assertEquals(20.00, mapped.get("button").getStatusProperty("sensor_value").get().getValue());
    System.out.println(mapped);
}
Also used : GattCharacteristic(org.eclipse.vorto.mapping.engine.model.blegatt.GattCharacteristic) GattDevice(org.eclipse.vorto.mapping.engine.model.blegatt.GattDevice) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) GattService(org.eclipse.vorto.mapping.engine.model.blegatt.GattService) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)1 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)1 GattCharacteristic (org.eclipse.vorto.mapping.engine.model.blegatt.GattCharacteristic)1 GattDevice (org.eclipse.vorto.mapping.engine.model.blegatt.GattDevice)1 GattService (org.eclipse.vorto.mapping.engine.model.blegatt.GattService)1 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)1 Test (org.junit.Test)1