2021/8/27

mender : 開啟 debug log

ref: mender default log level 是 info。有自己的 logfile,可以指定,例如 /data/mender/deployXXXX.log
mender 也會 log 到 system logger。但是不是所有的 log 都會。
可以在啟動mender 的systemd script 中,加入 log-level
ExecStart=/usr/bin/mender --log-level debug daemon
這樣 systemlog 也會有詳細的 debug log (包含 src line no).
Aug 27 06:41:40 Ambarella user.info mender[392]: time="2021-08-27T06:41:40Z" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]" func=github.com/mendersoftware/mender/app.transitionState file="/home/pi/mender-src/app/mender.go:461"
Aug 27 06:41:40 Ambarella user.info mender[392]: time="2021-08-27T06:41:40Z" level=info msg="Correct request for getting image from: https://s3.amazonaws.com/hosted-mender-artifacts/60114bfe1e73ac58902b5283/600f0b00-c182-4347-8fdc-e48e3ec40751?X-Amz-Algorithm=AWS4-HMAC-S
Aug 27 06:41:40 Ambarella user.info mender[392]: time="2021-08-27T06:41:40Z" level=info msg="State transition: update-check [Sync] -> update-fetch [Download_Enter]" func=github.com/mendersoftware/mender/app.transitionState file="/home/pi/mender-src/app/mender.go:461"
Aug 27 06:41:40 Ambarella user.info mender[392]: time="2021-08-27T06:41:40Z" level=info msg="Running Mender client version: 2.6.1" func="github.com/mendersoftware/mender/app.(*DeploymentLogManager).Enable" file="/home/pi/mender-src/app/deployment_logger.go:143"
Aug 27 06:41:41 Ambarella user.info mender[392]: time="2021-08-27T06:41:41Z" level=info msg="State transition: update-fetch [Download_Enter] -> update-store [Download_Enter]" func=github.com/mendersoftware/mender/app.transitionState file="/home/pi/mender-src/app/mender.g
Aug 27 06:41:42 Ambarella user.info mender[392]: time="2021-08-27T06:41:42Z" level=info msg="No public key was provided for authenticating the artifact" func=github.com/mendersoftware/mender/installer.ReadHeaders file="/home/pi/mender-src/installer/installer.go:109"
Aug 27 06:41:42 Ambarella user.info mender[392]: time="2021-08-27T06:41:42Z" level=info msg="Opening device \"/dev/mmcblk0p8\" for writing" func=github.com/mendersoftware/mender/installer.bdevice.Open file="/home/pi/mender-src/installer/block_device.go:66"
Aug 27 06:41:42 Ambarella user.info mender[392]: time="2021-08-27T06:41:42Z" level=info msg="Native sector size of block device /dev/mmcblk0p8 is 512 bytes. Mender will write in chunks of 1048576 bytes" func=github.com/mendersoftware/mender/installer.bdevice.Open file="/
..

2021/8/25

Azure web function, func . list supported template

ref: 其中有列出 support template 的command:
$ func templates list
C# Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity
  Durable Functions entity (class)
  Durable Functions entity (function)
  Durable Functions Entity HTTP starter
  Durable Functions HTTP starter
  Durable Functions orchestrator
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Kafka output
  Kafka trigger
  Azure Queue Storage trigger
  RabbitMQ trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  SignalR negotiate HTTP trigger
  Timer trigger

Custom Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Kafka trigger
  Azure Queue Storage trigger
  RabbitMQ trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  SignalR negotiate HTTP trigger
  Timer trigger

JavaScript Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity
  Durable Functions entity
  Durable Functions Entity HTTP starter
  Durable Functions HTTP starter
  Durable Functions orchestrator
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Kafka output
  Kafka trigger
  Azure Queue Storage trigger
  RabbitMQ trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  SignalR negotiate HTTP trigger
  Timer trigger

PowerShell Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity (preview)
  Durable Functions HTTP starter (preview)
  Durable Functions orchestrator (preview)
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Kafka output
  Kafka trigger
  Azure Queue Storage trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  SignalR negotiate HTTP trigger
  Timer trigger

Python Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity
  Durable Functions entity
  Durable Functions HTTP starter
  Durable Functions orchestrator
  Durable Functions orchestrator
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  Kafka output
  Kafka trigger
  Azure Queue Storage trigger
  RabbitMQ trigger
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  Timer trigger

