<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1102978090826895217</id><updated>2024-09-06T04:50:40.797+08:00</updated><category term="Linux"/><category term="Raspberry Pi"/><category term="C#"/><category term="ubuntu"/><category term="照片說故事"/><category term="C/C++"/><category term="Programming"/><category term="Batch File"/><category term="Ford Focus 1.5T"/><category term="Windows"/><category term="上海"/><category term="程式"/><category term="Windows Command"/><category term="Windows指令"/><category term="Windows設定"/><category term="免費軟體"/><category term="Autoit"/><category term="Leet Code"/><category term="PetaLinux"/><category term="python"/><category term="批次檔"/><category term="網路"/><title type='text'>快閃人生</title><subtitle type='html'>2015年底出走安逸生活，流浪半年多，2016年意外踏入快閃記憶體產業，快閃人生就此展開...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>76</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-6937611547349264930</id><published>2018-05-10T17:25:00.001+08:00</published><updated>2018-05-10T17:25:44.261+08:00</updated><title type='text'>Tashiba &amp; Samsung UFS Device Naming Rule</title><content type='html'>記錄一下兩家Flash大廠UFS產品的命名規則資訊&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Tashiba (東芝)&lt;br /&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/26551570&quot;&gt;https://zhuanlan.zhihu.com/p/26551570&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Samsung (三星)&lt;br /&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/26551649&quot;&gt;https://zhuanlan.zhihu.com/p/26551649&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
再補上稍舊的資訊&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Tashiba NAND產品命名規則 (含Controller與不含Controller)&lt;br /&gt;&lt;a href=&quot;https://drive.google.com/open?id=1JDM6aJISaTJlWbxcgH0hyU9MH6R99tXY&quot;&gt;https://drive.google.com/open?id=1JDM6aJISaTJlWbxcgH0hyU9MH6R99tXY&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Samsung NAND產品命名規則 (不含Controller)&lt;br /&gt;&lt;a href=&quot;https://drive.google.com/open?id=1wfXopE3uGzV3si0bFLcT-DXGtkL02oxi&quot;&gt;https://drive.google.com/open?id=1wfXopE3uGzV3si0bFLcT-DXGtkL02oxi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/6937611547349264930/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2018/05/tashiba-samsung-ufs-device-naming-rule.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6937611547349264930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6937611547349264930'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2018/05/tashiba-samsung-ufs-device-naming-rule.html' title='Tashiba &amp; Samsung UFS Device Naming Rule'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-3334492233818612140</id><published>2018-02-13T21:42:00.000+08:00</published><updated>2018-02-13T21:42:09.783+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>【C#】關於UI跨執行緒控制元件的問題</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
情境說明：在視窗介面開發常常會為了避免視窗凍結而將執行較久的函數用執行緒（Threading）去執行，若過程中需要把一些資訊丟到視窗元件上或是從視窗元件取得特定資料，就會發生跨執行緒存取權限的問題（=&amp;gt; 使用的執行緒與建立控制項的執行緒不同）。&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHRp5-F62a5ObhKREX7grCs-pDxLYw7E90H7ZIX2bsKZpOlBkv_4kzsT8cTSGWknE0sSIrkGbRUfb6ZLO86PoH7tzPMbde3ttG7rOqCrPYKyuOF5HEtaUxUmqKq1kNt7JQwvB9pHgWDE/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;252&quot; data-original-width=&quot;934&quot; height=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHRp5-F62a5ObhKREX7grCs-pDxLYw7E90H7ZIX2bsKZpOlBkv_4kzsT8cTSGWknE0sSIrkGbRUfb6ZLO86PoH7tzPMbde3ttG7rOqCrPYKyuOF5HEtaUxUmqKq1kNt7JQwvB9pHgWDE/s640/001.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
解決方法：透過C# Delegate（委派）機制把工作丟給另個執行緒（控制元件的執行緒）代為處理&lt;br /&gt;
&lt;br /&gt;
委派的寫法其實很簡單，其實就是幫元件寫個CallBack Function，在函數中首先先判斷元件是否在同個執行緒，若不是則呼叫CallBack Function（底下範例的if區塊），如果是則看需求把動作完成即可
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;delegate&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;TextBoxAppendCallback&lt;/span&gt;(TextBox Ctl, &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;string&lt;/span&gt; Str);
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;TextBoxAppend&lt;/span&gt;(TextBox Ctl, &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;string&lt;/span&gt; Str)
{
　　　　&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (Ctl.InvokeRequired)
　　　　{
　　　　　　　　TextBoxAppendCallback d = &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; TextBoxAppendCallback(TextBoxAppend);
　　　　　　　　&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.Invoke(d, &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;object&lt;/span&gt;[] { Ctl, Str });
　　　　}
　　　　&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
　　　　{
　　　　　　　　Ctl.AppendText(Str);
　　　　}
}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
若只有幾個地方需要用到元件存取，可以考慮偷懶一點的寫法
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;1
2
3
4&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.Invoke((MethodInvoker)&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;delegate&lt;/span&gt;()
{
　　　　textBox1.AppendText(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Hello, Sleep 3 Seconds ...&quot;&lt;/span&gt; + Environment.NewLine);
});
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
完整範例&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJOGwkwaDzF1H0R2NA3EC640l3jUsvsIKjlxjer3vvf45ztUq9R6-iSIctsQ9IE6KwAB6O5Ctk4lTfBAw8GFlzYLNYqm7l-MXUSC5pnmAefdlB8dbCtnFZLxRw4OoF0dqFEqYhhNBlaEo/s1600/002.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;300&quot; data-original-width=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJOGwkwaDzF1H0R2NA3EC640l3jUsvsIKjlxjer3vvf45ztUq9R6-iSIctsQ9IE6KwAB6O5Ctk4lTfBAw8GFlzYLNYqm7l-MXUSC5pnmAefdlB8dbCtnFZLxRw4OoF0dqFEqYhhNBlaEo/s1600/002.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;partial&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Form1&lt;/span&gt; : Form
{
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Form1&lt;/span&gt;()
	{
		InitializeComponent();
	}

	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;delegate&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;TextBoxAppendCallback&lt;/span&gt;(TextBox Ctl, &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;string&lt;/span&gt; Str);
	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;TextBoxAppend&lt;/span&gt;(TextBox Ctl, &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;string&lt;/span&gt; Str)
	{
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (Ctl.InvokeRequired)
		{
			TextBoxAppendCallback d = &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; TextBoxAppendCallback(TextBoxAppend);
			&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.Invoke(d, &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;object&lt;/span&gt;[] { Ctl, Str });
		}
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
		{
			Ctl.AppendText(Str);
		}
	}

	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Test&lt;/span&gt;()
	{
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.Invoke((MethodInvoker)&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;delegate&lt;/span&gt;()
		{
			textBox1.AppendText(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Hello, Sleep 3 Seconds ...&quot;&lt;/span&gt; + Environment.NewLine);
		});
		Thread.Sleep(&lt;span style=&quot;color: #6600ee; font-weight: bold;&quot;&gt;3000&lt;/span&gt;);
		&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.Invoke((MethodInvoker)&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;delegate&lt;/span&gt;()
		{
			textBox1.AppendText(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;I&#39;m Back, Oh Wait One More Second, Please ...&quot;&lt;/span&gt; + Environment.NewLine);
		});
		Thread.Sleep(&lt;span style=&quot;color: #6600ee; font-weight: bold;&quot;&gt;1000&lt;/span&gt;);
		TextBoxAppend(textBox1, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Everything Is Done&quot;&lt;/span&gt; + Environment.NewLine);
	}

	&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;button1_Click&lt;/span&gt;(&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
	{
		&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;var&lt;/span&gt; thread = &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; Thread(Test);
		thread.Start();
	}
}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/3334492233818612140/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2018/02/cui.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3334492233818612140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3334492233818612140'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2018/02/cui.html' title='【C#】關於UI跨執行緒控制元件的問題'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkHRp5-F62a5ObhKREX7grCs-pDxLYw7E90H7ZIX2bsKZpOlBkv_4kzsT8cTSGWknE0sSIrkGbRUfb6ZLO86PoH7tzPMbde3ttG7rOqCrPYKyuOF5HEtaUxUmqKq1kNt7JQwvB9pHgWDE/s72-c/001.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-740706418563945277</id><published>2018-01-13T09:58:00.000+08:00</published><updated>2018-01-13T09:58:05.412+08:00</updated><title type='text'>【Focus】一萬公里保養工單</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
記錄一下去年十月回廠一萬公里保養工單，這次總共花費3143元&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;工資　　　　　　　（900）&lt;/li&gt;
&lt;li&gt;5W30合成引擎機油　（498 * 3.8 = 1892）&lt;/li&gt;
&lt;li&gt;機油芯　　　　　　（263)&lt;/li&gt;
&lt;li&gt;放油塞墊片　　　　（88)&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
跟五千公里相比主要是工資多了300元，大概是多了輪胎對調工資才多加0.5個單位吧！？&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL8IfUF8Bk1ETxkiChyIFyoCmAA5qZCCBCdtLxKshfRnpCmxwrDfixiXg6dxEOpgc9XosPpljz_jS6bcH90l0RgezenVlwdXKDAuIm0JBQLKze5TGZS5unwxu6bLp5HKlaWdP-pUrR4OY/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL8IfUF8Bk1ETxkiChyIFyoCmAA5qZCCBCdtLxKshfRnpCmxwrDfixiXg6dxEOpgc9XosPpljz_jS6bcH90l0RgezenVlwdXKDAuIm0JBQLKze5TGZS5unwxu6bLp5HKlaWdP-pUrR4OY/s1600/001.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/740706418563945277/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2018/01/focus.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/740706418563945277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/740706418563945277'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2018/01/focus.html' title='【Focus】一萬公里保養工單'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL8IfUF8Bk1ETxkiChyIFyoCmAA5qZCCBCdtLxKshfRnpCmxwrDfixiXg6dxEOpgc9XosPpljz_jS6bcH90l0RgezenVlwdXKDAuIm0JBQLKze5TGZS5unwxu6bLp5HKlaWdP-pUrR4OY/s72-c/001.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-460026299865120126</id><published>2017-12-28T22:13:00.001+08:00</published><updated>2017-12-28T22:13:21.323+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>【C#】偵測Disk插入/卸除</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6QYM-5XlqC2buB_N7d9ngN483rJ0Qq513dRIDKk-Mcu5Af0tb44S04eTLjkCM373wH_GWJgAT4fVXujMihQMUB8PnENQSUcTot4KK6jrVcNEHIZ3GAR9UhWIRGa2VAfljYKUYdXlymPM/s1600/00.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;107&quot; data-original-width=&quot;674&quot; height=&quot;100&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6QYM-5XlqC2buB_N7d9ngN483rJ0Qq513dRIDKk-Mcu5Af0tb44S04eTLjkCM373wH_GWJgAT4fVXujMihQMUB8PnENQSUcTot4KK6jrVcNEHIZ3GAR9UhWIRGa2VAfljYKUYdXlymPM/s640/00.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
要在C#中偵測磁碟機的改變（新增／插入、移除／卸除）可以透過&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;ManagementEventWatcher&lt;/span&gt;&lt;/b&gt;類別加上Windows提供的&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;WMI&lt;/b&gt;&lt;/span&gt;來達到此功能，直接看程式碼內容：&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;System&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;System.Collections.Generic&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;System.Linq&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;System.Text&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;System.Management&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;namespace&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;DiskDetect&lt;/span&gt;
{
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Program&lt;/span&gt;
    {
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Main&lt;/span&gt;(&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;string&lt;/span&gt;[] args)
        {
            ManagementEventWatcher watcher = &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; ManagementEventWatcher();
            WqlEventQuery query = &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; WqlEventQuery(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2 or EventType = 3&quot;&lt;/span&gt;);
            watcher.EventArrived += &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; EventArrivedEventHandler(watcher_EventArrived);
            watcher.Query = query;
            watcher.Start();

            Console.ReadLine();
        }

        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;watcher_EventArrived&lt;/span&gt;(&lt;span style=&quot;color: #333399; font-weight: bold;&quot;&gt;object&lt;/span&gt; sender, EventArrivedEventArgs e)
        {
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (Convert.ToInt16(e.NewEvent.Properties[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;EventType&quot;&lt;/span&gt;].Value) == &lt;span style=&quot;color: #6600ee; font-weight: bold;&quot;&gt;2&lt;/span&gt;)
            {
                Console.WriteLine(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Disk Insert: &quot;&lt;/span&gt; + e.NewEvent.Properties[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;DriveName&quot;&lt;/span&gt;].Value);
            }
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;
            {
                Console.WriteLine(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Disk Remove: &quot;&lt;/span&gt; + e.NewEvent.Properties[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;DriveName&quot;&lt;/span&gt;].Value);
            }
        }
    }
}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/zh-tw/library/system.management.managementeventwatcher(v=vs.110).aspx&quot; target=&quot;_blank&quot;&gt;ManagementEventWatcher Class&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/aa394516(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;Win32_VolumeChangeEvent&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Keyword: How to detect disk state in C# language</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/460026299865120126/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2017/12/cdisk.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/460026299865120126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/460026299865120126'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2017/12/cdisk.html' title='【C#】偵測Disk插入/卸除'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6QYM-5XlqC2buB_N7d9ngN483rJ0Qq513dRIDKk-Mcu5Af0tb44S04eTLjkCM373wH_GWJgAT4fVXujMihQMUB8PnENQSUcTot4KK6jrVcNEHIZ3GAR9UhWIRGa2VAfljYKUYdXlymPM/s72-c/00.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-3928196581842854371</id><published>2017-12-21T20:37:00.001+08:00</published><updated>2017-12-21T20:37:17.484+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Autoit"/><title type='text'>【AutoIt】插入一個執行時期的錯誤</title><content type='html'>在任何程式語言要插入一個執行時期錯誤(run time error)最快的方式大概就是誤用陣列吧，所以要在AutoIt中埋入一個執行時期錯誤最簡單的方式也不外乎是用這招，直接看底下範例：&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;1
2
3
4
5
6&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;#cs
Inject a &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;run&lt;/span&gt; time error &lt;span style=&quot;color: #007020;&quot;&gt;for&lt;/span&gt; autoit script
#ce
&lt;span style=&quot;color: #007020;&quot;&gt;Global&lt;/span&gt; &lt;span style=&quot;color: #996633;&quot;&gt;$arr&lt;/span&gt;[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]
&lt;span style=&quot;color: #996633;&quot;&gt;$arr&lt;/span&gt;[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;] &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;50&lt;/span&gt;
&lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;MsgBox&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Run Time Error&quot;&lt;/span&gt;, &lt;span style=&quot;color: #996633;&quot;&gt;$arr&lt;/span&gt;[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;])
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/3928196581842854371/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2017/12/autoit.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3928196581842854371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3928196581842854371'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2017/12/autoit.html' title='【AutoIt】插入一個執行時期的錯誤'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-6343337493619271753</id><published>2017-04-06T20:33:00.000+08:00</published><updated>2017-04-06T20:33:09.950+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ford Focus 1.5T"/><title type='text'>【Focus】新成員：鐵男？小白？</title><content type='html'>想法真的會隨時間改變，原先很篤定先買房再買車，踏入社會堅守了六年左右還是轉念了，至於買車用途也不是為了上下班代步，很單純就是假日能自由的跑遠？&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvgz_0XK3Gtp_m4pSbj7grv26qHrgGVteEZCnNfm2MMDjEULBsaTp-XFidmqEbbVG5ezKG7YIlpznreR2Bk3CLllAMN-6IoNwNyd6lP5i7TpCsPFjK44RTD6bS8UTJLaPCtt76YbxdOYU/s1600/01.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvgz_0XK3Gtp_m4pSbj7grv26qHrgGVteEZCnNfm2MMDjEULBsaTp-XFidmqEbbVG5ezKG7YIlpznreR2Bk3CLllAMN-6IoNwNyd6lP5i7TpCsPFjK44RTD6bS8UTJLaPCtt76YbxdOYU/s640/01.png&quot; width=&quot;640&quot;&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://inpega.blogspot.com/2017/04/focus.html#more&quot;&gt;閱讀更多 »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/6343337493619271753/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2017/04/focus.html#comment-form' title='4 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6343337493619271753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6343337493619271753'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2017/04/focus.html' title='【Focus】新成員：鐵男？小白？'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvgz_0XK3Gtp_m4pSbj7grv26qHrgGVteEZCnNfm2MMDjEULBsaTp-XFidmqEbbVG5ezKG7YIlpznreR2Bk3CLllAMN-6IoNwNyd6lP5i7TpCsPFjK44RTD6bS8UTJLaPCtt76YbxdOYU/s72-c/01.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-2474771174275081429</id><published>2017-03-25T23:14:00.000+08:00</published><updated>2017-12-28T22:16:07.201+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ford Focus 1.5T"/><title type='text'>【Focus】五千公里保養工單</title><content type='html'>&lt;div&gt;
由於車子比較少使用里程累積速度較慢，滿半年也不過多了五千公里的里程，不然根據手冊每一萬公里再回廠保養即可。&lt;br&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
這次回廠一樣就讓接待直接帶出保養套餐，很好說話的我還是沒能成功ㄠ到折扣優惠，最後得到一瓶全效機油添加劑，看在接待跟技師都很熱心幫忙處理車子就不計較那點折扣了，這次仍是指定吳振毅技師幫忙，沒什麼考量想法，第一次找他是因為論壇車友鼎力推薦，這次還回去找他就是第一次過程覺得還不錯就繼續讓他服務囉，畢竟固定技師保養以後車有什麼怪毛病應該可以得到比較多的用心吧...!?&lt;br&gt;
&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;http://inpega.blogspot.com/2017/03/focus_25.html#more&quot;&gt;閱讀更多 »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/2474771174275081429/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2017/03/focus_25.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2474771174275081429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2474771174275081429'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2017/03/focus_25.html' title='【Focus】五千公里保養工單'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQsShTN1YrCRbx1rlzFcouVK7EQna13zcBwZwuzpVDZ4ztGInW1oZLGdcWXzUpSpGKyNRFxW5b_06q5Wiuc5MyI3mG3psr-a0HqQngV2ITEKhUibaLZgQEEaV94H9BYFmjJfUds6xrfic/s72-c/IMG_6203+%25281%2529.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-1092754185755242103</id><published>2017-03-23T22:21:00.000+08:00</published><updated>2017-03-25T23:19:35.745+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ford Focus 1.5T"/><title type='text'>【Focus】一千公里保養工單</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
在FSC &amp;amp; Mobile論壇上翻了一堆技師推薦文，最後決定回到台中九和復興廠找&lt;span style=&quot;background-color: #ffd966;&quot;&gt;吳振毅&lt;/span&gt;技師幫忙保養，第一次進廠保養全程跟著一起看底盤與所有的保養工序，也問了很多關於開車與養車觀念，吳技師滿建談的，稍微問個開頭就可以一路一直聊下去，比較麻煩的是指定吳振毅技師太熱門了，至少需要提早兩個星期預約比較不會撲空！&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;a href=&quot;http://inpega.blogspot.com/2017/03/focus.html#more&quot;&gt;閱讀更多 »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/1092754185755242103/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2017/03/focus.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/1092754185755242103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/1092754185755242103'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2017/03/focus.html' title='【Focus】一千公里保養工單'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5plvljVKNLptBNXw4_l0tTxi1EwUgjPycOvTV8nVyfu2lhdKM18dj16PBJjQ7iH0LVuBW3kcxtP38Spx76vaHa2GE4CYZJXd3kto7i9yoQHv-hAvNNbuPhJycGSQze61vcTK6WURqHV4/s72-c/IMG_6204.jpeg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-3761728042635670273</id><published>2016-04-22T09:10:00.000+08:00</published><updated>2016-04-22T09:10:04.640+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Leet Code"/><title type='text'>【LeetCode 231】Power of Two</title><content type='html'>&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 14px; line-height: 30px;&quot;&gt;&lt;i&gt;&lt;a href=&quot;https://leetcode.com/problems/power-of-two/&quot; target=&quot;_blank&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;1e7be6a1-76ba-4c9b-8254-21f18b940129&quot; id=&quot;78dfc2bf-044a-4df9-b9d5-996031a2842c&quot;&gt;LeetCode&lt;/gs&gt; 231: Power of Two&lt;/a&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; font-size: 14px; line-height: 30px;&quot;&gt;&lt;i&gt;&lt;b&gt;Question&lt;/b&gt;: Given an integer, write a function to determine if it is a power of two.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;1
2
3&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;77e5c46f-0b82-4820-86d4-ddcc25c8fb51&quot; id=&quot;f81abd22-ca6b-4bf8-a2c6-441295820463&quot;&gt;bool&lt;/gs&gt;&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;77e5c46f-0b82-4820-86d4-ddcc25c8fb51&quot; id=&quot;4d09ccf5-541b-472a-bf91-d0bdee7c9bd9&quot;&gt;isPowerOfTwo&lt;/gs&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;77e5c46f-0b82-4820-86d4-ddcc25c8fb51&quot; id=&quot;f9c45ebb-7f27-49fc-9b1d-44c3877f8ed7&quot;&gt;(&lt;/gs&gt;&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;n)&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;{&lt;/span&gt;

&lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;77e5c46f-0b82-4820-86d4-ddcc25c8fb51&quot; id=&quot;dced4b48-f3e2-4d84-8018-7e64c1310d61&quot;&gt;}&lt;/gs&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;1
2
3&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;bool&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;isPowerOfTwo(&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #00cd00;&quot;&gt;&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;n)&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;{&lt;/span&gt;
    &lt;span style=&quot;color: #cdcd00;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;n&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #cd00cd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;(n&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color: #cccccc;&quot;&gt;(n&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;- &lt;/span&gt;&lt;span style=&quot;color: #cd00cd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;))&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #cd00cd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #cccccc;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #cccccc;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;解析&lt;/b&gt;&lt;br /&gt;
在二進位中，只有出現一次1即為2的冪次方&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
0001 =&amp;gt; 1&lt;br /&gt;
0010 =&amp;gt; 2&lt;br /&gt;
0100 =&amp;gt; 4&lt;br /&gt;
1000 =&amp;gt; 8&lt;/blockquote&gt;
因此可用bit operator判斷完成題目要求&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
(&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;a44deb1c-ad10-4199-9b31-30097eaffd7e&quot; id=&quot;8d83db38-e59c-4df1-9e45-e4c43f76a53a&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;f35a2862-b1c0-43ec-b326-2e574f01d80e&quot; id=&quot;ec001d30-02ad-46b5-959b-07bf4fb668bc&quot;&gt;n&lt;/gs&gt;&lt;/gs&gt; &amp;amp; (n -1)) == 0&lt;/blockquote&gt;
描述式採用進位特性，來消除最低位的1，執行一次後若數值為0則表示只有一個1，因此可以判斷為2的冪次&lt;br /&gt;
考量題目框架帶入的參數值是帶有正負號的int型別，所以要多判斷數值是否大於0</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/3761728042635670273/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2016/04/leetcode-231power-of-two.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3761728042635670273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3761728042635670273'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2016/04/leetcode-231power-of-two.html' title='【LeetCode 231】Power of Two'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-173734177927100008</id><published>2016-02-25T11:57:00.000+08:00</published><updated>2016-03-01T09:31:34.744+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【RaspberryPi】開機自動登入UART終端機</title><content type='html'>新版的Raspbian Jessie系統除了將Kernel升級到4.1也採用了systemd，因此若要設定自動登入必須改變方法&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;把設定檔放到/etc/systemd/system目錄下
&lt;pre style=&quot;background: #000000; color: #d1d1d1;&quot;&gt;sudo cp &lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;lib&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;systemd&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;system&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;serial&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;getty&lt;span style=&quot;color: #d2cd86;&quot;&gt;@&lt;/span&gt;.service &lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;systemd&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;system&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;serial&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;getty&lt;span style=&quot;color: #d2cd86;&quot;&gt;@&lt;/span&gt;ttyAMA0.service
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;編輯設定檔內容
&lt;pre style=&quot;background: #000000; color: #d1d1d1;&quot;&gt;sudo vi &lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;systemd&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;system&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;serial&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;getty&lt;span style=&quot;color: #d2cd86;&quot;&gt;@&lt;/span&gt;ttyAMA0.service
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;找到下面這行
&lt;pre style=&quot;background: #000000; color: #d1d1d1;&quot;&gt;ExecStart&lt;span style=&quot;color: #d2cd86;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;sbin&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;agetty &lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;keep&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;baud &lt;span style=&quot;color: #00a800;&quot;&gt;115200&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;38400&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;9600&lt;/span&gt; %I $TERM
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;加入--autologin pi即可&lt;br /&gt;&lt;pre style=&quot;background: #000000; color: #d1d1d1;&quot;&gt;ExecStart&lt;span style=&quot;color: #d2cd86;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;sbin&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;agetty &lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;ab2dc226-31e6-4c73-9524-a6521163e443&quot; id=&quot;8b645981-9bfc-4494-aaf5-5e299c1f39c9&quot;&gt;autologin&lt;/gs&gt; pi &lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;keep&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;baud &lt;span style=&quot;color: #00a800;&quot;&gt;115200&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;38400&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;9600&lt;/span&gt; %I $TERM
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;若要自動登入為root則改成--autologin root
&lt;pre style=&quot;background: #000000; color: #d1d1d1;&quot;&gt;ExecStart&lt;span style=&quot;color: #d2cd86;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;sbin&lt;span style=&quot;color: #d2cd86;&quot;&gt;/&lt;/span&gt;agetty &lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;autologin root &lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;keep&lt;span style=&quot;color: #d2cd86;&quot;&gt;-&lt;/span&gt;baud &lt;span style=&quot;color: #00a800;&quot;&gt;115200&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;38400&lt;/span&gt;&lt;span style=&quot;color: #d2cd86;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #00a800;&quot;&gt;9600&lt;/span&gt; %I $TERM
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
Keyword：樹莓派、RPi、Auto Login</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/173734177927100008/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2016/02/raspberrypiuart.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/173734177927100008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/173734177927100008'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2016/02/raspberrypiuart.html' title='【RaspberryPi】開機自動登入UART終端機'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-2884038253536089771</id><published>2016-01-12T17:37:00.000+08:00</published><updated>2016-01-12T17:37:18.839+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Cross Compile For netperf</title><content type='html'>&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;下載source code (官網:&amp;nbsp;&lt;a href=&quot;http://www.netperf.org/&quot;&gt;http://www.netperf.org/&lt;/a&gt;)&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #996633;&quot;&gt;$ &lt;/span&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;e2aff4ac-7205-4981-ac10-c143bc8d4122&quot; id=&quot;073852d3-fa94-42b3-b824-b01adda7f29e&quot;&gt;wget&lt;/gs&gt; ftp://ftp.netperf.org/netperf/netperf-2.7.0.tar.gz
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;解壓縮套件
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #996633;&quot;&gt;$ &lt;/span&gt;tar zxvf netperf-2.7.0.tar.gz
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;進入source code目錄執行configure配置編譯選項
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #996633;&quot;&gt;$ &lt;/span&gt;./&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;f9941dfe-b868-4f08-b5b8-31c02a6dc66a&quot;&gt;configure&lt;/gs&gt; &lt;span style=&quot;color: #996633;&quot;&gt;CC&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;/opt/&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;c3cc4338-b5d1-48ac-b298-9abecbae39c4&quot;&gt;ti&lt;/gs&gt;-am335x-&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;df9f8d29-c500-4ea6-9e26-aa3a0baa899b&quot;&gt;linux&lt;/gs&gt;-&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;0370b4a1-f6d7-4e45-b937-f134af567704&quot;&gt;devkit&lt;/gs&gt;-08.00.00.00/bin/arm-&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;841bee57-c689-4f43-85a2-f285c867c1c1&quot;&gt;linux&lt;/gs&gt;-&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;27196bd3-03eb-4f68-afd7-ee273af1e7b8&quot;&gt;gnueabihf&lt;/gs&gt;-&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;c1ba4fbc-be84-4309-bb0a-05fc9da3a1e6&quot; id=&quot;0fe7e181-85e3-49e7-9974-3369445954d1&quot;&gt;gcc&lt;/gs&gt; --host arm --config-cache
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;若有出現下列錯誤，則執行執行步驟5，否則直接執行步驟6進行編譯即可
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;f831ab8b-9aba-4962-acaf-61ffcc57d853&quot; id=&quot;d1182046-ddab-43d2-b514-b1496e043270&quot;&gt;checking&lt;/gs&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for &lt;/span&gt;sys/socket&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;f831ab8b-9aba-4962-acaf-61ffcc57d853&quot; id=&quot;5580640a-6001-4a3e-8474-fe28feb9e216&quot;&gt;.&lt;/gs&gt;h... &lt;span style=&quot;color: #333333;&quot;&gt;(&lt;/span&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;78c9c3ef-6920-4061-9dfc-fb2fadea1e86&quot; id=&quot;9a8d8631-40f8-4ea3-863b-f413311132fa&quot;&gt;cached&lt;/gs&gt;&lt;span style=&quot;color: #333333;&quot;&gt;)&lt;/span&gt; yes
checking types of arguments &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for select&lt;/span&gt;... &lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;7eae390d-3306-4a6a-bce9-8a3dff2f72cb&quot; id=&quot;120a08e0-14ce-452e-a891-20ea6b9d6b30&quot;&gt;int&lt;/gs&gt;&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;7eae390d-3306-4a6a-bce9-8a3dff2f72cb&quot; id=&quot;9422c75a-7018-4e83-a414-542aabc74f4a&quot;&gt;,&lt;/gs&gt;fd_set *&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;7eae390d-3306-4a6a-bce9-8a3dff2f72cb&quot; id=&quot;b58e7f51-1dd5-4429-9efc-eee1f1af0293&quot;&gt;,&lt;/gs&gt;struct timeval *
checking whether setpgrp takes no argument... &lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;966fb8f5-0898-46ff-a560-8d57688f7ea9&quot; id=&quot;ac813657-5725-4c3c-8b95-7fd1ba4fc970&quot;&gt;configure&lt;/gs&gt;: error: cannot check setpgrp when cross compiling
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;修正setpgrp錯誤
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;$ echo&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;ac_cv_func_setpgrp_void=yes&quot;&lt;/span&gt; &amp;gt; config&lt;gs class=&quot;GINGER_SOFTWARE_mark&quot; ginger_software_uiphraseguid=&quot;77b3f6e5-47f6-4513-9277-20917eb83d94&quot; id=&quot;0df50cde-e45a-4c56-99f2-fdba02c69200&quot;&gt;.&lt;/gs&gt;cache
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;執行編譯
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #996633;&quot;&gt;$ &lt;/span&gt;make
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;編譯成功後可在src目錄下看到netperf與netserver，即可傳到目標機台上進行驗證&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/2884038253536089771/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2016/01/cross-compile-for-netperf.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2884038253536089771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2884038253536089771'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2016/01/cross-compile-for-netperf.html' title='Cross Compile For netperf'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-7883227188660356357</id><published>2016-01-05T09:06:00.002+08:00</published><updated>2016-01-05T09:06:53.615+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>Segmentation fault：FTP傳輸型態在搞鬼</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
首先看下面這段簡單的Hello World程式碼，按理說編譯完直接丟到目標機台上執行應該不會有什麼問題才對。&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLeyi0TtseYSxGKtRO5WAbEY0M7DbPfTkPjDybEheLG_cHr7AeuAyJdw4qtuiwFJyUQbChcs6IHRgZwfE1e2wFCfxCBXGFKPqElCS25fgLkaK7qnq0wqTUB7LELv4Q9d8XPGaMk9sF6tY/s1600/001.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;142&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLeyi0TtseYSxGKtRO5WAbEY0M7DbPfTkPjDybEheLG_cHr7AeuAyJdw4qtuiwFJyUQbChcs6IHRgZwfE1e2wFCfxCBXGFKPqElCS25fgLkaK7qnq0wqTUB7LELv4Q9d8XPGaMk9sF6tY/s400/001.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
但卻一直發生&lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Segmentation fault&lt;/span&gt;&lt;/span&gt;的錯誤提示&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5gSnxAW3ZXf3kcKyy6GX8fnEoL9GhAV4oMm5ZDhr4iZoITkKvPLOjejubDhwwhYCWEpjK-PGblTQkQKKllbzzCK7U9Pt6ozEzJinwqoVtQvJEjyMXMhTjHmrWYNg8WZSx0XNGjN1Nn4c/s1600/002.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5gSnxAW3ZXf3kcKyy6GX8fnEoL9GhAV4oMm5ZDhr4iZoITkKvPLOjejubDhwwhYCWEpjK-PGblTQkQKKllbzzCK7U9Pt6ozEzJinwqoVtQvJEjyMXMhTjHmrWYNg8WZSx0XNGjN1Nn4c/s1600/002.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
後來發現是因為使用&lt;span style=&quot;color: #bf9000;&quot;&gt;&lt;b&gt;FileZilla&lt;/b&gt;&lt;/span&gt;傳輸造成的，FileZilla有個設定值：&lt;span style=&quot;color: #274e13;&quot;&gt;&lt;b&gt;傳輸型態&lt;/b&gt;&lt;/span&gt;，預設為&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;自動&lt;/b&gt;&lt;/span&gt;，將這設定值改為&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;二進位檔案&lt;/b&gt;&lt;/span&gt;即可解決此問題。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq826VoL3ycyhSRqt5hoDtTMJ4u6BLPxTz34qEUxb62FoMzAKAlK31r6WXRRFO-kqbQ_PRhkv2MzBLrUzMuf2FEHn_6AhS7tN4d622ZHK-oC8kkhLJeFoq7imJQkQ9OryP6R0Th4T4ILg/s1600/003.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;156&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq826VoL3ycyhSRqt5hoDtTMJ4u6BLPxTz34qEUxb62FoMzAKAlK31r6WXRRFO-kqbQ_PRhkv2MzBLrUzMuf2FEHn_6AhS7tN4d622ZHK-oC8kkhLJeFoq7imJQkQ9OryP6R0Th4T4ILg/s400/003.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/7883227188660356357/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2016/01/segmentation-faultftp.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/7883227188660356357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/7883227188660356357'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2016/01/segmentation-faultftp.html' title='Segmentation fault：FTP傳輸型態在搞鬼'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLeyi0TtseYSxGKtRO5WAbEY0M7DbPfTkPjDybEheLG_cHr7AeuAyJdw4qtuiwFJyUQbChcs6IHRgZwfE1e2wFCfxCBXGFKPqElCS25fgLkaK7qnq0wqTUB7LELv4Q9d8XPGaMk9sF6tY/s72-c/001.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-486075285573858367</id><published>2015-09-07T18:16:00.000+08:00</published><updated>2015-09-07T18:22:29.117+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>iw指令連線操作記錄</title><content type='html'>以下範例假定無線網卡裝置名稱為&lt;b&gt;&lt;span style=&quot;color: #6fa8dc;&quot;&gt;wlan0&lt;/span&gt;&lt;/b&gt;（通常會是這名字），若不知道可以透過&lt;span style=&quot;color: #93c47d;&quot;&gt;&lt;b&gt;ifconfig -a&lt;/b&gt;&lt;/span&gt;指令查詢無線網卡裝置名稱。&lt;br /&gt;
&lt;br /&gt;
&lt;u style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;確認無線裝置連線狀態
&lt;/span&gt;&lt;/u&gt;&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# iw wlan0 link&lt;/span&gt;
Not connected.
&lt;/pre&gt;
&lt;/div&gt;
如果沒有任何連線，則會顯示Not connected，否則會顯示連線的相關資訊&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: yellow; color: #274e13;&quot;&gt;&lt;u&gt;掃描鄰近的wifi廣播訊號
&lt;/u&gt;&lt;/span&gt;&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# iw wlan0 scan&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;u style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;連線到WPA/WPA2加密的無線網路
&lt;/span&gt;&lt;/u&gt;&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# wpa_passphrase APPLE &amp;gt;&amp;gt; /tmp/wifi.conf&lt;/span&gt;
1234509876
&lt;/pre&gt;
&lt;/div&gt;
APPLE是無線網路的SSID資訊，輸入上述指令會停住等待使用者輸入連線密碼，1234509876即為設定的密碼，輸入完後按下Enter即會自動產生連線相關文件
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# reading passphrase from stdin&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;network&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;={&lt;/span&gt;
 &lt;span style=&quot;color: #996633;&quot;&gt;ssid&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;APPLE&quot;&lt;/span&gt;
 &lt;span style=&quot;color: #888888;&quot;&gt;#psk=&quot;1234509876&quot;&lt;/span&gt;
 &lt;span style=&quot;color: #996633;&quot;&gt;psk&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;a36065d029db325508281a51a19f8fff1c389c11129a74b6c6d3a25200cae713
&lt;span style=&quot;color: #333333;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
連線指令
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# wpa_supplicant -B -i wlan0 -c /tmp/wifi.conf&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
若沒跳出任何錯誤訊息應該就完成連線了&lt;br /&gt;
這時可以查詢連線狀態
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# iw wlan0 link&lt;/span&gt;
Connected to 36:a3:95:d7:a7:55 &lt;span style=&quot;color: #333333;&quot;&gt;(&lt;/span&gt;on wlan0&lt;span style=&quot;color: #333333;&quot;&gt;)&lt;/span&gt;
 SSID: APPLE
 freq: 2437
 RX: 59639 bytes &lt;span style=&quot;color: #333333;&quot;&gt;(&lt;/span&gt;440 packets&lt;span style=&quot;color: #333333;&quot;&gt;)&lt;/span&gt;
 TX: 12188 bytes &lt;span style=&quot;color: #333333;&quot;&gt;(&lt;/span&gt;76 packets&lt;span style=&quot;color: #333333;&quot;&gt;)&lt;/span&gt;
 signal: -58 dBm
 tx bitrate: 65.0 MBit/s MCS 7

 bss flags: short-preamble short-slot-time
 dtim period: 3
 beacon int: 100&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;&lt;u&gt;要求DHCP伺服器配發動態IP&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# dhclient wlan0&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/486075285573858367/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/09/iw.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/486075285573858367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/486075285573858367'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/09/iw.html' title='iw指令連線操作記錄'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-7037787246137507528</id><published>2015-07-20T17:21:00.001+08:00</published><updated>2015-07-20T17:21:47.677+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>在Linux系統上製作Windows的USB安裝隨身碟（EFI支援的GPT格式）</title><content type='html'>不論在Linux或是Windows上要製作Linux安裝隨身碟都有現成套件可以輕易完成（如UNetbootin），但反過來要在Linux系統上製作Windows安裝隨身碟就沒這麼容易了，但也只需要幾個步驟就可以了！&lt;br /&gt;
目前還是EFI跟Legacy BIOS的接棒時期，安裝隨身碟也就分為EFI支援的GPT格式跟Legacy BIOS的MBR格式，這篇文章方法僅適用GPT格式。&lt;br /&gt;
&lt;br /&gt;
先安裝gparted套件對隨身碟進行磁區分割
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo apt-get install gparted
sudo gparted
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFR8gRr7fN0BJI0MlHEeGlPke-rKRa1JfArKrMXK5aTE3GG2J3e8N33Q-jwCC5MtSAe0JFAEW79ZnOSDAMz5FP_Rv0v06OQAsIrUx_5r2GUN-5VJBrK3umxj3fGAGfIZ4uzGuCd1O6WGY/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;272&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFR8gRr7fN0BJI0MlHEeGlPke-rKRa1JfArKrMXK5aTE3GG2J3e8N33Q-jwCC5MtSAe0JFAEW79ZnOSDAMz5FP_Rv0v06OQAsIrUx_5r2GUN-5VJBrK3umxj3fGAGfIZ4uzGuCd1O6WGY/s400/001.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;在右上角下拉式選單中，選擇隨身碟裝置。&lt;/li&gt;
&lt;li&gt;卸載隨身碟裝置&lt;br /&gt;功能列選單：Partition &amp;gt; Unmount&lt;/li&gt;
&lt;li&gt;建立Partition表格&lt;br /&gt;功能列選單：Device &amp;gt; Create Partition Table ...&lt;br /&gt;選擇&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;gpt&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;建立分割區&lt;br /&gt;功能列選單：Partition &amp;gt; New&lt;br /&gt;選擇&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;fat32&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP36as_-Dn2fkahLvpSIYipqkEhP3TmWBAJTsamwvPeXI_M9hBfZ0Zwjynxb2QFFYTNzgqybZ3rzwBNXtApOPZdBW-plquh0q4B5GR9nBanVXanyGua13cM7lkgZMZkobkiQ4ERsZj4yk/s1600/002.png&quot; imageanchor=&quot;1&quot; style=&quot;font-weight: normal; margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP36as_-Dn2fkahLvpSIYipqkEhP3TmWBAJTsamwvPeXI_M9hBfZ0Zwjynxb2QFFYTNzgqybZ3rzwBNXtApOPZdBW-plquh0q4B5GR9nBanVXanyGua13cM7lkgZMZkobkiQ4ERsZj4yk/s320/002.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;儲存變更&lt;br /&gt;Ctrl + Enter&lt;/li&gt;
&lt;li&gt;關閉gparted&lt;/li&gt;
&lt;/ol&gt;
掛載windows安裝印象檔（*.iso）並將內容複製到隨身碟
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo mkdir /mnt/iso /mnt/usb
sudo mount *.iso /mnt/iso
sudo mount /dev/sdXY /mnt/usb
sudo cp -R /mnt/iso/* /mnt/usb
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
完成上述步驟後就可以重新開機，並將開機裝置指定到隨身碟，就會進入Windows安裝界面了。目前驗證過Windows7（64-bits）與Windows8（64-bits）均能成功進入安裝畫面。</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/7037787246137507528/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/07/linuxwindowsusbefigpt.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/7037787246137507528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/7037787246137507528'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/07/linuxwindowsusbefigpt.html' title='在Linux系統上製作Windows的USB安裝隨身碟（EFI支援的GPT格式）'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFR8gRr7fN0BJI0MlHEeGlPke-rKRa1JfArKrMXK5aTE3GG2J3e8N33Q-jwCC5MtSAe0JFAEW79ZnOSDAMz5FP_Rv0v06OQAsIrUx_5r2GUN-5VJBrK3umxj3fGAGfIZ4uzGuCd1O6WGY/s72-c/001.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-6458279348554978246</id><published>2015-07-16T16:56:00.000+08:00</published><updated>2015-07-16T16:56:03.447+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>【治具】RS232 迴路測試每根Pin腳功能</title><content type='html'>RS232是個歷久不衰的訊號通訊協議，雖然在主流電腦上已經很難看見其蹤跡，但在伺服器或是嵌入式裝置乃至於近年很夯的物連網裝置都很容易見到，這篇文章主要記錄如何設計硬體治具並撰寫對應測試程式。&lt;br /&gt;
&lt;br /&gt;
首先可以先參考RS232每根Pin腳的功能用途，網路上有大量文章介紹，就不再贅述，可以參考連結：&lt;a href=&quot;http://www.ethernut.de/en/documents/rs232primer.html&quot; target=&quot;_blank&quot;&gt;Ethernut RS-232 Primer&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
先看做好的治具成品圖&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXyYgF_eGPxo1Nd07xrzDzvkTOOPl4V84bt73xCucc26HTnlYYm46O7FRoQMTcpjkydHcRPJ4CY6lALNHKMpRctIn6T-bluy3oENJ-wDG6NFkVXuR6Y5qFhszgajYVgnALsXTm1ftQO_0/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;87&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXyYgF_eGPxo1Nd07xrzDzvkTOOPl4V84bt73xCucc26HTnlYYm46O7FRoQMTcpjkydHcRPJ4CY6lALNHKMpRctIn6T-bluy3oENJ-wDG6NFkVXuR6Y5qFhszgajYVgnALsXTm1ftQO_0/s400/001.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
治具硬體Rework&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;使用4.7kOhm電阻將TxD與RxD串接起來，如果只需要驗證資料傳輸只需做這部分重工即可，大部分情況下（未使用Hardware Flow Control）其他Pin腳都不會用到。&lt;/li&gt;
&lt;li&gt;使用4.7kOhm電阻將DCD與DSR串接起來。&lt;/li&gt;
&lt;li&gt;將DSR跟DTR直接短路串接。&lt;/li&gt;
&lt;li&gt;使用4.7kOhm電阻將RI與CTS串接起來。&lt;/li&gt;
&lt;li&gt;將CTS跟RTS直接短路串接。&lt;/li&gt;
&lt;/ol&gt;
測試概念&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;從TX發送資料，硬體TxD與RxD已經串接，因此會收到送出資料，確認收到資料並比對資料內容即可確認TxD與RxD腳位功能是否正常。&lt;/li&gt;
&lt;li&gt;硬體RTS與CTS及RI串接，因此設置／重置RTS訊號，再讀取CTS與RI訊號即可確認這三根腳位功能是否正常。&lt;/li&gt;
&lt;li&gt;硬體DTR與DSR及DCD串接，因此設置／重置DTR訊號，再讀取DSR與DCD訊號即可確認這三根腳位功能是否正常。&lt;/li&gt;
&lt;/ol&gt;
程式碼實做
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #f0f0f0; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// File name: uart.c&lt;/span&gt;
&lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// gcc -o uart uart.c&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;sys/ioctl.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;#include &amp;lt;termios.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: #06287e;&quot;&gt;main&lt;/span&gt; (&lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #902000;&quot;&gt;char&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;argv[])
{
 &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;;
 &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; len;
 &lt;span style=&quot;color: #902000;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: #902000;&quot;&gt;char&lt;/span&gt; buf[&lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;] &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; {&lt;span style=&quot;color: #40a070;&quot;&gt;0xAA&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x55&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x00&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0xFF&lt;/span&gt;,
    &lt;span style=&quot;color: #40a070;&quot;&gt;0x5A&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0xA5&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0xF0&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x0F&lt;/span&gt;,
    &lt;span style=&quot;color: #40a070;&quot;&gt;0x01&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x02&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x04&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x08&lt;/span&gt;,
    &lt;span style=&quot;color: #40a070;&quot;&gt;0x10&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x20&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x40&lt;/span&gt;, &lt;span style=&quot;color: #40a070;&quot;&gt;0x80&lt;/span&gt;};
 &lt;span style=&quot;color: #902000;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: #902000;&quot;&gt;char&lt;/span&gt; buf_rev[&lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;];
 &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; fd;
 &lt;span style=&quot;color: #902000;&quot;&gt;FILE&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;*&lt;/span&gt;fp &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;NULL&lt;/span&gt;;
 &lt;span style=&quot;color: #902000;&quot;&gt;int&lt;/span&gt; status;
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;struct&lt;/span&gt; termios tio;
 
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (argc &lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;) {
  fprintf(stderr, &lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Usage: %s &amp;lt;dev&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #4070a0; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;&lt;/span&gt;, argv[&lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;]);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; end;
 }

 fp &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; fopen (argv[&lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;], &lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;w+&quot;&lt;/span&gt;);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (fp &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;NULL&lt;/span&gt;) {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Fail to open device&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; end;
 }
 
 printf (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;+ TX: &quot;&lt;/span&gt;);
 fflush (fp);
 len &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; fwrite (buf, &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;sizeof&lt;/span&gt; (&lt;span style=&quot;color: #902000;&quot;&gt;char&lt;/span&gt;), &lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;, fp);
 fflush (fp);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (len &lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;) {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Fail to transfer data&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; clean;
 }
 puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Pass&quot;&lt;/span&gt;);

 printf (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;+ RX: &quot;&lt;/span&gt;);
 len &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; fread (buf_rev, &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;sizeof&lt;/span&gt; (&lt;span style=&quot;color: #902000;&quot;&gt;char&lt;/span&gt;), &lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;, fp);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (len &lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;) {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Fail to receive data&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; clean;
 } &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (memcmp (buf, buf_rev, &lt;span style=&quot;color: #40a070;&quot;&gt;16&lt;/span&gt;) &lt;span style=&quot;color: #666666;&quot;&gt;!=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;) {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Check data fail&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; clean;
 }
 puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Pass&quot;&lt;/span&gt;);
 fclose (fp);
 fp &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;NULL&lt;/span&gt;;

 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; ( (fd &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; open (argv[&lt;span style=&quot;color: #40a070;&quot;&gt;1&lt;/span&gt;], O_RDWR)) &lt;span style=&quot;color: #666666;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt; ) {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Fail to open device&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;255&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; end;
 }

 tcgetattr(fd, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;tio);
 printf (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;RTS -&amp;gt; CTS - RI: &quot;&lt;/span&gt;);
 status &lt;span style=&quot;color: #666666;&quot;&gt;|=&lt;/span&gt; TIOCM_RTS;
 ioctl(fd, TIOCMSET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ioctl(fd, TIOCMGET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt; (TIOCM_CTS &lt;span style=&quot;color: #666666;&quot;&gt;|&lt;/span&gt; TIOCM_RNG); &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// Should be 0xA0&lt;/span&gt;

 status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;~&lt;/span&gt;TIOCM_RTS;
 ioctl(fd, TIOCMSET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ioctl(fd, TIOCMGET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; ( (status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt; (TIOCM_CTS &lt;span style=&quot;color: #666666;&quot;&gt;|&lt;/span&gt; TIOCM_RNG)) &lt;span style=&quot;color: #666666;&quot;&gt;||&lt;/span&gt; ret &lt;span style=&quot;color: #666666;&quot;&gt;!=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0xA0&lt;/span&gt;) { &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// Status should be 0x00, false&lt;/span&gt;
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;FAIL&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x0&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; Case1: RTS fail; Case2: CTR &amp;amp; RI fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x80&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; CTS fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x20&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; RI fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt;
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  -&amp;gt; RTS fail&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;6&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; clean;
 } &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;PASS&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;;
 }

 printf (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;DTR -&amp;gt; DSR - DCD: &quot;&lt;/span&gt;);
 status &lt;span style=&quot;color: #666666;&quot;&gt;|=&lt;/span&gt; TIOCM_DTR;
 ioctl(fd, TIOCMSET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ioctl(fd, TIOCMGET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt; (TIOCM_DSR &lt;span style=&quot;color: #666666;&quot;&gt;|&lt;/span&gt; TIOCM_CAR); &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// Should be 0x140&lt;/span&gt;
 status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;=&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;~&lt;/span&gt;TIOCM_DTR;
 ioctl(fd, TIOCMSET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 ioctl(fd, TIOCMGET, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt;status);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; ( (status &lt;span style=&quot;color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt; (TIOCM_DSR &lt;span style=&quot;color: #666666;&quot;&gt;|&lt;/span&gt; TIOCM_CAR)) &lt;span style=&quot;color: #666666;&quot;&gt;||&lt;/span&gt; ret &lt;span style=&quot;color: #666666;&quot;&gt;!=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x140&lt;/span&gt;) { &lt;span style=&quot;color: #60a0b0; font-style: italic;&quot;&gt;// Status should be 0x00, false&lt;/span&gt;
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;FAIL&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x0&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; Case1: DTR fail; Case2: DSR &amp;amp; DCD fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x100&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; DCD fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (ret &lt;span style=&quot;color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0x40&lt;/span&gt;)
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  --&amp;gt; DSR fail&quot;&lt;/span&gt;);
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt;
   puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;  -&amp;gt; RTS fail&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;7&lt;/span&gt;;
  &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;goto&lt;/span&gt; clean;
 } &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;else&lt;/span&gt; {
  puts (&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;PASS&quot;&lt;/span&gt;);
  ret &lt;span style=&quot;color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;;
 }

&lt;span style=&quot;color: #002070; font-weight: bold;&quot;&gt;clean:&lt;/span&gt;
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (fp)
  fclose (fp);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;if&lt;/span&gt; (fd &lt;span style=&quot;color: #666666;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #40a070;&quot;&gt;0&lt;/span&gt;)
  close (fd);
&lt;span style=&quot;color: #002070; font-weight: bold;&quot;&gt;end:&lt;/span&gt;
 printf(&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;Return Code: %d&lt;/span&gt;&lt;span style=&quot;color: #4070a0; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #4070a0;&quot;&gt;&quot;&lt;/span&gt;, ret);
 &lt;span style=&quot;color: #007020; font-weight: bold;&quot;&gt;return&lt;/span&gt; ret;
}
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
參考連結&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.tldp.org/HOWTO/Serial-HOWTO-19.html&quot; target=&quot;_blank&quot;&gt;Serial-HOWTO&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.embeddedlinux.org.cn/EmbLinux/ch06lev1sec2.htm&quot; target=&quot;_blank&quot;&gt;Linux Serial Communications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/6458279348554978246/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/07/rs232-pin.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6458279348554978246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/6458279348554978246'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/07/rs232-pin.html' title='【治具】RS232 迴路測試每根Pin腳功能'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXyYgF_eGPxo1Nd07xrzDzvkTOOPl4V84bt73xCucc26HTnlYYm46O7FRoQMTcpjkydHcRPJ4CY6lALNHKMpRctIn6T-bluy3oENJ-wDG6NFkVXuR6Y5qFhszgajYVgnALsXTm1ftQO_0/s72-c/001.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-4484739177634390838</id><published>2015-07-08T11:32:00.002+08:00</published><updated>2015-07-08T11:32:10.731+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>Trace shell script的小技巧</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmy2vUdTHQPWcRzPeQLT_fN9NWg9soNRk1lRwZZ_F6vgcQGS7VQbM4nnOlLUfbNY0EsYf6IaputI75x4PP-7pTTX4YapDGCajZn2VX9aZ2aT4rVzs0mYeLg46IQeisV_697HcT8ui9Zik/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;45&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmy2vUdTHQPWcRzPeQLT_fN9NWg9soNRk1lRwZZ_F6vgcQGS7VQbM4nnOlLUfbNY0EsYf6IaputI75x4PP-7pTTX4YapDGCajZn2VX9aZ2aT4rVzs0mYeLg46IQeisV_697HcT8ui9Zik/s400/001.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
參考上圖，有三個script，先執行test1.sh，會帶起test2.sh；test2.sh會再帶起test3.sh，如果從test1.sh開始了解程式架構，很容易就可以得知彼此之間的執行關係；但有時候線頭只抓到test2.sh或是test3.sh時就麻煩了。&lt;br /&gt;
　　在Linux下可以使用bash maintain的$PPID變數再搭配ps指令就可以慢慢推敲出script file的呼叫關係。
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;br /&gt;
直接看範例：&lt;br /&gt;
&lt;div style=&quot;background: #f8f8f8; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;# file: test1.sh&lt;/span&gt;

&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: darkgoldenrod;&quot;&gt;$0&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #bb4444;&quot;&gt;&quot;Execute by `ps -o comm -h --pid $PPID`&quot;&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
./test2.sh
&lt;/pre&gt;
&lt;/div&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #f8f8f8; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;# file: test2.sh&lt;/span&gt;

&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: darkgoldenrod;&quot;&gt;$0&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #bb4444;&quot;&gt;&quot;Execute by `ps -o comm -h --pid $PPID`&quot;&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
./test3.sh
&lt;/pre&gt;
&lt;/div&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #f8f8f8; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-style: italic;&quot;&gt;# file: test3.sh&lt;/span&gt;

&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: darkgoldenrod;&quot;&gt;$0&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #bb4444;&quot;&gt;&quot;Execute by `ps -o comm -h --pid $PPID`&quot;&lt;/span&gt;
&lt;span style=&quot;color: #aa22ff;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
執行結果：
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #f8f8f8; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;./test1.sh
Execute by &lt;span style=&quot;color: darkgoldenrod;&quot;&gt;bash&lt;/span&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
./test2.sh
Execute by test1.sh
&lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
./test3.sh
Execute by test2.sh
&lt;span style=&quot;color: #666666;&quot;&gt;===========&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/4484739177634390838/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/07/trace-shell-script.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4484739177634390838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4484739177634390838'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/07/trace-shell-script.html' title='Trace shell script的小技巧'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmy2vUdTHQPWcRzPeQLT_fN9NWg9soNRk1lRwZZ_F6vgcQGS7VQbM4nnOlLUfbNY0EsYf6IaputI75x4PP-7pTTX4YapDGCajZn2VX9aZ2aT4rVzs0mYeLg46IQeisV_697HcT8ui9Zik/s72-c/001.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-2825687318070313945</id><published>2015-07-07T20:09:00.000+08:00</published><updated>2015-07-07T20:09:09.783+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>更改Shell輸出文字的顏色、底線、粗體等控制</title><content type='html'>要在Shell輸出文字中有顏色改變、底線與粗體效果，需要用到如下的控制碼：&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&#39;\033[0;31m&#39;Hello&#39;\033[0m&#39;&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
會在螢幕上顯示紅色的Hello，但這樣要記住所有效果的代碼也不是辦法，可以將每種效果定義為一種變數，如此要調用就會簡單多了，如下可以達到相同效果：
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #996633;&quot;&gt;Red&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;31m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;NC&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Red}Hello${NC}&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
完整的效果定義
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;# File: color.sh&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# Regular Colors&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Black&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;30m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Red&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;31m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Green&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;32m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Yellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;33m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;#Orange=&#39;\033[0;33m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Blue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;34m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Purple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;35m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Cyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;36m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;White&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;37m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# Bold&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;30m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;31m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;32m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;33m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;34m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;35m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BCyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;36m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;37m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# Underline&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;30m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;URed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;31m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;32m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;33m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;34m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;35m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UCyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;36m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;UWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[4;37m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# Background&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[40m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[41m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[42m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[43m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[44m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[45m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GCyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[46m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[47m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# High Intensity&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;90m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;91m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;92m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;93m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;94m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;95m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;ICyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;96m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;IWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;97m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# Bold High Intensity&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;90m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;91m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;92m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;93m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;94m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;95m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BICyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;96m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;BIWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;97m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #888888;&quot;&gt;# High Intensity Background&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIBlack&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;100m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;101m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;102m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIYellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;103m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;104m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;105m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GICyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;106m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;GIWhite&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;107m&#39;&lt;/span&gt;

&lt;span style=&quot;color: #996633;&quot;&gt;LightGray&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0;37m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;DarkGray&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;30m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;LightRed&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;31m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;LightGreen&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;32m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;Yellow&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;33m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;LightBlue&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;34m&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;LightPurple&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;35&#39;&lt;/span&gt;
&lt;span style=&quot;color: #996633;&quot;&gt;LightCyan&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[1;36&#39;&lt;/span&gt;

&lt;span style=&quot;color: #996633;&quot;&gt;NC&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\033[0m&#39;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
效果Demo
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;# File: color_demo.sh&lt;/span&gt;
. color.sh

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Black}Black${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Red}Red${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Green}Green${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Yellow}Yellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Blue}Blue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Purple}Purple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${Cyan}Cyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${White}White${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BBlack}BBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BRed}BRed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BGreen}BGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BYellow}BYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BBlue}BBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BPurple}BPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BCyan}BCyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BWhite}BWhite${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UBlack}UBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${URed}URed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UGreen}UGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UYellow}UYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UBlue}UBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UPurple}UPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UCyan}UCyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${UWhite}UWhite${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GBlack}GBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GRed}GRed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GGreen}GGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GYellow}GYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GBlue}GBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GPurple}GPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GCyan}GCyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GWhite}GWhite${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IBlack}IBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IRed}IRed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IGreen}IGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IYellow}IYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IBlue}IBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IPurple}IPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${ICyan}ICyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${IWhite}IWhite${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIBlack}BIBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIRed}BIRed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIGreen}BIGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIYellow}BIYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIBlue}BIBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIPurple}BIPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BICyan}BICyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${BIWhite}BIWhite${NC}\n&quot;&lt;/span&gt;

&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIBlack}GIBlack${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIRed}GIRed${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIGreen}GIGreen${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIYellow}GIYellow${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIBlue}GIBlue${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIPurple}GIPurple${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GICyan}GICyan${NC}\n&quot;&lt;/span&gt;
&lt;span style=&quot;color: #007020;&quot;&gt;printf&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;${GIWhite}GIWhite${NC}\n&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
呈現結果&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMSjc_46eCFSKHp2pHFFiuIawA8Ven7M6VZN_as3-62WX266xI5GPq7OopFoqNsoE5p7k8Hw1UV6ZbDAMSupEJ2QFobqXK2LCh52sIQihyphenhyphenQOtVHsMlEjpuO0CLVMVXayEJLdh_NseknU/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMSjc_46eCFSKHp2pHFFiuIawA8Ven7M6VZN_as3-62WX266xI5GPq7OopFoqNsoE5p7k8Hw1UV6ZbDAMSupEJ2QFobqXK2LCh52sIQihyphenhyphenQOtVHsMlEjpuO0CLVMVXayEJLdh_NseknU/s640/001.png&quot; width=&quot;60&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/2825687318070313945/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/07/shell.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2825687318070313945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2825687318070313945'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/07/shell.html' title='更改Shell輸出文字的顏色、底線、粗體等控制'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMSjc_46eCFSKHp2pHFFiuIawA8Ven7M6VZN_as3-62WX266xI5GPq7OopFoqNsoE5p7k8Hw1UV6ZbDAMSupEJ2QFobqXK2LCh52sIQihyphenhyphenQOtVHsMlEjpuO0CLVMVXayEJLdh_NseknU/s72-c/001.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-9003192831608044711</id><published>2015-07-07T17:13:00.000+08:00</published><updated>2015-07-07T17:13:18.366+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>讓ssh連線不用手動輸入密碼（自動登入）</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-839g-OU6eGl-N0j4jGY6YBLaH79Nl-Wq5WcTeJH-1fvR_KRTv6o-zgxnFR_2GCP5DMlu6i_fMfYTTxDeBlaAYoRKmjKpUvApH1mcpTrl4fNqJ8ohC_fYWV7fxTNqZRzXjrAcsI6CYEU/s1600/001.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-839g-OU6eGl-N0j4jGY6YBLaH79Nl-Wq5WcTeJH-1fvR_KRTv6o-zgxnFR_2GCP5DMlu6i_fMfYTTxDeBlaAYoRKmjKpUvApH1mcpTrl4fNqJ8ohC_fYWV7fxTNqZRzXjrAcsI6CYEU/s1600/001.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
最近專案有個應用：在客戶端透過ssh自動連線到伺服器並下達命令，卻遇到了需要手動輸入密碼的問題，發現ssh有提供公私鑰機制可以免除每次登入都需要輸入密碼，設定步驟也很簡單：&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;產生金鑰：在客戶端執行
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;ssh-keygen -t rsa -b 2048
&lt;/pre&gt;
&lt;/div&gt;
過程中會出現&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;Enter passphrase&lt;/b&gt;&lt;/span&gt;提示輸入訊息，直接按Enter跳過即可&lt;/li&gt;
&lt;li&gt;將產生的公鑰內容上傳到伺服器的~/.ssh/authorized_keys檔案
&lt;!-- HTML generated using hilite.me --&gt;&lt;div style=&quot;background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;ssh-copy-id user_id@server_ip
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
只要完成上述兩個步驟就完成了，步驟2的user_id需替換成遠端連線的帳號、server_ip則是遠端連線的ip，底下稍微做一下說明：&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;步驟1會產生一組本機的公鑰與私鑰，執行完後可以在~/.ssh目錄下看到兩個檔案&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color: #e69138;&quot;&gt;&lt;b&gt;id_rsa&lt;/b&gt;&lt;/span&gt;：私鑰，之後連線會使用這私鑰進行演算後傳送到遠端進行驗證&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e69138;&quot;&gt;&lt;b&gt;id_rsa.pub&lt;/b&gt;&lt;/span&gt;：公鑰，內容會儲存在遠端的&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;~/.ssh/authorized_keys&lt;/b&gt;&lt;/span&gt;檔案內，客戶端傳來的驗證資訊會以這資訊進行驗證&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;步驟2的ssh-copy-id其實是一隻script（/usr/bin/ssh-copy-id），功能就是把id_rsa.pub內容幫忙存到遠端的&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;~/.ssh/authorized_keys&lt;/b&gt;&lt;/span&gt;檔案內。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/9003192831608044711/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/07/ssh.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/9003192831608044711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/9003192831608044711'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/07/ssh.html' title='讓ssh連線不用手動輸入密碼（自動登入）'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-839g-OU6eGl-N0j4jGY6YBLaH79Nl-Wq5WcTeJH-1fvR_KRTv6o-zgxnFR_2GCP5DMlu6i_fMfYTTxDeBlaAYoRKmjKpUvApH1mcpTrl4fNqJ8ohC_fYWV7fxTNqZRzXjrAcsI6CYEU/s72-c/001.PNG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-4782628638845975009</id><published>2015-06-01T19:50:00.000+08:00</published><updated>2015-06-01T19:50:07.148+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><title type='text'>【QEMU】在X86 PC上執行其他平台（如ARM）程式</title><content type='html'>情境：要在X86 PC上透過QEMU模擬器執行ARM的程式。&lt;br /&gt;
&lt;br /&gt;
先透過file指令確認執行程式的格式內容為ARM平台所用
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;$ &lt;/span&gt;file hello
hello: ELF 32-bit LSB  executable, ARM, EABI5 version 1 &lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;SYSV&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;, dynamically linked &lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;uses shared libs&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;, &lt;span style=&quot;color: #cdcd00;&quot;&gt;for &lt;/span&gt;GNU/Linux 2.6.32, BuildID&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt;sha1&lt;span style=&quot;color: #3399cc;&quot;&gt;]=&lt;/span&gt;d7efe6f9528e036c383501d6fc0dd1ca6fc880b1, not stripped
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
qemu最後面加上要執行的程式即可，中間options視需求加入適當的參數
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;usage: qemu-arm &lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt;options&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; program &lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt;arguments...&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
先直接執行看看
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;$ &lt;/span&gt;qemu-arm ./hello
/lib/ld-linux.so.3: No such file or directory
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
qemu不知道去哪裡載入loader，手動指定路徑後再執行看看&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;$ &lt;/span&gt;qemu-arm /usr/arm-linux-gnueabi/lib/ld-2.19.so ./hello
./hello: error &lt;span style=&quot;color: #cdcd00;&quot;&gt;while &lt;/span&gt;loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
這時loader需要載入相關library，手動指定動態鏈結檔目錄再執行看看
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;$ &lt;/span&gt;qemu-arm /usr/arm-linux-gnueabi/lib/ld-2.19.so --library-path /usr/arm-linux-gnueabi/lib ./hello
Hello World
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
這時應該就可以看到正確執行結果了！</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/4782628638845975009/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/06/qemux86-pcarm.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4782628638845975009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4782628638845975009'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/06/qemux86-pcarm.html' title='【QEMU】在X86 PC上執行其他平台（如ARM）程式'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-4462963121322840196</id><published>2015-04-27T17:27:00.001+08:00</published><updated>2015-04-27T17:27:36.815+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>【Ubuntu】架設PXE Server</title><content type='html'>PXE開機運作原理是Bootloader（PC來說就是BIOS）在開機時動態要求分配IP，在取得IP資訊同時也會收到下一個伺服器的位址與該讀取的檔案資訊，接著透過TFTP服務取得開機核心與檔案系統。所以一台伺服器要提供PXE功能，至少要有DHCP與TFTP伺服器功能，首先安裝這兩個套件：
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo apt-get install isc-dhcp-server
apt-get install tftpd-hpa inetutils-inetd
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
指定提供DHCP服務的網路卡
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo vi /etc/default/isc-dhcp-server
&lt;/pre&gt;
&lt;/div&gt;
將interface指定為eth0
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;INTERFACES&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;eth0&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
設定DHCP服務
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo vi /etc/dhcp/dhcpd.conf
&lt;/pre&gt;
&lt;/div&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;# option definitions common to all supported networks...&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#option domain-name &quot;example.org&quot;;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#option domain-name-servers ns1.example.org, ns2.example.org;&lt;/span&gt;

subnet 192.168.0.0 netmask 255.255.255.0 &lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
  range 192.168.0.100 192.168.0.253;
  option routers 192.168.0.254;
  option broadcast-address 192.168.0.255;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;
allow booting;
allow bootp;
option option-128 code &lt;span style=&quot;color: #00cdcd;&quot;&gt;128&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; string;
option option-129 code &lt;span style=&quot;color: #00cdcd;&quot;&gt;129&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; text;
next-server 192.168.0.254;
filename &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;pxelinux.0&quot;&lt;/span&gt;;

default-lease-time 600;
max-lease-time 7200;
&lt;/pre&gt;
&lt;/div&gt;
若有domain name資訊則填入正確資訊，否則將相關兩的兩行敘述註解起來，否則啟動DHCP服務可能會帶不起來。這邊設定IP分配會從192.168.0.100到192.168.0.253，並指定client端取得IP資訊後接著要向192.168.0.254伺服器要求檔案pxelinux.0。&lt;br /&gt;
完成設定後重新啟動DHCP服務
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo service isc-dhcp-server restart
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
修改tftp設定
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo vi /etc/default/tftpd-hpa
&lt;/pre&gt;
&lt;/div&gt;
增加敘述：
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #00cdcd;&quot;&gt;RUN_DAEMON&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;yes&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
修改inet.conf
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo vi /etc/inetd.conf
&lt;/pre&gt;
&lt;/div&gt;
增加敘述
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;tftp dgram udp &lt;span style=&quot;color: #cd00cd;&quot;&gt;wait &lt;/span&gt;root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
重新啟動tftp服務
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo service tftpd-hpa restart
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
到這邊PXE服務就算設定完成了，這時在client端選擇網路開機，應該會成功取得IP配置，但會卡在取得檔案階段，底下說明使用ubuntu server的安裝光碟裡面提供的netboot檔案，讓client可以透過PXE服務開啟安裝程式。
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;br /&gt;
掛載安裝印象檔，並將需要的檔案複製到tftp目錄即可
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo mount ubuntu-14.10-server-amd64.iso /mnt
sudo cp -avr /mnt/install/netboot/* /var/lib/tftpboot/
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
這時client在選擇網路開機，就可以進到ubuntu安裝畫面了！</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/4462963121322840196/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/ubuntupxe-server.html#comment-form' title='3 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4462963121322840196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/4462963121322840196'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/ubuntupxe-server.html' title='【Ubuntu】架設PXE Server'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-8105388692555497593</id><published>2015-04-23T19:52:00.003+08:00</published><updated>2015-04-23T19:53:11.176+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【樹莓派】寫Driver控制GPIO</title><content type='html'>　　控制RPi的GPIO方法很多，在User Space下可以透過讀寫/dev/mem或是/sys/class/gpio來控制輸出與讀取狀態；在Kernel Space下就要自己寫一個Driver（或稱為核心模組）來實現了！另外有高手寫了&lt;a href=&quot;http://wiringpi.com/&quot; target=&quot;_blank&quot;&gt;WiringPi&lt;/a&gt;讓大家可以簡單透過python來實現IO控制（包括I2C與SPI），也提供API讓C語言之類的程式進行調用。&lt;br /&gt;
　　這篇文章提供一個簡單的範例，示範如何寫一個驅動程式控制RPi的GPIO。&lt;br /&gt;
　　首先查看電路圖（&lt;a href=&quot;https://www.raspberrypi.org/documentation/hardware/raspberrypi/schematics/README.md&quot; target=&quot;_blank&quot;&gt;Schematic&lt;/a&gt;），挑選GPIO_GEN0來連接LED燈正極，並將LED負極接到旁邊的地（Ground，Pin9），如此一來把Pin11設為1就會點亮LED燈，設為0就會讓LED熄滅。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8xzIBqXQjgEhk8hZklh5Q8l_DTqlfNkAxaMIr48jWuU9GEsgueVMFsrTQfQ8lyyfUWDjgQ81d3lrL2faV89cTr4ExP-Tblg4fZQZ_uTDjVG7IKLfrBv6RO_Y7nLZSpi6GjCdvzdOkKx4/s1600/001.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8xzIBqXQjgEhk8hZklh5Q8l_DTqlfNkAxaMIr48jWuU9GEsgueVMFsrTQfQ8lyyfUWDjgQ81d3lrL2faV89cTr4ExP-Tblg4fZQZ_uTDjVG7IKLfrBv6RO_Y7nLZSpi6GjCdvzdOkKx4/s1600/001.PNG&quot; height=&quot;373&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
　　上圖的GPIO_GEN0是Pin11，但這個Pin11指的是P1這個連接頭（Header）的編號，實際上我們要控制的是BCM2835（RPi的ARM核心）接腳，所以得在電路圖上找尋GPIO_GEN0在核心上對應的GPIO編號，查看下圖得知是&lt;b&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;GPIO17&lt;/span&gt;&lt;/b&gt;。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PZNbibiN-zEMhKDHqQn-g8tyLgLNQTuPWn3l9IogsVL1eYenRLg_4qdiJ3pYjOhb6sjzjdNAm0f08IJVd_go_ZBTPqqwyHZvB-mtM2w3mdke3GJm-kWGfpQlgF7iMcseAugp1skYiaQ/s1600/002.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PZNbibiN-zEMhKDHqQn-g8tyLgLNQTuPWn3l9IogsVL1eYenRLg_4qdiJ3pYjOhb6sjzjdNAm0f08IJVd_go_ZBTPqqwyHZvB-mtM2w3mdke3GJm-kWGfpQlgF7iMcseAugp1skYiaQ/s1600/002.PNG&quot; height=&quot;400&quot; width=&quot;350&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
確定好要控制的GPIO編號後，就可以來撰寫驅動程式了，直接看Code
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
rpi.c&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/module.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/kernel.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/init.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/interrupt.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/gpio.h&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: navy;&quot;&gt;#define DRIVER_AUTHOR    &quot;YS Wang &amp;lt;yaushung AT gmail.com&amp;gt;&quot;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#define DRIVER_DESC    &quot;RPi GPIO Output Demo&quot;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#define GPIO0_PIN    17&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#define GPIO0_DESC    &quot;GPIO0&quot;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#define GPIO0_DEVICE_DESC   &quot;GPIO17Output&quot;&lt;/span&gt;

MODULE_LICENSE&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Dual BSD/GPL&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
MODULE_AUTHOR&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;DRIVER_AUTHOR&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
MODULE_DESCRIPTION&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;DRIVER_DESC&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;

int rpi_init&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;void&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
 printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;KERN_NOTICE &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Hello, RPi !\n&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
 
 &lt;span style=&quot;color: #cdcd00;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;gpio_request&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;GPIO0_PIN, GPIO0_DESC&lt;span style=&quot;color: #3399cc;&quot;&gt;))&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
  printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;[%s] Request fail\n&quot;&lt;/span&gt;, GPIO0_DESC&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
  &lt;span style=&quot;color: #cdcd00;&quot;&gt;return&lt;/span&gt; -EIO;
 &lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;

 printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;KERN_ALERT &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;[%s] Request Pin%d ... Success.\n&quot;&lt;/span&gt;,
  GPIO0_DESC, GPIO0_PIN&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;

 gpio_direction_output&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;GPIO0_PIN, 1&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;

 &lt;span style=&quot;color: #cdcd00;&quot;&gt;return &lt;/span&gt;0;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;

void rpi_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;void&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
 printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;KERN_ALERT &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Goodbye, RPi\n&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
 gpio_direction_output&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;GPIO0_PIN, 0&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
 gpio_free&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;GPIO0_PIN&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
 &lt;span style=&quot;color: #cdcd00;&quot;&gt;return&lt;/span&gt;;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;

module_init&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;rpi_init&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
module_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;rpi_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;
Makefile
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-&lt;/span&gt;

&lt;span style=&quot;color: #00cdcd;&quot;&gt;CFILES&lt;/span&gt;  &lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; rpi.c

obj-m +&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; rpi.o
sample-objs :&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cdcd00;&quot;&gt;$(&lt;/span&gt;CFILES:.c&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;.o&lt;span style=&quot;color: #cdcd00;&quot;&gt;)&lt;/span&gt;

all:
 make -C /home/acos/rpi/linux &lt;span style=&quot;color: #00cdcd;&quot;&gt;M&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cdcd00;&quot;&gt;$(&lt;/span&gt;PWD&lt;span style=&quot;color: #cdcd00;&quot;&gt;)&lt;/span&gt; modules

clean:
 make -C /home/acos/rpi/linux &lt;span style=&quot;color: #00cdcd;&quot;&gt;M&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cdcd00;&quot;&gt;$(&lt;/span&gt;PWD&lt;span style=&quot;color: #cdcd00;&quot;&gt;)&lt;/span&gt; clean
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
直接下make（&lt;span style=&quot;color: navy; font-size: 13.1999998092651px; line-height: 16.5px;&quot;&gt;make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-&lt;/span&gt;）指令就會產生rpi.ko模組檔案，接著把檔案複製到RPi上執行&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo insmod rpi.ko      &lt;span style=&quot;color: navy;&quot;&gt;# 模組載入，這時會看到LED點亮&lt;/span&gt;
sudo rmmod rpi      &lt;span style=&quot;color: navy;&quot;&gt;# 模組卸除，這時會看到LED熄滅&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
編譯環境設置可以參考這篇&lt;a href=&quot;http://inpega.blogspot.tw/2015/04/hello-kernel-moduledriver.html&quot; target=&quot;_blank&quot;&gt;文章&lt;/a&gt;。</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/8105388692555497593/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/drivergpio.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/8105388692555497593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/8105388692555497593'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/drivergpio.html' title='【樹莓派】寫Driver控制GPIO'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8xzIBqXQjgEhk8hZklh5Q8l_DTqlfNkAxaMIr48jWuU9GEsgueVMFsrTQfQ8lyyfUWDjgQ81d3lrL2faV89cTr4ExP-Tblg4fZQZ_uTDjVG7IKLfrBv6RO_Y7nLZSpi6GjCdvzdOkKx4/s72-c/001.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-3488723527378654687</id><published>2015-04-20T10:47:00.003+08:00</published><updated>2015-04-20T10:47:47.804+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【樹莓派】架設DHCP Server</title><content type='html'>首先安裝DHCP Server套件
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo apt-get install isc-dhcp-server
&lt;/pre&gt;
&lt;/div&gt;
安裝完畢系統會嘗試帶起服務，但設定都還沒弄好所以會看到錯誤訊息，忽略即可。
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt;FAIL&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; Starting ISC DHCP server: dhcpd&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt;....&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; check syslog &lt;span style=&quot;color: #cdcd00;&quot;&gt;for &lt;/span&gt;diagnostics. ... failed!
 failed!
invoke-rc.d: initscript isc-dhcp-server, action &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;start&quot;&lt;/span&gt; failed.
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
設定eth0網卡IP為192.168.0.1，修改&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;/etc/network/interfaces&lt;/b&gt;&lt;/span&gt;文件
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#iface eth0 inet dhcp&lt;/span&gt;
allow-hotplug eth0
iface eth0 inet static
  address 192.168.0.1
  netmask 255.255.255.0
  gateway 192.168.0.1
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
設定dhcp組態文件&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;/etc/dhcp/dhcpd.conf&lt;/b&gt;&lt;/span&gt;，文件中有很多範例可以參考，依據自己需求挑一個合適的範本進行設定，這裡讓Server會配發192.168.0.200到192.168.0.253之間的IP給Client端&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;subnet 192.168.0.0 netmask 255.255.255.0 &lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
  range 192.168.0.200 192.168.0.253;
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name-servers 168.95.1.1;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
編輯&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;/etc/default/isc-dhcp-server&lt;/b&gt;&lt;/span&gt;文件，指定提供DHCP服務的網卡，找到&lt;span style=&quot;color: #e69138;&quot;&gt;&lt;b&gt;INTERFACES&lt;/b&gt;&lt;/span&gt;敘述，填上eth0
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#       Separate multiple interfaces with spaces, e.g. &quot;eth0 eth1&quot;.&lt;/span&gt;
&lt;span style=&quot;color: #00cdcd;&quot;&gt;INTERFACES&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;eth0&quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
最後重新啟動服務，看到ok就表示服務正常啟動了
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo service isc-dhcp-server restart
&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt; ok &lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; Stopping ISC DHCP server: dhcpd.
&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt; ok &lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; Starting ISC DHCP server: dhcpd.
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
這時接上一台電腦應該就會自動獲取RPi指派的IP了，可以搭配【&lt;a href=&quot;http://inpega.blogspot.tw/2015/04/blog-post_18.html&quot; target=&quot;_blank&quot;&gt;無線網路轉送有線網路橋接&lt;/a&gt;】設定封包轉送服務，這樣RPi就可以當作一台簡易的無線轉有線橋接器！</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/3488723527378654687/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/dhcp-server.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3488723527378654687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3488723527378654687'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/dhcp-server.html' title='【樹莓派】架設DHCP Server'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-3488176506940693852</id><published>2015-04-18T18:20:00.000+08:00</published><updated>2015-04-18T18:20:01.004+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【樹莓派】無線網路轉送有線網路橋接</title><content type='html'>參考下圖，需求是讓RPi連接無線的網路訊號並用網路線連接到一台電腦，讓電腦能夠透過樹莓派來上網。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvyURfFvCoMm30jagg5AWoYhqE4VAu3GZw4hxoqCWowv5KBhCjuu33Edtfk1urElKnYT8q0wVclFGBWL8FcjGV1ix8xWEtFkCqZagiaz2IADvdOK-xvzMhG6j-uB6p6qzMLz4S9-F-0Ek/s1600/001.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvyURfFvCoMm30jagg5AWoYhqE4VAu3GZw4hxoqCWowv5KBhCjuu33Edtfk1urElKnYT8q0wVclFGBWL8FcjGV1ix8xWEtFkCqZagiaz2IADvdOK-xvzMhG6j-uB6p6qzMLz4S9-F-0Ek/s1600/001.bmp&quot; height=&quot;283&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
無線網路的設定可以參考【&lt;a href=&quot;http://inpega.blogspot.tw/2013/09/blog-post_15.html&quot; target=&quot;_blank&quot;&gt;設定無線網路&lt;/a&gt;】，這篇文章著重在有線的網路封包轉傳。在Linux上要實現封包轉送只需要設定好iptable就可以了！&lt;br /&gt;
&lt;br /&gt;
首先編&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;/etc/sysctl.conf&lt;/b&gt;&lt;/span&gt;檔案，將net.ipv4.ip_forward=1這行註解拿掉
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;# Uncomment the next line to enable packet forwarding for IPv4&lt;/span&gt;
net.ipv4.ip_forward&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;1
&lt;/pre&gt;
&lt;/div&gt;
重新載入設定檔，讓設定生效
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sysctl --system
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
完成上述動作RPi的iptable功能就被啟動了，接著設定RPi的eth0網卡IP設定為192.168.0.1&lt;br /&gt;
，修改/etc/network/interfaces
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#iface eth0 inet dhcp&lt;/span&gt;
allow-hotplug eth0
iface eth0 inet static
  address 192.168.0.1
  network 192.168.0.0
  netmask 255.255.255.0
  broadcast 192.168.0.255
  gateway 192.168.0.1
&lt;/pre&gt;
&lt;/div&gt;
修改後重新啟動eth0
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;ifconfig eth0 down
ifconfig eth0 up
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
最後設定iptable，在家目錄下編輯一個新檔nat.sh
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span style=&quot;color: #00cdcd;&quot;&gt;IPT&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;/sbin/iptables
&lt;span style=&quot;color: #00cdcd;&quot;&gt;LOCAL_IFACE&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;eth0
&lt;span style=&quot;color: #00cdcd;&quot;&gt;INET_IFACE&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;wlan0
&lt;span style=&quot;color: #00cdcd;&quot;&gt;INET_ADDRESS&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;`&lt;/span&gt;ifconfig wlan0 | grep &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;inet addr&quot;&lt;/span&gt; | cut -d &lt;span style=&quot;color: #cd0000;&quot;&gt;&#39; &#39;&lt;/span&gt; -f 12 | cut -d : -f 2&lt;span style=&quot;color: #cd0000;&quot;&gt;`&lt;/span&gt;

&lt;span style=&quot;color: navy;&quot;&gt;# Flush the tables&lt;/span&gt;
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -F INPUT
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -F OUTPUT
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -F FORWARD

&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -t nat -P PREROUTING ACCEPT
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -t nat -P POSTROUTING ACCEPT
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -t nat -P OUTPUT ACCEPT

&lt;span style=&quot;color: navy;&quot;&gt;# Allow forwarding packets:&lt;/span&gt;
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -A FORWARD -p ALL -i &lt;span style=&quot;color: #00cdcd;&quot;&gt;$LOCAL_IFACE&lt;/span&gt; -j ACCEPT
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -A FORWARD -i &lt;span style=&quot;color: #00cdcd;&quot;&gt;$INET_IFACE&lt;/span&gt; -m state --state ESTABLISHED,RELATED -j ACCEPT

&lt;span style=&quot;color: navy;&quot;&gt;# Packet masquerading&lt;/span&gt;
&lt;span style=&quot;color: #00cdcd;&quot;&gt;$IPT&lt;/span&gt; -t nat -A POSTROUTING -o &lt;span style=&quot;color: #00cdcd;&quot;&gt;$INET_IFACE&lt;/span&gt; -j SNAT --to-source &lt;span style=&quot;color: #00cdcd;&quot;&gt;$INET_ADDRESS&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
執行nat.sh
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;chmod +x ~/nat.sh
~/nat.sh
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
到這裡一切就設定完成了，接著在電腦端設定固定IP（ex. 192.168.0.2）、路由與DNS等資訊就可以透過RPi上網了。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEVBgcynyHfVrSvT8FbyMG4Tu7Us7KW7im8_8GFDWCnJ4y_F8w5pp_uwheksizX1wkI5njxYukg5DOH0LtbuEgeEOqgzNhpwY-9w4WgV5ZhieL9k9KnR6bQ7YDHlnsLRS-BC5swUWAGrI/s1600/001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEVBgcynyHfVrSvT8FbyMG4Tu7Us7KW7im8_8GFDWCnJ4y_F8w5pp_uwheksizX1wkI5njxYukg5DOH0LtbuEgeEOqgzNhpwY-9w4WgV5ZhieL9k9KnR6bQ7YDHlnsLRS-BC5swUWAGrI/s1600/001.png&quot; height=&quot;400&quot; width=&quot;363&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/3488176506940693852/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/blog-post_18.html#comment-form' title='3 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3488176506940693852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/3488176506940693852'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/blog-post_18.html' title='【樹莓派】無線網路轉送有線網路橋接'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvyURfFvCoMm30jagg5AWoYhqE4VAu3GZw4hxoqCWowv5KBhCjuu33Edtfk1urElKnYT8q0wVclFGBWL8FcjGV1ix8xWEtFkCqZagiaz2IADvdOK-xvzMhG6j-uB6p6qzMLz4S9-F-0Ek/s72-c/001.bmp" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-619983425346514764</id><published>2015-04-18T15:08:00.000+08:00</published><updated>2015-04-18T15:08:07.202+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【樹莓派】編譯一個Hello Kernel Module（Driver）</title><content type='html'>　　編譯Driver給RPi使用需要準備Toolchain與Kernel Source Tree，步驟可以參考【&lt;a href=&quot;http://inpega.blogspot.tw/2015/04/kernel.html&quot; target=&quot;_blank&quot;&gt;重編Kernel，客制化自己的核心&lt;/a&gt;】，以下範例目錄結構為&lt;br /&gt;
&amp;nbsp;/home/acos&lt;br /&gt;
--+ rpi&lt;br /&gt;
----+ linux: 存放Kernel Source&lt;br /&gt;
----+ tools: 存放Toolchain&lt;br /&gt;
----+ driver: 存放此範例檔案hello.c與Makefile&lt;br /&gt;
&lt;br /&gt;
hello.c
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/module.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#include &amp;lt;linux/init.h&amp;gt;&lt;/span&gt;

MODULE_LICENSE&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Dual BSD/GPL&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;

static int hello_init&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;void&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
 printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;KERN_ALERT &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Hello, RPi!\n&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;

 &lt;span style=&quot;color: #cdcd00;&quot;&gt;return &lt;/span&gt;0;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;

static void hello_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;void&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;
&lt;span style=&quot;color: #3399cc;&quot;&gt;{&lt;/span&gt;
 printk&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;KERN_ALERT &lt;span style=&quot;color: #cd0000;&quot;&gt;&quot;Goodbye, RPi\n&quot;&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
&lt;span style=&quot;color: #3399cc;&quot;&gt;}&lt;/span&gt;

module_init&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;hello_init&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
module_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;(&lt;/span&gt;hello_exit&lt;span style=&quot;color: #3399cc;&quot;&gt;)&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Makefile
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;obj-m :&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt; hello.o

all:
 make -C /home/acos/rpi/linux &lt;span style=&quot;color: #00cdcd;&quot;&gt;M&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cdcd00;&quot;&gt;$(&lt;/span&gt;PWD&lt;span style=&quot;color: #cdcd00;&quot;&gt;)&lt;/span&gt; modules

clean:
 make -C /home/acos/rpi/linux &lt;span style=&quot;color: #00cdcd;&quot;&gt;M&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #cdcd00;&quot;&gt;$(&lt;/span&gt;PWD&lt;span style=&quot;color: #cdcd00;&quot;&gt;)&lt;/span&gt; clean
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
進到driver目錄下執行
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;make &lt;span style=&quot;color: #00cdcd;&quot;&gt;ARCH&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;arm &lt;span style=&quot;color: #00cdcd;&quot;&gt;CROSS_COMPILE&lt;/span&gt;&lt;span style=&quot;color: #3399cc;&quot;&gt;=&lt;/span&gt;arm-linux-gnueabihf-
&lt;/pre&gt;
&lt;/div&gt;
結束後會在目錄中看到hello.ko，將這檔案複製到RPi上進行載入與卸除動作就會看到對應訊息
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;root@raspberrypi:~# insmod hello.ko
&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt; 5835.187137&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; Hello, RPi!
root@raspberrypi:~# rmmod hello
&lt;span style=&quot;color: #3399cc;&quot;&gt;[&lt;/span&gt; 5842.134762&lt;span style=&quot;color: #3399cc;&quot;&gt;]&lt;/span&gt; Goodbye, RPi
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/619983425346514764/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/hello-kernel-moduledriver.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/619983425346514764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/619983425346514764'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/hello-kernel-moduledriver.html' title='【樹莓派】編譯一個Hello Kernel Module（Driver）'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1102978090826895217.post-2776658056393129811</id><published>2015-04-17T17:59:00.002+08:00</published><updated>2015-04-17T17:59:29.043+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Raspberry Pi"/><title type='text'>【樹莓派】開機自動登入</title><content type='html'>要讓RPi自動登入並執行預設程式很簡單，只需要修改/etc/inittab檔案與登入帳號家目錄下的.profile檔案即可。&lt;br /&gt;
&lt;br /&gt;
首先設定自動登入，編輯/etc/inittab檔案：
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;sudo vi /etc/inittab
&lt;/pre&gt;
&lt;/div&gt;
把最後一行敘述T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100註解起來，並加入T0:23:respawn:/bin/login -f pi ttyAMA0 &amp;lt;/dev/ttyAMA0 &amp;gt;/dev/ttyAMA0 2&amp;gt;&amp;amp;1
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;#Spawn a getty on Raspberry Pi serial line&lt;/span&gt;
&lt;span style=&quot;color: navy;&quot;&gt;#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100&lt;/span&gt;
T0:23:respawn:/bin/login -f pi ttyAMA0 &amp;lt;/dev/ttyAMA0 &amp;gt;/dev/ttyAMA0 2&amp;gt;&amp;amp;1
&lt;/pre&gt;
&lt;/div&gt;
存檔重開機，就會自動使用pi帳號完成登入，若想要以root身分自動登入，則將上面敘述的pi改為root即可。&lt;br /&gt;
&lt;br /&gt;
自動登入後若想自動執行程式，可以從&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;b&gt;~/.profile&lt;/b&gt;&lt;/span&gt;帶起。</content><link rel='replies' type='application/atom+xml' href='http://inpega.blogspot.com/feeds/2776658056393129811/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://inpega.blogspot.com/2015/04/blog-post_17.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2776658056393129811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1102978090826895217/posts/default/2776658056393129811'/><link rel='alternate' type='text/html' href='http://inpega.blogspot.com/2015/04/blog-post_17.html' title='【樹莓派】開機自動登入'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>