⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsdatalogger.java

📁 gpsLogger是一个基于手机或PDA的个人移动导航(车载导航)系统中记录gps信息的小工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//********************************************************************
//***                    gpsDataLogger 0.12                      ***
//***                      April 14, 2007                          ***
//***                  (c)2007 Glenn Hollowell                     ***
//***                     glenn@blepsias.net                       ***
//***  **********************************************************  ***
//***  Software is provided "AS IS," without a warranty of any     ***
//***  kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,***
//***  INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS  ***
//***  FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY    ***
//***  EXCLUDED. THE ENTIRE RISK ARISING OUT OF USING THE SOFTWARE ***
//***  IS ASSUMED BY THE USER. See the GNU General Public License  ***
//***  for more details.                                           ***
//***  **********************************************************  ***
//***  This program was written to use while conducting aerial     ***
//***  surveys of salmon migration in rivers and near shore areas. ***
//***  A primary objective was to create an application that could ***
//***  be used with minimal visual contact w/the device. This will ***
//***  1) minimize the possibility of air sickness, and 2) maximize***
//***  the amount of time that the observer can spend observing    ***
//***  events outside of the aircraft.                             ***
//***  *********************************************************** ***
//***  The application was written using the SuperWaba toolset     ***
//***  developed by Guilherme Hazan and his fine staff at          ***
//***  Superwaba, Ltd. Superwaba is a proprietary development      ***
//***  environment based in part on the Waba development           ***
//***  environment developed by WabaSoft, Inc.                     ***                         ***
//********************************************************************                              


/*********************************************************************
Todo
-What's up with 5-way center knob, (IKeys.ENTER) it does not send event...
-fix PotHole omission
-fix location field lengths to prevent populating adjacent columns
    +1)Eyak Lake East Beaches (220)...~31chars
    +25)Martin River above Ragged
    +73)Eyak Lake wesr beaches (220)...~32chars
 **/

import litebase.*;
import waba.sys.*;
import waba.ui.*;
import waba.sys.Convert;
import waba.sys.Time;
import waba.sys.Vm;
import waba.ui.ControlEvent;
import waba.ui.Event;
import waba.ui.Label;
import waba.ui.MainWindow;
import waba.ui.MessageBox;
import waba.io.File;
import litebase.LitebaseConnection;
import litebase.ResultSet;


public class gpsDataLogger extends MainWindow{
	String szChangeLog = "19 June 2007-|  +Cleaned up 5-Way species |and location table browse.|  +Added n = zero count option|  ";
	LitebaseConnection driver;
	TabPanel tp;
	public dataCapture dataCapture;	
	public dataEdit dataEdit;
	public dataGps dataGps;
	public Grid grid;
	public locationEdit locationEdit;
	public speciesEdit speciesEdit;
	MessageBox mbExitApplication,mbCreateCsvFile,mbPurgeTrackLog,mbPurgeMainTable,mbMainTableDeleted,mbTrackLogTableDeleted,mbAboutGpsDataLogger,mbChangeLog;
	private MenuBar mbar; 
	static String szPlatform = Settings.platform;//gets host device information
	//returned strings are "Java", "PalmOS", "Win32", "WindowsCE",or "PocketPC"
	static String szWidth = Convert.toString(Settings.screenWidth,1);
	static String szHeight = Convert.toString(Settings.screenHeight,1);
	static String []szLocationLookup = {""};
	static String []szSpeciesLookup = {""};
	static String szValid = "";
	
	static String szLat, szLatNs, szLong, szLongEw, szTime;
	
