Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: it2901g10/GROUP10-baf_sintef_arduino
base: e6993cbb84
...
head fork: it2901g10/GROUP10-baf_sintef_arduino
compare: 3c3186cc36
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
5 arduino/serialWShield/serialWShield.ino
@@ -37,7 +37,10 @@ void* buttons(byte flag, byte content[], byte contentSize){
return status;
}
void* deviceInfo(byte flag, byte content[], byte contentSize){
- byte response[] = "<VERSION=1.0.1><OS=LINUX http:linux.net><OS=WINDOWS windows.net><SERVICE=TEXT><SERVICE=SENSOR><SERVICE=LCD>";
+ byte response[] = "{NAME:\"Anders Arduino Module\", VERSION:\"1.2.0\","
+ "SERVICES:[\"SERVICE_LED_LAMP\", \"SERVICE_LCD_SCREEN\", \"SERVICE_RGB_LAMP\"],"
+ "LINKS:[{\"DEFAULT\":\"No download link\"}]}";
+
return &response;
}
View
52 java/src/no/ntnu/osnap/com/BluetoothConnection.java
@@ -20,16 +20,8 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.concurrent.TimeoutException;
-import no.ntnu.osnap.com.ConnectionMetadata.Platform;
-import no.ntnu.osnap.com.ConnectionMetadata.Service;
-import no.ntnu.osnap.com.ConnectionMetadata.DefaultServices;
-import no.ntnu.osnap.com.ConnectionMetadata.DefaultPlatforms;
+import org.json.JSONObject;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
@@ -333,43 +325,13 @@ protected synchronized void sendBytes(byte[] data) throws IOException {
public ConnectionMetadata getConnectionData() {
if(super.connectionMetadata == null)
{
- HashMap<Platform, URI> downloadLinks = new HashMap<Platform, URI>();
- ArrayList<Service> services = new ArrayList<Service>();
-
+ JSONObject object;
try {
- String rawData = super.getDeviceInfo();
- String lines[] = rawData.split("<");
- for(String line : lines){
-
- //Remove ending
- if(!line.endsWith(">")) {
- Log.w(getClass().getName(), "ConnectionMetadata malformed format: " + line + "(should end with >)");
- continue;
- }
- line = line.substring(0, line.length()-1);
-
- if(line.startsWith("VERSION=")) {
- line = line.substring(7);
- //TODO: unused
- }
- else if(line.startsWith("OS=")) {
- line = line.substring(3);
- Platform platform = DefaultPlatforms.valueOf(line); //get platform identifier
- URI link; //get download link
-
- try { downloadLinks.put(platform, new URI(line)); }
- catch (URISyntaxException e) { Log.w("", "Error parsing URI: " + e); continue; }
-
- }
- else if(line.startsWith("SERVICE=")) {
- line = line.substring(8);
- services.add(DefaultServices.valueOf(line));
- }
- }
-
- } catch (TimeoutException e) {}
-
- super.connectionMetadata = new ConnectionMetadata(device.getName(), device.getAddress(), downloadLinks, (Service[])services.toArray());
+ object = new JSONObject(super.getDeviceInfo());
+ super.connectionMetadata = new ConnectionMetadata(object);
+ } catch (Exception e) {
+ Log.e(getClass().getName(), "Oh no! Failed to get connection data correctly: " + e);
+ }
}
return super.connectionMetadata;
View
62 java/src/no/ntnu/osnap/com/ConnectionMetadata.java
@@ -16,14 +16,19 @@
*/
package no.ntnu.osnap.com;
-import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.util.Log;
+
public class ConnectionMetadata {
private String name;
private String address;
- private HashMap<Platform, URI> applicationDownloadLinks;
+ private HashMap<String, String> applicationDownloadLinks;
private HashSet<String> servicesSupported;
public interface Service {
@@ -54,9 +59,10 @@
*/
public enum DefaultServices implements Service {
SERVICE_LED_LAMP,
+ SERVICE_LCD_SCREEN,
+ SERVICE_RGB_LAMP,
SERVICE_SERVO_MOTOR,
SERVICE_VIBRATION,
- SERVICE_LCD_SCREEN,
SERVICE_TEMPERATURE_SESNOR
}
@@ -67,7 +73,7 @@
* @param applicationDownloadLink a list of download links mapped to specific platforms
* @param services an arbitrary list of Services this device supports
*/
- public ConnectionMetadata(String deviceName, String deviceAddress, HashMap<Platform, URI> applicationDownloadLink, Service[] services) {
+ public ConnectionMetadata(String deviceName, String deviceAddress, HashMap<String, String> applicationDownloadLink, Service[] services) {
this.name = deviceName;
this.applicationDownloadLinks = applicationDownloadLink;
@@ -80,12 +86,54 @@ public ConnectionMetadata(String deviceName, String deviceAddress, HashMap<Platf
//Add download links
this.applicationDownloadLinks = applicationDownloadLink;
}
+
+ /**
+ * Constructs a ConnectionMetadata object out of a JSON object
+ * @param deviceInfo JSONObject reperesentation of the ConnectionMetadata
+ * @param address an unique address specifier represented as a String (mac address, IP address, phone number, etc.)
+ */
+ public ConnectionMetadata(JSONObject deviceInfo) {
+
+ //Get custom name
+ this.name = deviceInfo.optString("NAME");
+
+ //Device address
+ this.address = deviceInfo.optString("ADDRESS");
+
+ //Get services supported
+ servicesSupported = new HashSet<String>();
+ JSONArray services = deviceInfo.optJSONArray("SERVICES");
+ if(services != null) {
+ for(int i = 0; i < services.length(); i++)
+ servicesSupported.add(services.optString(i));
+ }
+
+ //Get download links
+ this.applicationDownloadLinks = new HashMap<String, String>();
+ JSONArray downloadLinks = deviceInfo.optJSONArray("LINKS");
+ if(downloadLinks != null) {
+ for(int i = 0; i < downloadLinks.length(); i++) {
+ JSONObject pair;
+ try {
+ pair = downloadLinks.getJSONObject(i);
+ String platform = pair.getString("PLATFORM");
+ String link = pair.getString("LINK");
+ applicationDownloadLinks.put(platform, link);
+ } catch (JSONException e) {
+ //Failed to get link
+ Log.v(getClass().getName(), "Failed to parse JSON link: " + e.getMessage());
+ continue;
+ }
+ }
+ }
+
+ }
/**
* Gets the download link for the application for this device.
* @return URI of the default application
*/
- public URI getDefaultApplicationDownloadLink(){
+ public String getDefaultApplicationDownloadLink(){
return getApplicationDownloadLink(DefaultPlatforms.PLATFORM_DEFAULT);
}
@@ -95,8 +143,8 @@ public URI getDefaultApplicationDownloadLink(){
* @return URI of the application for this device
* @see DefaultPlatforms
*/
- public URI getApplicationDownloadLink(Platform platform){
- return applicationDownloadLinks.get(platform);
+ public String getApplicationDownloadLink(Platform platform){
+ return applicationDownloadLinks.get(platform.name());
}
/**

No commit comments for this range

Something went wrong with that request. Please try again.