TypeScript Templates:
  Azure Blob Storage trigger
  Azure Cosmos DB trigger
  Durable Functions activity
  Durable Functions entity
  Durable Functions Entity HTTP starter
  Durable Functions HTTP starter
  Durable Functions orchestrator
  Azure Event Grid trigger
  Azure Event Hub trigger
  HTTP trigger
  IoT Hub (Event Hub)
  Kafka output
  Kafka trigger
  Azure Queue Storage trigger
  RabbitMQ trigger
  SendGrid
  Azure Service Bus Queue trigger
  Azure Service Bus Topic trigger
  SignalR negotiate HTTP trigger
  Timer trigger

Powershell Templates:
  RabbitMQ trigger

dhcpc to resolv.conf, deal with multiple dns

# udhcpc -iwlan0 -A 1 -b 
udhcpc: started, v1.31.1
udhcpc: sending discover
udhcpc: sending select for 192.168.1.100
udhcpc: lease of 192.168.1.100 obtained, lease time 86400
deleting routers
route: SIOCDELRT: No such process
adding dns 168.95.1.1
adding dns 168.95.192.1
所以就..
# udhcpc -iwlan0 -A 1 -b 2>&1 | grep dns | sed 's/adding dns/nameserver/g' > /etc/resolv.conf
看看對不對...
# cat /etc/resolv.conf 
nameserver 168.95.1.1
nameserver 168.95.192.1

2021/8/18

uart console tool (picocom) support baudrate 1500000

果然,在 /usr/include/x86_64-linux-gnu/bits/termios.h
#define  B57600   0010001
#define  B115200  0010002
#define  B230400  0010003
#define  B460800  0010004
#define  B500000  0010005
#define  B576000  0010006
#define  B921600  0010007
#define  B1000000 0010010
#define  B1152000 0010011
#define  B1500000 0010012
#define  B2000000 0010013
#define  B2500000 0010014
#define  B3000000 0010015
#define  B3500000 0010016
#define  B4000000 0010017
有一堆高速baudrate 定義。

open source 就有這個好處。

1500000 這個 baudrate 沒 support,所以 checkout 出來改。
我用 master 的 68ca528b563b8693ae2c0835629a7457fd211599 來改:
~/picocom$ git diff
diff --git a/term.c b/term.c
index 4abe6cd..66a72ee 100644
--- a/term.c
+++ b/term.c
@@ -637,6 +637,9 @@ term_set_baudrate (int fd, int baudrate)
                case 921600:
                        spd = B921600;
                        break;
+               case 1500000:
+                       spd = B1500000;
+                       break;
 #endif
                default:
                        term_errno = TERM_EBAUD;
其實就加上去就可以了。
然後就可以用 -b1500000 了。

2021/8/17

mender : state script

都沒有文件...

mender 把更新分成幾個 state (9個?)。
然後給個 state 一個 run script 的機會 (兩個?. enter , leave)
但是說明很少。

transient error: update commit failed: statescript: The statescript version file is missing. 
This file needs to be present and contain a single number representing which version of the statescript support 
the client is using in order to successfully run statescripts on the client
只好去找 source..
    versionFilePath := filepath.Join(l.RootfsScriptsPath, "version")
    f, err := os.Open(versionFilePath)
    if err != nil && os.IsNotExist(err) {
        errmsg := "statescript: The statescript version file is missing. This file needs to be " +
            "present and contain a single number representing which version of the statescript " +
            "support the client is using in order to successfully run statescripts on the client"
        return errors.New(errmsg)
    } else if err != nil {
        return errors.Wrap(err, "statescript")
    }
    ver, err := readVersion(f)
    if _, ok := err.(readVersionParseError); ok {
        errmsg := "statescript: Failed to parse the version file in the statescript directory (%s). " +
            "The file needs to contain a single integer signifying which version of the statescript " +
            "support which this client is using"
        return fmt.Errorf(errmsg, err)
    }
所以是需要一個叫 version 的 file,裡面是數字。

然後這個 RootfsScriptsPath 就是
conf/paths.go:	DefaultRootfsScriptsPath = path.Join(GetConfDirPath(), "scripts")
應該就是 /etc/mender/scripts

