10月份自我學習日誌回顧

前言

這次十月份的學習方向和預設有點不太一樣,主要是因為某天在因緣際會之下,接觸到交大開放式課程 微處理機系統實驗 Microprocessor System Lab.,覺得實在是太有趣了,所以就欲罷不能的聽下去,順便把一些相關教學材料也買齊,好好學一下 MCU 。可以預知,接下來會繼續上曹孝櫟老師的 嵌入式系統設計概論與實作 Introduction to Embedded Systems Design and Implementation ,剛好本身也是在 IOT 產業,每天都要接觸到 Embedded Systems,這老師說的很好,讓我學習到很多 :D

預設目標

  1. Protocol proctise MQTT and modbus
  2. Operating System Book
  3. Implementation: C (c-example)

每日學習內容

  • 10/31: Review STM32 Timer Configuration - OSI -> PLL -> SYSCLK, AHB, APB
  • 10/30: USART - 1
  • 10/29: LCD lecture - 字形檔 / display mem addr / cg rom / cg ram
  • 10/28: Implement 7 segment LED and Interrupt and Exception 2
  • 10/27: Interrupt and Exception 1
  • 10/26: How to use Advanced Timer and Counter
  • 10/25: Basic Timer concept and how to calculate correct time period. The concept of general timer and advanced timer
  • 10/24: Got a board and practice basic I/O output. and blog post.
  • 10/23: The algorithm of page replacement. Memory - map file (such as 顯示卡)
  • 10/22: Virtual Memory - Demand Page / GPIO Input setting and DIP Switch
  • 10/21: STM32 General purpose I/O configuration, memory map
  • 10/20: Qemu enviorment / ARM STM 32 base assembly language
  • 10/19: Page Table - Outer table, Hashtable / Modbus slave daemon implement
  • 10/18: Parse Modbus Slave Data
  • 10/17: Page Table and Mapping. (Page, Offset, Page Size, Byte Address)
  • 10/16: Swap (mid-term scheduler) / Memory allocation - page, frame | Modbus slave data format parse
  • 10/15: Implement sjf scheduler
  • 10/14 : Process Syncchoronization
  • 10/13: Implement Hashmap with a effective way / C unit test using Check framework.
  • 10/12: Process Syncchoronization 204 - 207
  • 10/11: C Source code trace: How to use & and FNV hash fun. The effective way to create hashmap.
  • 10/10: EDF scheduling, Share scheduling, Linux CFS scheduling.
  • 10/9: Protocol packet format study
  • 10/8: Real-time Process Schedulers / C - How to use define # and ##
  • 10/7: thread_pool
  • 10/6: C - pthread / sem_wait / pthread_cond_wait
  • 10/5: 星期五,休息
  • 10/4: CPU scheduler concept
  • 10/3: something you should note about using threads. Signal / thread pools
  • 10/2: multi thread - thread content, models, and Pthread.
  • 10/1: RPC concept (book 154 -160) / Linux Netcat / Stub class

Read more →

Microprocessor System Lab. - Nucleo-64 development board

前言:

在英國的時候,學校大多專注在純軟開發課程上,例如敏捷開發(Agile Development), Web Development, database 等。其中有一堂課令我印象深刻,就是用 logic Unit, MUX 零件自組 16 Instruction Processor,然後自己手動按 Clock 去 fetch / execute instrction,透過這樣的學習,讓我更清楚整個電腦實際運作 Code 的流程。

自從經過這樣的學習後,對於 Processor 總是有種幻想,雖然回到台灣之後都是在做純軟工作,不過還是很希望可以接觸到更多相關知識(在台灣這些都是資工基本課程,可惜我大學是偏資管,並沒有機會能修到這些課)。幸好,在交大課程找到 微處理機系統實驗嵌入式系統設計概論與實作 這兩堂課程,其中曹孝櫟教授教的非常詳細又很有重點,讓我瞬間變他的腦粉啊 <3

由於學的很開心,也收穫很多,就來記錄一下學習過程。

課程連結

  1. Lecture03 Overview of STM32 Board/Development Environment

Nucleo-64 development board

這堂課是使用 Nucleo 系列板子,Processor 是 ARM Cortex-4M,所以就也買了類似的開發板來玩玩。我是從 物聯網科技 這邊買的,寄件速度快,有可以超商取貨,材料種類又多,很推薦這個網站。

Read more →

9月份自我學習日誌回顧

9月份目標

  • 把 Effective Go 看完
  • 複習 JavaScript 概念,釐清各細節
  • 工作上用到的 Protocol 相關知識

目標回顧

1. 把 Effective Go 看完

已看完,印象比較深刻的部分包含:

The difference between new and make

New - It’s a built-in function that allocates memory, but unlike its namesakes in some other languages it does not initialize the memory, it only zeros it.

Read more →

Node.js Addons N-API example (v10.11.0)

前言

由於專案需要整合 Node-RED ,我們必須開發自己的 Node 來讓用戶可以直接透過視覺化方式來建立簡單邏輯,又我們的 SDK 是 C 版本,因此有這機會可以接觸 Node.js 所提供的 C/C++ Addons 功能。另外,自己寫 server-side 都是使用 Golang,所以這也是難得的機會可以試試 Node.js。

目前網路上使用 Node.js N-API v10.x 版本的範例並不多,初期在使用時也因為對於原理不熟悉,因而踩過一些坑,希望這篇文章能講述基本概念,讓其他使用者能避免也踩到相同的坑。

相關技術

  • C
  • Node.js N-API 與v8一些原理知識
  • JavaScript

How C/C++ Addons Work With JavaScript

