Skip to content

接口参考 ​

这一页是索引:列出 Python 绑定的公开名字与 Rust 内核的公开模块,说明每个对象负责什么,并把签名细节交给自动生成的 API 参考。写代码前先看这里的组合方式,比逐个翻签名更快。

Python 公开面 ​

公开面固定为 14 个名字,__all__ 在 bindings/python/src/fly_ruler_proto_python/__init__.py:40。

名字用途定义位置
PROTOCOL_VERSION协议语义版本字符串bindings/python/src/lib.rs:55
get_protocol_version()以函数形式返回同一版本号bindings/python/src/lib.rs:26
Vector3三分量向量,构造需要三个浮点bindings/python/src/protocol.rs:8
Attitude校验过的姿态,支持四元数、旋转矩阵与欧拉角互转bindings/python/src/protocol.rs:55
DerivedState气动与导航派生量bindings/python/src/protocol.rs:129
ControlSurfaceState控制面物理状态bindings/python/src/protocol.rs:241
PropulsorState单个推进器状态bindings/python/src/protocol.rs:302
PropulsorKind推进器类型枚举bindings/python/src/fly_ruler_proto_python/__init__.py:24
TelemetryValueType遥测标量类型bindings/python/src/protocol.rs:316
TelemetryField单个遥测字段的元数据bindings/python/src/protocol.rs:336
TelemetryStreamSchema一条遥测流的声明bindings/python/src/protocol.rs:384
AircraftState完整飞机状态,全部字段可选bindings/python/src/protocol.rs:467
FlyRulerClient绑定单架飞机生命周期的客户端bindings/python/src/fly_ruler_proto_python/client.py:76
create_aircraft_state()带默认值的状态构造助手bindings/python/src/fly_ruler_proto_python/client.py:35

公开名字的构造与调用方式在 Rust 扩展模块里定义,纯 Python 层只负责补默认值与校验,分界见 Python 绑定。

组合方式 ​

python
from fly_ruler_proto_python import (
    FlyRulerClient,
    TelemetryField,
    TelemetryStreamSchema,
    TelemetryValueType,
    create_aircraft_state,
)

schema = TelemetryStreamSchema(
    stream_id="aero",
    fields=[
        TelemetryField(
            field_id="mach",
            label="Ma",
            unit="1",
            value_type=TelemetryValueType.F64,
        )
    ],
    nominal_rate_hz=10.0,
)

with FlyRulerClient("127.0.0.1:18002", "F-16", telemetry_schemas=[schema]) as aircraft:
    aircraft.update_state(create_aircraft_state(position=(100.0, 0.0, -1000.0)))
    aircraft.create_event("flyruler.control.gear_down")

事件名没有枚举约束,字符串原样通过网络发送;flyruler.control.gear_up 与 flyruler.control.gear_down 是协议保留名(core/src/events.rs:4、core/src/events.rs:7),模拟器侧消费者会识别它们。

读签名的边界 ​

  • 构造函数即完成连接、握手与生成飞机,失败直接抛异常,不存在"已创建但未连接"的实例(bindings/python/src/fly_ruler_proto_python/client.py:79-97)。
  • close() 幂等,with 退出后会再调一次也安全;关闭后继续调用其他方法会得到 ConnectionError(bindings/python/src/client.rs:341)。
  • 遥测流的 stream_id 必须非空且互不重复,nominal_rate_hz 若给出必须是有限正数(bindings/python/src/client.rs:94-110)。
  • Attitude 只读,必须通过 from_quaternion()、from_rotation_matrix()、from_euler() 构造,非法输入抛 ValueError 而不是自动归一化(bindings/python/src/protocol.rs:75-107)。
  • proto3 的可选字段在 Python 侧表现为 None,不是零值;只有需要区分"未提供"与"零"的字段才使用可选语义。
  • 游标与回放订阅不在 Python 公开面内,需要通过管理 HTTP 接口调用,操作方式见 docs/guide/06-sessions.md。

完整签名与每个字段的单位说明见主仓生成的接口参考(../docs/api/proto/),改注释后在主仓用 cd docs && just api 重新生成。

Rust 公开模块 ​

内核 crate fly_ruler_proto_core 的公开模块在 core/src/lib.rs:10-30 声明:

模块内容定义位置
attitude姿态校验与旋转运算core/src/lib.rs:10
config运行、传输、存储、回放与管理配置类型core/src/lib.rs:12
cursor游标对齐的快照组装与 UDP 流式类型core/src/lib.rs:14
events协议消费者共享的自定义事件名core/src/lib.rs:16
kernel内核编排与服务器生命周期core/src/lib.rs:18
loggingtracing 订阅器初始化core/src/lib.rs:20
managementHTTP/WebSocket 管理 APIcore/src/lib.rs:22
pb由 schema 生成的 protobuf 类型core/src/lib.rs:24
playback实时与回放共用的时间轴控制器core/src/lib.rs:26
store时间序列存储与持久化core/src/lib.rs:28
transportUDP 传输运行时core/src/lib.rs:30

常用类型通过 crate 根重导出,避免下游写深路径:core/src/lib.rs:37-63 导出 Attitude/AttitudeError、配置类型、游标客户端与运行时、KernelRuntime/RuntimeError、init_logging、管理与回放类型、TimeSeriesStore 与相关数据结构和传输类型。PROTOCOL_VERSION 是 crate 根常量(core/src/lib.rs:34)。

内核 crate 是唯一发布到 crates.io 的 Rust 包,版本化文档见 docs.rs 上的 fly_ruler_proto_core。

相关页面 ​