diff --git a/.travis.yml b/.travis.yml index 5bf78bd..bbb5294 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,8 @@ jdk: - oraclejdk7 - openjdk7 -script: mvn clean package +install: mvn dependency:resolve dependency:resolve-plugins + +before_script: mvn clean + +script: mvn package diff --git a/libISOBlue-aar/pom.xml b/libISOBlue-aar/pom.xml index 2de104d..d7b3832 100644 --- a/libISOBlue-aar/pom.xml +++ b/libISOBlue-aar/pom.xml @@ -1,4 +1,27 @@ + 4.0.0 diff --git a/libISOBlue-example/pom.xml b/libISOBlue-example/pom.xml index 16dc25e..42e0b9d 100644 --- a/libISOBlue-example/pom.xml +++ b/libISOBlue-example/pom.xml @@ -1,4 +1,27 @@ + 4.0.0 @@ -27,6 +50,11 @@ libisoblue-aar aar + + com.mcxiaoke.volley + library + aar + diff --git a/libISOBlue-example/res/layout/main.xml b/libISOBlue-example/res/layout/main.xml index 3f79524..bda15c4 100755 --- a/libISOBlue-example/res/layout/main.xml +++ b/libISOBlue-example/res/layout/main.xml @@ -15,73 +15,107 @@ limitations under the License. --> + android:orientation="vertical" > + android:orientation="horizontal" > - - - + android:baselineAligned="false" + android:orientation="vertical" > - + - + + + + android:baselineAligned="false" + android:orientation="vertical" > + + + + + - - + android:orientation="horizontal" > - + android:baselineAligned="false" + android:orientation="vertical" > - + - + + + + android:baselineAligned="false" + android:orientation="vertical" > + + + + + \ No newline at end of file diff --git a/libISOBlue-example/res/menu/option_menu.xml b/libISOBlue-example/res/menu/option_menu.xml index 1f619da..254cabf 100755 --- a/libISOBlue-example/res/menu/option_menu.xml +++ b/libISOBlue-example/res/menu/option_menu.xml @@ -21,6 +21,11 @@ android:icon="@android:drawable/ic_menu_search" android:showAsAction="ifRoom|withText" android:title="@string/insecure_connect"/> + Connect a device + Get Buffered Data Make discoverable Select PGNs About diff --git a/libISOBlue-example/src/org/isoblue/ISOBlueDemo/BluetoothService.java b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/BluetoothService.java index 274388a..4a4e933 100755 --- a/libISOBlue-example/src/org/isoblue/ISOBlueDemo/BluetoothService.java +++ b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/BluetoothService.java @@ -49,6 +49,8 @@ public class BluetoothService { private ConnectedThread mBufEngConnectedThread, mBufImpConnectedThread; private int mState; + private boolean mPast; + // Constants that indicate the current connection state public static final int STATE_NONE = 0; // we're doing nothing public static final int STATE_LISTEN = 1; // now listening for incoming @@ -122,12 +124,13 @@ public synchronized void start() { * * @param device * The BluetoothDevice to connect + * @param past * @param secure * Socket Security type - Secure (true) , Insecure (false) * @throws InterruptedException * @throws IOException */ - public synchronized void connect(BluetoothDevice device) + public synchronized void connect(BluetoothDevice device, boolean past) throws IOException, InterruptedException { // Cancel any thread attempting to make a connection if (mState == STATE_CONNECTING) { @@ -147,6 +150,8 @@ public synchronized void connect(BluetoothDevice device) mImpConnectedThread = null; } + mPast = past; + // Start the thread to connect with the given device try { mConnectThread = new ConnectThread(device); @@ -189,14 +194,20 @@ public synchronized void connected(ISOBUSSocket engSocket, } // Start the thread to manage the connection and perform transmissions - mEngConnectedThread = new ConnectedThread(engSocket, ISOBlueDemo.MESSAGE_ARG1_NEW); + mEngConnectedThread = new ConnectedThread(engSocket, + ISOBlueDemo.MESSAGE_ARG1_NEW); mEngConnectedThread.start(); - mImpConnectedThread = new ConnectedThread(impSocket, ISOBlueDemo.MESSAGE_ARG1_NEW); + mImpConnectedThread = new ConnectedThread(impSocket, + ISOBlueDemo.MESSAGE_ARG1_NEW); mImpConnectedThread.start(); - mBufEngConnectedThread = new ConnectedThread(bufEngSocket, ISOBlueDemo.MESSAGE_ARG1_BUF); - mBufEngConnectedThread.start(); - mBufImpConnectedThread = new ConnectedThread(bufImpSocket, ISOBlueDemo.MESSAGE_ARG1_BUF); - mBufImpConnectedThread.start(); + if (mPast) { + mBufEngConnectedThread = new ConnectedThread(bufEngSocket, + ISOBlueDemo.MESSAGE_ARG1_BUF); + mBufEngConnectedThread.start(); + mBufImpConnectedThread = new ConnectedThread(bufImpSocket, + ISOBlueDemo.MESSAGE_ARG1_BUF); + mBufImpConnectedThread.start(); + } // Send the name of the connected device back to the UI Activity Message msg = mHandler.obtainMessage(ISOBlueDemo.MESSAGE_DEVICE_NAME); @@ -307,10 +318,12 @@ public void run() { mmImpSocket = new ISOBUSSocket(mmDevice.getImplementBus(), null, pgns); - ISOBUSSocket[] bufSocks = mmDevice - .createBufferedISOBUSSockets(0); - mmBufEngSocket = bufSocks[0]; - mmBufImpSocket = bufSocks[1]; + if (mPast) { + ISOBUSSocket[] bufSocks = mmDevice + .createBufferedISOBUSSockets(0); + mmBufEngSocket = bufSocks[0]; + mmBufImpSocket = bufSocks[1]; + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/libISOBlue-example/src/org/isoblue/ISOBlueDemo/ISOBlueDemo.java b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/ISOBlueDemo.java index a15d998..31acade 100755 --- a/libISOBlue-example/src/org/isoblue/ISOBlueDemo/ISOBlueDemo.java +++ b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/ISOBlueDemo.java @@ -17,18 +17,7 @@ package org.isoblue.ISOBlueDemo; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; - -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.HttpClient; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.message.BasicNameValuePair; import android.annotation.SuppressLint; import android.app.ActionBar; @@ -40,7 +29,6 @@ import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -48,11 +36,14 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import android.view.Window; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.Volley; import com.authorwjf.AboutDialog; /** @@ -106,6 +97,11 @@ public class ISOBlueDemo extends Activity { private SQLiteOpenHelper mHelper; private SQLiteDatabase mDatabase; + private boolean mPast; + + // Volley queue + private RequestQueue mRequestQueue; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -130,6 +126,7 @@ public void onCreate(Bundle savedInstanceState) { mHelper = new ISOBUSOpenHelper(this.getApplicationContext()); mDatabase = mHelper.getWritableDatabase(); + mRequestQueue = Volley.newRequestQueue(getApplicationContext()); } @Override @@ -328,7 +325,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { try { - connectDevice(data); + connectDevice(data, mPast); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -353,7 +350,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } - private void connectDevice(Intent data) throws IOException, + private void connectDevice(Intent data, boolean past) throws IOException, InterruptedException { // Get the device MAC address String address = data.getExtras().getString( @@ -361,13 +358,15 @@ private void connectDevice(Intent data) throws IOException, // Get the BluetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device - mChatService.connect(device); + mChatService.connect(device, past); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.option_menu, menu); + + setPastData(menu.findItem(R.id.get_past_data).isChecked()); return true; } @@ -381,6 +380,13 @@ public boolean onOptionsItemSelected(MenuItem item) { startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); return true; + case R.id.get_past_data: + // Toggle + item.setChecked(!item.isChecked()); + // Update accordingly + setPastData(item.isChecked()); + return true; + case R.id.select_pgns: PGNDialog.show(fm, "pgn_dialog"); return true; @@ -394,58 +400,20 @@ public boolean onOptionsItemSelected(MenuItem item) { return false; } - private void postMessage(String bus, org.isoblue.isobus.Message m) { - new PostTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bus, - Short.toString(m.getDestAddr()), - Short.toString(m.getSrcAddr()), Arrays.toString(m.getData()), - Long.toString(m.getTimeStamp())); - } + private void setPastData(boolean past) { + mPast = past; - // Acquired from Cyrus - private void postData(String bus, String dest, String src, String data, - String time) { - // Create a new HttpClient and Post Header - HttpClient httpclient = new DefaultHttpClient(); - HttpPost httppost = new HttpPost( - "https://docs.google.com/forms/d/1mszF-1Dvk18ajb6WhP22ctkDqizNI9-wMjylDznPKjs/formResponse"); - - try { - // Add your data - List nameValuePairs = new ArrayList(2); - nameValuePairs.add(new BasicNameValuePair("entry.2120486804", bus)); - nameValuePairs.add(new BasicNameValuePair("entry.363860839", dest)); - nameValuePairs.add(new BasicNameValuePair("entry.80712516", src)); - nameValuePairs - .add(new BasicNameValuePair("entry.1759126747", data)); - nameValuePairs.add(new BasicNameValuePair("entry.478698627", time)); - httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); - - // Execute HTTP Post Request - HttpResponse response = httpclient.execute(httppost); - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // Update views accordingly + if (mPast) { + findViewById(R.id.buf_view).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.buf_view).setVisibility(View.GONE); } } - private class PostTask extends AsyncTask { - @Override - protected Void doInBackground(String... params) { - postData(params[0], params[1], params[2], params[3], params[4]); - return null; - } - - @Override - protected void onPostExecute(Void result) { - // This is executed on ui thread - } - - @Override - protected void onProgressUpdate(Void... values) { - // This is executed on ui thread - } + private void postMessage(String bus, org.isoblue.isobus.Message m) { + mRequestQueue.add(new MessagePostRequest(bus, Short.toString(m + .getDestAddr()), Short.toString(m.getSrcAddr()), Arrays + .toString(m.getData()), Long.toString(m.getTimeStamp()))); } } diff --git a/libISOBlue-example/src/org/isoblue/ISOBlueDemo/MessagePostRequest.java b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/MessagePostRequest.java new file mode 100644 index 0000000..f1c34cc --- /dev/null +++ b/libISOBlue-example/src/org/isoblue/ISOBlueDemo/MessagePostRequest.java @@ -0,0 +1,91 @@ +/* + * Author: Alex Layton + * + * Copyright (c) 2014 Purdue University + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.isoblue.ISOBlueDemo; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.android.volley.AuthFailureError; +import com.android.volley.NetworkResponse; +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.VolleyLog; + +/** + * Uses Google Volley to post to a Google form as a way to upload data. TODO: + * Use response to check if the data was actually uploaded. + * + * @author Alex Layton + */ +public class MessagePostRequest extends Request { + + private static final String URL = "https://docs.google.com/forms/d/1mszF-1Dvk18ajb6WhP22ctkDqizNI9-wMjylDznPKjs/formResponse"; + private static final String BUS_ENTRY = "entry.2120486804"; + private static final String DEST_ENTRY = "entry.363860839"; + private static final String SRC_ENTRY = "entry.80712516"; + private static final String DATA_ENTRY = "entry.1759126747"; + private static final String TIME_ENTRY = "entry.478698627"; + + private final Map mParams; + + public MessagePostRequest(String bus, String dest, String src, String data, + String time) { + super(Method.POST, URL, new ErrorListener()); + + Map params = new HashMap(); + params.put(BUS_ENTRY, bus); + params.put(DEST_ENTRY, dest); + params.put(SRC_ENTRY, src); + params.put(DATA_ENTRY, data); + params.put(TIME_ENTRY, time); + mParams = Collections.unmodifiableMap(params); + } + + @Override + protected Response parseNetworkResponse(NetworkResponse response) { + // Don't Care about response + return null; + } + + @Override + protected void deliverResponse(Void response) { + // Don't Care about response + } + + @Override + protected Map getParams() throws AuthFailureError { + return mParams; + } + + private static class ErrorListener implements Response.ErrorListener { + + @Override + public void onErrorResponse(VolleyError error) { + VolleyLog.d("Error: " + error.getMessage()); + } + } +} diff --git a/libISOBlue/pom.xml b/libISOBlue/pom.xml index ee51d78..eb206a8 100644 --- a/libISOBlue/pom.xml +++ b/libISOBlue/pom.xml @@ -1,4 +1,27 @@ + 4.0.0 diff --git a/pom.xml b/pom.xml index d7e86d8..64ae824 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,27 @@ + 4.0.0 @@ -88,6 +111,13 @@ ${project.version} aar + + + com.mcxiaoke.volley + library + 1.0.4 + aar +