20160419_jeffrey - silenceuncrio/diary GitHub Wiki

Index

  • 0830 - engineering notebook
  • 0910 - UART cli
  • 0950 - Working with command line arguments
  • 1155 - 複習 CGI 學到一個重點 fflush(stdout)
  • 1455 - LinkIt 控制 多個 Plug
  • 1510 - CSR gatt_client application

0830

先寫 engineering notebook

0910

來包裝 UART cli 參數囉

之前都是用 getopt

#include <unistd.h>

extern int optind, opterr, optopt;
extern char *optarg;

int getopt(int  argc , char *const  argv [], const char * optstring );
                         See main text for description of return value

這個只能 parsing 單一個字元

來用 getopt_long 玩玩看

0950

這一篇不錯 - C:Working with command line arguments

1155

複習 CGI 學到一個重點

#include <stdio.h>

int main() {
    printf("Content-Type: text/plain\r\n\r\n");

    // if not fflush here, the output of the printf will after system() output
    fflush(stdout); 

    system("/bin/ls");
    return 0;
}

例如我們想透過 CGI 來呼叫 shell command ls 並看到其輸出的結果

除了呼叫 printf("Content-Type: text/plain\r\n\r\n"); 印出 html header 之外
還要記住再呼叫 system() 之前
要先利用 fflush(stdout) 先將 html header flush 出去
不然 system("/bin/ls"); 的輸出結果會優先於 html header
造成的後果便是 browser 會把 system("/bin/ls"); 的輸出當成是 html header 的一部分

1455

再來要來試一下 LinkIt 控制多個 O'SMART Plug 了

先把目前的 CSR source code git commit

1510

希望 CSR 提供的 gatt_client application 寫得夠好啊...

先從 user_config.h 改起

/* The MAX_CONNECTED_DEVICES macro defines the number of devices that can be
 * connected at any given time to the Client device. It must not exceed 1.
 */
#define MAX_CONNECTED_DEVICES                     (2)
⚠️ **GitHub.com Fallback** ⚠️