|
|
@ -2,6 +2,9 @@ package org.wso2.carbon.iot.android.sense.data.publisher;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This hold the definition of the stream that android sense is publishing to.
|
|
|
|
* This hold the definition of the stream that android sense is publishing to.
|
|
|
@ -26,8 +29,11 @@ public class Event {
|
|
|
|
private String wordStatus;
|
|
|
|
private String wordStatus;
|
|
|
|
private long timestamp;
|
|
|
|
private long timestamp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = Event.class.getName();
|
|
|
|
|
|
|
|
LocationData gpsLoc;
|
|
|
|
|
|
|
|
|
|
|
|
private int getBattery() {
|
|
|
|
private int getBattery() {
|
|
|
|
return battery;
|
|
|
|
return this.battery;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setBattery(int battery) {
|
|
|
|
public void setBattery(int battery) {
|
|
|
@ -36,7 +42,8 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private double[] getGps() {
|
|
|
|
private double[] getGps() {
|
|
|
|
return gps != null ? gps : new double[]{0, 0};
|
|
|
|
|
|
|
|
|
|
|
|
return gps != null ? this.gps : new double[]{gps[0],gps[1]};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGps(double[] gps) {
|
|
|
|
public void setGps(double[] gps) {
|
|
|
@ -45,7 +52,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getAccelerometer() {
|
|
|
|
private float[] getAccelerometer() {
|
|
|
|
return accelerometer != null ? accelerometer : new float[]{0, 0, 0};
|
|
|
|
return this.accelerometer != null ? this.accelerometer : new float[]{0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setAccelerometer(float[] accelerometer) {
|
|
|
|
public void setAccelerometer(float[] accelerometer) {
|
|
|
@ -54,7 +61,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getMagnetic() {
|
|
|
|
private float[] getMagnetic() {
|
|
|
|
return magnetic != null ? magnetic : new float[]{0, 0, 0};
|
|
|
|
return this.magnetic != null ? this.magnetic : new float[]{0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setMagnetic(float[] magnetic) {
|
|
|
|
public void setMagnetic(float[] magnetic) {
|
|
|
@ -63,7 +70,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getGyroscope() {
|
|
|
|
private float[] getGyroscope() {
|
|
|
|
return gyroscope != null ? gyroscope : new float[]{0, 0, 0};
|
|
|
|
return this.gyroscope != null ? this.gyroscope : new float[]{0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGyroscope(float[] gyroscope) {
|
|
|
|
public void setGyroscope(float[] gyroscope) {
|
|
|
@ -72,7 +79,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float getLight() {
|
|
|
|
public float getLight() {
|
|
|
|
return light;
|
|
|
|
return this.light;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setLight(float light) {
|
|
|
|
public void setLight(float light) {
|
|
|
@ -81,7 +88,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float getPressure() {
|
|
|
|
public float getPressure() {
|
|
|
|
return pressure;
|
|
|
|
return this.pressure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setPressure(float pressure) {
|
|
|
|
public void setPressure(float pressure) {
|
|
|
@ -90,7 +97,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float getProximity() {
|
|
|
|
public float getProximity() {
|
|
|
|
return proximity;
|
|
|
|
return this.proximity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setProximity(float proximity) {
|
|
|
|
public void setProximity(float proximity) {
|
|
|
@ -99,7 +106,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getGravity() {
|
|
|
|
private float[] getGravity() {
|
|
|
|
return gravity != null ? gravity : new float[]{0, 0, 0};
|
|
|
|
return this.gravity != null ? this.gravity : new float[]{0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGravity(float gravity[]) {
|
|
|
|
public void setGravity(float gravity[]) {
|
|
|
@ -108,7 +115,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getRotation() {
|
|
|
|
private float[] getRotation() {
|
|
|
|
return rotation != null ? rotation : new float[]{0, 0, 0};
|
|
|
|
return this.rotation != null ? this.rotation : new float[]{0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setRotation(float rotation[]) {
|
|
|
|
public void setRotation(float rotation[]) {
|
|
|
@ -125,7 +132,7 @@ public class Event {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getWord() {
|
|
|
|
private String getWord() {
|
|
|
|
return word != null ? word : "";
|
|
|
|
return this.word != null ? this.word : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setWord(String word) {
|
|
|
|
public void setWord(String word) {
|
|
|
@ -176,44 +183,60 @@ public class Event {
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonPayloadData = new JSONObject();
|
|
|
|
JSONObject jsonPayloadData = new JSONObject();
|
|
|
|
jsonPayloadData.put("battery", getBattery());
|
|
|
|
jsonPayloadData.put("battery", getBattery());
|
|
|
|
//gps
|
|
|
|
//gps & accelerometer
|
|
|
|
double gpsEvents[] = getGps();
|
|
|
|
|
|
|
|
jsonPayloadData.put("gps_lat", gpsEvents[0]);
|
|
|
|
if (gps !=null && accelerometer !=null) {
|
|
|
|
jsonPayloadData.put("gps_long", gpsEvents[1]);
|
|
|
|
jsonPayloadData.put("gps_lat", gps[0]);
|
|
|
|
//acceleromter
|
|
|
|
jsonPayloadData.put("gps_long", gps[1]);
|
|
|
|
float events[] = getAccelerometer();
|
|
|
|
|
|
|
|
jsonPayloadData.put("accelerometer_x", events[0]);
|
|
|
|
jsonPayloadData.put("accelerometer_x", accelerometer[0]);
|
|
|
|
jsonPayloadData.put("accelerometer_y", events[1]);
|
|
|
|
jsonPayloadData.put("accelerometer_y", accelerometer[1]);
|
|
|
|
jsonPayloadData.put("accelerometer_z", events[2]);
|
|
|
|
jsonPayloadData.put("accelerometer_z", accelerometer[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//magnetic
|
|
|
|
//magnetic
|
|
|
|
events = getMagnetic();
|
|
|
|
//events = getMagnetic();
|
|
|
|
jsonPayloadData.put("magnetic_x", events[0]);
|
|
|
|
if (magnetic !=null) {
|
|
|
|
jsonPayloadData.put("magnetic_y", events[1]);
|
|
|
|
jsonPayloadData.put("magnetic_x", magnetic[0]);
|
|
|
|
jsonPayloadData.put("magnetic_z", events[2]);
|
|
|
|
jsonPayloadData.put("magnetic_y", magnetic[1]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("magnetic_z", magnetic[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
//gyroscope
|
|
|
|
//gyroscope
|
|
|
|
events = getGyroscope();
|
|
|
|
//events = getGyroscope();
|
|
|
|
jsonPayloadData.put("gyroscope_x", events[0]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("gyroscope_y", events[1]);
|
|
|
|
if (gyroscope != null) {
|
|
|
|
jsonPayloadData.put("gyroscope_z", events[2]);
|
|
|
|
jsonPayloadData.put("gyroscope_x", gyroscope[0]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("gyroscope_y", gyroscope[1]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("gyroscope_z", gyroscope[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonPayloadData.put("light", getLight());
|
|
|
|
jsonPayloadData.put("light", getLight());
|
|
|
|
|
|
|
|
|
|
|
|
jsonPayloadData.put("pressure", getPressure());
|
|
|
|
jsonPayloadData.put("pressure", getPressure());
|
|
|
|
jsonPayloadData.put("proximity", getProximity());
|
|
|
|
jsonPayloadData.put("proximity", getProximity());
|
|
|
|
//gravity
|
|
|
|
//gravity
|
|
|
|
events = getGravity();
|
|
|
|
//events = getGravity();
|
|
|
|
jsonPayloadData.put("gravity_x", events[0]);
|
|
|
|
if (gravity!=null) {
|
|
|
|
jsonPayloadData.put("gravity_y", events[1]);
|
|
|
|
jsonPayloadData.put("gravity_x", gravity[0]);
|
|
|
|
jsonPayloadData.put("gravity_z", events[2]);
|
|
|
|
jsonPayloadData.put("gravity_y", gravity[1]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("gravity_z", gravity[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
//rotation
|
|
|
|
//rotation
|
|
|
|
events = getRotation();
|
|
|
|
//events = getRotation();
|
|
|
|
jsonPayloadData.put("rotation_x", events[0]);
|
|
|
|
if (rotation!=null) {
|
|
|
|
jsonPayloadData.put("rotation_y", events[1]);
|
|
|
|
jsonPayloadData.put("rotation_x", rotation[0]);
|
|
|
|
jsonPayloadData.put("rotation_z", events[2]);
|
|
|
|
jsonPayloadData.put("rotation_y", rotation[1]);
|
|
|
|
|
|
|
|
jsonPayloadData.put("rotation_z", rotation[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
//word
|
|
|
|
//word
|
|
|
|
jsonPayloadData.put("word", getWord());
|
|
|
|
jsonPayloadData.put("word", getWord());
|
|
|
|
jsonPayloadData.put("word_sessionId", getWordSessionId());
|
|
|
|
jsonPayloadData.put("word_sessionId", getWordSessionId());
|
|
|
|
jsonPayloadData.put("word_status", getWordStatus());
|
|
|
|
jsonPayloadData.put("word_status", getWordStatus());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonEvent.put("payloadData", jsonPayloadData);
|
|
|
|
jsonEvent.put("payloadData", jsonPayloadData);
|
|
|
|
|
|
|
|
|
|
|
|
return jsonEvent;
|
|
|
|
return jsonEvent;
|
|
|
|