From 542724dedce5470848f62735187910594a8cac03 Mon Sep 17 00:00:00 2001 From: Menaka Madushanka Date: Thu, 17 Dec 2015 15:17:53 +0530 Subject: [PATCH 1/3] Sensor streams corrected and code restructured --- .../service/impl/AndroidSenseService.java | 140 +++++++++--------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index 3699154040..c9a79d28ad 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -260,89 +260,87 @@ public class AndroidSenseService { String sensorName = null; for (SensorJSON sensor : sensorData) { - switch (sensor.key) { - case "battery": - streamDef = BATTERY_STREAM_DEFINITION; - payloadData = new Object[]{Float.parseFloat(sensor.value)}; - sensorName = SENSOR_BATTERY; - break; - case "GPS": - streamDef = GPS_STREAM_DEFINITION; - String gpsValue = sensor.value; - String gpsValues[] = gpsValue.split(","); - Float gpsValuesF[] = new Float[2]; - gpsValuesF[0] = Float.parseFloat(gpsValues[0]); - gpsValuesF[1] = Float.parseFloat(gpsValues[0]); - payloadData = gpsValuesF; - sensorName = SENSOR_GPS; - break; - default: - try { - int androidSensorId = Integer.parseInt(sensor.key); - - if (androidSensorId == 2) { - streamDef = MAGNETIC_STREAM_DEFINITION; - String value = sensor.value; - String valuesM[] = value.split(","); - Float gValuesF[] = new Float[1]; + if(sensor.key.equals("battery")){ + streamDef = BATTERY_STREAM_DEFINITION; + payloadData = new Float[]{Float.parseFloat(sensor.value)}; + sensorName = SENSOR_BATTERY; + log.info(sensor.key +"***************************************************************" + sensor.value); + } else if (sensor.key.equals("GPS")){ + streamDef = GPS_STREAM_DEFINITION; + String gpsValue = sensor.value; + String gpsValues[] = gpsValue.split(","); + Float gpsValuesF[] = new Float[2]; + gpsValuesF[0] = Float.parseFloat(gpsValues[0]); + gpsValuesF[1] = Float.parseFloat(gpsValues[0]); + payloadData = gpsValuesF; + sensorName = SENSOR_GPS; + log.info(sensor.key +"***************************************************************" + sensor.value); + } else { + + try{ + int androidSensorId = Integer.parseInt(sensor.key); + + String value = sensor.value; + String valuesM[] = value.split(","); + Float gValuesF[] = new Float[1]; + + switch (androidSensorId){ + case 1: + streamDef = ACCELEROMETER_STREAM_DEFINITION; + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float .parseFloat(valuesM[0]); payloadData = gValuesF; - sensorName = SENSOR_MAGNETIC; - } else if (androidSensorId == 5) { - streamDef = LIGHT_STREAM_DEFINITION; - sensorName = SENSOR_LIGHT; - payloadData = new Object[]{Float.parseFloat(sensor.value)}; - } else if (androidSensorId == 1) { - streamDef = ACCELEROMETER_STREAM_DEFINITION; - String value = sensor.value; - String valuesM[] = value.split(","); - Float gValuesF[] = new Float[1]; + sensorName = SENSOR_ACCELEROMETER; + break; + case 2: + streamDef = MAGNETIC_STREAM_DEFINITION; gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float .parseFloat(valuesM[0]); payloadData = gValuesF; - sensorName = SENSOR_ACCELEROMETER; - } else if (androidSensorId == 4) { + sensorName = SENSOR_MAGNETIC; + break; + case 4: streamDef = GYROSCOPE_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); payloadData = gValuesF; sensorName = SENSOR_GYROSCOPE; - } else if (androidSensorId == 9) { + break; + case 5: + streamDef = LIGHT_STREAM_DEFINITION; + sensorName = SENSOR_LIGHT; + payloadData = new Float[]{Float.parseFloat(sensor.value)}; + break; + case 6: + streamDef = PRESSURE_STREAM_DEFINITION; + sensorName = SENSOR_PRESSURE; + payloadData = new Float[]{Float.parseFloat(sensor.value)}; + break; + case 8: + streamDef = PROXIMITY_STREAM_DEFINITION; + sensorName = SENSOR_PROXIMITY; + payloadData = new Float[]{Float.parseFloat(sensor.value)}; + break; + case 9: streamDef = GRAVITY_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); payloadData = gValuesF; sensorName = SENSOR_GRAVITY; - } else if (androidSensorId == 11) { + break; + case 11: streamDef = ROTATION_STREAM_DEFINITION; - String value = sensor.value; - String valuesG[] = value.split(","); - Float gValuesF[] = new Float[1]; - gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float - .parseFloat(valuesG[0]); + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); payloadData = gValuesF; sensorName = SENSOR_ROTATION; - } else if (androidSensorId == 8) { - streamDef = PROXIMITY_STREAM_DEFINITION; - sensorName = SENSOR_PROXIMITY; - payloadData = new Object[]{Float.parseFloat(sensor.value)}; - } else if (androidSensorId == 6) { - streamDef = PRESSURE_STREAM_DEFINITION; - sensorName = SENSOR_PRESSURE; - payloadData = new Object[]{Float.parseFloat(sensor.value)}; - } - //Add the remaining sensor types. + break; - } catch (NumberFormatException e) { - continue; } + } catch (NumberFormatException e) { + continue; + } } Object metdaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time}; @@ -467,7 +465,7 @@ public class AndroidSenseService { SensorRecord sensorRecord = null; try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ROTATION); } catch (DeviceControllerException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } @@ -486,7 +484,7 @@ public class AndroidSenseService { SensorRecord sensorRecord = null; try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_PROXIMITY); } catch (DeviceControllerException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } @@ -505,7 +503,7 @@ public class AndroidSenseService { SensorRecord sensorRecord = null; try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_GYROSCOPE); } catch (DeviceControllerException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } @@ -524,7 +522,7 @@ public class AndroidSenseService { SensorRecord sensorRecord = null; try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_PRESSURE); } catch (DeviceControllerException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } @@ -543,7 +541,7 @@ public class AndroidSenseService { SensorRecord sensorRecord = null; try { - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_GRAVITY); } catch (DeviceControllerException e) { response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } From cc50b8afd9c20c77de8c05a3e1f25509139a7e02 Mon Sep 17 00:00:00 2001 From: Menaka Madushanka Date: Thu, 17 Dec 2015 16:37:38 +0530 Subject: [PATCH 2/3] Scripts changes --- .../iot/androidsense/service/impl/AndroidSenseService.java | 2 +- .../org.wso2.iot.devices.light_1.0.0.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index c9a79d28ad..97e4f532ec 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -64,7 +64,7 @@ public class AndroidSenseService { private static final String PRESSURE_STREAM_DEFINITION = "org.wso2.iot.devices.pressure"; private static final String GRAVITY_STREAM_DEFINITION = "org.wso2.iot.devices.gravity"; private static final String ROTATION_STREAM_DEFINITION = "org.wso2.iot.devices.rotation"; - private static final String PROXIMITY_STREAM_DEFINITION = "org.wso2.iot.device.proximity"; + private static final String PROXIMITY_STREAM_DEFINITION = "org.wso2.iot.devices.proximity"; private static final String SENSOR_ACCELEROMETER = "accelerometer"; private static final String SENSOR_GYROSCOPE = "gyroscope"; diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics/Light/Eventstream_light_1.0.0/org.wso2.iot.devices.light_1.0.0.json b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics/Light/Eventstream_light_1.0.0/org.wso2.iot.devices.light_1.0.0.json index f9da446f8a..253f0b0c0d 100644 --- a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics/Light/Eventstream_light_1.0.0/org.wso2.iot.devices.light_1.0.0.json +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics/Light/Eventstream_light_1.0.0/org.wso2.iot.devices.light_1.0.0.json @@ -1,8 +1,8 @@ { "name": "org.wso2.iot.devices.light", "version": "1.0.0", - "nickName": "Light Data", - "description": "Light data received from the Device", + "nickName": "light Data", + "description": "light data received from the Device", "metaData": [ {"name":"owner","type":"STRING"}, {"name":"deviceType","type":"STRING"}, From 58f87962fa932d9eda7620a46ec3f522f0088157 Mon Sep 17 00:00:00 2001 From: Menaka Madushanka Date: Thu, 17 Dec 2015 16:44:04 +0530 Subject: [PATCH 3/3] Unnecessary lines removed --- .../mgt/iot/androidsense/service/impl/AndroidSenseService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index 97e4f532ec..3003d898c1 100644 --- a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -264,7 +264,6 @@ public class AndroidSenseService { streamDef = BATTERY_STREAM_DEFINITION; payloadData = new Float[]{Float.parseFloat(sensor.value)}; sensorName = SENSOR_BATTERY; - log.info(sensor.key +"***************************************************************" + sensor.value); } else if (sensor.key.equals("GPS")){ streamDef = GPS_STREAM_DEFINITION; String gpsValue = sensor.value; @@ -274,7 +273,6 @@ public class AndroidSenseService { gpsValuesF[1] = Float.parseFloat(gpsValues[0]); payloadData = gpsValuesF; sensorName = SENSOR_GPS; - log.info(sensor.key +"***************************************************************" + sensor.value); } else { try{