2019年5月25日 星期六

2019年5月23日 星期四

NMEA標準格式

Source http://annheilong.pixnet.net/blog/post/24919514-%E3%80%90%E9%9B%BB%E8%85%A6%E3%80%91nmea%E6%A8%99%E6%BA%96%E6%A0%BC%E5%BC%8F

大部份的GPS receiver都具被有美國國家海洋電子學會(National Marine Electronics Association,NMEA)所制定的標準規格,其制定了所有航海電子儀器間的通訊標準,包括了資料的格式及傳輸資料的通訊協定。

NMEA規格有0180、0182、0183等三種,NMEA-0183是架構在0180及0182的基礎上,增加了GPS receiver輸出的內容而完成的。在電子傳輸的實體界面上,NMEA-0183包括了NMEA-0180及NMEA-0182所定的RS232界面格式,而且又多增加了EIA-422的工業標準界面,在傳輸的資料內容方面,也比NMEA-0180及NMEA-0182來得多。目前廣泛使用的NMEA-0183的版本為Ver. 2.01。

NMEA格式所傳輸的資料為美國國家標準資訊交換碼(American Standard Code for Information Interchange,ASCII),以「句子(Sentence)」的方式傳輸資料,每一個句子以「$」為起始位置,而以16進位控制碼「13」、「10」為終止,及ASCII中的Carriage Return{CR}和Line Feed{LF}碼。

每一個句子的長度不一定,最長可達82個字元(Character),而句中的欄位(Field)以逗號「,」分格。第二、三個字元為傳輸設備的識別碼,如「GP」為GPS的接收儀;「LC」為Loran-C接收儀;「OM」為Omega Navigation接收儀。第四五六個字元為傳輸句子的名稱,如「RMC」為GPS建議的最小傳輸資料(Recommended Minimum Specific GPS/TRANSIT Data);「GGA」為GPS固定資料(Global Positioning System Fix Data)。

當衛星接收機定位後,便經由輸出管道開始傳送有效的定位資料。
◎ 這些資料包含如下:

1) 經度
2) 緯度
3) 定位完成代號
4) 採用有效的衛星顆數
5) 所用的衛星編號,及仰角,方向角,接收訊號強度。
6) 衛星方位角
7) 高度
8) 相對位移位移速度
9) 相對位移位移方向角度
10) 日期
11) UTC時間
12) DOP誤差參考值
13) 衛星狀態及接收狀態
NMEA-0183 輸出資訊表
NMEA 種類 說明
GGA 衛星定位資訊。
GLL 基本地理位置-經度及緯度
GSA GNSS DOP(誤差資訊)
GSV GNSS 天空範圍內的衛星
RMC 基本定位資訊(指已達到定位目的時)
VTG 相對位移方向及相對位移速度


GPS常用的NMEA數據資料格式介紹如下:

「GGA」=>GPS固定資料$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh範例說明:
$GPGGA,055148,2407.8945,N,12041.7649,E,1,00,1.0,155.2,M,16.6,M,X.X,xxxx,*47

$GPGGA = Global Positioning System Fix Data 
1 055148 = UTC of Position [接收的時間(世界標準時),格式:時分秒] 
2 2407.8945 = Latitude [緯度,格式:度分.分], 
3 N = N or S[N指北半球(S指南半球)], 
4 12041.7649 = Longitude [經度,格式:度分.分] 
5 E = E or W [E指東半球(W指西半球)] 
6 1 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix) [GPS等級,0:表示資料可用;1:非DGPS定位資料;2:DGPS定位資料], 
7 00 = Number of satellites in use [not those in view] [所使用之衛星數], 
8 1.0 = Horizontal dilution of position [平面精度指標(HDOP)], 
9 155.2 = Antenna altitude above/below mean sea level (geoid) [天線高度(平均海水面)], 
10 M = Meters (Antenna height unit) [單位(公尺)], 
11 16.6 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. -=geoid is below WGS-84 ellipsoid) [大地起伏值], 
12 M = Meters (Units of geoidal separation) [單位(公尺)], 
13 X.X = Age in seconds since last update from diff. reference station [差分GPS數據期], 
14 xxxx = Diff. reference station ID# [基站站號0000-1023], 
15 *47 = Checksum (檢查位元)
「RMC」=>GPS建議最小傳輸資料$--RMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,xxxxxx,x.x,a*hh
($GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>)
範例說明:
$GPRMC,055148,A,2407.8945,N,12041.7649,E,000.0,000.0,061196,003.1,W*69
1) $GPRMC,055148 接收定位時間(UTC time)格式:時時分分秒秒.秒秒秒(hhmmss.sss)。
2) A = 定位狀態,A:資料可用,V:資料不可用。
3) 2407.8945 = 緯度,格式:度度分分.分分分分(ddmm.mmmm)。
4) N = 緯度區分,北半球(N)或南半球(S)。
5) 12041.7649 = 經度,格式:度度分分.分分分分。
6) E = 經度區分,東(E)半球或西(W)半球。
7) 000.0 = 相對航行速度, 0.0 至 1851.8 knots(節)
8) 000.0 = 相對航行方向,000.0 至 359.9度。實際值。
9) 061196 = 日期,格式:日日月月年年(ddmmyy)。
10) 003.1 = 磁極變量,000.0 至180.0度。
11) W = 磁方位角(西W或東E)度數。
12) *hh = Checksum.(檢查位元)


