Added Database and Content provider for Raw Packet Table and bluetooth tnc service puts data into db via content provider now.
Added Database and Content provider for Raw Packet Table and bluetooth tnc service puts data into db via content provider now.

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -13,8 +13,8 @@
     <uses-permission android:name="android.permission.BLUETOOTH"/>
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-

-    <application

+
+	<application

         android:allowBackup="true"

         android:icon="@drawable/ic_launcher"

         android:label="@string/app_name"

@@ -31,6 +31,13 @@
 
         <activity android:name="com.dryerzinia.aprs_x.test.DeviceScanActivity" />
         <activity android:name="com.dryerzinia.aprs_x.test.DeviceControlActivity"/>
+
+		<provider
+       		android:authorities="com.dryerzinia.aprs_x.db"
+       		android:name="com.dryerzinia.aprs_x.db.APRSContentProvider"
+       		android:exported="true"
+		/>
+
         <service android:name="com.dryerzinia.aprs_x.services.BluetoothLeService" android:enabled="true"/>

 
     </application>


--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/data_model/packet/APRSExtendedData.java
@@ -1,1 +1,8 @@
+package com.dryerzinia.aprs_x.data_model.packet;
 
+public abstract class APRSExtendedData {
+
+	//
+
+}
+

--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/data_model/packet/RawPacket.java
@@ -1,1 +1,110 @@
+package com.dryerzinia.aprs_x.data_model.packet;
 
+import java.util.ArrayList;
+
+public class RawPacket {
+
+	private long id;
+
+	private long timeStamp;
+
+	private String sourceAddress;
+	private String destinationAddress;
+
+	private ArrayList<String> repeaterAddresses = new ArrayList<String>();
+
+	private byte[] data;
+
+	private APRSExtendedData exData;
+
+	public long getID(){
+		
+		return id;
+
+	}
+
+	public String getSourceAddress() {
+
+		return sourceAddress;
+
+	}
+
+	public String getDestinationAddress() {
+
+		return destinationAddress;
+
+	}
+
+	public long getTimeStamp(){
+		
+		return timeStamp;
+
+	}
+	
+	public byte[] getRawData() {
+
+		return data;
+
+	}
+
+	public void setID(long id){
+
+		this.id = id;
+
+	}
+
+	public static RawPacket fromRawData(byte[] data){
+
+		RawPacket pkt = new RawPacket();
+
+		pkt.timeStamp = 0;
+
+		pkt.data = data;
+
+		pkt.destinationAddress = "";
+		for(int i = 0; i < 6 && data[i] != 0x40; i++)
+			pkt.destinationAddress +=  (char)((data[i] & 0xFF) >> 1);
+		pkt.destinationAddress += "-" + ((data[6] & 0x1F) >> 1);
+
+		pkt.sourceAddress = "";
+		for(int i = 7; i < 13 && data[i] != 0x40; i++)
+			pkt.sourceAddress +=  (char)((data[i] & 0xFF) >> 1);
+		pkt.sourceAddress += "-" + ((data[13] & 0x1F) >> 1);
+
+		int n = 14;
+		while(true){
+
+			if( n + 1 >= data.length) break;
+
+			// Check for 0 bit set on end of last address character indicating that
+			// there are no more repeater addresses
+			if( (data[n - 1] & 0x01) != 0) break;
+
+			if(pkt.repeaterAddresses.size() > 7) break;
+
+			if(n+7 >= data.length) break;
+
+			String new_address = "";
+			for(int i = n; i < n + 6 && data[i] != 0x40; i++)
+				new_address += (char)((data[i] & 0xFF) >> 1);
+			new_address +=  "-" + ((data[n-1] & 0x1F) >> 1);
+
+			n += 7;
+
+			pkt.repeaterAddresses.add(new_address);
+
+		}
+
+		return pkt;
+
+	}
+
+	@Override
+	public String toString() {
+
+		return "";
+
+	}
+
+}
+

--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/data_model/packet/RawPacketDataSource.java
@@ -1,1 +1,25 @@
+package com.dryerzinia.aprs_x.data_model.packet;
 
+import com.dryerzinia.aprs_x.db.APRSDatabaseHelper;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+
+public class RawPacketDataSource {
+
+	private SQLiteDatabase database;
+	private APRSDatabaseHelper dbHelper;
+	private String[] allColumns =
+		{
+			"id",
+			""
+		};
+
+	public RawPacketDataSource(Context context) {
+
+		dbHelper = new APRSDatabaseHelper(context);
+
+	}
+
+}
+

