Search in sources :

Example 1 with GattService

use of org.eclipse.vorto.service.mapping.ble.json.GattService in project vorto by eclipse.

the class BinaryMappingTest method testMappingWithGattStructure.

@Test
public void testMappingWithGattStructure() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecGattConverter()).buildDittoMapper();
    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);
    DittoData mappedDittoOutput = mapper.map(DataInputFactory.getInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(20.00, buttonFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : GattCharacteristic(org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic) GattDevice(org.eclipse.vorto.service.mapping.ble.json.GattDevice) ArrayList(java.util.ArrayList) SpecGattConverter(org.eclipse.vorto.service.mapping.spec.SpecGattConverter) Gson(com.google.gson.Gson) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) GattService(org.eclipse.vorto.service.mapping.ble.json.GattService) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 GattCharacteristic (org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic)1 GattDevice (org.eclipse.vorto.service.mapping.ble.json.GattDevice)1 GattService (org.eclipse.vorto.service.mapping.ble.json.GattService)1 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)1 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)1 SpecGattConverter (org.eclipse.vorto.service.mapping.spec.SpecGattConverter)1 Test (org.junit.Test)1