「GSA」=>GPS幾何精度因子 偏差資訊(GNSS DOP)及衛星狀態(GSA) 
$--GSA,a,x,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,x.x,x.x,x.x,*hh
($GPGSA,<1>,<2>,<3>,<3>,,,,,<3>,<3>,<3>,<4>,<5>,<6>,<7>) 

範例說明:
$GPGSA,A,3,01,05,09,17,21,2,26,39,,,,1.9,1.0,1.7,*33
$GPGSA,
1) A = 定位模式,M:手動模式;A:自動模式
2) 3 = 定位模式,1:位置不可用;2:二度空間定位;3:三度空間定位
3) 01,05,09,17,21,2,26,39,,, = 接收衛星編號 (PRN)
4) 1.9 = PDOP-位置精度稀釋 0.5 至 99.9.
5) 1.0 = HDOP-水平精度稀釋 0.5 to 99.9.
6) 1.7 = VDOP-垂直精度稀釋 0.5 to 99.9.
7) *33 = Checksum.(檢查位元).

「GSV」=>可視衛星狀態
$--GSV,x,x,xx,xx,xx,xxx,xx,………,*h
($GPGSV, <1>,<2>,<3>,<4>,<5>,<6>,<7>,…<4>,<5>,<6>,<7>,<8> )
範例說明:
$GPGSV,3,1,09,01,27,299,43,………*70
1) 3 = 天空中收到訊號的衛星總數。
2) 1 = 定位的衛星總數。
3) 09 = 天空中的衛星總數,00 至 12。
4) 01 = 衛星編號, 01 至 32。
5) 27 = 衛星仰角, 00至 90 度。
6) 299 = 衛星方位角, 0 至 359 度。實際值。
7) 43 = 訊號雜訊比(C/No), 00 至 99 dB;無表未接收到訊號。
注意!第<4>,<5>,<6>,<7>項個別衛星會重複出現,每行最多有四顆衛星。其餘衛星資訊會於次一行出現,若未使用,這些欄位會空白。
8) Checksum.(檢查位元).

WGS-84


世界大地測量系統(英語:World Geodetic System, WGS)是一種用於地圖學、大地測量學和導航(包括全球定位系統)的大地測量系統標準。WGS包含一套地球的標準經緯坐標系、一個用於計算原始海拔數據的參考橢球體,和一套用以定義海平面高度的引力等勢面數據。
WGS的最新版本為WGS 84(也稱作WGS 1984、EPSG:4326),1984年定義、最後修訂於2004年。[1]之前的版本有WGS 72、WGS 66、WGS 60。全球定位系統使用的就是WGS 84參考系。
在Android系統內取得的海拔高度預設是參照WGS84而不是當地平均海平面,使得用戶在海邊定位是可能發現自己的測量值位於海平面以下。

WGS-84[編輯]

初版WGS84通過遍布世界的衛星觀測站觀測到的坐標建立,其精度為1-2m。1994年1月2日,通過10個觀測站在GPS測量方法上改正,得到了WGS84(G730),G表示由GPS測量得到,730表示為GPS時間第730個周。
1996年,National Imagery and Mapping Agency (NIMA) 為美國國防部 (U.S.Department of Defense, DoD)做了一個新的坐標系統。這樣實現了新的WGS版本WGS(G873)。其因為加入了美國海軍天文台和北京站的改正,其東部方向加入了31-39cm 的改正。所有的其他坐標都有在1公寸之內的修正。

GDOP,PDOP,HDOP,VDOP,TDOP

