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,13 +260,11 @@ 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 Object[]{Float.parseFloat(sensor.value)}; payloadData = new Float[]{Float.parseFloat(sensor.value)};
sensorName = SENSOR_BATTERY; sensorName = SENSOR_BATTERY;
break; } else if (sensor.key.equals("GPS")){
case "GPS":
streamDef = GPS_STREAM_DEFINITION; streamDef = GPS_STREAM_DEFINITION;
String gpsValue = sensor.value; String gpsValue = sensor.value;
String gpsValues[] = gpsValue.split(","); String gpsValues[] = gpsValue.split(",");
@ -275,71 +273,69 @@ public class AndroidSenseService {
gpsValuesF[1] = Float.parseFloat(gpsValues[0]); gpsValuesF[1] = Float.parseFloat(gpsValues[0]);
payloadData = gpsValuesF; payloadData = gpsValuesF;
sensorName = SENSOR_GPS; sensorName = SENSOR_GPS;
break; } else {
default:
try{ try{
int androidSensorId = Integer.parseInt(sensor.key); int androidSensorId = Integer.parseInt(sensor.key);
if (androidSensorId == 2) {
streamDef = MAGNETIC_STREAM_DEFINITION;
String value = sensor.value; String value = sensor.value;
String valuesM[] = value.split(","); String valuesM[] = value.split(",");
Float gValuesF[] = new Float[1]; Float gValuesF[] = new Float[1];
switch (androidSensorId){
case 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) { } catch (NumberFormatException e) {
continue; continue;
} }
@ -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