20160418_jeffrey - silenceuncrio/diary GitHub Wiki
Index
- 0935 - CSR iPlug
- 1510 - serviceIndNotifHandler callback
- 1800 - 觸發的關鍵 gatt_client.c SetState()
- 1820 - UART CSR
0935
要從 CSR 再出發了
將 iPlug 能控制的方式都作上去
1510
為了 serviceIndNotifHandler 的 callback 從早上奮鬥到現在...
直接修改 IplugServiceHandlerNotifInd
這支 function
bool IplugServiceHandlerNotifInd(uint16 dev,
uint16 handle,
uint16 size,
uint8 *value)
{
...
if (handle == 0x2e) {
#if LINKIT_DBG
uartSendString("decode something for hadle(0x002e)\r\n");
uint16 size_print; /* Loop counter */
uartSendString(" Value = 0x");
for(size_print = 0; size_print < size; size_print ++) {
DebugWriteUint8(value[size - size_print - 1]);
}
#endif
}
...
}
我如果在 charDiscovered
裡頭乖乖地加上 0x2e
相關的部分
目前會因為 insufficient authentication and/or authorisation 死在 appGattSignalGattReadCharValCfm
1800
目前 觸發的關鍵從 gatt_client.c
的 SetState()
開始
void SetState(uint16 dev, app_state new_state)
{
...
/* Check if the new state to be set is not the same as the present state */
if (old_state != new_state)
{
...
/* Handle entering new state */
switch (new_state)
{
...
case app_state_configured:
{
/* Peer device has been configured for all the supported
* services */
iplugDemoInit();
iplugDemoSetOn();
}
break;
...
}
}
}
為了 O'SMART Plug 寫了兩支
- iplugDemoInit();
- init command string array for O'SMART Plug
- on/off
- init command string array for O'SMART Plug
- iplugDemoSetOn();
- set O'SMART Plug on
- write 的行為會讓 Plug 發 indication
- 觸發
iplug_service_data.c
的IplugServiceHandlerNotifInd
- 觸發
bool IplugServiceHandlerNotifInd(uint16 dev,
uint16 handle,
uint16 size,
uint8 *value)
{
...
if (handle == 0x2e) {
/*
"ATR" + status
the 7th bit represents power status
the 4th bit represents time table status if be cleared ==> 1 = all timer be cleared, 0=working
the 5th bit represent 延遲開關 status => 1 = enable, 0=disable
*/
iplugUpdateStatus(dev, value[3]);
}
...
}
status 剛好是 value[3]
iplugUpdateStatus()
寫在 gatt_client.c
裡面因為要維護 static APP_DATA_T g_app_data;
裡為了 plug 新增的三筆
- uint16 iplugAtrStatusTimeTable;
- uint16 iplugAtrStatusDelay;
- uint16 iplugAtrStatusPower;
這樣的機制會讓每一次從 plug 來的 indication 都會更新到 static APP_DATA_T g_app_data;
去
之後 LinkIt 透過 UART 要 status 就直接在 CSR 的 static APP_DATA_T g_app_data;
撈就好了
1820
透過 UART 跟 CSR 互動的小程式可以在 shell 執行
應該寫個簡單的參數傳遞機制
如果是從 CGI 來呼叫這些程式的時候
最好由某個參數來讓 這些程式的輸出轉成 json 的格式
讓 cgi 可以專心當個 inteface