Source

 PDOP:位置精度因子(Position Dilution of Precision),直譯為“精度強弱度”,通常翻譯為“相對誤差”。具體含義是:由於觀測成果的好壞與被測量的人造衛星和接收儀間的幾何形狀有關且影響甚大,所以計算上述所引起的誤差量稱為精度的強弱度。天空中衛星分佈程度越好,定位精度越高(數值越小精度越高)。PDOP表示三維位置定位精度與導航臺幾何配置關係的一個引數。在全球定位(GPS)系統中,等於使用者位置的徑向誤差(1°)與使用者到衛星的距離測量誤差(1°)的比值。
           Pdop取值範圍為:0.5--99.9,為緯度、經度和高程等誤差平方和的開根號值,所以Pdop的平方 =Hdop 的平方 +Vdop 的平方。
           在幾何上,PDOP按由接收機和所能觀測到的四顆衛星的連線所組成的錐狀物的體積比例來平分1。對於好的定位而言,PDOP值小,例如3。比7大的值被認為是較差。因此,小的PDOP值與相隔較遠的衛星相關。
          在GPS導航和定位中,我們使用幾何精度因子(DOP,dilution of precision,也翻譯為精度衰減因子)來衡量觀測衛星的空間幾何分佈對定位精度的影響。DOP分為以下幾種:
           PDOP( position dilution of precision ) 三維位置精度因子:為緯度、經度和高程等誤差平方和的開根號值
          TDOP(time dilution of precision )鐘差精度因子:為接收儀內時表偏移誤差值。
           HDOP(horizontal dilution of precision )水平分量精度因子:為緯度和經度等誤差平方和的開根號值。
           VDOP(vertical dilution of precision )垂直分量精度因子
            DOP值的大小與GPS定位的誤差成正比,DOP值越大,定位誤差越大,定位的精度就低。PDOP則直接反映GPS衛星的分佈情況,當PDOP較大時,表明空中的4顆GPS衛星幾何分佈不是太理想,他們構成的圖形周長太短,定位精度就低,反之亦然。
             精度衰減因子(DOP)是位置質量的指示器。它是考慮每顆衛星相對於星座(幾何位置)中其它衛星的位置來預計用該星座能得到的位置精度的計算結果。小的DOP值表示強的衛星幾何位置和精度的較高概率。高的DOP值表示弱的衛星幾何位置和精度的較低概率.
           一個GPS接收器可以在同一時間得到許多顆衛星定位資訊,但在精密定位上,只要四顆衛星訊號即已足夠了,一個好的接收器便可判斷如何在這些衛星訊號當中去擷取較可靠的訊號來計算,如果接收器所選取的訊號當中,有二顆衛星距離甚近,二顆衛星訊號在角度較小的地方會有一個重疊的區域產生,隨著距離愈近,此區域便愈大,影響精度的誤差亦愈大。如果選取的衛星彼此相距有一段距離,則訊號相交之處便較為明確,誤差當然就縮減了不少。
           這也從另外一個方面說明,雖然我們正頭頂上的衛星訊號比較好,比較容易鎖定,但其實它們的作用卻不如角度比較低的衛星的。
它們之間的簡單關係為:
HDOP2+VDOP2=PDOP2
PDOP2+TDOP2=GDOP2 
            幾何精度因子(Geometric Dilution Precision ,縮寫為GDOP)是衡量定位精度的很重要的一個係數,它代表GPS 測距誤差造成的接收機與空間衛星間的距離向量放大因子。實際表徵參與定位解的從接收機至空間衛星的單位向量所勾勒的形體體積與GDOP成反比,故又稱為幾何精度因子。
            實際上,GDOP的數值越大,所代表的單位向量形體體積越小,即接收機至空間衛星的角度十分相似導致的結果,此時的GDOP會導致定位精度變差。好的GDOP, 是指其數值小,代表大的單位向量形體體積,導致高的定位精度。好的幾何因子實際上是指衛星在空間分佈不集中於一個區域,同時能在不同方位區域均勻分佈。

2019年4月7日 星期日

Source Insight in Linux

Source http://apple-rookie.blogspot.com/2012/09/linux-wine-source-insight.html

Source Insight 比 cscope, ctags 這類 Mac/Unix 上的代碼閱讀軟體好用。在 Linux 內可以透過 WINE 安裝 Windows 下的 Source Insight,比如

$ sudo apt-get install wine

(不需要 root 權限)
$ wine Si3570Setup.exe

就可以用了。

Source Insight 預設使用 Courier New 字體,不算很理想。如果手邊有安裝 Visual Studio 的話,微軟有提供一套「非常好」的 Programming Fonts 叫做 Consolas。

可以在 C:/Windows/Fonts 中找到 Consolas,把這個字體拖拉到另一個資料夾後,一般來講會跑出四隻檔案,然後再把這些檔案複製到 Linux Home 目錄下的 .fonts 目錄,Source Insight 就可以選擇 Consolas 字體了。

理論上 Mac 也可以安裝 Source Insight,但 WINE 在 Mac 上的支援比較不好,直接用 VMware/Parallel Desktops 跑 Source Insight 會比較簡單。

