wfb-ng 开源工程结构&代码框架简明介绍

Posted lida2003

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wfb-ng 开源工程结构&代码框架简明介绍相关的知识,希望对你有一定的参考价值。

wfb-ng 开源工程结构&代码框架简明介绍

1. 获取开源代码

1.1 开源代码版本

首先,获取代码的步骤很便捷的,直接通过github下载来获取,要注意的是版本号。

注:目前(截止发稿日)wfb-ng相对稳定,提出的问题和新增的功能都不多,代码框架应该改动不会太大。

$ git log -n 1
commit 02942ce0d52150a4ac75a4ed59680ef453042fb9 (HEAD -> master, origin/master, origin/HEAD)
Author: Vasily Evseenko <svpcom@gmail.com>
Date:   Tue Feb 7 21:25:03 2023 +0300

    Update codec settings

1.2 克隆开源代码

然后,要确保系统上已经安装git工具。通过clone命令将代码下载到本地,版本问题请大家自行匹配,这里为了确保一致性,所以将代码版本记录下来了(其实这个对学习来说并不太重要,主要是方法论)。

$ git clone git@github.com:svpcom/wfb-ng.git

2. 了解工程情况

了解工程最简单的方法,就是阅读README。通常github上code页面显示的就是README.md文件,在浏览器上格式更美观(当然vi也是可以的)。
这里摘要部分内容,做个情况了解,为后续研读提供方向。

2.1 支持特性&功能

  • 1:1 map of RTP to IEEE80211 packets for minimum latency (doesn’t serialize to byte steam)
  • Smart FEC support (immediately yeild packet to video decoder if FEC pipeline without gaps)
  • Bidirectional mavlink telemetry. You can use it for mavlink up/down and video down link.
  • IP-over-WFB tunnel support. You can transmit ordinary ip packets over WFB link. Note, don’t use ip tunnel for high-bandwidth transfers like video or mavlink. It use less efficient FEC coding and doesn’t aggregate small packets.
  • Automatic TX diversity (select TX card based on RX RSSI)
  • Stream encryption and authentication (libsodium)
  • Distributed operation. It can gather data from cards on different hosts. So you don’t limited to bandwidth of single USB bus.
  • Aggreagation of mavlink packets. Doesn’t send wifi packet for every mavlink packet.
  • Enhanced OSD for Raspberry PI (consume 10% CPU on PI Zero) or any other system which supports gstreamer (Linux X11, etc). Compatible with any screen resolution. Supports aspect correction for PAL to HD scaling.
  • Provides IPv4 tunnel for generic usage

2.2 安装&文档链接

这里提供了两个文档链接,供读者阅读:

2.3 快速使用指南(树莓派)

  1. 通过Release下载(*.img.gz)文件映像
  2. 使用工具(Raspberry Pi Imager/balena/dd命令等)刷写固件镜像到tf卡上
  3. 插入图传使用的WiFi大功率无线网卡
  4. 重启树莓派,并登录系统进行天空端/地面端配置

注1:如果需要备份可采用dd命令sudo dd bs=4M if=/dev/sdb of=/home/daniel/wfb-ng_23.01.001-rpi3-daniel.img。
注2:烧录方式可参考:Raspbian镜像无头烧录

2.3.1 天空端命令

启动天空端wfb_ng

$ sudo systemctl start wifibroadcast@drone

天空端wfb_ng状态查询

$ sudo systemctl status wifibroadcast@drone

天空端wfb_ng日志查询

sudo journalctl -xu wifibroadcast@drone

停止天空端wfb_ng

$ sudo systemctl stop wifibroadcast@drone

视频采集命令(CTRL + C 退出)

$ raspivid -n  -ex fixedfps -w 1280 -h 720 -b 4000000 -fps 30 -t 0 -o - \\
				| gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=35 ! udpsink sync=false host=127.0.0.1 port=5602

or

$ gst-launch-1.0 v4l2src do-timestamp=true io-mode=mmap device=/dev/video0 \\
				extra-controls="controls,image_stabilization=1,h264_profile=4,h264_i_frame_period=60,h264_level=11,power_line_frequency=1,exposure_metering_mong=1,exposure_dynamic_framerate=0,scene_mode=0,video_bitrate_mode=1,video_bitrate=2000000,repeat_sequence_header=1" \\
				! video/x-h264,profile=high,width=1280,height=720,framerate=30/1,stream-format=byte-stream \\
				! h264parse disable-passthrough=true ! rtph264pay config-interval=1 pt=96 mtu=1400 aggregate-mode=zero-latency ! udpsink host=127.0.0.1 port=5602 sync=false

功能使能/去使能命令(使能后,进程随系统自启动)

$ sudo systemctl enable wifibroadcast@drone
$ sudo systemctl disable wifibroadcast@drone
$ sudo systemctl enable fpv-camera
$ sudo systemctl disable fpv-camera

2.3.2 地面端命令

启动地面端wfb_ng

$ sudo systemctl start wifibroadcast@gs

地面端wfb_ng状态查询

$ sudo systemctl stop wifibroadcast@gs

地面端wfb_ng日志查询

sudo journalctl -xu wifibroadcast@gs

停止地面端wfb_ng

