捡了个ebaz4205玩玩

今天随便刷了刷手机,发祥fpga也有矿了…然后随手一搜发现好久前就有了,闲鱼上入了两片玩玩

手里的下载器是10pin的,还要买个转接板子,于是说100块的zynq体验之旅开始

接下来等待到货,顺便前几天为了给cuda腾地方,随手又把vivado给删了,这两天还要再安上,我觉得我可能需要一个大号的固态来放/opt

Advertisements

srcnn训练记录

最近打算改造下tachiyomi的图像加载,准备研究下超分辨率,改良一下缩放算法

srcnn

直接用的https://github.com/tegg89/SRCNN-Tensorflow,不过这个库貌似直接把所有图像一次全加载到内存了,所以我就少放了几张图

先测试下srcnn,貌似是最古老的,也比较好理解。最新(2019)的貌似是小米的那个算法

标记一下,预计这周训练够抢能结束o.o

记录下中间过程,训练一个下午(看视频+午觉)的时间,生成的图像还是不太能看的

orugin
srcnn
二次平方插值

现在这个明显发暗,而且高频噪声好多。虽然比插值好些,但是差的有点多(训练一下午,收敛的好慢,要是不如插值直接删代码~~)不过可以通过曲线调节下

调节前
srcnn+gimp曲线
调节后

迭代400次

迭代700次,效果明显好很多,不过由于夜间模式,手动调色可能有偏差

看来默认迭代15000次是有道理的

目标

下面这个是目标(waifu2x,我直接用的bigjpg.com的结果)(测试完srcnn,准备转到这个算法上来)

waifu2x(bigjpg)

闲的没事再看看Fuchsia

首先就是蛋疼的jiri update,最近恰逢网络维护节,因此托代码很难受。

本来想体验下国内镜像的,但我刚打开tg就看见大家在爱国…

下载

依旧去官网参考教程吧…

git config --global https.proxy 'http://127.0.0.1:7777'
git config --global http.proxy 'http://127.0.0.1:7777'
env http_proxy=http://127.0.0.1:7777 ./.jiri_root/bin/jiri update

安装

首先依旧替换系统python到python2

⋊> /s/w/p/f/fuchsia on dd551fb3e4  sudo rm /usr/bin/python
⋊> /s/w/p/f/fuchsia on dd551fb3e4  sudo ln -s /usr/bin/python2 /usr/bin/python 

执行fx set的时候提示数据收集