--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/db/APRSContentProvider.java
@@ -1,1 +1,155 @@
+package com.dryerzinia.aprs_x.db;
 
+import com.dryerzinia.aprs_x.db.table.RawPacketTable;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteQueryBuilder;
+import android.net.Uri;
+
+public class APRSContentProvider extends ContentProvider {
+
+	private APRSDatabaseHelper db;
+
+	private static final String AUTHORITY = "com.dryerzinia.aprs_x.db";
+
+	public static final Uri RAW_PACKET_URI = Uri.parse("content://" + AUTHORITY + "/" + RawPacketTable.TABLE_RAW_PACKET);
+
+	private static final int RAW_PACKET = 1;
+
+	private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+	static {
+
+		sURIMatcher.addURI(AUTHORITY, RawPacketTable.TABLE_RAW_PACKET, RAW_PACKET);
+
+	}
+
+	@Override
+	public boolean onCreate() {
+
+		db = new APRSDatabaseHelper(getContext());
+		return false;
+
+	}
+
+	@Override
+	public Cursor query(Uri uri, String[] projection, String selection,
+			String[] selectionArgs, String sortOrder) {
+
+		SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
+
+		int uriType = sURIMatcher.match(uri);
+		switch(uriType){
+
+			case RAW_PACKET:
+
+				RawPacketTable.checkColumns(projection);
+				queryBuilder.setTables(RawPacketTable.TABLE_RAW_PACKET);
+
+				break;
+
+			default:
+				throw new IllegalArgumentException("Unknown URI: " + uri);
+
+		}
+
+		SQLiteDatabase sqlDB = db.getWritableDatabase();
+		Cursor cursor = queryBuilder.query(sqlDB, projection, selection, selectionArgs, null, null, sortOrder);
+		cursor.setNotificationUri(getContext().getContentResolver(), uri);
+
+		return cursor;
+
+	}
+
+	@Override
+	public String getType(Uri uri) {
+
+		return null;
+
+	}
+
+	@Override
+	public Uri insert(Uri uri, ContentValues values) {
+
+		int uriType = sURIMatcher.match(uri);
+		SQLiteDatabase sqlDB = db.getWritableDatabase();
+
+		String basePath = "";
+		long id = 0;
+
+		switch(uriType){
+
+			case RAW_PACKET:
+
+				id = sqlDB.insert(RawPacketTable.TABLE_RAW_PACKET, null, values);
+				basePath = RawPacketTable.TABLE_RAW_PACKET;
+
+				break;
+
+			default:
+				throw new IllegalArgumentException("Unknown URI: " + uri);
+
+		}
+
+		getContext().getContentResolver().notifyChange(uri, null);
+
+		return Uri.parse(basePath + "/" + id);
+
+	}
+
+	@Override
+	public int delete(Uri uri, String selection, String[] selectionArgs) {
+
+		int rowsDeleted = 0;
+		SQLiteDatabase sqlDB = db.getWritableDatabase();
+
+		int uriType = sURIMatcher.match(uri);
+		switch(uriType){
+
+			case RAW_PACKET:
+
+				rowsDeleted = sqlDB.delete(RawPacketTable.TABLE_RAW_PACKET, selection, selectionArgs);
+				break;
+
+			default:
+				throw new IllegalArgumentException("Unknown URI: " + uri);
+
+		}
+
+		getContext().getContentResolver().notifyChange(uri, null);
+
+		return rowsDeleted;
+
+	}
+
+	@Override
+	public int update(Uri uri, ContentValues values, String selection,
+			String[] selectionArgs) {
+
+		int rowsUpdated = 0;
+		SQLiteDatabase sqlDB = db.getWritableDatabase();
+
+		int uriType = sURIMatcher.match(uri);
+		switch(uriType){
+
+			case RAW_PACKET:
+
+				rowsUpdated = sqlDB.update(RawPacketTable.TABLE_RAW_PACKET, values, selection, selectionArgs);
+				break;
+
+			default:
+				throw new IllegalArgumentException("Unknown URI: " + uri);
+
+		}
+
+		getContext().getContentResolver().notifyChange(uri, null);
+		
+		return rowsUpdated;
+
+	}
+
+}
+