	static int iPortNumber = 8;
	static int iFirstLocationIteration = 0;
	static int iFirstSpeciesIteration = 0;
	static int iEmptyLocationLookupTable = 0;
	static int iEmptySpeciesLookupTable = 0;
	static int iTrackLogInterval = 5000;
	static int iTrackLogFlag = 0;
	
	
	public gpsDataLogger(){
		super("gpsDataLogger 0.12b",TAB_ONLY_BORDER);
		if (!Settings.onDevice)
			waba.applet.JavaBridge.showMsgs = false;
		setDoubleBuffer(true);
		Settings.setUIStyle(Settings.Flat);
		driver = LitebaseConnection.getInstance("AZoe");
		String []szLocationLookup;//maybe delete??
		String []szSpeciesLookup;//maybe delete??
		InterceptSystemKeys();		
	}
	public void onStart(){
		if (!verifyDrivers()) 
			return;
		CreateMainTable();
		CreateTrackLogTable();
		CreateLocationLookupTable();
		CreateSpeciesLookupTable();
		//gps variables to move between containers
		szLat = szLatNs = szLong = szLongEw = szTime = "";
		//menubar titles and dropdown fields
		String col0[] = {"File","Edit Location Table","Edit Species Table","Purge Main Table","Purge TrackLog Table","Make *.csv files","Exit application"};//first dropdown title and item.
		String col1[] = {"Settings","Restart Bluetooth","Start/Stop TrackLog"};//second dropdown title and items.		
		String col2[] = {"Info","About gpsDataLogger 0.12","About SuperWaba VM","DeviceOS, screensize","General Instructions"};//third dropdown title and item.
		//Instantiate menubar
		setMenuBar(mbar = new MenuBar(new String[][]{col0,col1,col2}));
		//Strings for tab labels, then create tab panels
		String []tpCaptions = {"Data Capture","Data Edit","Table","GPS"};
		add(tp = new TabPanel(tpCaptions));
		tp.setBorderStyle(Window.NO_BORDER);
		tp.setRect(getClientRect()); 
		//Grid column headers... Note: Grid setup must be first otherwise grid overlays tp #0. Bug??
		String []gridCaptions = {"rowid","Timestamp","Species","Count","Location","Terrain","Latitude","N/S","Longitude","E/W","Sky","Water","Overall","Live"};
		//Instantiate tab panels
		tp.setPanel(2,grid = new Grid(gridCaptions,false));		
		tp.setPanel(0,dataCapture = new dataCapture());
		tp.setPanel(1,dataEdit = new dataEdit());
		tp.setPanel(3,dataGps = new dataGps());	
		
		//creates string array from lookup tables, then loads into comboboxes
		LoadSpeciesComboBoxStringArray();
		LoadLocationComboBoxStringArray();
		invalidateRS(); //loads updated grid on grid tab
		/*
		 * locationEdit = locationEdit.instance was up in Public gpsDataLogger, 
		 * but this requires a lookup table. Would get an exception thrown
		 * if there had not been a lookup table created yet. Check this out
		 * and delete if not so...
		 */ 		
		locationEdit = locationEdit.instance;	
		speciesEdit = speciesEdit.instance;
		//below loads ComboBox correctly when CB is in 0 tab place
		dataCapture.updateSpeciesComboBox();
		dataCapture.updateLocationComboBox();		
		dataCapture.cbLocation.repaintNow();
		dataCapture.cbSpecies.repaintNow();	
		dataCapture.ShowSum();
	}
	public void invalidateRS(){ //refreshes grid to match main data table		
		ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live,lastUpdated from surveyDB");
		//rs.setDecimalPlaces(5,2); //investigate this...
		if (rs.first()) // checks to see if rs is new, (empty)
			grid.setItems(rs.getStrings(-1,true,false));
		else 
			grid.clear();
		rs.close();
	}
	////////////////////////////Start Main Table methods//////////////////////////////
	private void CreateMainTable(){//main data table
		try{
			driver.execute("create table surveyDB(time_stamp char(16), species char(30), surveycount int, location char(50), terrain char(30), latitude char(16), latns char(2), longitude char(16), longew char (2), sky char(2), water char(2), overall char(2), live char(12), lastUpdated long)");
		}		
		catch (AlreadyCreatedException ace) {} 
		catch (DriverException pe){
			Vm.debug(pe.getMessage()); 
		}
	}
	private void CreateMainTableIndexes(){
		driver.execute("CREATE INDEX IDX_0 ON surveyDB(rowid)"); // the index names are completely ignored
		driver.execute("CREATE INDEX IDX_1 ON surveyDB(time_stamp)");	
		//new MessageBox("Attention","Main Table Indexes May have been created").popupModal();
	}
	private void PurgeMainTable(){     	  
		driver.executeUpdate("drop table surveyDB");	
		grid.clear();
	}
///////////////End Main Table methods, Start trackLog table methods/////////////////////
	
	private void CreateTrackLogTable(){//table to store Track Log table, (i.e., snail tracks, bread crumbs, etc...
		try{
			driver.execute("create table trackLog(time_stamp char(16), latitude char(16), latns char(2), longitude char(16), longew char (2))");
		}		
		catch (AlreadyCreatedException ace) {} 
		catch (DriverException pe){
			Vm.debug(pe.getMessage()); 
		}
	}
	private void PurgeTrackLogTable(){     	  
		driver.executeUpdate("drop table trackLog");	
	}
///////////////End trackLog Table methods, Start Location Lookup table methods/////////////////////
	
