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 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";
@ -260,89 +260,85 @@ 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;
} 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;
} 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 +463,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 +482,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 +501,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 +520,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 +539,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());
}

@ -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"},

Loading…
Cancel
Save