diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e19db40ed..452b8f2ae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,8 +12,8 @@ Redistribution and use in source and binary forms, with or without modification, --> @@ -22,6 +22,7 @@ Redistribution and use in source and binary forms, with or without modification, + diff --git a/app/src/main/assets/help.html b/app/src/main/assets/help.html index 4640d922e..beff43bc4 100644 --- a/app/src/main/assets/help.html +++ b/app/src/main/assets/help.html @@ -60,19 +60,25 @@

Notice

CAUTION - Before flight the user must always ensure that Avare is updated to and thoroughly tested on the latest version, and ensure that all Avare databases and charts are kept current. If Avare and its databases and charts are not of the exact same version, the GPS position displayed may be inaccurate, because the FAA sometimes changes the format of their materials. Avare does not automatically fetch any databases and charts when they are expired, so it is the user's sole responsibility to update any expired charts and databases. To do so, ensure that your device has an internet connection and then just press the Map, Menu, Preferences, Download, and Update buttons in Avare.

Avare Releases

+

10.2.8

+
    +
  • Added auto pilot control over USB serial

  • +

    +
+

10.2.7

    -
  • Fix plate tagging
  • +
  • Fix plate tagging

10.2.6

    -
  • Improved help file
  • +
  • Improved help file

10.2.5

    -
  • Improved audible traffic alerts for traffic
  • +
  • Improved audible traffic alerts for traffic

10.2.4

@@ -92,9 +98,9 @@

Avare Releases

10.2.1

    -
  • Improved ADS-B traffic display +

  • Improved ADS-B traffic display

    -
  • Added audible traffic alerts for +

  • Added audible traffic alerts for traffic

  • Improved weather display color @@ -112,10 +118,10 @@

    Avare Releases

10.1.8

    -
  • Bluetooth and USB connection +

  • Bluetooth and USB connection improvements

    -
  • Changed UI for long-press in Find +

  • Changed UI for long-press in Find and Search tabs

  • Improvements in drawing @@ -126,37 +132,6 @@

    Avare Releases

  • Stop bug fix

-

10.1.6

-
    -
  • Increase in max zoom -

    -
  • Stop bug fix -

    -
  • Preferences can be exported / imported / deleted -

    -
-

10.1.5

-
    -
  • New improved mapping engine. -

    -
  • Added ability to delete imported - waypoints. -

    -
  • Added elevation profile to - imported waypoints. -

    -
  • Fixed destination in IO/GPS - simulation destination. -

    -
  • Added auto connect to external Bluetooth, WiFi, USB, and - autopilots on start. -

    -
-

10.1.4

-
    -
  • Bug fix -

    -

Help Categories

