GPS/GNSS测试工具
先說一下GPS和GNSS的區(qū)別, 很多人把GPS等同于GNSS,我們在生活和工作中也常以GPS的概念描述GNSS。其實不然。
GNSS全球導航衛(wèi)星系統(tǒng)(Global Navigation Satellite System)。泛指所有的衛(wèi)星導航系統(tǒng),包括全球的、區(qū)域的和增強的導航系統(tǒng),如美國的GPS、俄羅斯的Glonass、歐洲的Galileo、中國的北斗衛(wèi)星導航系統(tǒng),以及相關的增強系統(tǒng),如美國的WAAS(廣域增強系統(tǒng))、歐洲的EGNOS(歐洲靜地導航重疊系統(tǒng))和日本的MSAS(多功能運輸衛(wèi)星增強系統(tǒng))等,還涵蓋在建和以后要建設的其他衛(wèi)星導航系統(tǒng)。國際GNSS系統(tǒng)是個多系統(tǒng)、多層面、多模式的復雜組合系統(tǒng)。
用簡潔的公式表述就是:
GNSS = 衛(wèi)星導航系統(tǒng)(GPS+Glonass+Galileo+Beidou等)+ 區(qū)域增強/擴增系統(tǒng)(WAAS+EGNOS+MSAS+QZSS+SBAS等)+ ...
最近猶豫工作需要,需要寫一個測試GNSS搜星能力的工具。
1. Qcom平臺默認提供“garden_app”命令可測試GNSS。該命令需要root權限才可運行。
2. server call 調用LocationManager相關接口進行搜星,同時打開相關log,查看log中搜星信息。該方法遇到傳參問題。
3. 寫一個GNSS測試apk,可界面顯示搜星信息,也可將搜星信息寫進文件,供其它工具讀取。
調用的關鍵類及方法:
LocationManager.requestLocationUpdates()? //調用該接口發(fā)起搜星,需要定義接口所需參數(shù),如LocationListener
GpsStatus, GpsStatus.Listener //通過該類獲取衛(wèi)星信息
GPS (1-32) / SBAS (33-54) / GLONASS (65-96) / QZSS (193-200) / BEIDOU (201-235) / GALILEO (301-) //android中定義的各個GNSS系統(tǒng)中衛(wèi)星prn所屬閾值。
代碼如下:
package com.example.gpstest;import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator;import android.app.Activity; import android.location.GpsSatellite; import android.location.GpsStatus; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.util.Log; import android.widget.TextView;public class MainActivity<GpsStatellite, StingBuilder> extends Activity {protected static final String TAG = "GNSSTEST";private String GNSS_RESULT_FILE; private static final long MIN_TIME_INTERVAL = 1 * 1000;private static final float MIN_DISTANCE_INTERVAL = 10;LocationManager mLocationManager = null;LocationListener mLocationListener = null;GpsStatus.Listener mListener= null;TextView gnss_result = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// /data/user/0/com.example.gpstest/files/gnss_result.txt, need root to cat// GNSS_RESULT_FILE= this.getFilesDir().getPath() + "/gnss_result.txt";GNSS_RESULT_FILE= "/sdcard/gnss_result.txt";mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);mLocationListener = new LocationListener() {@Overridepublic void onStatusChanged(String arg0, int arg1, Bundle arg2) {// TODO Auto-generated method stub}@Overridepublic void onProviderEnabled(String arg0) {// TODO Auto-generated method stub}@Overridepublic void onProviderDisabled(String arg0) {// TODO Auto-generated method stub}@Overridepublic void onLocationChanged(Location arg0) {// TODO Auto-generated method stub}};mListener = new GpsStatus.Listener() {@Overridepublic void onGpsStatusChanged(int event) {// TODO Auto-generated method stubswitch (event) {case GpsStatus.GPS_EVENT_SATELLITE_STATUS:// get current statusGpsStatus gpsStatus = mLocationManager.getGpsStatus(null);// get MAX default number of statesint maxStatellites = gpsStatus.getMaxSatellites();// get all statesIterator<GpsSatellite> iters = gpsStatus.getSatellites().iterator();// calculate number of statesint stateNumber = 0;String type = "UNKNOWN";StringBuilder mStringBuilder = new StringBuilder();while (iters.hasNext() && stateNumber <= maxStatellites) {stateNumber++;GpsSatellite nextStatellite = iters.next();//get signal to noise ratiofloat snr = ((GpsSatellite) nextStatellite).getSnr();int prn = nextStatellite.getPrn();// check the type of statellite, GPS/GLONASS/BEIDOU or SBAS/QZSS// GPS (1-32) / SBAS (33-54) / GLONASS (65-96) / QZSS (193-200) / BEIDOU (201-235) / GALILEO (301-)if (1 <= prn && prn <= 32){type = "GPS";} else if (64 < prn && prn <=96) {type = "GLONASS";} else if (200 < prn && prn <= 235) {type = "BEIDOU";} else if (33 <= prn && prn <= 54) {type = "SBAS";} else if (193 <= prn && prn <= 200) {type = "QZSS";} else if (301 <= prn) {type = "GALILEO";}mStringBuilder.append("NO.").append(stateNumber).append("\t").append("snr: ").append(snr).append("\t").append("prn: ").append(prn).append("\t").append("type: ").append(type).append("\n");}gnss_result = (TextView) findViewById(R.id.text_view);gnss_result.setMovementMethod(ScrollingMovementMethod.getInstance());gnss_result.setText("total search statellite's number: "+ stateNumber + "\n" + mStringBuilder.toString());try {File file = new File(GNSS_RESULT_FILE);// if file doesn't exists, then create itif (!file.exists()) {file.createNewFile();}FileWriter fw = new FileWriter(file.getAbsoluteFile());BufferedWriter bw = new BufferedWriter(fw);bw.write("total search statellite's number: "+ stateNumber + "\n" + mStringBuilder.toString());bw.close();} catch (IOException e) {// TODO Auto-generated catch blockLog.e(TAG, "IOException in writing gnss informance to file");e.printStackTrace();}break;default:break;}}};mLocationManager.addGpsStatusListener(mListener);mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_INTERVAL, MIN_DISTANCE_INTERVAL, mLocationListener);} }?
總結
以上是生活随笔為你收集整理的GPS/GNSS测试工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机以一级上级模拟试题,全国计算机等级
- 下一篇: 迅捷CAD编辑器如何修改快捷键