--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/db/APRSDatabaseHelper.java
@@ -1,1 +1,29 @@
+package com.dryerzinia.aprs_x.db;

+

+import com.dryerzinia.aprs_x.db.table.RawPacketTable;

+

+import android.content.Context;

+import android.database.sqlite.SQLiteDatabase;

+import android.database.sqlite.SQLiteOpenHelper;

+

+public class APRSDatabaseHelper extends SQLiteOpenHelper {

+

+	public static final String DATABASE_NAME = "aprsx.db";

+	public static final int DATABASE_VERSION = 1;

+

+	public APRSDatabaseHelper(Context context) {

+		super(context, DATABASE_NAME, null, DATABASE_VERSION);

+	}

+

+	@Override

+	public void onCreate(SQLiteDatabase db) {

+		RawPacketTable.onCreate(db);

+	}

+

+	@Override

+	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

+		RawPacketTable.onUpgrade(db);

+	}

+

+}

 

--- a/src/com/dryerzinia/aprs_x/db/DatabaseHelper.java
+++ /dev/null
@@ -1,28 +1,1 @@
-package com.dryerzinia.aprs_x.db;

-

-import android.content.Context;

-import android.database.sqlite.SQLiteDatabase;

-import android.database.sqlite.SQLiteDatabase.CursorFactory;

-import android.database.sqlite.SQLiteOpenHelper;

-