Below is a list of your choices for Help with Avare (pronounced "Ah-vAir" - like "aware" with a "v"). Nearly all are available Offline (without internet access on your device), such as when you are flying or your device is in Airplane Mode.
diff --git a/app/src/main/java/com/ds/avare/IOActivity.java b/app/src/main/java/com/ds/avare/IOActivity.java index 9141dc317..b12d8a976 100644 --- a/app/src/main/java/com/ds/avare/IOActivity.java +++ b/app/src/main/java/com/ds/avare/IOActivity.java @@ -49,7 +49,7 @@ public class IOActivity extends BaseActivity { private Location mCurrentLocation; private GpsStatus mCurrentGpsStatus; - private Fragment[] mFragments = new Fragment[10]; + private Fragment[] mFragments = new Fragment[11]; private WifiManager.MulticastLock mMulticastLock; @@ -122,6 +122,7 @@ public void onCreate(Bundle savedInstanceState) { mFragments[pos++] = new FileFragment(); mFragments[pos++] = new GPSSimulatorFragment(); mFragments[pos++] = new USBInFragment(); + mFragments[pos++] = new USBOutFragment(); mFragments[pos++] = new Dump1090Fragment(); mFragments[pos++] = new ToolsFragment(); @@ -154,6 +155,7 @@ public void onNothingSelected(AdapterView parent) { getString(R.string.Play), getString(R.string.GPSSIM), getString(R.string.USBIN), + getString(R.string.APUSB), "Dump1090", getString(R.string.Tools) }); @@ -225,10 +227,14 @@ private void changeFragment(int id) { fragmentTransaction.replace(R.id.detailFragment, usbin); break; case 8: + USBOutFragment usbout = (USBOutFragment) mFragments[id]; + fragmentTransaction.replace(R.id.detailFragment, usbout); + break; + case 9: Dump1090Fragment d1090 = (Dump1090Fragment) mFragments[id]; fragmentTransaction.replace(R.id.detailFragment, d1090); break; - case 9: + case 10: ToolsFragment tools = (ToolsFragment) mFragments[id]; fragmentTransaction.replace(R.id.detailFragment, tools); break; diff --git a/app/src/main/java/com/ds/avare/USBOutFragment.java b/app/src/main/java/com/ds/avare/USBOutFragment.java new file mode 100644 index 000000000..0fd88fc28 --- /dev/null +++ b/app/src/main/java/com/ds/avare/USBOutFragment.java @@ -0,0 +1,105 @@ +/* +Copyright (c) 2012, Apps4Av Inc. (ds.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +package com.ds.avare; + + +import android.app.Fragment; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.Button; + +import com.ds.avare.connections.Connection; +import com.ds.avare.connections.ConnectionFactory; +import com.ds.avare.storage.Preferences; +import com.ds.avare.storage.SavedEditText; + +import java.io.File; + +/** + * + * @author zkhan + * + */ +public class USBOutFragment extends Fragment { + + private Connection mUSB; + private Context mContext; + private Button mConnectButton; + private SavedEditText mParamsText; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + mContext = container.getContext(); + + View view = inflater.inflate(R.layout.layout_usbout, container, false); + + mParamsText = (SavedEditText) view.findViewById(R.id.usbout_params_text); + + mUSB = ConnectionFactory.getConnection(ConnectionFactory.CF_USBConnectionOut, mContext); + + mConnectButton = (Button) view.findViewById(R.id.usbout_button_connect); + mConnectButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + /* + * If connected, disconnect + */ + if (mUSB.isConnected()) { + mUSB.stop(); + mUSB.disconnect(); + setStates(); + return; + } + /* + * Connect to the given device in list + */ + if (!mUSB.isConnected()) { + mConnectButton.setText(getString(R.string.Connect)); + mUSB.connect(mParamsText.getText().toString(), false); + Preferences pref = StorageService.getInstance().getPreferences(); + if (mUSB.isConnected()) { + mUSB.start(); + pref.setLastConnectedUSB(mParamsText.getText().toString()); // save where we connected + } else { + pref.setLastConnectedUSB(null); // clear + } + setStates(); + } + } + }); + return view; + } + + /** + * + */ + private void setStates() { + if (mUSB.isConnected()) { + mConnectButton.setText(getString(R.string.Disconnect)); + } else { + mConnectButton.setText(getString(R.string.Connect)); + } + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/ds/avare/connections/ConnectionFactory.java b/app/src/main/java/com/ds/avare/connections/ConnectionFactory.java index 528cb84a0..e1facafae 100644 --- a/app/src/main/java/com/ds/avare/connections/ConnectionFactory.java +++ b/app/src/main/java/com/ds/avare/connections/ConnectionFactory.java @@ -30,6 +30,7 @@ public class ConnectionFactory { public static final String CF_USBConnectionIn = "USBConnectionIn"; public static final String CF_XplaneConnection = "XplaneConnection"; public static final String CF_Dump1090Connection = "Dump1090Connection"; + public static final String CF_USBConnectionOut = "USBConnectionOut"; public static Connection getConnection(String type, Context ctx) { if(type.equals(CF_BlueToothConnectionIn)) { @@ -59,6 +60,9 @@ public static Connection getConnection(String type, Context ctx) { if(type.equals(CF_Dump1090Connection)) { return Dump1090Connection.getInstance(ctx); } + if(type.equals(CF_USBConnectionOut)) { + return USBConnectionOut.getInstance(ctx); + } return null; } @@ -76,6 +80,7 @@ public static String getActiveConnections(Context ctx) { s += getConnection(CF_FileConnectionIn, ctx).isConnected() ? "," + ctx.getString(R.string.Play) : ""; s += getConnection(CF_GPSSimulatorConnection, ctx).isConnected() ? "," + ctx.getString(R.string.GPSSIM) : ""; s += getConnection(CF_USBConnectionIn, ctx).isConnected() ? "," + ctx.getString(R.string.USBIN) : ""; + s += getConnection(CF_USBConnectionOut, ctx).isConnected() ? "," + ctx.getString(R.string.APUSB) : ""; s += getConnection(CF_Dump1090Connection, ctx).isConnected() ? "," + ctx.getString(R.string.DUMP1090) : ""; if(s.startsWith(",")) { s = s.substring(1); diff --git a/app/src/main/java/com/ds/avare/connections/USBConnectionOut.java b/app/src/main/java/com/ds/avare/connections/USBConnectionOut.java new file mode 100644 index 000000000..be2a7106f --- /dev/null +++ b/app/src/main/java/com/ds/avare/connections/USBConnectionOut.java @@ -0,0 +1,261 @@ +/* +Copyright (c) 2012, Apps4Av Inc. (ds.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package com.ds.avare.connections; + +import android.bluetooth.BluetoothAdapter; +import android.content.Context; +import android.hardware.usb.UsbDeviceConnection; +import android.hardware.usb.UsbManager; + +import com.ds.avare.storage.Preferences; +import com.ds.avare.utils.GenericCallback; +import com.ds.avare.utils.Logger; +import com.hoho.android.usbserial.driver.UsbSerialDriver; +import com.hoho.android.usbserial.driver.UsbSerialPort; +import com.hoho.android.usbserial.driver.UsbSerialProber; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + + +/** + * + * @author zkhan + * + */ +public class USBConnectionOut extends Connection { + + private static USBConnectionOut mConnection; + private static UsbManager mUsbManager; + private String mParams; + private static UsbDeviceConnection mDriverConnection; + private static UsbSerialPort mPort; + private UsbSerialDriver mDriver = null; + /** + * + */ + private USBConnectionOut() { + super("USB Output"); + setCallback(new GenericCallback() { + @Override + public Object callback(Object o, Object o1) { + + /* + * This state machine will keep trying to connect to + * ADBS/GPS receiver + */ + int msgCount = 1; + while(isRunning()) { + + /* + * Read data from Avare + */ + String r = getDataFromHelper(); + if (null == r) { + continue; + } + + // Build the JSON object from the received string. Contained therein + // is a collection of NMEA sentences that drives the autopilot. Send that data + // over the connection + try { + JSONObject object; + object = new JSONObject(r); + + // Read the type of this object. We are only interested in NMEANAV + // messages + String type = object.getString("type"); + if (type.equals("nmeanav")) { + + // Log our intent to the trace window. The data itself was logged in the base object + Logger.Logit(msgCount++ + ". Sending sentences to USB out"); + + // Extract the autopilot sentences from the message + String apData = object.getString("apsentences"); + if(0 != apData.length()) { + int wrote = writeToStream(apData.getBytes()); + if (wrote <= 0) { + if (isStopped()) { + break; + } + try { + Thread.sleep(1000); + } catch (Exception ignore) { + + } + + /* + * Try to reconnect + */ + Logger.Logit("Disconnected from USB out, retrying to connect"); + disconnect(); + connect(mParams, false); + } + } + } + } catch(Exception ignore) { } + } + return null; + } + }); + } + + /** + * + * @return + */ + public static USBConnectionOut getInstance(Context ctx) { + if(null == mConnection) { + mConnection = new USBConnectionOut(); + mUsbManager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE); + } + return mConnection; + } + + /** + * + * A device name devNameMatch, will connect to first device whose + * name matched this string. + * @return + */ + @Override + public boolean connect(String params, boolean secure) { + + mParams = params; + List availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(mUsbManager); + if (availableDrivers.isEmpty()) { + Logger.Logit("No USB serial device available"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return false; + } + mDriver = availableDrivers.get(0); + if(mDriver == null) { + Logger.Logit("No USB serial device available"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return false; + } + + + /* + * Only when not connected, connect + */ + if(getState() != Connection.DISCONNECTED) { + Logger.Logit("Failed! Already connected?"); + + return false; + } + setState(Connection.CONNECTING); + + try { + + mDriverConnection = mUsbManager.openDevice(mDriver.getDevice()); + if (mDriverConnection == null) { + Logger.Logit("Failed!"); + + return false; + } + + mPort = mDriver.getPorts().get(0); + mPort.open(mDriverConnection); + + String tokens[] = mParams.split(","); + // 115200, 8, n, 1 + // rate, data, parity, stop + int rate = Integer.parseInt(tokens[0]); + int data = Integer.parseInt(tokens[1]); + int parity; + if(tokens[2].equals("n")) { + parity = UsbSerialPort.PARITY_NONE; + } + else if (tokens[2].equals("o")) { + parity = UsbSerialPort.PARITY_ODD; + } + else { + parity = UsbSerialPort.PARITY_EVEN; + } + int stop = Integer.parseInt(tokens[3]); + mPort.setParameters(rate, data, stop, parity); + } + catch (Exception e) { + setState(Connection.DISCONNECTED); + Logger.Logit("Failed!"); + return false; + } + + return connectConnection(); + } + + @Override + public void write(byte[] aData) { + + } + + /** + * + * @return + */ + private int writeToStream(byte[] buffer) { + int wrote = buffer.length; + try { + mPort.write(buffer, 0); + } + catch(Exception e) { + wrote = -1; + } + return wrote; + } + + /** + * + */ + @Override + public void disconnect() { + + try { + mPort.close(); + mDriverConnection.close(); + } + catch (Exception e) { + + } + mDriver = null; + /* + * Exit + */ + disconnectConnection(); + } + + @Override + public List getDevices() { + return new ArrayList(); + } + + + @Override + public String getConnDevice() { + return ""; + } + + +} diff --git a/app/src/main/res/layout/layout_usbout.xml b/app/src/main/res/layout/layout_usbout.xml new file mode 100644 index 000000000..8bf8e1c08 --- /dev/null +++ b/app/src/main/res/layout/layout_usbout.xml @@ -0,0 +1,55 @@ + + + + + + + + + +