C/C++ Addons Node.js Addons are dynamically-linked shared objects, written in C++, that can be loaded into Node.js using the require() function, and used just as if they were an ordinary Node.js module.

Read more →

Go - Archive files with archive/tar lib

前言

由於專案要提供 API 來讓使用者 export 匯出檔案, 因此需要將所需檔案集結成一個 archive file。這個流程是透過 Go 的標準 lib archive/tar 來處理,以下文章將簡單介紹流程和實作方式,並於最後附上完整程式碼。

Tar

tar 在UNIX/Linux系統中是最常見的打包工具,透過 tar 的協助,我們可以把數個檔案打包成一個 <file name>.tar 檔案,以利進行後續處理。

![Go-Tar-1.png]({{ site.url }}/assets/images/Go-Tar-1.png)

tar file format

.tar 的檔案格式主要是由 file object 和其對應的 header 所組成。 header 裡面包含了一個 file 的 metadata(例如檔案名稱,數據大小等),這樣系統就可以透過 header 去檢測檔案屬性和完整度。

Read more →

Google Sign-in with OAuth 2.0

前言:

由於目前專案是以 Embedded System 為主,比較少有機會接入第三方 api 的機會,所以這次 side project 就以 Google Sign-in for Web application with Go 的流程當作練習。由於網路上可以找到很多範例,所以在以下文章中會側重在原理 + 為什麼要這樣做,希望除了寫 code 之外,還能建立起基本概念。

Oauth 2.0

要實作 Google Sign-in 流程之前,不免要來簡單提到 Oauth 2.0。 OAuth 是一個用於授權認證的標準協議(RFC 6749),與一般網站常用到的個人帳號驗證機制不同的地方是,OAuth 強調第三方應用程式授權機制,所以它的內容有明確定義出各角色定義,包含:

  • resource owner
  • resource server
  • client
  • authorization server

以這次要實作的場景為例,使用者要透過 Google 帳號來登入我的網站,這裡 resource owner 是指使用者,client 是指我的網站,resource serverauthorization server 則都是指 Google 所提供的服務。

Read more →

Go Fundamental - Array

前言

最近在學 Go,而之前有一些 C 的基礎,因此在學到 Go 的 Array 時,發現它和 C 的 Array 差異性蠻大的,所以特別記錄下來。

Array

Go

1
students := [3]string{"student1", "student2", "student3"}

C

1
char *students[3] = {"student1", "student2", "student3"}

Go’s arrays are values.

首先,最大的不同點是: Go 的 Array 是一個 Value,也就是 students 這個 Variable 就代表整個 Array 。反之, C 在宣告 Array 後, students 是代表指向 Array 第一個 element 的 pointer,而不是整個 Array。

Read more →

Angular Schematics

前言:

最近專案需要提供工具讓外部人員一同參與 Web App 的開發,由於我們的 Web App 已經有基本架構和開發方式,為了讓外部人員能夠更方便的 follow 架構,所以就決定使用 Schematics 來創建專屬樣板,讓協作開發人員可以迅速地建立專案用的 component page,然後他們只需要修改部分程式碼即可。

Angular Schematics

因為我們使用 Angular 框架,所以就使用 Angular Schematics 來建立樣板。Schematics 是一個改善 workflow 的工具,而透過 Angular Schematics ,我們可以模組化地調整專案現有檔案,例如在專案內新增指定檔案,或是修改既有檔案的內容等,減少手動調整 effort 和錯誤發生。

如同圖片所示,我們使用 Schematics 將要修改的部分(橘色方塊)apply 在 staging area,當所有內容調整完成,再 apply 到既有的專案中。(為什麼要有 staging area,主要是因為 Schematics 中可能有不只一個修改步驟,透過先應用在 staging area ,可以避免中間有錯誤發生,而導致直接影響到既有專案) Schematics are atomic Image source:http://recurship.com/blog/2018/5/31/xfvrq9aauqkayhkd4kzp7gsbfg2bfl

Read more →

Redux Anti Pattern

前言

這篇文章是基於 Redux Anti-Patterns - Part 1. State Management 所進行的探討,包含在專案內是否有犯類似的錯誤,以及後續該如何改善。文章會結合目前專案所使用的 Redux(ngrx),並檢視使用 Ngrx 是否能避免這些錯誤發生。

1. State Duplication

問題點

錯誤的建立 state 導致 state 內部 property 或是與其他 state 內容重複。文章內以 session 為例子:

1
2
3
4
5
interface Store {
  sessions: Session[];
  /** The currentSession would be a part of sessions*/
  currentSession: Session;
}

解決方式

如上面的例子,將 currentSession 改成 index 檢索,所以我們實際取用資料時,還是使用 sessions 內的資料,而不是複製一份到 currentSession。

Read more →

CSS Typed Object Model

前言

Chrome 66 版本全新支援 CSS Typed Object Model,透過這種新型的 CSS Typed OM,可以有效提升使用 JavaScript 操作 CSSOM 屬性的效率。雖然目前僅有 Chrome 支援( Firefox 據說在努力中, Edge 目前沒下文),不過既然此方式能對網頁呈現效能有所提升,讓開發者和使用者都因此受惠,未來想必會成為主流方式。

CSSOM & CSS Typed Object Model

CSSOM

傳統的 CSSOM 是使用 string 格式來進行 style 修改或是讀取等行為,當開發者傳遞一個 string 內容給 CSSOM 時,它會再解析 string 成真正需要的數值。這樣一來一往需要蠻大的成本,再加上開發者傳送 string 時不好偵錯,以及不方便開發者進行一些數值的運算等,讓傳統 CSSOM 似乎不太適合樣式操作。

Read more →