version 裡面只有一個 0,然後 Error 變成
transient error: update commit failed: statescript: unsupported scripts version: 0
找到:
func NewStateScriptExecutor(config *conf.MenderConfig) statescript.Launcher {
    ret := statescript.Launcher{
        ArtScriptsPath:          config.ArtifactScriptsPath,
        RootfsScriptsPath:       config.RootfsScriptsPath,
        SupportedScriptVersions: []int{2, 3},
..
把version內容由 0 改為 3 之後,果然就 ota OK 了,沒有 Error,但是 state script 以=也沒有執行....

execute.go 有 l.get( )
func (l Launcher) get(state, action string) ([]os.FileInfo, string, error) {

    sDir := l.ArtScriptsPath
    if state == "Idle" || state == "Sync" || state == "Download" {
        sDir = l.RootfsScriptsPath
    }
...
先看script 位置,依照 state 而有不同。
path.go
    DefaultArtScriptsPath    = path.Join(GetStateDirPath(), "scripts")
    DefaultRootfsScriptsPath = path.Join(GetConfDirPath(), "scripts")

DefaultDataStore   = "/var/lib/mender"

func GetStateDirPath() string {
    return DefaultDataStore
}
func GetConfDirPath() string {
    return "/etc/mender"
}
所以 Idle, Sync, Download 是在 /etc/mender。
其他state 是 /var/lib/mender

查實際的機器, 把 state script 放到 update OS (ext4) 的 /etc/mender/scripts/ 下後。包進 ota file (mender),然後 更新到機器上。
script folder 好像會被 copy 到 /data/mender/script (就是 /var/lib/mender 的 symbolic link)。(不是全部 copy)。
而 /etc/mender/script 跟 /var/lib/mender 剛好就是上面的 RootfsScriptsPath 跟 ArtScriptsPath。

但是... RootfsScriptPath 是在ota file 的 ext4 裡, /var/lib/mender 是working 的 os..不一樣。

把一些 example 的 script copy 到 update image 的 /etc/mender/scripts 下
# ls /etc/mender/scripts/
ArtifactCommit_Enter_00   Download_Enter_00         Sync_Enter_00
ArtifactInstall_Enter_00  Download_Leave_01         version
ArtifactReboot_Enter_00   Download_Leave_02
每一個 script 都是在 /data/ 下 touch 自己的 filename.
用 mender ota 成功,到 /data 下只有看到 Sync_Enter_00
符合上面的code,, idle,sync,download 都看 /etc/mender/script
所以把 一樣的 script 都 copy 到 /var/lib/mender/scripts ...


測試,每個 script 都是
date > /data/$(basename "$0")
然後從 /data 就可以知道有哪些 script 有正確執行。
mender 的 yocto recipes 也是用一樣的 script。
-- 裡面 script 都 copy 到一樣的地方喔。


最後:

state scripts 分成兩種,一種是預先要再系統的。一種是放在 artifacr (*.mender) 。
因為 Artifact(mender) 要 download 完會有,所以download 之後的 state ,script 都可以放在 artifacr (*.mender) 中。
其他沒有 download,或是還沒download 的 state,script 就要在系統力。

系統的位置是 /etc/mender/scripts
裡面要有一個 "version" 檔,內容是一個數字,例如 3。代表 script 的版本。
放在 artifact (*.mender) 的,就要在 create mender file 時給定。
用 -s 選項就可以。
這格選項家的 state script,一定要用 Artifact 開頭,例如 ArtifactCommit_Enter_00,ArtifactInstall_Enter_00
把 scripts 都放到 state_script foldler,用 shell scipt 找出來就是...
#!/bin/bash
LIST=""
for f in state_scripts/Artifact*
do
	LIST="${LIST} -s ${f}"
done
echo ${LIST}

2021/8/12

bookmark: periodic trigger Azuer function

Azure App service 有一個簡單的 service : function。就是一個小程式。

2021/8/5

memo: 一些 ADAS 的縮寫

  • LDWS : Land Departure Warning System
  • FCWS : Forward Collision Warning System
  • Stop & Go : 開啟 ACC 時,因為交通壅塞而停止,壅塞解除,恢復行進後,自動啟動 ACCM
  • TLDS : Traffic Light Detection System
  • HMW : Headway Monitoring & Warning (前方車距偵測)
  • Cut in Warning : 旁車切入告警
  • Zigzag Driving Warning : 蛇行告警(自己還是別人?)
  • Temporal Stop Sign : 停車號誌 (Traffic Sign Recognition)
  • Reverse Driving Warning : 前車倒車告警
  • Red Light Violation Detection : 闖紅燈偵測
  • Pedestrian warning : 行人告警
  • MOD : Moving Object Detection
  • BSD : Blind Spot Detection
  • Rear ZigZag driving warning : 後方車輛蛇行告警
  • RCW : Rear Collision Warning,或是 BCW (Back Collision Warning)
  • Rear Zigzag Driving :
  • Zone30 : Zone 30 (traffic sign recognition)
  • Speed Limit Post : 速限號誌(traffic sign recognition

  • Face Detection
  • determine drowsiness or not
  • Head Pose detection : Yaw/Pitch/Roll
  • Distraction : Using Mobilephone
  • Distraction : Smoking
  • Distraction : Yawning
  • Eye ball taking
  • Wearing Mask
  • Landmark
  • Face Identification
  • Eye ball taking (Eye Gaze)
  • Seat Belt
  • OMS (Occupant Monitoring System)