	private void CreateLocationLookupTable(){ //reference table that comboboxes are populated from.
		try{
			driver.execute("create table locationLookupDB(location char(50), lastUpdated long)");
			driver.execute("CREATE INDEX IDX_0 ON locationLookupDB(rowid)"); // the index names are completely ignored
			driver.execute("CREATE INDEX IDX_1 ON locationLookupDB(location)");
		}
		catch (AlreadyCreatedException ace) {} 
		catch (DriverException pe){
			Vm.debug(pe.getMessage()); 
		}
	} 
	private void CreateLocationLookupTableIndexes(){
		driver.execute("CREATE INDEX IDX_0 ON locationLookupDB(rowid)"); // the index names are completely ignored
		driver.execute("CREATE INDEX IDX_1 ON locationLookupDB(location)");	
		new MessageBox("Attention","Location Lookup Table Indexes May have been created").popupModal();
	}
///////////////End Location Lookup Table methods...Start Species Lookup table methods//////////////////
/////////////// Start Species Lookup table methods/////////////////////
	private void CreateSpeciesLookupTable(){ //reference table that comboboxes are populated from.
		try{
			driver.execute("create table speciesLookupDB(species char(50), lastUpdated long)");
			driver.execute("CREATE INDEX IDX_0 ON speciesLookupDB(rowid)"); // the index names are completely ignored
			driver.execute("CREATE INDEX IDX_1 ON speciesLookupDB(species)");
		}
		catch (AlreadyCreatedException ace) {} 
		catch (DriverException pe){
			Vm.debug(pe.getMessage()); 
		}
	} 
	/*
	 * Delete this if not needed, other wise fix it.
	 */
	private void CreateSpeciesLookupTableIndexes(){
		driver.execute("CREATE INDEX IDX_0 ON speciesLookupDB(rowid)"); // the index names are completely ignored
		driver.execute("CREATE INDEX IDX_1 ON speciesLookupDB(species)");	
		new MessageBox("Attention","Species Lookup Table Indexes May have been created").popupModal();
	}
///////////////////////////End Species Lookup Table methods//////////////////////////////
	
	public boolean LoadLocationComboBoxStringArray(){ //sets initial string length 
		ResultSet rs = driver.executeQuery("select rowid,location from locationLookupDB");
		rs.first();
		if (!rs.first()){//checks to see if the lookup table is empty, if so
			repaintNow();   //a messagebox is posted to the user
			//new MessageBox("Attention","LocationLookup Table is empty, | please enter a field.").popupModal();
			iEmptyLocationLookupTable = 1; //sets flag to be read by datacapture.updateLocationComboBox().			
			return(true);// Read comments there for explanation.
		}	
		else{//iterates through lookup table and loads string array that populates cbLocation 
			szLocationLookup[0] = rs.getString("location");
			int i = 1;
			while (rs.next()){
				//make string array dynamic
				if (i >= szLocationLookup.length) {
					String[] tmp = new String[szLocationLookup.length + 1];
					Vm.copyArray(szLocationLookup, 0, tmp, 0, szLocationLookup.length);
					szLocationLookup = tmp;
				} 	  			 
				szLocationLookup[i] = rs.getString("location");			    			 
				++i;			    			 
			}
		}
		return true;
	}   	
	public boolean LoadSpeciesComboBoxStringArray(){ //sets initial string length 
		ResultSet rs = driver.executeQuery("select rowid,species from speciesLookupDB");
		rs.first();
		if (!rs.first()){//checks to see if the lookup table is empty, if so
			repaintNow();   //a messagebox is posted to the user
			//new MessageBox("Attention","SpeciesLookup Table is empty, | please enter a field.").popupModal();
			iEmptySpeciesLookupTable = 1; //sets flag to be read by datacapture.updateSpeciesComboBox().			
			return(true);// Read comments there for explanation.
		}	
		else{//sets string that populates cbSpecies to rs from lookuptable
			szSpeciesLookup[0] = rs.getString("species");
			int i = 1;
			while (rs.next()){
				//make string array dynamic
				if (i >= szSpeciesLookup.length) {
					String[] tmp = new String[szSpeciesLookup.length + 1];
					Vm.copyArray(szSpeciesLookup, 0, tmp, 0, szSpeciesLookup.length);
					szSpeciesLookup = tmp;
				} 	  			 
				szSpeciesLookup[i] = rs.getString("species");			    			 
				++i;			    			 
			}
		}
		return true;
	}  
	private boolean verifyDrivers(){
		try{
			Class.forName("litebase.LitebaseConnection");
		}
		catch (ClassNotFoundException cnfe){
			add(new Label("Please install file|litebase.LitebaseConnection"),CENTER,TOP);
			return false;
		}
		return true;
	}
	/*********************************************************************************
	 * 		     Does carriage return for CSV file creation
	 **********************************************************************************/
	private static byte []enter = {(byte)'\r',(byte)'\n'};	
	/*********************************************************************************
	 *           Makes .csv file on the device of the surveyDB data table
	 **********************************************************************************/	
	protected void makeCsvFileSurveyDB(){ 
		int iFlag = 0;//sets up header row on first iteration through while loop
		
		String sb = "Time_stamp,Species,Count,Location,Terrain,Latitude,N-S,Longitude,E-W,Sky,Water,Overall,Live,RowId";
		
		String szDateTime;		//creates timestamp for the filename
		long T = new Time().getTimeLong();
		szDateTime = Convert.toString(T,1);		  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -