Skip to content

Commit

Permalink
Version 0.3.1
Browse files Browse the repository at this point in the history
-------------
- OpenCV Camera (removed old Camera API)
- FTP Bugfixes
- Configurable image type
- Sounds
  • Loading branch information
francescogabbrielli committed Sep 28, 2018
1 parent 1c3d122 commit 0d8eaf9
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 162 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ android {
versionCode 8
versionName "0.3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "sensor-logger"
abiFilters 'armeabi-v7a'//, 'arm64-v8a'
}
}
buildTypes {
release {
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/assets/defaults.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# filenames (TODO: use just prefixes)
pref_filename_data=sensors.csv
pref_filename_frame=frame.jpg
pref_app_folder =SensorLogger

# filenames
pref_filename_data =sensors.csv
pref_filename_frame =frame

# milliseconds between one sample and the other (frequency in Hz = 1 / (default_logging_rate/1000))
pref_logging_rate=100
# nanoseconds between one sample and the other (frequency in Hz = 1000000000 / pref_logging_rate)
pref_logging_rate =100000000

pref_app_folder=SensorLogger
# capture
pref_capture_imgformat =.png
pref_capture_camera =true
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void write(byte[] data) throws IOException {
* Implement final cleanup
*/
public void close() throws IOException {
out.close();
if (out!=null)
out.close();
out = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ public LogFTPUploader(SharedPreferences prefs) {
public void open(String folder, String filename) throws IOException {
if (!client.isConnected())
try {
Util.Log.d(getTag(), "Connecting to "+address);
client.connect(address);
client.login(user, password);
client.enterLocalPassiveMode();
client.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
out = client.storeFileStream(folder+"/"+filename);
Log.d(getTag(), "Client connected");
client.makeDirectory(folder);
client.changeWorkingDirectory(folder);
out = client.storeFileStream(filename);
if (out!=null)
Util.Log.d(getTag(), "File opened: "+filename);
else {
Util.Log.w(getTag(), "Cannot create or access file "+filename);
close();
}
} catch (Exception e) {
Log.e(getTag(), "Can't connect to " + address + ", user: " + user);
Util.Log.e(getTag(), "Can't connect to " + address + ", user: " + user, e);
}
}

Expand All @@ -51,17 +59,17 @@ public void open(String folder, String filename) throws IOException {
@Override
public void close() throws IOException {
super.close();
Util.Log.d(getTag(), "Disconnecting from "+address);
if (client != null && client.isConnected()) {
try {
client.completePendingCommand();
client.logout();
client.disconnect();
Log.d(getTag(), "Client disconnected");
Util.Log.d(getTag(), "Client disconnected");
} catch (Exception e) {
Log.e(getTag(), "Error finalizing FTP connection", e);
Util.Log.e(getTag(), "Error finalizing FTP connection", e);
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import android.support.annotation.Nullable;
import android.util.Log;

import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.imgcodecs.Imgcodecs;

import java.util.LinkedList;
import java.util.List;

Expand All @@ -35,6 +39,7 @@ public class LoggingService extends Service {

HandlerThread thread;
Handler handler;
private String ext;


public class Binder extends android.os.Binder {
Expand Down Expand Up @@ -74,34 +79,35 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
@Nullable
@Override
public IBinder onBind(Intent intent) {
Log.v(TAG, "in onBind");
Util.Log.v(TAG, "in onBind");
return binder;
}

@Override
public void onRebind(Intent intent) {
Log.v(TAG, "in onRebind");
Util.Log.v(TAG, "in onRebind");
ext = prefs.getString(Util.PREF_CAPTURE_IMGFORMAT, ".png");
super.onRebind(intent);
}

@Override
public boolean onUnbind(Intent intent) {
Log.v(TAG, "in onUnbind");
Util.Log.v(TAG, "in onUnbind");
return true;
}

@Override
public void onLowMemory() {
super.onLowMemory();
Log.d(TAG, "onLowMemory");
Util.Log.d(TAG, "onLowMemory");
}

@Override
public void onDestroy() {
atomicLoggers.clear();
openLoggers.clear();
thread.quit();
Log.d(TAG, "onDestroy");
Util.Log.d(TAG, "onDestroy");
super.onDestroy();
}

Expand All @@ -125,8 +131,15 @@ private void handleStart(final Bundle extras) {
log(folder, filename, type, data);
}

public void log(final String folder, final String filename, final int type, final byte[] data) {
// Log.v(TAG, "Logging to "+filename+" type "+type);
/**
* Log on available {@link ILogTarget}s
* @param folder
* @param filename
* @param type
* @param data
*/
public void log(final String folder, final String filename, final int type, final Object data) {
Util.Log.v(TAG, "Logging to "+filename+" type "+type+"; data: "+(data!=null));
handler.post(new Runnable() {
@Override
public void run() {
Expand All @@ -139,7 +152,7 @@ public void run() {
t.open(folder, filename);
case ILogTarget.WRITE:
for (ILogTarget t : openLoggers)
t.write(data);
t.write((byte[]) data);
break;
case ILogTarget.CLOSE:
for (ILogTarget t : openLoggers)
Expand All @@ -149,14 +162,14 @@ public void run() {
case ILogTarget.SEND:
for (ILogTarget t : atomicLoggers) {
t.open(folder, filename);
t.write(data);
t.write((byte[]) data);
t.close();
}
break;
}
// Log.d(TAG, "Logged to "+filename+", type "+type);
// Util.Log.d(TAG, "Logged to "+filename+", type "+type);
} catch(Exception exc) {
Log.e(TAG, "Logging error", exc);
Util.Log.e(TAG, "Logging error", exc);
}
}
});
Expand Down
Loading

0 comments on commit 0d8eaf9

Please sign in to comment.