yueqiumao 发布的文章

智能家居

hc

https://github.com/brutella/hc

hc is a lightweight framework to develop HomeKit accessories in Go. It abstracts the HomeKit Accessory Protocol (HAP) and makes it easy to work with services and characteristics.

hc handles the underlying communication between HomeKit accessories and clients. You can focus on implementing the business logic for your accessory, without having to worry about the protocol.

https://luaunit.readthedocs.io/en/latest/

local lu = require("luaunit")

-- 注册单元测试函数 (函数必须以test开头)

function test_fun1()

end

function test_fun2()

end

-- 注册单元测试模块 (模块必须以test开头)

test_mod = {}

function test_mod:setUp()
    -- 调用模块测试函数前执行
end

function test_mod:tearDown()
    -- 调用模块测试函数后执行
end

function test_mod:test_fun1() -- 测试函数必须以test开头,并且使用:调用模式

end

function test_mod:test_fun2()

end

lu.LuaUnit.verbosity = 2
os.exit(lu.LuaUnit.run())

断言方法:
lu.assertEquals(a, b) -- 深度对比,包括 table
lu.assertNotEquals(a, b)
lu.assertEvalToTrue(a)
lu.assertEvalToFalse(a)
lu.assertTrue(a)
lu.assertFalse(b)
error(a)
assert(a)

使用到的 stlink 命令行工具
https://github.com/stlink-org/stlink

st-flash 烧录,读写芯片,擦除之类
st-info 主要获取芯片相关信息
st-util gdb调试的

在mac下推荐的安装方式如下:
brew install stlink

擦除芯片
./st-flash erase
2020-08-21T23:56:08 INFO common.c: F04x: 6 KiB SRAM, 16 KiB flash in at least 1 KiB pages.
Mass erasing

烧录
./st-flash write xxx.bin 0x8000000
file xxx.bin md5 checksum: f44aa7045a596c4693a908fc68a1972, stlink checksum: 0x0001ac10
2020-08-21T23:55:11 INFO common.c: Attempting to write 1220 (0x4c4) bytes to stm32 address: 134217728 (0x8000000)
2020-08-21T23:55:11 INFO common.c: Flash page at addr: 0x08000000 erased
2020-08-21T23:55:11 INFO common.c: Flash page at addr: 0x08000400 erased
2020-08-21T23:55:11 INFO common.c: Finished erasing 2 pages of 1024 (0x400) bytes
2020-08-21T23:55:11 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2020-08-21T23:55:11 INFO flash_loader.c: Successfully loaded flash loader in sram
2/2 pages written
2020-08-21T23:55:11 INFO common.c: Starting verification of write complete
2020-08-21T23:55:11 INFO common.c: Flash written and verified! jolly good!

import (
    "net/http"
    "strings"
    urlpkg "net/url"
)

url := "http://jenkins/job/test/buildWithParameters"
data := urlpkg.Values{}
data.Add("SERVER_NAME", "测试服")
data.Add("SERVER_URI", "refs/heads/master")
data.Add("CONFIG_URI", "refs/heads/master")

req, err := http.NewRequest("POST", url, strings.NewReader(data.Encode()))
if err != nil {
    panic(err.Error())
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth("wameidemao", "1151edd79316129baea8911ce078908130")
resp, err := http.DefaultClient.Do(req)

package main

import "github.com/rjeczalik/notify"
import "fmt"

func main() {
    // Make the channel buffered to ensure no event is dropped. Notify will drop
    // an event if the receiver is not able to keep up the sending pace.
    c := make(chan notify.EventInfo, 1)

    // Set up a watchpoint listening on events within current working directory.
    // Dispatch each create and remove events separately to c.
    if err := notify.Watch(".", c, notify.Create, notify.Write, notify.Rename, notify.Remove); err != nil {
        fmt.Println("Error:", err)
    }
    defer notify.Stop(c)

    // Block until an event is received.
    for ie := range c {

     fmt.Println("Got event:", ie)

    }
}