Update Development Doc

+ Update development.md
+ Add the English version of Development.md
This commit is contained in:
BuGu
2025-04-10 10:55:38 +08:00
committed by GitHub
3 changed files with 292 additions and 23 deletions

View File

@@ -0,0 +1,251 @@
---
title: Development
keywords: NanoKVM, Remote desktop, Lichee, PiKVM, RISCV, tool
update:
- date: 2024-9-26
version: v0.1
author: BuGu
content:
- Release docs
- date: 2025-4-10
version: v1.0
author: BuGu
content:
- Update docs
---
In addition to implementing KVM functionality, NanoKVM has opened up some data for secondary development by users. This document describes the purpose of this data and the considerations for development.
## Obtaining Streaming Related Data
Streaming and image parameters are located in the `/kvmapp/kvm` folder.
### HDMI Obtained Image Native Resolution
- **Image Width**: `/kvmapp/kvm/width`
- **Image Height**: `/kvmapp/kvm/height`
Example: Check the current resolution in the terminal
```bash
echo "$(cat /kvmapp/kvm/width) * $(cat /kvmapp/kvm/height)"
```
> Note: width/height is read-only and cannot be written to. `kvm_stream` dynamically modifies vi parameters based on this data; manual modification will cause the vi subsystem to misinterpret the correct image. When either or both parameters are 0, it indicates the HDMI cable has been unplugged or the HDMI resolution is switching.
### Stream Transmission Resolution
- **Transmission Resolution**: `/kvmapp/kvm/res`
- 0: Automatic, follows HDMI native resolution
- 480: Transmit at 640x480
- 600: Transmit at 800x600
- 720: Transmit at 1280x720
- 1080: Transmit at 1920x1080
> Note: This parameter is readable and writable.
Example: Set `kvm_stream` to transmit at 1280x720 resolution in the terminal
```bash
echo 720 > /kvmapp/kvm/res
```
### Stream Maximum Transmission Frame Rate
- **Maximum Transmission Frame Rate**: `/kvmapp/kvm/fps`
- **Range**: 0-60
Example: Limit `kvm_stream` to a maximum of 45 fps in the terminal
```bash
echo 45 > /kvmapp/kvm/fps
```
### Stream Current Transmission Frame Rate
- **Current Transmission Frame Rate**: `/kvmapp/kvm/now_fps`
Example: View current stream frame rate
```bash
cat /kvmapp/kvm/now_fps
```
### Check Hardware Version
NanoKVM has different versions, and there are hardware differences between versions. Please refer to the [schematic diagram]. The boot script will detect hardware differences and save them in `/etc/kvm/hw`.
- alpha: Early access version NanoKVM Full
- beta: Official version NanoKVM Full and Lite
- pcie: NanoKVM PCIe
### Network Related Configuration
- `/etc/kvm/server.yaml`
- For details, refer to WiKi -> KVM -> NanoKVM Cube -> Network
### USB Status Retrieval
```bash
cat /sys/class/udc/4340000.usb/state
```
- configured: Connected
- not attached: Not connected
### HDMI Status Retrieval
```bash
cat /kvmapp/kvm/state
```
- 1: HDMI Normal
- 0: HDMI Abnormal
### ETH Status Retrieval
```bash
cat /sys/class/net/eth0/carrier
```
- 1: Ethernet Cable Connected
- 0: Ethernet Cable Disconnected (inaccurate)
### WiFi Presence
The file `/etc/kvm/wifi_exist` indicates the presence of the WiFi module.
### WiFi Status Retrieval
```bash
cat /kvmapp/kvm/wifi_state
```
- 0: WiFi exists but not connected
- 1: WiFi connected
### Enable Watchdog (Real-time)
```bash
touch /etc/kvm/watchdog # Enable
rm /etc/kvm/watchdog # Disable
```
### Disable Ping Function
```bash
touch /etc/kvm/stop_ping # Disable
rm /etc/kvm/stop_ping # Enable
```
## USB HID Simulation Devices
- **Initialization**: NanoKVM uses USB Gadget to simulate USB HID devices, initializing keyboard, mouse, and touchscreen in the device boot script `/etc/init.d/S03usbdev`.
### Simulated Keyboard
- **Device**: `/dev/hidg0`
- **Message**: 8 bytes
```plaintext
| 0x00 | 0x00 | 0xXX | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 |
```
- The fourth byte represents the ordinary key value, e.g., F11: 0x44.
- After sending the key value, it must be released promptly.
Example: Pressing the F11 key
```bash
echo -ne \\x00\\x00\\x44\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0 # Press F11 key
echo -ne \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg0 # Release
```
### Simulated Mouse
- **Device**: `/dev/hidg1`
- **Message**: 4 bytes
```plaintext
| b8 Button | s8 X-axis Relative Movement | s8 Y-axis Relative Movement | s8 Wheel |
```
#### Buttons
- Left button down: 0x01
- Right button down: 0x12 (compatible with multiple systems)
- Release: 0x00
Example: Clicking the left button
```bash
echo -ne \\x01\\x00\\x00\\x00 > /dev/hidg1 # Press left button
echo -ne \\x00\\x00\\x00\\x00 > /dev/hidg1 # Release
```
#### Movement (Relative Movement)
- X/Y axis relative movement is signed, where positive x moves right and positive y moves down.
Example: Move right by 5 units, up by 1 unit
```bash
echo -ne \\x00\\x05\\xff\\x00 > /dev/hidg1
```
#### Wheel
- The wheel is signed, where positive values move down.
Example: Move down by 1 unit
```bash
echo -ne \\x00\\x00\\x00\\x01 > /dev/hidg1
```
### Simulated Touchscreen
- **Device**: `/dev/hidg2`
- **Message**: 6 bytes
```plaintext
| Button | X-axis Absolute Position Low 8 bits | X-axis Absolute Position High 8 bits | Y-axis Absolute Position Low 8 bits | Y-axis Absolute Position High 8 bits | Wheel |
```
#### Buttons
- Left button down: 0x01
- Right button down: 0x10
- Release: 0x00
Example: Clicking the left button
```bash
echo -ne \\x01\\x00\\x00\\x00\\x00\\x00 > /dev/hidg2 # Press left button
echo -ne \\x00\\x00\\x00\\x00\\x00\\x00 > /dev/hidg2 # Release
```
#### Movement (Absolute Position)
- X/Y are unsigned numbers, with (0x0001, 0x0001) representing the top left corner and (0x7fff, 0x7fff) representing the bottom right corner.
Example: Move the mouse to the center of the screen
```bash
echo -ne \\x00\\xff\\x3f\\xff\\x3f\\x00 > /dev/hidg2
```
#### Wheel
- The wheel is signed, where positive values move down.
Example: Move down by 1 unit
```bash
echo -ne \\x00\\x00\\x00\\x00\\x00\\x01 > /dev/hidg2
```
## Precautions
- Users should not place their own built programs in the `/kvmapp` directory, as any updates will reset all contents within the folder.
- Simulated keyboard and mouse operations may conflict with operations on the front-end page.

