5050import android .location .GnssMeasurementsEvent ;
5151
5252import static java .time .Instant .now ;
53+ import static mil .nga .geopackage .db .GeoPackageDataType .INT ;
5354import static mil .nga .geopackage .db .GeoPackageDataType .INTEGER ;
5455import static mil .nga .geopackage .db .GeoPackageDataType .TEXT ;
5556import static mil .nga .geopackage .db .GeoPackageDataType .REAL ;
@@ -147,8 +148,11 @@ public class MainActivity extends AppCompatActivity {
147148 private static final String PtsTableName = "gps_observation_points" ;
148149 private static final String satTblName = "sat_data" ;
149150 private static final String clkTblName = "rcvr_clock" ;
151+ private static final String motionTblName = "motion" ;
150152 private static final String satmapTblName = PtsTableName + "_" + satTblName ;
151153 private static final String clkmapTblName = satTblName + "_" + clkTblName ;
154+ private static final String motionmapTblName = PtsTableName + "_" + motionTblName ;
155+
152156
153157 HashMap <String , SatStatus > SatStatus = new HashMap <>();
154158 HashMap <String , GnssMeasurement > SatInfo = new HashMap <>();
@@ -161,6 +165,7 @@ public class MainActivity extends AppCompatActivity {
161165 UserTable PtsTable = null ;
162166 UserTable SatTable = null ;
163167 UserTable ClkTable = null ;
168+ UserTable MotionTable = null ;
164169
165170
166171 @ RequiresApi (26 )
@@ -426,25 +431,58 @@ public void onLocationChanged(final Location loc) {
426431 frow .setValue ("RadialAccuracy" , (double ) 0.0 );
427432 frow .setValue ("HasRadialAccuracy" , 0 );
428433 }
434+
435+ if (loc .hasSpeed ()) {
436+ frow .setValue ("Speed" , (double ) loc .getAccuracy ());
437+ frow .setValue ("HasSpeed" , 1 );
438+ } else {
439+ frow .setValue ("Speed" , (double ) 0.0 );
440+ frow .setValue ("HasSpeed" , 0 );
441+ }
442+
443+ if (loc .hasBearing ()) {
444+ frow .setValue ("Bearing" , (double ) loc .getAccuracy ());
445+ frow .setValue ("HasBearing" , 1 );
446+ } else {
447+ frow .setValue ("Bearing" , (double ) 0.0 );
448+ frow .setValue ("HasBearing" , 0 );
449+ }
450+
429451 if (Build .VERSION .SDK_INT >= MIN_SDK_GNSS ) {
430452 frow .setValue ("SysTime" , now ().toString ());
453+
431454 if (loc .hasVerticalAccuracy ()) {
432- if (loc .hasVerticalAccuracy ()) {
433455 frow .setValue ("VerticalAccuracy" , (double ) loc .getVerticalAccuracyMeters ());
434- frow .setValue ("HasVerticalAccuracy" , 1 );
435- } else {
436- frow .setValue ("VerticalAccuracy" , (double ) 0.0 );
437- frow .setValue ("HasVerticalAccuracy" , 0 );
438- }
456+ frow .setValue ("HasVerticalAccuracy" , 1 );
439457 } else {
440- Date currentTime = Calendar .getInstance ().getTime ();
441- SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" , Locale .US );
442- frow .setValue ("SysTime" , df .format (currentTime ));
443- frow .setValue ("HasVerticalAccuracy" , 0 );
444458 frow .setValue ("VerticalAccuracy" , (double ) 0.0 );
459+ frow .setValue ("HasVerticalAccuracy" , 0 );
460+ }
461+
462+ if (loc .hasSpeedAccuracy ()) {
463+ frow .setValue ("SpeedAccuracy" , (double ) loc .getAccuracy ());
464+ frow .setValue ("HasSpeedAccuracy" , 1 );
465+ } else {
466+ frow .setValue ("SpeedAccuracy" , (double ) 0.0 );
467+ frow .setValue ("HasSpeedAccuracy" , 0 );
468+ }
469+
470+ if (loc .hasBearingAccuracy ()) {
471+ frow .setValue ("BearingAccuracy" , (double ) loc .getAccuracy ());
472+ frow .setValue ("HasBearingAccuracy" , 1 );
473+ } else {
474+ frow .setValue ("BearingAccuracy" , (double ) 0.0 );
475+ frow .setValue ("HasBearingAccuracy" , 0 );
445476 }
477+ } else {
478+ Date currentTime = Calendar .getInstance ().getTime ();
479+ SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" , Locale .US );
480+ frow .setValue ("SysTime" , df .format (currentTime ));
481+ frow .setValue ("HasVerticalAccuracy" , 0 );
482+ frow .setValue ("VerticalAccuracy" , (double ) 0.0 );
446483 }
447- frow .setValue ("data_dump" , loc .toString ());
484+
485+ frow .setValue ("data_dump" , loc .toString () + " " + loc .describeContents ());
448486
449487 featDao .insert (frow );
450488
@@ -630,6 +668,8 @@ private GeoPackage setupGpkgDB(Context context, String folder, String file) thro
630668 SatTable = createSatelliteTable (contents , RTE , srs , satTblName , satmapTblName , PtsTableName );
631669 ClkTable = createClockTable (contents , RTE , srs , clkTblName , clkmapTblName , satTblName );
632670
671+ MotionTable = createMotionTable (contents , RTE , srs , motionTblName , motionmapTblName , PtsTableName );
672+
633673 return gpkg ;
634674 }
635675
@@ -660,6 +700,19 @@ private UserTable createObservationTable(GeoPackage geoPackage, SpatialReference
660700 tblcols .add (FeatureColumn .createColumn (colNum ++, "HasVerticalAccuracy" , INTEGER , false , null ));
661701 tblcols .add (FeatureColumn .createColumn (colNum ++, "RadialAccuracy" , REAL , false , null ));
662702 tblcols .add (FeatureColumn .createColumn (colNum ++, "VerticalAccuracy" , REAL , false , null ));
703+
704+ tblcols .add (FeatureColumn .createColumn (colNum ++, "ElapsedRealtimeNanos" , REAL , false , null ));
705+
706+ tblcols .add (FeatureColumn .createColumn (colNum ++, "HasSpeed" , INTEGER , false , null ));
707+ tblcols .add (FeatureColumn .createColumn (colNum ++, "HasSpeedAccuracy" , INTEGER , false , null ));
708+ tblcols .add (FeatureColumn .createColumn (colNum ++, "Speed" , REAL , false , null ));
709+ tblcols .add (FeatureColumn .createColumn (colNum ++, "SpeedAccuracy" , REAL , false , null ));
710+
711+ tblcols .add (FeatureColumn .createColumn (colNum ++, "HasBearing" , INTEGER , false , null ));
712+ tblcols .add (FeatureColumn .createColumn (colNum ++, "HasBearingAccuracy" , INTEGER , false , null ));
713+ tblcols .add (FeatureColumn .createColumn (colNum ++, "Bearing" , REAL , false , null ));
714+ tblcols .add (FeatureColumn .createColumn (colNum ++, "BearingAccuracy" , REAL , false , null ));
715+
663716 tblcols .add (FeatureColumn .createColumn (colNum ++, "data_dump" , TEXT , false , null ));
664717
665718 FeatureTable table = new FeatureTable (tableName , tblcols );
@@ -783,6 +836,68 @@ private UserTable createClockTable(Contents contents, RelatedTablesExtension rte
783836 return (table );
784837 }
785838
839+ private UserTable createMotionTable (Contents contents , RelatedTablesExtension rte , SpatialReferenceSystem srs , String tableName , String mapTblName , String baseTblName ) {
840+ contents .setTableName (tableName );
841+ contents .setDataType (ContentsDataType .FEATURES );
842+ contents .setIdentifier (tableName );
843+ contents .setDescription (tableName );
844+ contents .setSrs (srs );
845+
846+ int colNum = 1 ;
847+ List <UserCustomColumn > tblcols = new LinkedList <>();
848+ // tblcols.add(UserCustomColumn.createPrimaryKeyColumn(colNum++, ID_COLUMN));
849+ // Dublin Core metadata descriptor profile
850+ // tblcols.add(UserCustomColumn.createColumn(colNum++, DublinCoreType.DATE.getName(), DATETIME, false, null));
851+ // tblcols.add(FeatureColumn.createColumn(colNum++, DublinCoreType.TITLE.getName(), TEXT, false, null));
852+ // tblcols.add(FeatureColumn.createColumn(colNum++, DublinCoreType.SOURCE.getName(), TEXT, false, null));
853+ // tblcols.add(FeatureColumn.createColumn(colNum++, DublinCoreType.DESCRIPTION.getName(), TEXT, false, null));
854+
855+ // android intertial sensor measurements
856+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "accel_x" , REAL , true , null ));
857+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "accel_y" , REAL , true , null ));
858+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "accel_z" , REAL , true , null ));
859+
860+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "linear_accel_x" , REAL , true , null ));
861+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "linear_accel_y" , REAL , true , null ));
862+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "linear_accel_z" , REAL , true , null ));
863+
864+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "mag_x" , REAL , true , null ));
865+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "mag_y" , REAL , true , null ));
866+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "mag_z" , REAL , true , null ));
867+
868+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gyro_x" , REAL , true , null ));
869+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gyro_y" , REAL , true , null ));
870+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gyro_z" , REAL , true , null ));
871+
872+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gravity_x" , REAL , true , null ));
873+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gravity_y" , REAL , true , null ));
874+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "gravity_z" , REAL , true , null ));
875+
876+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "rot_vec_x" , REAL , true , null ));
877+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "rot_vec_y" , REAL , true , null ));
878+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "rot_vec_z" , REAL , true , null ));
879+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "rot_vec_cos" , REAL , true , null ));
880+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "rot_vec_hdg_acc" , REAL , true , null ));
881+
882+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "baro" , REAL , true , null ));
883+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "humidity" , REAL , true , null ));
884+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "temp" , REAL , true , null ));
885+
886+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "lux" , REAL , true , null ));
887+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "prox" , REAL , true , null ));
888+
889+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "stationary" , INTEGER , true , null ));
890+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "motion" , INTEGER , true , null ));
891+
892+ tblcols .add (UserCustomColumn .createColumn (colNum ++, "data_dump" , TEXT , true , null ));
893+
894+ SimpleAttributesTable table = SimpleAttributesTable .create (tableName , tblcols );
895+
896+ UserMappingTable mapTbl = UserMappingTable .create (mapTblName );
897+ ClkExtRel = rte .addSimpleAttributesRelationship (baseTblName , table , mapTbl );
898+
899+ return (table );
900+ }
786901
787902 @ Override
788903 public boolean onCreateOptionsMenu (Menu menu ) {
0 commit comments