-public class DatabaseHelper extends SQLiteOpenHelper {

-

-	public static final String DATABASE_NAME = "aprsx.db";

-	public static final int DATABASE_VERSION = 1;

-

-	public DatabaseHelper(Context context) {

-		super(context, DATABASE_NAME, null, DATABASE_VERSION);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

-

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/DatabaseManager.java
+++ b/src/com/dryerzinia/aprs_x/db/DatabaseManager.java
@@ -6,7 +6,7 @@
 

 	private Activity mActivity;

 

-	private DatabaseHelper dbHelper;

+	private APRSDatabaseHelper dbHelper;

 

 	private DatabaseManager() {

 

@@ -22,14 +22,14 @@
 

 	public void initialize(Activity activity) {

 		this.mActivity = activity;

-		this.setDbHelper(new DatabaseHelper(mActivity));

+		this.setDbHelper(new APRSDatabaseHelper(mActivity));

 	}

 

-	public DatabaseHelper getDbHelper() {

+	public APRSDatabaseHelper getDbHelper() {

 		return dbHelper;

 	}

 

-	public void setDbHelper(DatabaseHelper dbHelper) {

+	public void setDbHelper(APRSDatabaseHelper dbHelper) {

 		this.dbHelper = dbHelper;

 	}

 


--- a/src/com/dryerzinia/aprs_x/db/table/AprsStatusTable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class AprsStatusTable extends Table {

-

-	public AprsStatusTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/ContactsTable.java
+++ b/src/com/dryerzinia/aprs_x/db/table/ContactsTable.java
@@ -2,20 +2,12 @@
 

 import android.database.sqlite.SQLiteDatabase;

 

-public class ContactsTable extends Table {

+public class ContactsTable {

 

-	public ContactsTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

+	public void onCreate(SQLiteDatabase db) {

 	}

 

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

 	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

 	}

 

 }


--- a/src/com/dryerzinia/aprs_x/db/table/ConversationTable.java
+++ b/src/com/dryerzinia/aprs_x/db/table/ConversationTable.java
@@ -2,20 +2,12 @@
 

 import android.database.sqlite.SQLiteDatabase;

 

-public class ConversationTable extends Table {

+public class ConversationTable {

 

-	public ConversationTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

+	public void onCreate(SQLiteDatabase db) {

 	}

 

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

 	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

 	}

 

 }


--- a/src/com/dryerzinia/aprs_x/db/table/CurrentMicETable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class CurrentMicETable extends Table {

-

-	public CurrentMicETable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/OldMicETable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class OldMicETable extends Table {

-

-	public OldMicETable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/PacketMasterTable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class PacketMasterTable extends Table {

-

-	public PacketMasterTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/PositionWithTimestampNoMessagingTable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class PositionWithTimestampNoMessagingTable extends Table {

-

-	public PositionWithTimestampNoMessagingTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/PositionWithTimestampTable.java
+++ /dev/null
@@ -1,23 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class PositionWithTimestampTable extends Table{

-

-	public PositionWithTimestampTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/PositionWithoutTimestampNoMessaging.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class PositionWithoutTimestampNoMessaging extends Table {

-

-	public PositionWithoutTimestampNoMessaging(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/PositionWithoutTimestampTable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class PositionWithoutTimestampTable extends Table {

-

-	public PositionWithoutTimestampTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- /dev/null
+++ b/src/com/dryerzinia/aprs_x/db/table/RawPacketTable.java
@@ -1,1 +1,139 @@
+package com.dryerzinia.aprs_x.db.table;

+

+import java.util.Arrays;

+import java.util.HashSet;

+

+import com.dryerzinia.aprs_x.data_model.packet.RawPacket;

+

+import android.content.ContentValues;

+import android.database.sqlite.SQLiteDatabase;

+

+public class RawPacketTable {

+

+	public static final String TABLE_RAW_PACKET = "packet_master";

+

+	public static final String COLUMN_ID = "id";

+

+	public static final String COLUMN_TIME_STAMP = "time_stamp";

+

+	public static final String COLUMN_SOURCE_ADDRESS = "source_address";

+	public static final String COLUMN_DESTINATION_ADDRESS = "desination_address";

+

+	public static final String COLUMN_REPEATER_1_ADDRESS = "repeater_1_address";

+	public static final String COLUMN_REPEATER_2_ADDRESS = "repeater_2_address";

+	public static final String COLUMN_REPEATER_3_ADDRESS = "repeater_3_address";

+	public static final String COLUMN_REPEATER_4_ADDRESS = "repeater_4_address";

+	public static final String COLUMN_REPEATER_5_ADDRESS = "repeater_5_address";

+	public static final String COLUMN_REPEATER_6_ADDRESS = "repeater_6_address";

+	public static final String COLUMN_REPEATER_7_ADDRESS = "repeater_7_address";

+	public static final String COLUMN_REPEATER_8_ADDRESS = "repeater_8_address";

+

+	public static final String COLUMN_PACKET_TYPE = "packet_type";

+	public static final String COLUMN_PACKET_TYPE_DATA_ID = "packet_type_data_id";

+

+	public static final String COLUMN_RAW_DATA = "raw_rata";

+

+	public static final String TABLE_CREATE =

+		  "create table " + TABLE_RAW_PACKET

+		+ "("

+

+		+ COLUMN_ID + " INTEGER primary key autoincrement, "

+

+		+ COLUMN_TIME_STAMP + " INTEGER not null, "

+

+		+ COLUMN_SOURCE_ADDRESS + " TEXT not null, "

+		+ COLUMN_DESTINATION_ADDRESS + " TEXT not null, "

+

+		+ COLUMN_REPEATER_1_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_2_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_3_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_4_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_5_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_6_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_7_ADDRESS + " TEXT, "

+		+ COLUMN_REPEATER_8_ADDRESS + " TEXT, "

+

+		+ COLUMN_PACKET_TYPE + " INTEGER, "

+		+ COLUMN_PACKET_TYPE_DATA_ID + " INTEGER, "

+

+		+ COLUMN_RAW_DATA + " BLOB"

+

+		+ ");";

+

+	private static final HashSet<String> availableColumns =

+		new HashSet<String>(

+			Arrays.asList(new String[]{

+

+				COLUMN_ID,

+

+				COLUMN_TIME_STAMP,

+

+				COLUMN_SOURCE_ADDRESS,

+				COLUMN_DESTINATION_ADDRESS,

+

+				COLUMN_REPEATER_1_ADDRESS,

+				COLUMN_REPEATER_2_ADDRESS,

+				COLUMN_REPEATER_3_ADDRESS,

+				COLUMN_REPEATER_4_ADDRESS,

+				COLUMN_REPEATER_5_ADDRESS,

+				COLUMN_REPEATER_6_ADDRESS,

+				COLUMN_REPEATER_7_ADDRESS,

+				COLUMN_REPEATER_8_ADDRESS,

+

+				COLUMN_PACKET_TYPE,

+				COLUMN_PACKET_TYPE_DATA_ID,

+

+				COLUMN_RAW_DATA

+			})

+		);

+	

+	public RawPacketTable(){

+

+		//

+

+	}

+

+	public static void onCreate(SQLiteDatabase db){

+

+		db.execSQL(TABLE_CREATE);

+

+	}

+

+	public static void onUpgrade(SQLiteDatabase db){

+

+		db.execSQL("DROP TABLE IF EXISTS " + TABLE_RAW_PACKET);

+		onCreate(db);

+

+	}

+

+	public static ContentValues getContentValues(RawPacket pkt){

+

+		ContentValues values = new ContentValues();

+

+		values.put(RawPacketTable.COLUMN_TIME_STAMP, pkt.getTimeStamp());

+

+		values.put(RawPacketTable.COLUMN_SOURCE_ADDRESS, pkt.getSourceAddress());

+		values.put(RawPacketTable.COLUMN_DESTINATION_ADDRESS, pkt.getDestinationAddress());

+

+		values.put(RawPacketTable.COLUMN_RAW_DATA, pkt.getRawData());

+

+		return values;

+

+	}

+

+	public static void checkColumns(String[] projection){

+

+		if(projection != null) {

+

+			HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));

+

+			if(!availableColumns.containsAll(requestedColumns)){

+				throw new IllegalArgumentException("Unknown columns in projection");

+			}

+

+		}

+

+	}

+

+}

 

--- a/src/com/dryerzinia/aprs_x/db/table/Table.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public abstract class Table {

-	private String createStatement, dropTableStatement;

-

-	public Table(String createStatement, String dropTableStatement) {

-		this.createStatement = createStatement;

-		this.dropTableStatement = dropTableStatement;

-	}

-

-	public void onCreate(SQLiteDatabase db) {

-		db.execSQL(createStatement);

-	}

-

-	public void onUpgrade(SQLiteDatabase db) {

-		db.execSQL(dropTableStatement);

-		onCreate(db);

-	}

-}

 

--- a/src/com/dryerzinia/aprs_x/db/table/WeatherReportTable.java
+++ /dev/null
@@ -1,22 +1,1 @@
-package com.dryerzinia.aprs_x.db.table;

-

-import android.database.sqlite.SQLiteDatabase;

-

-public class WeatherReportTable extends Table {

-

-	public WeatherReportTable(String createStatement, String dropTableStatement) {

-		super(createStatement, dropTableStatement);

-	}

-

-	@Override

-	public void onCreate(SQLiteDatabase db) {

-		super.onCreate(db);

-	}

-

-	@Override

-	public void onUpgrade(SQLiteDatabase db) {

-		super.onUpgrade(db);

-	}

-

-}

 

--- a/src/com/dryerzinia/aprs_x/services/BluetoothLeService.java
+++ b/src/com/dryerzinia/aprs_x/services/BluetoothLeService.java
@@ -26,6 +26,7 @@
 import android.bluetooth.BluetoothGattService;
 import android.bluetooth.BluetoothManager;
 import android.bluetooth.BluetoothProfile;
+import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Binder;
@@ -36,6 +37,10 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
+
+import com.dryerzinia.aprs_x.data_model.packet.RawPacket;
+import com.dryerzinia.aprs_x.db.APRSContentProvider;
+import com.dryerzinia.aprs_x.db.table.RawPacketTable;
 
 /**
  * Service for managing connection and data communication with a GATT server hosted on a
@@ -50,9 +55,10 @@
     private BluetoothGatt mBluetoothGatt;
     private int mConnectionState = STATE_DISCONNECTED;
 
-    private int packetTotalLength = 0;
-    private int packetCurrentLength = 256;
-    private byte[] packetData = new byte[256];
+    private final static int MAX_PACKET_LENGTH = 1000;
+
+    private int packetCurrentLength = 1000;
+    private byte[] packetData;
 
     private static final int STATE_DISCONNECTED = 0;
     private static final int STATE_CONNECTING = 1;
@@ -147,6 +153,7 @@
                                  final BluetoothGattCharacteristic characteristic) {
 
         Log.d(TAG, "Update");
+
         if (UUID_BLE_TNC_PACKET_DATA.equals(characteristic.getUuid())){
 
         	final byte[] data = characteristic.getValue();
@@ -157,31 +164,29 @@
 
         		Log.d(TAG, "Packet Start Length: " + (data[1] & 0xFF));
 
-        		packetTotalLength = data[1] & 0xFF; // Convert to unsigned
-        		packetData[0] = data[1];
+        		packetData = new byte[data[1] & 0xFF];
         		packetCurrentLength = 0;
         		for(int i = 2; i < data.length; i++){
-        			packetData[packetCurrentLength + 1] = data[i];
+        			packetData[packetCurrentLength] = data[i];
         			packetCurrentLength++;
         		}
 
-        	} else if(data[0] == 0x02){
+        	} else if(data[0] == 0x02 && packetData != null){
 
         		Log.d(TAG, "Packet Continued...");
 
-        		if(packetCurrentLength + data.length >= packetData.length){
+        		if(packetCurrentLength + data.length - 1 > packetData.length){
 
         			Log.e(TAG, "Error: Packet to long!");
 
-        			packetTotalLength = 0;
-            		packetCurrentLength = 256;
+            		packetCurrentLength = MAX_PACKET_LENGTH;
 
             		return;
 
         		}
 
         		for(int i = 1; i < data.length; i++){
-        			packetData[packetCurrentLength + 1] = data[i];
+        			packetData[packetCurrentLength] = data[i];
         			packetCurrentLength++;
         		}
 
@@ -195,28 +200,34 @@
 
         	}
 
-        	Log.d(TAG, "ptl: " + packetTotalLength);
         	Log.d(TAG, "pcl: " + packetCurrentLength);
 
-        	if(packetTotalLength == packetCurrentLength){
-
-        		Log.d(TAG, "Broadcasting packet");
-
-        		final Intent intent = new Intent(action);
-        		intent.putExtra(BLE_TNC_PACKET_DATA, packetData);
-                sendBroadcast(intent);
-
-        		packetTotalLength = 0;
-        		packetCurrentLength = 256;
-
-        	} else if(packetTotalLength < packetCurrentLength && packetCurrentLength != 256){
-
-        		Log.e(TAG, "Error: Packet to long!");
-
-        		// Error, don't broadcast
-        		packetTotalLength = 0;
-        		packetCurrentLength = 256;
-
+        	if(packetData != null){
+	        	if(packetData.length == packetCurrentLength){
+	
+	        		Log.d(TAG, "Broadcasting packet");
+	
+	        		// Put packet in DB
+	        		RawPacket pkt = RawPacket.fromRawData(packetData);
+	        		getContentResolver().insert(
+	        			APRSContentProvider.RAW_PACKET_URI,
+	        			RawPacketTable.getContentValues(pkt)
+	        		);
+	
+	        		final Intent intent = new Intent(action);
+	        		intent.putExtra(BLE_TNC_PACKET_DATA, packetData);
+	                sendBroadcast(intent);
+	
+	        		packetCurrentLength = MAX_PACKET_LENGTH;
+	
+	        	} else if(packetData.length < packetCurrentLength && packetCurrentLength != MAX_PACKET_LENGTH){
+	
+	        		Log.e(TAG, "Error: Packet to long!");
+	
+	        		// Error, don't broadcast
+	        		packetCurrentLength = MAX_PACKET_LENGTH;
+	
+	        	}
         	}
 
         }

--- a/src/com/dryerzinia/aprs_x/test/DeviceControlActivity.java
+++ b/src/com/dryerzinia/aprs_x/test/DeviceControlActivity.java
@@ -152,25 +152,20 @@
                     Log.d(TAG, "Displaying Packet");
 
                 	byte[] data = intent.getByteArrayExtra(BluetoothLeService.BLE_TNC_PACKET_DATA);
-	            	byte[] shortData = new byte[data[0] & 0xFF];
 	
-	            	for(int i = 0; i < (data[0] & 0xFF); i++){
-	            		shortData[i] = data[i + 1];
-	            	}
-	
-	                Log.d(TAG, "Len: " + (data[0] & 0xFF));
+	                Log.d(TAG, "Len: " + data.length);
 	
 	                try {
 	                	mLogOutputStream.write(0x00);
-	                	mLogOutputStream.write(data[0]);
-						mLogOutputStream.write(shortData);
+	                	mLogOutputStream.write(data.length);
+						mLogOutputStream.write(data);
 						mLogOutputStream.flush();
 					} catch (IOException e1) {
 					}
 	
 	            	try {
-	                    Log.d(TAG, "Data: " + new String(shortData, "US-ASCII"));
-	            		displayData(new String(shortData, "US-ASCII"));
+	                    Log.d(TAG, "Data: " + new String(data, "US-ASCII"));
+	            		displayData(new String(data, "US-ASCII"));
 					} catch (UnsupportedEncodingException e) {
 					}