2019年4月1日 星期一

How to resume scp with partially copied files?

Source https://stackoverflow.com/questions/26411225/how-to-resume-scp-with-partially-copied-files

You should use rsync over ssh
rsync -P -e ssh remoteuser@remotehost:/remote/path /local/path
The key option is -P, which is the same as --partial --progress
Other options, such -a (for archive mode), and -z (to enable compression) can also be used.

2019年3月27日 星期三

Bash Scripting: How to Output and Format Text on Linux Shell

Source: https://stackoverflow.com/questions/378829/convert-decimal-to-hexadecimal-in-unix-shell-script

Convert decimal to hexadecimal in UNIX shell script

printf "%x\n" 34
22


Source: https://vitux.com/how-to-output-text-on-linux-shell/

Bash Scripting: How to Output and Format Text on Linux Shell


Bash scripting is quite popular is the easiest scripting language. Like any programming or scripting language, you come across printing text on the terminal. This can happen in numerous scenarios such as when you want to output the contents of a file or check the value of a variable. Programmers also debug their applications by printing the values of their variables on the console. Therefore, before we delve into bash scripting which will be another tutorial, let’s look at the different ways in which we could output text in the terminal.
Echo is the most important command that you need to know in order to output text on the terminal. As the name itself suggests, echo displays number or string on standard output in the terminal. It also has a number of options available as shown in the table below.
OptionsDefinition
-nDo not print the trailing newline
-EDisable interpretation of back-slash escaped characters
-eEnable interpretation of backslash escapes
\aAlert
\bBackspace
\cSuppress trailing newline
\eEscape
\fForm feed
\\backslash
\nNew line
\rCarriage return
\tHorizontal tab
\vVertical tab
According to the Linux documentation, the following is the syntax for echo command.
echo [option(s)][string(s)]
Now, we shall see the different ways in which we can output the text on the terminal.

Send Text to Standard Output


To output any string or number or text on the terminal, type the following command and press enter.
echo "Hello World"
The following output will be shown on the terminal
Send text to stdout with echo command

Print a Variable


Let’s declare a variable and prints its value on the terminal. Suppose x is a variable which we have initialized at 100.
x=100
Now, we will output the value of the variable on the terminal.
echo x
100 will be printed on the terminal. Likewise, you can also store a string in a variable and output it on the terminal.
Print content of a variable
Try it out and let us know if it was easy for you.

Remove Space between Words


This is one of my favorite option of echo as it removes all the space between different words in the sentences and jumbles them up together. In this feature, we will be using two of the options as mentioned in Table 1.
echo -e "Hello \bmy \bname \bis \bjohn \bDoe"
As you can see from the above example, we are enabling the interpretation of backslash escapes as well as adding backspace. The following output was shown.
Remove space between words with backspace

Output Word in New Line


This option of echo comes in really handy when you are working bash scripting. Mostly you need to move to the next line once you are done. Therefore, this is the best option to use for that.
echo -e "Hello \nmy \nname \nis \nJohn \nDoe"
The output will display each word in a separate line as shown in the screenshot below.
Add newlines to the text output

Output Text with Sound


This is a simple option of outputting text with bell or alert. To do this, type the following command.
echo -e "Hello \amy name is John Doe"
Make sure that your system’s volume is high enough for you to hear the tiny bell that sounds when the text is outputted on the terminal.

Remove Trailing New Line


Another option of the echo is to remove the trailing newline so that everything outputs on the same line. For this, we use “\c” option as shown in the figure below.
echo -e "Hello my name \cis John Doe"
The following output is shown
Remove trailing newline

Add a Carriage Return to the output


To add a specific carriage return in your output, we have “\r” option for this.
echo -e "Hello my name \ris John Doe"
The following output is shown to you on the terminal.
Add a Carriage Return to the output

Use Tabs in Output


While printing output on the terminal, you can add horizontal and vertical tabs as well. These come in handy for cleaner outputs. To add horizontal tabs, you have to add “\t” and for vertical tabs, add “\v”. We will be doing a sample for each of these and then a combined one.
echo -e "Hello my name \tis John Doe"
The output for this command will be shown as follows
Use tabs to format the text output
echo -e "Hello my name \vis John Doe"
The output for this command will be shown as follows
Use \v in bash output
Now we will combine this example for a set of sentences we have.
echo -e "Hello my name \vis John Doe. Hello! My name is \tJane Doe"
The following will be printed on the terminal.
Advanced formatting example
Well, that’s all the options that can be used for printing text on a terminal. This is an important feature to learn as it will help you further when you start working on bash scripting. Make sure that you implement each of the options and practice hard. Let us know if this tutorial helped you solve a problem.