Wednesday, August 31, 2016

Jekyll 一些問題解法

用github架Jekyll 一些問題解法

當一開始使用

jekyll serve
view raw jekyll serve hosted with ❤ by GitHub

的時候,可能會遇到一些問題(其實是我遇到的啦)

jekyll serve not found

這是一個很好處理的問題,因爲你的~/.gem/ruby/{version}/bin資料夾沒有在$PATH路徑下。加上去就可解決了。

缺少bundler
kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)

大概的error如上。處理方式很簡單,就是安裝bundler。


$gem install bundler

這樣就解決了。
如果還有以下錯誤:
resolver.rb:356:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'jekyll-sitemap' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)
則多下一行指令:
$ bundle install --path vendor/bundle

invalid date ...YAML..

跑jekyll serve的時候可能會有噴出一堆如下的錯誤。

Invalid date '<%= Time.now.strftime('%Y-%m-%d %H:%M:%S %z') %>': Document 'vendor/bundle/ruby/2.3.0/gems/jekyll-3.2.1/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb' does not have a valid date in the YAML front matter.
view raw YAML error hosted with ❤ by GitHub

處理方法稍微麻煩一點。找到repo底下的_config.yml檔案,在約第五行
...
...
...exclude:[......,"vendor"...]
的exclude中加入vendor。

一些asset link出錯

我自己在架的時候他的一些bootstrap的css和js檔案link不到,原因是它要link的連結在
assets/themes/bootstrap-3下,但其原本目錄並沒有這個子目錄,所以在assets/themes下建立bootstrap-3,並將原本的bootstrap移到底下。



Wednesday, August 24, 2016

HackNTU2016小小心得

HackNTU2016小小心得

其實我本身已經去過去年(2015)的HackNTU了,所以這篇文章會稍微比較這兩年。HackNTU為台灣規模最大的hackthon,但其核心價值已經逐漸遠離黑客松的"合作"、"效率"、"有用"、"有趣"的精神了。hackNTU逐漸變成一種比賽,創業比賽。我個人認為有好有壞。好處讓hacker可以更有商業頭腦,除了設計搞怪小東西外,還可以走進市場,同時,由於評審來自商業界,有種吸引創投的fu。壞處當然就是過度商業化得黑客松已經變成創業松,一堆人拿早就跑很久的專案進來投,失去了黑客松該有的短期高效合作模式,另外過度傾向賺錢,偏離了其實這是一個技術性活動,一些不好的事情就這樣發生了:"簡報松"、"不會coding只做簡報拿獎"、"SetTimeout"。這樣失去了hacker們自我實現與實做的目標了。

今年由於受到COSCUP的撞期影響,人數大減3~4成,加上去年的風評不佳(評審問了『你怎麼賺錢』、『你怎麼make money』、『你的business model是什麼』)造成在社群間不好的名聲流傳。不過今年其實沒這個問題,評審都問一些本質與技術,這是一個好現象。可能因為人數大減的原因,使得今年食物較少(食物也是黑客松的精華阿),肥宅我的心得試吃不飽。

今年贊助廠商變多,變得多元,不過兩排排了一排攤位,大投影牆還播著廣告,害我以為我來到世貿之類的地方了XD。

Tuesday, August 16, 2016

[tools]GNU 開發工具:nm

[tools]GNU 開發工具:nm

nm

nm這東西是來列出object files(binary file)的符號(symbol),包括列出地址(address)、類型、名稱。
以下我打了一個範例。

#include<stdio.h>
void foo(){
printf("bar");
}
int Global_var;
int Global_var_init = 0;
int main()
{
int local_var;
int local_var_init = 0;
int a = local_var_init + Global_var_init;
foo();
}

接下來是對其編譯出來的a.out下nm指令的結果。


0000000000601030 B __bss_start
0000000000601030 b completed.6916
0000000000601020 D __data_start
0000000000601020 W data_start
0000000000400430 t deregister_tm_clones
00000000004004b0 t __do_global_dtors_aux
0000000000600e10 t __do_global_dtors_aux_fini_array_entry
0000000000601028 D __dso_handle
0000000000600e20 d _DYNAMIC
0000000000601030 D _edata
0000000000601040 B _end
00000000004005b4 T _fini
00000000004004f6 T foo
00000000004004d0 t frame_dummy
0000000000600e08 t __frame_dummy_init_array_entry
0000000000400718 r __FRAME_END__
0000000000601000 d _GLOBAL_OFFSET_TABLE_
0000000000601038 B Global_var
0000000000601034 B Global_var_init
w __gmon_start__
00000000004005c8 r __GNU_EH_FRAME_HDR
00000000004003c8 T _init
0000000000600e10 t __init_array_end
0000000000600e08 t __init_array_start
00000000004005c0 R _IO_stdin_used
0000000000600e18 d __JCR_END__
0000000000600e18 d __JCR_LIST__
00000000004005b0 T __libc_csu_fini
0000000000400540 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
000000000040050c T main
U printf@@GLIBC_2.2.5
0000000000400470 t register_tm_clones
0000000000400400 T _start
0000000000601030 D __TMC_END__
view raw nm_out_test hosted with ❤ by GitHub

第一列為地址,第二列為類型,第三列為名稱。類型部份可以man一下nm。以下是擷取自man nm。