View File

@@ -454,6 +454,8 @@ items:
file: kvm/NanoKVM/system/configuration.md
- label: FAQ
file: kvm/NanoKVM/faq.md
- label: Development
file: kvm/NanoKVM/development.md
- label: NanoKVM PCIe
items:
- label: Introduction
@@ -482,6 +484,8 @@ items:
file: kvm/NanoKVM/system/configuration.md
- label: FAQ
file: kvm/NanoKVM/faq.md
- label: Development
file: kvm/NanoKVM/development.md
- label: NanoKVM USB
items:
- label: Introduction

View File

@@ -7,6 +7,11 @@ update:
author: BuGu
content:
- Release docs
- date: 2025-4-10
version: v1.0
author: BuGu
content:
- Update docs
---
NanoKVM除实现KVM功能外还开放了一些数据,用于用户的二次开发,此文档用于描述这些数据的作用,以及开发的注意事项
@@ -46,29 +51,6 @@ NanoKVM除实现KVM功能外还开放了一些数据,用于用户的二次开发
+ 注: 参数只读
> 示例: 查看当前stream分辨率: `cat /kvmapp/kvm/now_fps`
+ **Stream 传输流格式**
+ 传输流格式: /kvmapp/kvm/type
+ mjpeg
+ h264
+ 注: 参数可读可写
+ stream h264 格式开发中,预计10月上线
> 示例: 终端修改传输格式为MJPEG: `echo mjpeg > /kvmapp/kvm/type`
+ **Stream 传输流质量**
+ 传输流格式: /kvmapp/kvm/qlty
+ 范围: 50-100
+ 注: 参数可读可写,仅针对MJPEG格式调整质量,设置95以上质量时,受限于SG2002 CPU和编码器,传输帧率会变慢,延迟变大.
> 示例: 终端修改MJPEG质量为60%: `echo 60 > /kvmapp/kvm/qlty`
+ **Stream 帧差检测设置**
+ KVM 捕获的电脑画面并非时刻改变,当画面静止时,可以暂停流的传输来降低流量消耗
+ 帧差检测设置: /etc/kvm/frame_detact
+ 创建文件: 启动帧差检测
+ 删除文件: 关闭帧差检测
+ 帧差计算需要消耗大量CPU资源,所以stream使用 320\*240 的图像计算帧差,并且每100帧检测一次,此时帧差检测带来的CPU消耗约为2%, 当检测到画面静止时, kvm_stream 停止流传输, now_fps降低为0, CPU 开始连续检测图像变化, 当图像改变时可以以最快速度恢复流的传输.
+ 注: 帧差计算尺寸和跳帧数暂不可调
> 示例: 打开 kvm_stream 帧差检测功能: `touch /etc/kvm/frame_detact`
+ **查看硬件版本**
+ NanoKVM有不同的版本,版本之间硬件有所差异,详情请自行翻阅[原理图](https://cn.dl.sipeed.com/shareURL/KVM/nanoKVM/HDK/02_Schematic),开机脚本将检测硬件差异,并保存在`/etc/kvm/hw`
+ alpha : 早期内测版 NanoKVM Full
@@ -79,6 +61,38 @@ NanoKVM除实现KVM功能外还开放了一些数据,用于用户的二次开发
+ /etc/kvm/server.yaml
+ 详情参考WiKi->KVM->NanoKVM Cube->网络
+ **USB状态获取**
+ cat /sys/class/udc/4340000.usb/state
+ configured 已连接
+ not attached 未连接
+ **HDMI状态获取**
+ cat /kvmapp/kvm/state
+ 1HDMI正常
+ 0HDMI异常
+ **ETH状态获取**
+ cat /sys/class/net/eth0/carrier
+ 1网线接入
+ 0网线断开不准确
+ **WiFi存在**
+ /etc/kvm/wifi_exist 文件存在即为wifi模块存在
+ **WiFi状态获取**
+ cat /kvmapp/kvm/wifi_state
+ 0wifi存在但未连接
+ 1wifi已连接
+ **打开watchdog实时**
+ touch /etc/kvm/watchdog 打开
+ rm /etc/kvm/watchdog 关闭
+ **关闭ping功能**
+ touch /etc/kvm/stop_ping 关闭
+ rm /etc/kvm/stop_ping 打开
## USB HID模拟设备
+ 初始化: NanoKVM借助USB Gedget 模拟 USB HID 设备, 在设备开机脚本 `/etc/init.d/S03usbdev` 中完成了键盘,鼠标,触屏的初始化