⋊> /s/w/p/f/fuchsia on dd551fb3e4  ./scripts/fx set core.x64                                                                                                                                                                                                                        07:32:42
WARNING: Please opt in or out of fx metrics collection.
You will receive this warning until an option is selected.
To check what data we collect, run `fx metrics`
To opt in or out, run `fx metrics <enable|disable>

Generating compile_commands took 1113ms
Done. Made 25631 targets from 2150 files in 29551ms

看一下fx metrics的说明

When enabled, this tool creates a random unique user ID (UUID) for the Fuchsia
repository and uses that to collect the following anonymized metrics of
the session and user workflow in order to improve the user experience:

1. For every "fx" invocation:
   - The output of "uname -rs" (Kernel name and release)
   - The name of the "fx" subcommand invoked
   - (in the future) Imports in BUILDDIR/args.gn for product and board
   - (in the future) Value FUCHSIA_ARCH from BUILDDIR/fx.config

2. For the following subcomand(s) [set]:
   - All arguments passed to the subcommand

3. (in the future) For the following subcomand(s) [set,build]:
   - Time taken to complete
   - Exit status

When metrics collection is disabled, any existing UUID is deleted, and a
new UUID will be created if metrics is later re-enabled.

When enabled, the UUID and the status are stored in /storage/wine/project/fuchsia/fuchsia/.fx-metrics-config

usage:
 fx metrics
      Show what metrics are collected when enabled

 fx metrics status
      Show if metrics collection is enabled or disabled

 fx metrics [--log=LOG_FILE] enable
      Enable metrics collection in fx tools
      --log=<LOG_FILE>  Log all metrics collected to LOG_FILE for
                     debugging purposes. The LOG_FILE setting is persisted
                     in a config file in the /tmp filesystem and will be
                     reset when the user logs out.

 fx metrics disable
      Disable metrics collection in fx tools

说的挺好的,比某些强制要权限的安卓软件强不少,我就启用了吧

⋊> /s/w/p/f/fuchsia on dd551fb3e4  ./scripts/fx metrics enable                                                                                                                                                                                                                      07:37:04
Collection of metrics is now enabled for /storage/wine/project/fuchsia/fuchsia

重新set一下

⋊> /s/w/p/f/fuchsia on dd551fb3e4  ./scripts/fx set core.x64                                                                                                                                                                                                                        07:37:10
Generating compile_commands took 604ms
Done. Made 25631 targets from 2150 files in 11538ms

于是开始编译fx full-build

⋊> /s/w/p/f/fuchsia on dd551fb3e4  time ./scripts/fx full-build
。。。。。。
ERROR: Unknown command full-build
Command exited with non-zero status 1
1.06user 0.38system 0:01.32elapsed 109%CPU (0avgtext+0avgdata 8120maxresident)k
0inputs+0outputs (0major+107996minor)pagefaults 0swaps

好吧,看来编译的脚本改了不少,这命令已经没了,执行fx build,依旧对硬盘要求很大,由于没用固态编译,所以速度还是很慢,link的时候内存上到了10左右(我偶然看到的,没一直看)不足16g内存编译需要swap

⋊> /s/w/p/f/fuchsia on dd551fb3e4  time ./scripts/fx build                                                                                                                                                                                                                          07:40:56
ninja: Entering directory `/storage/wine/project/fuchsia/fuchsia/out/default.zircon'
[39787/39787] STAMP obj/default.stamp
ninja: Entering directory `/storage/wine/project/fuchsia/fuchsia/out/default'
[16270/16358] ACTION //build/images:system_image.manifest(//build/toolchain/fuchsia:x64)
WARNING: no debug file found for ../../prebuilt/third_party/libvulkan_goldfish/x64/libvulkan_goldfish.so
[16358/16358] STAMP obj/default.stamp
26148.47user 1925.21system 1:03:52elapsed 732%CPU (0avgtext+0avgdata 1236300maxresident)k
5097256inputs+14035232outputs (20020major+238362932minor)pagefaults 0swaps

附一张系统状态的图

编译开始的时候系统状态

运行

经过艰难的编译等待(看电影一集),终于要运行了

⋊> /s/w/p/f/fuchsia on 24db8fdf7f ⨯ ./scripts/fx run -m 4096                                                                          09:49:26
ERROR: could not extend fvm, unable to stat fvm image
CMDLINE: TERM=screen-256color kernel.serial=legacy kernel.entropy-mixin=bcb8e29762ee95ba5422aec030bf808a7733262acb36a876425a6ec97746dea5 kernel.halt-on-panic=true
+ exec /storage/wine/project/fuchsia/fuchsia/buildtools/linux-x64/qemu/bin/qemu-system-x86_64 -kernel /storage/wine/project/fuchsia/fuchsia/out/default/../default.zircon/multiboot.bin -initrd /tmp/tmp.hZ2R9qWKFQ/fuchsia-ssh.zbi -m 4096 -nographic -drive file=/tmp/tmp.hZ2R9qWKFQ/fvm.b
lk,format=raw,if=none,id=mydisk -device ich9-ahci,id=ahci -device ide-drive,drive=mydisk,bus=ahci.0 -net none -smp 4,threads=2 -machine q35 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -cpu Haswell,+smap,-check,-fsgsbase -append 'TERM=screen-256color kernel.serial=legacy kernel.ent
ropy-mixin=bcb8e29762ee95ba5422aec030bf808a7733262acb36a876425a6ec97746dea5 kernel.halt-on-panic=true '
qemu-system-x86_64: -drive file=/tmp/tmp.hZ2R9qWKFQ/fvm.blk,format=raw,if=none,id=mydisk: Could not open '/tmp/tmp.hZ2R9qWKFQ/fvm.blk': No such file or directory

emmm,很有意思,怎么又挂了,开始查下坑

./script/fx脚本得知所有像run,build这些命令存放在${fuchsia_dir}/tools/devshell/${cmd},也就是说run命令作为一个脚本放在devshell里面。报错代码位于50行

if [ -n "$IMAGE_FVM_RAW" ]; then
  fvmimg="${imgdir}/fvm.blk"
  args+=(-d -D "${fvmimg}" --diskfmt=raw)
  stat_flags=()
  if [[ $(uname) == "Darwin" ]]; then
    stat_flags+=("-x")
  fi
  stat_output=$(stat "${stat_flags[@]}" "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}")
  if [[ "$stat_output" =~ Size:\ ([0-9]+) ]]; then
    size="${BASH_REMATCH[1]}"
    newsize=$(($size * 2))
    # We must take a copy of the build artifact, rather than re-use it, as we
    # need to modify it in order to extend it.
    echo -n "Creating disk image..."
    cp "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}" "${fvmimg}"
    "${ZIRCON_TOOLS_DIR}/fvm" "${fvmimg}" extend --length "${newsize}"
    echo "done"
  else
    fx-error "could not extend fvm, unable to stat fvm image"
  fi
fi

为了调试在stat附近添加echo来获得更详细的信息

⋊> /s/w/p/f/fuchsia on 24db8fdf7f ⨯ ./scripts/fx run -m 4096                                                                          09:49:26
stat /storage/wine/project/fuchsia/fuchsia/out/default/obj/build/images/fvm.blk
文件:/storage/wine/project/fuchsia/fuchsia/out/default/obj/build/images/fvm.blk 大小:184713216 块:294176 IO 块:4096 普通文件 设备:812h/2066d Inode:652306 硬链接:1 权限:(0777/-rwxrwxrwx) Uid:( 0/ root) Gid:( 0/ root) 最近访问:2019-06-06 08:46:25.654604100 +0800 最近更改:20
19-06-06 08:46:33.984950900 +0800 最近改动:2019-06-06 08:46:33.984950900 +0800 创建时间:-
ERROR: could not extend fvm, unable to stat fvm image
CMDLINE: TERM=screen-256color kernel.serial=legacy kernel.entropy-mixin=bcb8e29762ee95ba5422aec030bf808a7733262acb36a876425a6ec97746dea5 kernel.halt-on-panic=true
+ exec /storage/wine/project/fuchsia/fuchsia/buildtools/linux-x64/qemu/bin/qemu-system-x86_64 -kernel /storage/wine/project/fuchsia/fuchsia/out/default/../default.zircon/multiboot.bin -initrd /tmp/tmp.hZ2R9qWKFQ/fuchsia-ssh.zbi -m 4096 -nographic -drive file=/tmp/tmp.hZ2R9qWKFQ/fvm.b
lk,format=raw,if=none,id=mydisk -device ich9-ahci,id=ahci -device ide-drive,drive=mydisk,bus=ahci.0 -net none -smp 4,threads=2 -machine q35 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -cpu Haswell,+smap,-check,-fsgsbase -append 'TERM=screen-256color kernel.serial=legacy kernel.ent
ropy-mixin=bcb8e29762ee95ba5422aec030bf808a7733262acb36a876425a6ec97746dea5 kernel.halt-on-panic=true '
qemu-system-x86_64: -drive file=/tmp/tmp.hZ2R9qWKFQ/fvm.blk,format=raw,if=none,id=mydisk: Could not open '/tmp/tmp.hZ2R9qWKFQ/fvm.blk': No such file or directory

这样错误原因就很明显了,我的stat是中文输出的,不匹配正则表达式,因此修改正则,看着好怪异

if [ -n "$IMAGE_FVM_RAW" ]; then
  fvmimg="${imgdir}/fvm.blk"
  args+=(-d -D "${fvmimg}" --diskfmt=raw)
  stat_flags=()
  if [[ $(uname) == "Darwin" ]]; then
    stat_flags+=("-x")
  fi
  stat_output=$(stat "${stat_flags[@]}" "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}")
  echo stat "${stat_flags[@]}" "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}"
  echo $stat_output
  if [[ "$stat_output" =~ 大小:([0-9]+) ]]; then
    size="${BASH_REMATCH[1]}"
    newsize=$(($size * 2))
    # We must take a copy of the build artifact, rather than re-use it, as we
    # need to modify it in order to extend it.
    echo -n "Creating disk image..."
    cp "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}" "${fvmimg}"
    "${ZIRCON_TOOLS_DIR}/fvm" "${fvmimg}" extend --length "${newsize}"
    echo "done"
  else
    fx-error "could not extend fvm, unable to stat fvm image"
  fi
fi

于是就能运行了~~

随手一个ls,然后…

$ ls
/boot/bin/sh: 4: Cannot create child process: -1 (ZX_ERR_INTERNAL): failed to resolve fuchsia-pkg://fuchsia.com/ls#bin/ls

去看代码,这命令真没了o.o按理来说不应该啊

于是想了想,还是把tree再拉过来用下吧,顺便感谢@Patrick(https://blog.simplypatrick.com) 提醒,可以不用修改tree的代码,将BUILD.gn修改成这样

# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

config("tree_config") {
  cflags = [
    "-Wno-discarded-qualifiers",
    "-Wno-implicit-fallthrough",
    "-Wno-sign-compare",
    "-Wno-unused-but-set-parameter",
    "-Wno-incompatible-pointer-types",
  ]
  cflags_c = [
    "-Wno-strict-prototypes",
  ]
}

executable("tree") {
  configs += [ ":tree_config" ]

  sources = [
    "color.c",
    "hash.c",
    "json.c",
    "tree.c",
    "unix.c",
    "file.c",
    "html.c",
    "strverscmp.c",
    "tree.h",
    "xml.c",
  ]

  deps = [
    "$zx/system/ulib/fdio",
  ]
}

运行日志https://gist.github.com/feilongfl/51b4b6dc26d6a60e53f61ad5069d2ed4

使用nodemcu和mpu6050给cemu做一个体感

说明

cemu就是这个 http://cemu.info/ (之所以做这个是因为我xbox手柄没体感 + 闲的)

nodemcu硬件选的esp12,体感用mpu6050

目前勉强每秒17帧数据吧,lua语言真的不会

项目地址 https://github.com/feilongfl/wifi-gyro

测试用硬件

我真的懒得焊板子…

绿色的是逻辑电平转换,我也不知道这是什么鬼,以前从来没用过这货,这次竟然不用读取不出来数据,不然我几根线就连好了(就是不想焊板子…)mpu6050插在IIC0上面

准备工作

wireshark

nodemcu代码及编译工具

cemu作者提供的PadTest(https://files.sshnuke.net/PadTest_1011.zip)

cemu传感器协议

这个主要可以参考项目 https://github.com/hjmmc/WebGyroForCemuhook ,里面注释描述了整个cemu传感器包

整个协议我也描述在 https://gist.github.com/feilongfl/2fe93501561d46ba59689b6a26b91ec5 这个wireshark插件里面了(虽然偷懒了一些只描述了陀螺仪和加速度计).

我实际用到的只有三种报文,分别是电脑的ping,mcu的pong和传输传感器数据的报文,三种报文使用相应的头部算法

头部

定义了包头,版本号,包长度,校验,id和类型,crc使用的是特征值为 0xCBF43926 的crc算法,nodemcu固件库中不存在,可使用https://github.com/nodemcu/nodemcu-firmware/pull/2771 (由于nodemcu成员希望绝大多数包使用lua语言创建,所以这个pr被合并的可能性不大)

电脑端ping报文

这个数据是电脑发送出来用于识别器件的,mcu收到后需要响应

这个包不需要制作出来,收到后解析(解析时候可以偷懒,毕竟mcu性能有限(我的lua太渣)),可得到电脑ip和端口

mcu的pong报文

这个报文就需要自己制作了,里面写一些状态参数,电池,id什么的

这个包基本是常量,直接硬拼出来就行了

传感器数据报文

先声明所有的unused指的是我没用到(偷懒)协议里面是有用的

陀螺仪单位是°,加速度单位是g,都是浮点型

lua优化记录

这个货开始的时候每秒2包都不到,经过一番艰难爬坑终于能有个十七八包左右(凑合应该能用了吧).

首先,绝对不要使用table.insert函数,这个函数巨慢无比可以使用t[#t+1] = xxx的写法,会快不少.

表的插入巨慢无比,因此在启动时先初始化包,以后每次仅修改有变化的位置

table序列化如果单纯使用lua去循环会奇慢无比,本来我制作了 https://github.com/nodemcu/nodemcu-firmware/pull/2774 来实现table序列化,但是被https://github.com/nwf指出修改了lua语言…好吧,这个库是lua的,nodemcu只是移植过来,不能乱改

不过https://github.com/nwf提供了lua的快速实现方法,利用unpack将table拆开送给string.char方法,不过这样的问题就是table里面只能存在数字,字符串是不可以的,也就是报文头部dsus和dsuc需要用ascii代替

mpu6050驱动在https://github.com/nodemcu/nodemcu-firmware/pull/2769不过同crc,他们更希望lua语言实现(这里在校准零点漂移需要注意喂狗,不然会重启)

float转化字符在https://github.com/nodemcu/nodemcu-firmware/pull/2773不过被指出可以用struct包实现(我没试,不过看文档好像可以)

启动的时候检查到lua文件则启动编译成.lc,按道理应该会快,不过我没感觉

尽量不要写死循环,用定时器代替,长时间循环注意喂狗

大量数据打印会浪费时间同时导致lua传输失败

目前还记得的就这些,想起来再补充 (最核心的就是lua太慢的时候就拿c来提速,逃:)

参考链接

https://github.com/hjmmc/WebGyroForCemuhook

https://nodemcu.readthedocs.io/en/master/

https://cemuhook.sshnuke.net/padudpserver.html

https://www.wireshark.org/

mpu6050 datasheet