Skip to content

Commit

Permalink
various bugfixes.
Browse files Browse the repository at this point in the history
Router V0.5 and Android App V0.5 ready for testing deployment
Relevant: #12, #6, #4
  • Loading branch information
Fabian Tschopp committed Sep 14, 2014
1 parent d718891 commit c4ea51a
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 2,848 deletions.
2 changes: 1 addition & 1 deletion android/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/javanervousvm"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/javanervousvm"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
Expand Down
7 changes: 6 additions & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand All @@ -31,6 +32,10 @@
android:name=".SensorService"
android:enabled="true" />

<service
android:name=".UploadService"
android:enabled="true" />

<activity
android:name=".IfThisThenThatActivity"
android:label="@string/title_activity_if_this_then_that"
Expand Down
12 changes: 8 additions & 4 deletions android/src/ch/ethz/soms/nervous/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ public void startSensorService() {
public void stopSensorService() {
// Cancel
AlarmManager scheduler = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), SensorService.class);
PendingIntent scheduledIntent = PendingIntent.getService(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

scheduler.cancel(scheduledIntent);
Intent sensorIntent = new Intent(getApplicationContext(), SensorService.class);
PendingIntent scheduledSensorIntent = PendingIntent.getService(getApplicationContext(), 0, sensorIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Intent uploadIntent = new Intent(getApplicationContext(), UploadService.class);
PendingIntent scheduledUploadIntent = PendingIntent.getService(getApplicationContext(), 0, uploadIntent, PendingIntent.FLAG_UPDATE_CURRENT);

scheduler.cancel(scheduledSensorIntent);
scheduler.cancel(scheduledUploadIntent);

serviceRunning = false;
new ServiceInfo(getApplicationContext()).clean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescAccelerometer extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000000;
public static final long SENSOR_ID = 0x0000000000000000L;

private final int accuracy;
private final float accX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescBattery extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000001;
public static final long SENSOR_ID = 0x0000000000000001L;

private final float batteryPercent;
private final boolean isCharging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class SensorDescGyroscope extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000002;
public static final long SENSOR_ID = 0x0000000000000002L;

private final int accuracy;
private final float gyrX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescHumidity extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000003;
public static final long SENSOR_ID = 0x0000000000000003L;

private final int accuracy;
private final float humidity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescLight extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000004;
public static final long SENSOR_ID = 0x0000000000000004L;


private final int accuracy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescMagnetic extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000005;
public static final long SENSOR_ID = 0x0000000000000005L;

private final int accuracy;
private final float magX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescProximity extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000006;
public static final long SENSOR_ID = 0x0000000000000006L;


private final int accuracy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SensorDescTemperature extends SensorDesc {

public static final long SENSOR_ID = 0x0000000000000007;
public static final long SENSOR_ID = 0x0000000000000007L;

private final int accuracy;
private final float temperature;
Expand Down
12 changes: 5 additions & 7 deletions android/src/ch/ethz/soms/nervous/android/StoreTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
public class StoreTask extends AsyncTask<SensorDesc, Void, Void> {

private Context context;

public StoreTask(Context context)
{

public StoreTask(Context context) {
this.context = context;
}

@Override
protected Void doInBackground(SensorDesc... params) {

if (params != null && params.length > 0) {
NervousVM nervousVM = NervousVM.getInstance(context.getFilesDir());
for(int i = 0; i < params.length; i++)
{
nervousVM.storeSensor(params[i].getTimestamp(), params[i].toProtoSensor());
for (int i = 0; i < params.length; i++) {
nervousVM.storeSensor(params[i].getSensorIdentifier(), params[i].toProtoSensor());
}
}
return null;
Expand Down
40 changes: 35 additions & 5 deletions android/src/ch/ethz/soms/nervous/android/UploadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;

import ch.ethz.soms.nervous.android.SensorService.SensorBinder;
import ch.ethz.soms.nervous.nervousproto.SensorUploadProtos.SensorUpload;
import ch.ethz.soms.nervous.nervousproto.SensorUploadProtos.SensorUpload.Builder;
import ch.ethz.soms.nervous.nervousproto.SensorUploadProtos.SensorUpload.SensorData;
import ch.ethz.soms.nervous.vm.NervousVM;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class UploadService extends Service {

private static final String DEBUG_TAG = "UploadService";

private final IBinder mBinder = new UploadBinder();

public class UploadBinder extends Binder {
UploadService getService() {
return UploadService.this;
}
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

Expand Down Expand Up @@ -48,18 +63,33 @@ public void onDestroy() {
}

@Override
public IBinder onBind(Intent arg0) {
return null;
public IBinder onBind(Intent intent) {
return mBinder;
}

public class UploadTask extends AsyncTask<SensorDesc, Void, Void> {

@Override
protected Void doInBackground(SensorDesc... params) {
try {
Socket socket = new Socket("127.0.0.1", 25600);
NervousVM nvm = NervousVM.getInstance(getApplicationContext().getFilesDir());
Socket socket = new Socket("192.168.1.53", 25600);
OutputStream os = socket.getOutputStream();
//sensorupload.writeDelimitedTo(os);
for (long i = 0x0; i < 0x10; i++) {
Builder sub = SensorUpload.newBuilder();
sub.setHuuid(nvm.getUUID().getMostSignificantBits());
sub.setLuuid(nvm.getUUID().getLeastSignificantBits());
sub.setSensorId(i);
// Upload everything with "timestamp" > "last uploaded timestamp"
List<SensorData> sensorDataList = nvm.retrieve(i, nvm.getLastUploadedTimestamp(i) + 1, Long.MAX_VALUE);
// Only upload if there is actual data
if (sensorDataList != null && sensorDataList.size() > 0) {
sub.addAllSensorValues(sensorDataList);
sub.setUploadTime(System.currentTimeMillis());
sub.build().writeDelimitedTo(os);
nvm.setLastUploadedTimestamp(i, sensorDataList.get(sensorDataList.size() - 1).getRecordTime());
}
}
os.flush();
os.close();
socket.close();
Expand Down
Loading

0 comments on commit c4ea51a

Please sign in to comment.