$ sudo systemctl stop wifibroadcast@gs

地面端维测命令(CTRL + C 退出)

$ wfb-cli gs

视频播放命令(CTRL + C 退出)

$ gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' \\
               ! rtph264depay ! avdec_h264 ! clockoverlay valignment=bottom ! autovideosink fps-update-interval=1000 sync=false

or

$ gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' \\
               ! rtph264depay ! avdec_h264 ! clockoverlay valignment=bottom ! xvimagesink sync=false

功能使能/去使能命令(使能后,进程随系统自启动)

$ sudo systemctl enable wifibroadcast@gs
$ sudo systemctl disable wifibroadcast@gs
$ sudo systemctl enable fpv-video
$ sudo systemctl disable fpv-video
$ sudo systemctl enable osd
$ sudo systemctl disable osd

2.3.3 RTL8812AU 驱动安装

安装dkms

$ sudo apt-get install dkms

获取工程

$ git clone -b v5.2.20 https://github.com/svpcom/rtl8812au.git

一键安装

$ cd rtl8812au/
$ sudo ./dkms-install.sh

or
$ cd rtl8812au && make && sudo make install

2.4 详细安装指南(树莓派)

请参考:

3. Makefile结构

wfb-ng采用了Unix-style工程结构,也是笔者非常喜欢的一种软件工程组织方式。

Makefile
 ├──> C代码
 │   ├──> wfb_keygen
 │   ├──> wfb_rx
 │   ├──> wfb_tx
 │   └──> all_bin: wfb_rx wfb_tx wfb_keygen
 ├──> python代码
 │   ├──> wfb-cli 
 │   ├──> wfb-test-latency
 │   └──> wfb-server
 └──> 工程目标
     ├──> env //python环境
     ├──> rpm:  all_bin env //rpm包
     ├──> deb:  all_bin env //deb包
     ├──> bdist: all_bin
     ├──> clean //工程清理
     ├──> test //测试
     ├──> gs.key //生成drone.key & gs.key
     └──> all: all_bin gs.key test

4. 工程目录结构

  • wfb_ng下主要是python代码,实现wfb-cli/wfb-test-latency/wfb-server
  • src下主要是C代码,实现wfb_keygen/wfb_rx/wfb_tx
  • scripts下主要是程序在linux系统上所用到的脚本和配置文件
  • doc下主要是一些技术资料
.
├── doc
│   ├── Analysis of Injection Capabilities and Media Access of IEEE 802.11 Hardware in Monitor Mode.pdf
│   ├── enhanced_setup.dot
│   ├── logo-big.png
│   ├── logo-small.png
│   ├── Makefile
│   ├── mimo_for_dummies.pdf
│   └── wfb-ng-std-draft.md
├── LICENSE.txt
├── Makefile
├── README.md
├── scripts
│   ├── 98-wifibroadcast.conf
│   ├── default
│   │   └── wifibroadcast
│   ├── install_gs.sh
│   ├── rx_standalone.sh
│   ├── sample_voice_radio.sh
│   ├── systemd
│   │   ├── fpv-camera.service
│   │   ├── fpv-video.service
│   │   └── osd.service
│   ├── tx_standalone.sh
│   ├── video_test_sink.sh
│   ├── video_test_src.sh
│   ├── wifibroadcast
│   ├── wifibroadcast.service
│   └── wifibroadcast@.service
├── setup.py
├── src
│   ├── fec.c
│   ├── fec.h
│   ├── ieee80211_radiotap.h
│   ├── keygen.c
│   ├── radiotap.c
│   ├── rx.cpp
│   ├── rx.hpp
│   ├── tx.cpp
│   ├── tx.hpp
│   ├── wifibroadcast.cpp
│   └── wifibroadcast.hpp
├── stdeb.cfg
├── version.py
└── wfb_ng
    ├── cli.py
    ├── common.py
    ├── conf
    │   ├── __init__.py
    │   ├── local.cfg
    │   └── master.cfg
    ├── config_parser.py
    ├── __init__.py
    ├── latency_test.py
    ├── mavlink_protocol.py
    ├── mavlink.py
    ├── proxy.py
    ├── server.py
    ├── tests
    │   ├── __init__.py
    │   ├── test_proxy.py
    │   ├── test_tuntap.py
    │   └── test_txrx.py
    └── tuntap.py

8 directories, 55 files

5. 参考资料

【1】Raspbian镜像无头烧录
【2】wfb-ng Release 23.01镜像无头烧录&配置(1)
【3】wfb-ng Release 23.01镜像无头烧录&配置(2)
【4】FPV Camera(RPI3+V2.1) | wfb_ng Release 23.01 | Ubuntu 20.04 xfce软解测试
【5】FPV Camera(RPI3+V2.1) | wfb_ng Release 23.01 | ubuntu 20.04 gnome软解测试

以上是关于wfb-ng 开源工程结构&代码框架简明介绍的主要内容,如果未能解决你的问题,请参考以下文章

PX4开源工程结构简明介绍

PX4开源软件框架简明简介

wfb-ng Release 23.01镜像无头烧录&配置

wfb-ng Release 23.01镜像无头烧录&配置

wfb-ng 锁定WiFi接口

PX4模块设计之一:SITL & HITL模拟框架