【正文】
amp。 if(AxWzhGpsWidth amp。 //====以左上點為標準,計算并裝載的各區(qū)域 (amp。 (%s/_%,mapPath,idC)。 //裝載備用圖片,如果已經(jīng)存在就不要裝了 40 (%s/_%,mapPath,idA)。 idC=idj*WidthNumber+idi。 idj=By/subWidth。 idi=Ax/subWidth+1。 Cy=Ay+zhGpsHeight。 Ay=ycenter(zhGpsHeight)/2。 return 1。 return 1。//用于處理 A 點的圖塊,表明取了多少走 39 QString fileStr。 int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy。 =B_lont。 A_gpsdata,GPS_DATA amp。///圖像垂直分割的個數(shù) pixPerLont=((double)Width)/(B_lontA_lont)。 mapPath=()。 pixPerLati=((double)Height)/(A_latiB_lati)。 readMapCfg(QStrmappath)。//像素的 Height=978。//左上點經(jīng)度 小數(shù)度數(shù)制 A_lati=。 CMD_Analysis(msg)。 if ((infile = fopen(OfilePtr, rb)) == NULL) { PDF(1,can39。//./。//只對此語句解析 if (pcmd!=NULL) {} return 0。 PDF(2,Width=%d,Height=%d,subWidth=%d\n,Width,Height,subWidth)。 //請檢查 sscanf 的返回值,可能會失敗,如果小于要收得的數(shù)目。 B_lati, amp。//只對此語句解析 if (pcmd!=NULL) { i= sscanf(pcmd,%[^:]:%lf,%lf,%lf,%lf,%d,%d,%d, msgid, amp。 int i。}// 解析完所有的語句。WfifoFixString(c)。 if ( readbytes 0 ) { PDF(2,tty readbytes1=%d\n,readbytes)。 36 if(eventtimerId()==id) { PDF(3,zh_gpsDriver timer is alarm!\n)。 } fifoctl(amp。fifo,39。 if(data!=39。attr))!=0) {printf(active set attr error!\n)。 if(i!=0) {printf(error for get attr!\n)。 } } else if(==9600) { i=cfsetispeed(amp。 i=cfsetospeed(amp。 if(i!=0) {printf(error for get attr!\n)。return 1。 // 打開串口 if(fd==1) { //close(fd)。 GPSStaSNR) { GPSStaSNR=mGPSStaSNR。 =mpGPS_GPRMClongitude 。 pcmd_bufsw=0。 } out:CMDBUF_Init(amp。 //請檢查 sscanf 的返回值,可能會失敗,如果小于要收得的數(shù)目。mpGPS_GPGSV,amp。mpGPS_GPGSV,amp。mpGPS_GPGSV,amp。mpGPS_GPGSV,amp。 i= sscanf(pcmd,%[^,],%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s, mpGPS_GPGSVGPGSV, amp。 /*CMDBUF_Init(amp。 } ///======================= pcmd=strstr(amp。 mpGPS_GPRMClongitude=ddmm2dddd((mpGPS_GPRMClongitude/100))。buf)。 if(i13) //轉(zhuǎn)換失敗, { PDF(2,sscanf error\n)。mpGPS_GPRMCangle,mpGPS_GPRMCutc_date,amp。mpGPS_GPRMClati_ns, amp。 // printf(Gpsid=%s\n utc_time=%s\n gps_sw=%c\n latitude=%lf\n lati_ns=%c\n longitude=%lf\n longi_ew=%c\n spd=%lf, //Gpsid,utc_time,gps_sw,latitude, lati_ns,longitude,longi_ew,spd)。 CMDBUF_Init(amp。 PDF(3,gpsSwFiled=%c\n,mpGPS_GPRMCgps_sw)。 return 1。//只對此語句解析 if (pcmd!=NULL) { if (!nmea_checksum(amp。 int i。(pGPS_GPGSVSta4),sizeof(STA_INFO))。([10]),amp。 memcpy(amp。 break。(pGPS_GPGSVSta3),sizeof(STA_INFO))。([5]),amp。 case 2:memcpy(amp。 memcpy(amp。(pGPS_GPGSVSta2),sizeof(STA_INFO))。([0]),amp。//取小數(shù)部分 fi=ffz+ffx/。 fi=ddmm。 =mpGPS_GPRMClongitude 。 return 1。} PDF(2,pos=%d\n,pcmd_bufpos)。} } while(j++BUFSIZE)。pcmd_bufsw=1。\n39。 do { idata=fifoctl(amp。 /* Open modem device for reading and writing and not as controlling * tty. | O_NONBLOCK*/ fd=1。V39。 =0。 =/dev/ttyUSB0。 return temp。return 1。 privw_idx = (privw_idx + 1) % BUFSIZE。 //保證是環(huán)狀的 FIFO。 unsigned int widx = 0。amp。A39。039。0x0f。) { sum ^= c。 char c, *p = sentence,csum[2]。 } Gps_driver 類程序: include include include sys/ include sys/ include include /*NMEA 0183 的 Checksum 只能作 8位異或包括 ,的運算,但不包括 $ 及 * 定義符號的運算。 (amp。 28 GpGPSmpGPSinfoSetData(mGPSData)。 int i。 addTab(GpGPS,QString(GPS INFO))。 GpConfigGetObject(GpGPS)。 附錄: 附錄 1:測試儀器 表 7 測試儀器設(shè)備清單 序號 型號、名稱 用途 數(shù)量 1 PC機 編譯程序 1 2 UT33D 數(shù)字萬用表 測量各電路工作情況 1 3 Gps 導航儀 測試顯示的 gps正誤 1 4 vm 虛擬機 測試操作系統(tǒng) 1 5 成都、南充市區(qū)地圖 測試顯示地圖正誤 2 6 精密電流、電壓表 測試系統(tǒng)功耗 2 附錄 2:部分參考源程序 Maintab 類程序: include include include include include include include include include include include include include include include include include 27 include include include include include //============ include include include include include MainTab::MainTab(QWidget *parent,const char * name):QTabWidget(parent,name) { GpMainLayout=new MainLayout。回想過去的點點滴滴,如果沒有學校、學院、老師、同學的關(guān)心和幫助,我也無法按期完成這令我滿意的作品。已具有一定的實用價值。 5 總結(jié) 25 本系統(tǒng)成功的模擬了個人手持 gps 導航系 統(tǒng)。 其他測試 1)地圖路徑變更測試 。 地圖顯示測試 地圖顯示測試的目的是測試載入地圖的正誤、驗證地圖上下左右移動的功能。 圖 操作系統(tǒng)啟動畫面 Figure operating system to start screen 系統(tǒng)燒寫成功 衛(wèi)星接收測試 衛(wèi)星接收測試的目的是檢測接收到衛(wèi)星的數(shù)量,以便在接收到相同衛(wèi)星的情況下,檢測 gps 信號。 地圖軟件獲取方法:采用專業(yè)地圖下載軟件 UMD( universal maps download),用戶只需在此軟件里輸入想要地圖的四角經(jīng)緯度坐標。 文件里包含了整張地圖信 18 息。 17 定義如下: include include ifndef DEBUG_PDF_H define DEBUG_PDF_H //===============debug level for info trace bug define debug 1 define POP3DEBUG 1 ifdef POP3DEBUG define PDF(level, fmt, args...) \ if (debug = level) printf([%s:%d] fmt, __PRETTY_FUNCTION__, __LINE__ , args) else define PDF(level, fmt, args...) do {} while(0) endif 0:沒有任何的顯示! 1:正常工作的,能顯示工作運行主流程 error exit fatal show it 2:更進一顯示信息 3:完全跟蹤! Makefile 文件 Makefile 文件為整個工程的管理文件 ,作用是連接各個頭文件、 c 文件,最終編譯成可執(zhí)行文件。 開始 設(shè)置串口屬性,訪問 gps模塊 設(shè)置 gps時鐘 驅(qū)動 gps模塊 16 計算經(jīng)緯度坐標值 結(jié)束 圖 gps_driver類流程圖 gps_driver class Flowchart staSNR 類 StaSnR 類負責對檢測衛(wèi)星數(shù)量,并告知 gps_driver 類。民用 GPS 信號調(diào)試成 C/A 碼 發(fā)送,C/A 碼又被稱為粗捕獲碼 , 是 1MHz 的偽隨機噪聲碼( PRN 碼),其碼長為 1023 位(周期為 1ms)。然后系統(tǒng)通過得知整張地圖四角的坐標,計算出地圖每個像素點所對應的坐標。 g p s d a t a , Q P ix m a p amp。 G P S _D A T A G P S D a t a )顯示 G P S 信息:時間,經(jīng)緯度,日期M A P _V I E W+S e t P os it ion ( amp。 C O M P a ra m )獲取 G P S 數(shù)據(jù)G P SP a r s e r+G e t D a t a ( amp。程序定義了許多類來分別管理各個模塊,通過對各個類的操作,來構(gòu)建整個程序框架。該芯片掉電不丟失數(shù)據(jù)、壽命長,可反復擦寫。 Mini2440 硬件特性如下圖: 6 圖 2 主控芯片電路 Masterchip circuitry 主控芯片電路 主控芯片為 s3c2440 的 6層核心板,該核心板性能穩(wěn)定、工藝精良。但能存放大量數(shù)據(jù)(1G~8G),地圖更新升級也很方便。 Nand flash 讀取速度快。