Search in sources :

Example 1 with BleGattCharacteristic

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

the class BleGattMappingTest method testBleGattMapping.

@Test
public void testBleGattMapping() throws Exception {
    // SETUP
    TestMappingSpecification mapping = new TestMappingSpecification();
    BleGattDevice bleGattDevice = BleGattDeviceBuilder.newBuilder().withSpecification(mapping).build();
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mapping).buildDittoMapper();
    // RUNTIME
    BleGattCharacteristic barometerValue = bleGattDevice.getCharacteristics().get("f000aa41-0451-4000-b000-000000000000");
    barometerValue.setData(new Short[] { 0x00, 0x00, 0x00, 0xD0, 0x07, 0x00 });
    BleGattCharacteristic accelerometerValue = bleGattDevice.getCharacteristics().get("f000aa81-0451-4000-b000-000000000000");
    accelerometerValue.setData(new Short[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X Value = 1.0 */
    0x00, 0x40, /* Y Value = -1 */
    0x00, 0xC0, /* Z Value  = 0.0 */
    0x00, 0x00 });
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(bleGattDevice), MappingContext.empty());
    // TEST
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("accelerometer");
    assertEquals(1.0, buttonFeature.getStatusProperties().get("x_value"));
    assertEquals(-1.0, buttonFeature.getStatusProperties().get("y_value"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("barometer");
    assertEquals(20.00, voltageFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : BleGattDevice(org.eclipse.vorto.service.mapping.ble.BleGattDevice) BleGattCharacteristic(org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Aggregations

BleGattCharacteristic (org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic)1 BleGattDevice (org.eclipse.vorto.service.mapping.ble.BleGattDevice)1 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)1 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)1 Test (org.junit.Test)1