DESCRIPTION
GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out.
For each symbol, nm shows:
· The symbol value, in the radix selected by options (see below), or hexadecimal by default.
· The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase,
the symbol is usually local; if uppercase, the symbol is global (external). There are however a few lowercase symbols that are
shown for special global symbols ("u", "v" and "w").
"A" The symbol's value is absolute, and will not be changed by further linking.
"B"
"b" The symbol is in the uninitialized data section (known as BSS).
"C" The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same
name. If the symbol is defined anywhere, the common symbols are treated as undefined references.
"D"
"d" The symbol is in the initialized data section.
"G"
"g" The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small
data objects, such as a global int variable as opposed to a large global array.
"i" For PE format files this indicates that the symbol is in a section specific to the implementation of DLLs. For ELF format
files this indicates that the symbol is an indirect function. This is a GNU extension to the standard set of ELF symbol types.
It indicates a symbol which if referenced by a relocation does not evaluate to its address, but instead must be invoked at
runtime. The runtime execution will then return the value to be used in the relocation.
"I" The symbol is an indirect reference to another symbol.
"N" The symbol is a debugging symbol.
"p" The symbols is in a stack unwind section.
"R"
"r" The symbol is in a read only data section.
"S"
"s" The symbol is in an uninitialized data section for small objects.
"T"
"t" The symbol is in the text (code) section.
"U" The symbol is undefined.
"u" The symbol is a unique global symbol. This is a GNU extension to the standard set of ELF symbol bindings. For such a symbol
the dynamic linker will make sure that in the entire process there is just one symbol with this name and type in use.
"V"
"v" The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is
used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes
zero with no error. On some systems, uppercase indicates that a default value has been specified.
"W"
"w" The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is
linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked
and the symbol is not defined, the value of the symbol is determined in a system-specific manner without error. On some
systems, uppercase indicates that a default value has been specified.
"-" The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the
stabs desc field, and the stab type. Stabs symbols are used to hold debugging information.
"?" The symbol type is unknown, or object file format specific.
· The symbol name.
view raw man_nm hosted with ❤ by GitHub

這個工具可以幫助我們了解object file的資料layout,函式定義等,對於無source code只有object files的開發者來說十分方便(有source code可用compiler的參數來分析)。

nm可以幫助我們分析undefined reference狀況與data的分區(bss,text,data)。

相關連結:1.http://www.wuzesheng.com/?p=1595
                 2.http://sp1.wikidot.com/elfobjfile
                 3.http://enginechang.logdown.com/posts/248172-linker-loader-library
            4.https://github.com/torvalds/linux/blob/9256d5a308c95a50c6e85d682492ae1f86a70f9b/arch/powerpc/boot/elf.h

用Compiler Explorer學習C/C++的效能與實做

用Compiler Explorer學習C/C++的效能與實做

今天我發現一個網站:compiler explorer,這個網站可以將C和C++即時編譯為組語,而且寒可以選AT&T語法的nasm和INTEL語法的nasm,對於底層學習很有幫助。

支援

這個網站支援ARM、MIPS、X86、AVR等指令集的compiler,支援度甚廣,且網頁本身也開源(使用node.js),連結:https://github.com/mattgodbolt/gcc-explorer

操作畫面


Friday, August 5, 2016

使用Ardunio Atmega2560 連接 nRF24L01+

使用Ardunio Atmega2560 連接 nRF24L01+

關於library

其中TMRh20大大做的這個還可支援linux(Raspberry pi),支援度較廣。不過本篇文章選用maniacbug大大的library。

mega2560連接nRF24L01

以下是nRF24L01 模組的照片與pinout。

從左上開始,右下結束。
                           
1.GND2.VDD(3.6V以下)
3.CE4.CSN
5.SCLK6.MOSI
7.MISO8.IRQ


Mega2560部份,我們不需要接IRQ,因為library沒有實做,讀者有興趣可以修改library中關於nRF24L01一個名叫config的暫存器,將mask中斷的部份歸零。

Mega2560的部份需要其上頭內建的SPI BUS,才能使用這個函式庫(TMRh20的library有提供Software SPI應用)。以下是Mega2560的SPI接腳對應。



SCK要接nRF24L01的SCLK,MOSI接MOSI,MISO接MISO,CE和CSN可自行定義腳位。

程式碼部份直接利用官往提供的example來做測試。
http://maniacbug.github.io/RF24/GettingStarted_8pde-example.html
原始碼中RF24物件建構子這行
RF24 radio(9,10);
9表示CE接腳,10表示CSN接腳。

程式運行時可以開啟Serial port monitor來觀察其運作,其中他在radio.printDetails();部份印出的細節可以多留意,尤其是收發兩端的address,在TX_ADDR那項兩邊要不同。接下來就可開心的看著她發送了。

連不上的一些解法

地址錯誤

兩邊的地址要可對到,一邊RX_ADDR要為另一邊TX_ADDR,這樣才可收到。

雜訊

有些nRF24L01模組的電源供應沒有電容濾波,可以自行用電容跨接GND和VCC兩端,建議選擇10uF到50uF的電容,另外模組的GND要和Ardunio的GND共地(從Ardunio直接拉GND是好選擇)。

傳輸速率過快

example預設為2Mbps,可自行降為1Mbps,有機會收到較佳的訊號。

精選文章

使用Ardunio Atmega2560 連接 nRF24L01+

使用Ardunio Atmega2560 連接 nRF24L01+ 關於library 目前主流有 https://github.com/maniacbug/RF24 與 https://github.com/TMRh20/RF24 這兩個。 其中TMRh20大大做...