Merge pull request #65 from menaka121/IoTS-1.0.0-M1

Sensor streams changes
Ruwan 9 years ago
commit c7b7586c35

@ -64,7 +64,7 @@ public class AndroidSenseService {
private static final String PRESSURE_STREAM_DEFINITION = "org.wso2.iot.devices.pressure"; 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 GRAVITY_STREAM_DEFINITION = "org.wso2.iot.devices.gravity";
private static final String ROTATION_STREAM_DEFINITION = "org.wso2.iot.devices.rotation"; 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_ACCELEROMETER = "accelerometer";
private static final String SENSOR_GYROSCOPE = "gyroscope"; private static final String SENSOR_GYROSCOPE = "gyroscope";
@ -260,89 +260,85 @@ public class AndroidSenseService {
String sensorName = null; String sensorName = null;
for (SensorJSON sensor : sensorData) { for (SensorJSON sensor : sensorData) {
switch (sensor.key) { if(sensor.key.equals("battery")){
case "battery": streamDef = BATTERY_STREAM_DEFINITION;
streamDef = BATTERY_STREAM_DEFINITION; payloadData = new Float[]{Float.parseFloat(sensor.value)};
payloadData = new Object[]{Float.parseFloat(sensor.value)}; sensorName = SENSOR_BATTERY;
sensorName = SENSOR_BATTERY; } else if (sensor.key.equals("GPS")){
break; streamDef = GPS_STREAM_DEFINITION;
case "GPS": String gpsValue = sensor.value;
streamDef = GPS_STREAM_DEFINITION; String gpsValues[] = gpsValue.split(",");
String gpsValue = sensor.value; Float gpsValuesF[] = new Float[2];
String gpsValues[] = gpsValue.split(","); gpsValuesF[0] = Float.parseFloat(gpsValues[0]);
Float gpsValuesF[] = new Float[2]; gpsValuesF[1] = Float.parseFloat(gpsValues[0]);
gpsValuesF[0] = Float.parseFloat(gpsValues[0]); payloadData = gpsValuesF;
gpsValuesF[1] = Float.parseFloat(gpsValues[0]); sensorName = SENSOR_GPS;
payloadData = gpsValuesF; } else {
sensorName = SENSOR_GPS;
break; try{
default: int androidSensorId = Integer.parseInt(sensor.key);
try {
int androidSensorId = Integer.parseInt(sensor.key); String value = sensor.value;
String valuesM[] = value.split(",");
if (androidSensorId == 2) { Float gValuesF[] = new Float[1];
streamDef = MAGNETIC_STREAM_DEFINITION;
String value = sensor.value; switch (androidSensorId){
String valuesM[] = value.split(","); case 1:
Float gValuesF[] = new Float[1]; streamDef = ACCELEROMETER_STREAM_DEFINITION;
gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float
.parseFloat(valuesM[0]); .parseFloat(valuesM[0]);
payloadData = gValuesF; payloadData = gValuesF;
sensorName = SENSOR_MAGNETIC; sensorName = SENSOR_ACCELEROMETER;
} else if (androidSensorId == 5) { break;
streamDef = LIGHT_STREAM_DEFINITION; case 2:
sensorName = SENSOR_LIGHT; streamDef = MAGNETIC_STREAM_DEFINITION;
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];
gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float
.parseFloat(valuesM[0]); .parseFloat(valuesM[0]);
payloadData = gValuesF; payloadData = gValuesF;
sensorName = SENSOR_ACCELEROMETER; sensorName = SENSOR_MAGNETIC;
} else if (androidSensorId == 4) { break;
case 4:
streamDef = GYROSCOPE_STREAM_DEFINITION; streamDef = GYROSCOPE_STREAM_DEFINITION;
String value = sensor.value; gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float
String valuesG[] = value.split(","); .parseFloat(valuesM[0]);
Float gValuesF[] = new Float[1];
gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float
.parseFloat(valuesG[0]);
payloadData = gValuesF; payloadData = gValuesF;
sensorName = SENSOR_GYROSCOPE; 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; streamDef = GRAVITY_STREAM_DEFINITION;
String value = sensor.value; gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float
String valuesG[] = value.split(","); .parseFloat(valuesM[0]);
Float gValuesF[] = new Float[1];
gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float
.parseFloat(valuesG[0]);
payloadData = gValuesF; payloadData = gValuesF;
sensorName = SENSOR_GRAVITY; sensorName = SENSOR_GRAVITY;
} else if (androidSensorId == 11) { break;
case 11:
streamDef = ROTATION_STREAM_DEFINITION; streamDef = ROTATION_STREAM_DEFINITION;
String value = sensor.value; gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float
String valuesG[] = value.split(","); .parseFloat(valuesM[0]);
Float gValuesF[] = new Float[1];
gValuesF[0] = Float.parseFloat(valuesG[0]) * Float.parseFloat(valuesG[0]) * Float
.parseFloat(valuesG[0]);
payloadData = gValuesF; payloadData = gValuesF;
sensorName = SENSOR_ROTATION; sensorName = SENSOR_ROTATION;
} else if (androidSensorId == 8) { break;
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.
} catch (NumberFormatException e) {
continue;
} }
} catch (NumberFormatException e) {
continue;
}
} }
Object metdaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time}; Object metdaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time};
@ -467,7 +463,7 @@ public class AndroidSenseService {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ROTATION);
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
@ -486,7 +482,7 @@ public class AndroidSenseService {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_PROXIMITY);
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
@ -505,7 +501,7 @@ public class AndroidSenseService {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_GYROSCOPE);
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
@ -524,7 +520,7 @@ public class AndroidSenseService {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_PRESSURE);
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
@ -543,7 +539,7 @@ public class AndroidSenseService {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_GRAVITY);
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }

@ -1,8 +1,8 @@
{ {
"name": "org.wso2.iot.devices.light", "name": "org.wso2.iot.devices.light",
"version": "1.0.0", "version": "1.0.0",
"nickName": "Light Data", "nickName": "light Data",
"description": "Light data received from the Device", "description": "light data received from the Device",
"metaData": [ "metaData": [
{"name":"owner","type":"STRING"}, {"name":"owner","type":"STRING"},
{"name":"deviceType","type":"STRING"}, {"name":"deviceType","type":"STRING"},

Loading…
Cancel
Save