Skip to content

Commit

Permalink
IT BLOODY WORKS
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 20, 2014
1 parent 287df0f commit 995ed43
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 34 deletions.
11 changes: 0 additions & 11 deletions app/Locabean/src/com/locaudio/api/Location.java

This file was deleted.

8 changes: 4 additions & 4 deletions app/Locabean/src/com/locaudio/api/Locaudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public Locaudio(String ipAddress, int port) {
super(ipAddress, port);
}

public Location[] getSoundLocations(final String soundName) {
AsyncGetRequest<Location[]> agr = new AsyncGetRequest<Location[]>(
Location[].class, LOCATIONS_ROUTE, soundName);
public SoundLocation[] getSoundLocations(final String soundName) {
AsyncGetRequest<SoundLocation[]> agr = new AsyncGetRequest<SoundLocation[]>(
SoundLocation[].class, LOCATIONS_ROUTE, soundName);
return agr.getResponse(this);
}

Expand All @@ -31,7 +31,7 @@ public NotifyResponse notifyEvent(final NotifyForm event)
throws ClientProtocolException, IOException {
AsyncPostRequest<NotifyResponse> apr = new AsyncPostRequest<NotifyResponse>(
NotifyResponse.class, event.toMap(), NOTIFY_ROUTE);

return apr.getResponse(this);
}
}
15 changes: 8 additions & 7 deletions app/Locabean/src/com/locaudio/api/NotifyForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.locaudio.api;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -24,13 +25,13 @@ public NotifyForm(float x, float y, float soundPressureLevel,
this.fingerprint = fingerprint;
}

public Map<String, ?> toMap() {
Map<String, Object> map = new HashMap<String, Object>();
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<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
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;
}

Expand Down
19 changes: 17 additions & 2 deletions app/Locabean/src/com/locaudio/api/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
28 changes: 28 additions & 0 deletions app/Locabean/src/com/locaudio/api/SoundLocation.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion app/Locabean/src/com/locaudio/io/WaveWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
32 changes: 30 additions & 2 deletions app/Locabean/src/com/locaudio/locabean/NodeActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Locabean/src/com/locaudio/net/AsyncPostRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public class AsyncPostRequest<T> extends AsyncTask<Requests, Integer, T> {

private Class<T> tClass;
private Map<String, ?> postForm = null;
private Map<String, String> postForm = null;
private String[] urlParams = null;

public AsyncPostRequest(Class<T> tClass, Map<String, ?> postForm,
public AsyncPostRequest(Class<T> tClass, Map<String, String> postForm,
String... urlParams) {
this.tClass = tClass;
this.postForm = postForm;
Expand Down
7 changes: 3 additions & 4 deletions app/Locabean/src/com/locaudio/net/Requests.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Requests(String ipAddress, int port) {
this.url = "http://" + this.ipAddress + ":" + this.port;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> T post(Class<T> classType, Map<String, ?> paramMap,
public <T> T post(Class<T> classType, Map<String, String> paramMap,
String... urlParams) throws ClientProtocolException, IOException {

String requestUrl = this.concatWithUrl(urlParams);
Expand All @@ -51,11 +50,11 @@ public <T> T post(Class<T> classType, Map<String, ?> paramMap,
// Request parameters and other properties.
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();

Iterator<?> it = paramMap.entrySet().iterator();
Iterator<Entry<String, String>> it = paramMap.entrySet().iterator();
Entry<String, String> pair = null;

while (it.hasNext()) {
pair = (Entry) it.next();
pair = (Entry<String, String>) it.next();
params.add(new BasicNameValuePair(pair.getKey(), pair.getValue()));
}

Expand Down
2 changes: 1 addition & 1 deletion locaudio/detectionserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 995ed43

Please sign in to comment.