From 995ed434fa483aaa94929d576ea14aafe6fe188b Mon Sep 17 00:00:00 2001 From: Alexander James Wallar Date: Mon, 20 Jan 2014 12:52:22 -0500 Subject: [PATCH] IT BLOODY WORKS --- .../src/com/locaudio/api/Location.java | 11 ------- .../src/com/locaudio/api/Locaudio.java | 8 ++--- .../src/com/locaudio/api/NotifyForm.java | 15 +++++---- app/Locabean/src/com/locaudio/api/Point.java | 19 +++++++++-- .../src/com/locaudio/api/SoundLocation.java | 28 ++++++++++++++++ .../src/com/locaudio/io/WaveWriter.java | 2 +- .../com/locaudio/locabean/NodeActivity.java | 32 +++++++++++++++++-- .../com/locaudio/net/AsyncPostRequest.java | 4 +-- .../src/com/locaudio/net/Requests.java | 7 ++-- locaudio/detectionserver.py | 2 +- 10 files changed, 94 insertions(+), 34 deletions(-) delete mode 100644 app/Locabean/src/com/locaudio/api/Location.java create mode 100644 app/Locabean/src/com/locaudio/api/SoundLocation.java diff --git a/app/Locabean/src/com/locaudio/api/Location.java b/app/Locabean/src/com/locaudio/api/Location.java deleted file mode 100644 index 141c8c3..0000000 --- a/app/Locabean/src/com/locaudio/api/Location.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.locaudio.api; - -import com.google.gson.annotations.SerializedName; - -public class Location { - @SerializedName("position") - public Point position; - - @SerializedName("confidence") - public float confidence; -} diff --git a/app/Locabean/src/com/locaudio/api/Locaudio.java b/app/Locabean/src/com/locaudio/api/Locaudio.java index 26ed76f..27ffe09 100644 --- a/app/Locabean/src/com/locaudio/api/Locaudio.java +++ b/app/Locabean/src/com/locaudio/api/Locaudio.java @@ -15,9 +15,9 @@ public Locaudio(String ipAddress, int port) { super(ipAddress, port); } - public Location[] getSoundLocations(final String soundName) { - AsyncGetRequest agr = new AsyncGetRequest( - Location[].class, LOCATIONS_ROUTE, soundName); + public SoundLocation[] getSoundLocations(final String soundName) { + AsyncGetRequest agr = new AsyncGetRequest( + SoundLocation[].class, LOCATIONS_ROUTE, soundName); return agr.getResponse(this); } @@ -31,7 +31,7 @@ public NotifyResponse notifyEvent(final NotifyForm event) throws ClientProtocolException, IOException { AsyncPostRequest apr = new AsyncPostRequest( NotifyResponse.class, event.toMap(), NOTIFY_ROUTE); - + return apr.getResponse(this); } } diff --git a/app/Locabean/src/com/locaudio/api/NotifyForm.java b/app/Locabean/src/com/locaudio/api/NotifyForm.java index 94cbafe..489712d 100644 --- a/app/Locabean/src/com/locaudio/api/NotifyForm.java +++ b/app/Locabean/src/com/locaudio/api/NotifyForm.java @@ -1,5 +1,6 @@ package com.locaudio.api; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -24,13 +25,13 @@ public NotifyForm(float x, float y, float soundPressureLevel, this.fingerprint = fingerprint; } - public Map toMap() { - Map map = new HashMap(); - map.put("x", this.x); - map.put("y", this.y); - map.put("spl", this.soundPressureLevel); - map.put("timestamp", this.timestamp); - map.put("fingerprint", this.fingerprint); + public Map toMap() { + Map map = new HashMap(); + map.put("x", "" + this.x); + map.put("y", "" + this.y); + map.put("spl", "" + this.soundPressureLevel); + map.put("timestamp", "" + this.timestamp); + map.put("fingerprint", Arrays.toString(this.fingerprint)); return map; } diff --git a/app/Locabean/src/com/locaudio/api/Point.java b/app/Locabean/src/com/locaudio/api/Point.java index acaca26..4e09315 100644 --- a/app/Locabean/src/com/locaudio/api/Point.java +++ b/app/Locabean/src/com/locaudio/api/Point.java @@ -3,10 +3,25 @@ import com.google.gson.annotations.SerializedName; public class Point { - + @SerializedName("x") public float x; - + @SerializedName("y") public float y; + + @Override + public String toString() { + return "( X: " + this.x + ", Y: " + this.y + " )"; + } + + @Override + public boolean equals(Object obj) { + Point p = (Point) obj; + if (p.x == this.x && p.y == this.y) { + return true; + } else { + return false; + } + } } diff --git a/app/Locabean/src/com/locaudio/api/SoundLocation.java b/app/Locabean/src/com/locaudio/api/SoundLocation.java new file mode 100644 index 0000000..c6ebf95 --- /dev/null +++ b/app/Locabean/src/com/locaudio/api/SoundLocation.java @@ -0,0 +1,28 @@ +package com.locaudio.api; + +import com.google.gson.annotations.SerializedName; + +public class SoundLocation { + @SerializedName("position") + public Point position; + + @SerializedName("confidence") + public float confidence; + + @Override + public String toString() { + return "{ Position: " + this.position.toString() + ", Confidence: " + + this.confidence + " }"; + } + + @Override + public boolean equals(Object obj) { + SoundLocation sl = (SoundLocation) obj; + if (sl.position.equals(this.position) + && sl.confidence == this.confidence) { + return true; + } else { + return false; + } + } +} diff --git a/app/Locabean/src/com/locaudio/io/WaveWriter.java b/app/Locabean/src/com/locaudio/io/WaveWriter.java index dadd8a3..7c6b277 100644 --- a/app/Locabean/src/com/locaudio/io/WaveWriter.java +++ b/app/Locabean/src/com/locaudio/io/WaveWriter.java @@ -14,7 +14,7 @@ public class WaveWriter { private static final String AUDIO_RECORDER_FILE_EXT_WAV = ".wav"; - private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder"; + private static final String AUDIO_RECORDER_FOLDER = "LocabeanAudio"; private static final String AUDIO_RECORDER_TEMP_FILE = "record_temp.raw"; private static final String AUDIO_RECORDER_FILENAME = "locabean_audio"; diff --git a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java index 48a4dc3..db77c1a 100644 --- a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java +++ b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java @@ -1,7 +1,10 @@ package com.locaudio.locabean; +import java.io.IOException; import java.util.Arrays; +import org.apache.http.client.ClientProtocolException; + import android.app.Activity; import android.media.AudioRecord; import android.os.Bundle; @@ -14,6 +17,9 @@ import com.locaudio.io.WaveWriter; import com.locaudio.api.Locaudio; +import com.locaudio.api.NotifyForm; +import com.locaudio.api.NotifyResponse; +import com.locaudio.api.SoundLocation; public class NodeActivity extends Activity { @@ -23,6 +29,9 @@ public class NodeActivity extends Activity { private TextView fingerprintTextView = null; private Locaudio locaudio = null; + private static final String IP_ADDRESS = "192.168.1.9"; + private static final int PORT = 8000; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,7 +42,7 @@ public void onCreate(Bundle savedInstanceState) { fingerprintTextView = (TextView) findViewById(R.id.fingerprintText); fingerprintTextView.setMovementMethod(new ScrollingMovementMethod()); - locaudio = new Locaudio("192.168.1.9", 8000); + locaudio = new Locaudio(IP_ADDRESS, PORT); } private void setButtonHandlers() { @@ -109,8 +118,27 @@ public void onClick(View v) { Wave wave = new Wave(WaveWriter.getFilename()); fingerprintTextView.setText(Arrays.toString(wave .getFingerprint())); + + SoundLocation[] soundLocations = locaudio + .getSoundLocations("Cock"); + System.out.println(Arrays.toString(soundLocations)); + + NotifyForm postForm = new NotifyForm(); + postForm.setFingerprint(wave.getFingerprint()); + postForm.setSoundPressureLevel(100); + postForm.setTimestamp(10); + postForm.setX(1); + postForm.setY(0); + + try { + NotifyResponse nr = locaudio.notifyEvent(postForm); + System.out.println(nr.name); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } - System.out.println(locaudio.getSoundLocations("Cock")[0].position.x); break; } } diff --git a/app/Locabean/src/com/locaudio/net/AsyncPostRequest.java b/app/Locabean/src/com/locaudio/net/AsyncPostRequest.java index f51fa1d..4d6e35d 100644 --- a/app/Locabean/src/com/locaudio/net/AsyncPostRequest.java +++ b/app/Locabean/src/com/locaudio/net/AsyncPostRequest.java @@ -13,10 +13,10 @@ public class AsyncPostRequest extends AsyncTask { private Class tClass; - private Map postForm = null; + private Map postForm = null; private String[] urlParams = null; - public AsyncPostRequest(Class tClass, Map postForm, + public AsyncPostRequest(Class tClass, Map postForm, String... urlParams) { this.tClass = tClass; this.postForm = postForm; diff --git a/app/Locabean/src/com/locaudio/net/Requests.java b/app/Locabean/src/com/locaudio/net/Requests.java index 6478dd3..ae89fcf 100644 --- a/app/Locabean/src/com/locaudio/net/Requests.java +++ b/app/Locabean/src/com/locaudio/net/Requests.java @@ -40,8 +40,7 @@ public Requests(String ipAddress, int port) { this.url = "http://" + this.ipAddress + ":" + this.port; } - @SuppressWarnings({ "rawtypes", "unchecked" }) - public T post(Class classType, Map paramMap, + public T post(Class classType, Map paramMap, String... urlParams) throws ClientProtocolException, IOException { String requestUrl = this.concatWithUrl(urlParams); @@ -51,11 +50,11 @@ public T post(Class classType, Map paramMap, // Request parameters and other properties. List params = new ArrayList(); - Iterator it = paramMap.entrySet().iterator(); + Iterator> it = paramMap.entrySet().iterator(); Entry pair = null; while (it.hasNext()) { - pair = (Entry) it.next(); + pair = (Entry) it.next(); params.add(new BasicNameValuePair(pair.getKey(), pair.getValue())); } diff --git a/locaudio/detectionserver.py b/locaudio/detectionserver.py index 1aacad6..bd56c61 100644 --- a/locaudio/detectionserver.py +++ b/locaudio/detectionserver.py @@ -85,7 +85,7 @@ def get_sound_positions(sound_name): """ if not sound_name in config.detection_events.keys(): - return jsonify(error=1, message="No detection events yet") + return json.dumps([]) radius, spl, _ = db.get_reference_data(sound_name)