GPS北鬥雙模技術應用開發研究—應用資料互動

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   ar   color   sp   for   

 

GPS北鬥雙模技術應用開發研究—應用資料互動

 

        Android開發原則就是誰對哪個資料感興趣就可以通過listener去監聽一下,那邊定位元據肯定也是這樣的,關於位置上報的話,筆者不準備在這累贅了,網上好多文章,下面就講一下雙模相關的北鬥gps衛星星圖搜星具體情況的資料上報以及私人協議的定製。

       在locationmanager裡面有一個介面addGpsStatusListener,在應用裡通過這個介面把listen傳下去,這中間有很多過程,最終這個listener在location的provider裡面存了起來,中間被service轉了一手,但是service裡面是直接用的provider的addGpsStatusListener。下面可以看看service裡面的addGpsStatusListener介面情況,如下:

    public boolean addGpsStatusListener(IGpsStatusListener listener, String packageName) {        if (mGpsStatusProvider == null) {            return false;        }        int allowedResolutionLevel = getCallerAllowedResolutionLevel();        checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel,                LocationManager.GPS_PROVIDER);        final int uid = Binder.getCallingUid();        final long ident = Binder.clearCallingIdentity();        try {            if (!checkLocationAccess(uid, packageName, allowedResolutionLevel)) {                return false;            }        } finally {            Binder.restoreCallingIdentity(ident);        }        try {            mGpsStatusProvider.addGpsStatusListener(listener);        } catch (RemoteException e) {            Slog.e(TAG, "mGpsStatusProvider.addGpsStatusListener failed", e);            return false;        }        return true;    }

      這裡就註冊下去了。這樣就相當於在provider裡面就掛了個鉤子了,一旦有新資料更新就可以直接傳到應用裡面了,當然這個listener中間轉的那幾手有興趣的可以去看看代碼,都不難看懂的。那看看衛星sv狀態上報吧,直接觸發了listener的onSvStatusChanged介面,如下:

    private void reportSvStatus() {        int svCount = native_read_sv_status(mSvs, mSnrs, mSvElevations, mSvAzimuths, mSvMasks);        synchronized (mListeners) {            int size = mListeners.size();            for (int i = 0; i < size; i++) {                Listener listener = mListeners.get(i);                try {                    listener.mListener.onSvStatusChanged(svCount, mSvs, mSnrs,                            mSvElevations, mSvAzimuths, mSvMasks[EPHEMERIS_MASK],                            mSvMasks[ALMANAC_MASK], mSvMasks[USED_FOR_FIX_MASK],                            mSvMasks[BD_SVS_NUM], mSvMasks[BD_EPHEMERIS_MASK],                            mSvMasks[BD_ALMANAC_MASK],mSvMasks[BD_USED_FOR_FIX_MASK]);                } catch (RemoteException e) {                    Log.w(TAG, "RemoteException in reportSvInfo");                    mListeners.remove(listener);                    // adjust for size of list changing                    size--;                }            }        }

   這樣就call到了GpsStatusListenerTransport裡面的onSvStatusChanged了,在這裡面要下點文章,它會發送一個GpsStatus.GPS_EVENT_SATELLITE_STATUS的訊息,但是沒有帶參數,筆者就把兩個參數利用起來了,一個存gps的數量,一個存北鬥的數量。這個訊息發送出去以後,會在他的handle裡面處理轉換一次。

        private final Handler mGpsHandler = new Handler() {            @Override            public void handleMessage(Message msg) {                if (msg.what == NMEA_RECEIVED) {                    synchronized (mNmeaBuffer) {                        int length = mNmeaBuffer.size();                        for (int i = 0; i < length; i++) {                            Nmea nmea = mNmeaBuffer.get(i);                            mNmeaListener.onNmeaReceived(nmea.mTimestamp, nmea.mNmea);                        }                        mNmeaBuffer.clear();                    }                } else {                    // synchronize on mGpsStatus to ensure the data is copied atomically.                    synchronized(mGpsStatus) {                    if(GpsStatus.GPS_EVENT_SATELLITE_STATUS == msg.what){int pri_event ;pri_event = 0x77 + (msg.arg1<<8) + (msg.arg2<<16);//Log.d(TAG, "LM: msg.arg1 "+msg.arg1 +" msg.arg2 "+msg.arg2+ " pri "+pri_event);                        mListener.onGpsStatusChanged(pri_event);                    }                        mListener.onGpsStatusChanged(msg.what);                    }                }            }
     因此,在轉寄訊息的時候做一下特殊處理,合成一個特殊的訊息,帶上我們的gps數量北鬥數量,其他沒有什麼特別的了,第三方應用同樣也可以收到sv的變化,只是不知道gps跟北鬥具體的數量。其他沒有差異。

   

 

 

GPS北鬥雙模技術應用開發研究—應用資料互動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.