Pure MoonBit MAVLink v2/v1 wire protocol, SHA-256 packet signing, microservice state machines, and recursive XML-to-MoonBit code generator
fn AttitudeQuaternion::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[AttitudeQuaternion, MavError]fn AttitudeTargetTypemask::not_equal(x : AttitudeTargetTypemask, y : AttitudeTargetTypemask) -> Boolpub(all) struct AutopilotVersion {
capabilities : UInt64
flight_sw_version : UInt
middleware_sw_version : UInt
os_sw_version : UInt
board_version : UInt
flight_custom_version : FixedArray[Byte]
middleware_custom_version : FixedArray[Byte]
os_custom_version : FixedArray[Byte]
vendor_id : UInt
product_id : UInt
uid : UInt64
uid2 : FixedArray[Byte]
} derive(Eq, Debug)fn AutopilotVersion::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[AutopilotVersion, MavError]pub(all) struct BatteryStatus {
id : Byte
battery_function : Byte
mav_type : Byte
temperature : Int
voltages : FixedArray[UInt]
current_battery : Int
current_consumed : Int
energy_consumed : Int
battery_remaining : Int
time_remaining : Int
charge_state : Byte
voltages_ext : FixedArray[UInt]
mode : Byte
fault_bitmask : UInt
} derive(Eq, Debug)pub(all) struct CommandClient {
target_system : Byte
target_component : Byte
timeout_ms : UInt64
max_retries : Int
state : CommandTxState
active_cmd : CommandLong?
last_sent_ms : UInt64
retries : Int
} derive(Eq, Debug)fn CommandClient::new(target_system : Byte, target_component : Byte, timeout_ms? : UInt64, max_retries? : Int) -> CommandClientfn CommandClient::send_command_long(self : CommandClient, command : UInt, now_ms : UInt64, param1? : Float, param2? : Float, param3? : Float, param4? : Float, param5? : Float, param6? : Float, param7? : Float) -> MavMessagepub(all) struct DialectSchema {
version : Int
dialect : Int
includes : Array[String]
enums : Array[XmlEnumDef]
messages : Array[XmlMessageDef]
} derive(Eq, Debug)pub(all) struct ExtendedParameterClient {
target_system : Byte
target_component : Byte
last_ack_result : ParamAck?
params : Array[ExtParameterEntry]
} derive(Eq, Debug)fn ExtendedParameterClient::new(target_system : Byte, target_component : Byte) -> ExtendedParameterClientfn ExtendedParameterClient::not_equal(x : ExtendedParameterClient, y : ExtendedParameterClient) -> Boolfn ExtendedParameterClient::set_param(self : ExtendedParameterClient, param_id : String, param_value : String, param_type : Byte) -> MavMessagepub(all) struct ExtendedParameterServer {
sysid : Byte
compid : Byte
params : Array[ExtParameterEntry]
} derive(Eq, Debug)fn ExtendedParameterServer::handle_message(self : ExtendedParameterServer, msg : MavMessage) -> Array[MavMessage]fn ExtendedParameterServer::new(sysid : Byte, compid : Byte, initial_params : Array[(String, String, Byte)]) -> ExtendedParameterServerfn ExtendedParameterServer::not_equal(x : ExtendedParameterServer, y : ExtendedParameterServer) -> Boolfn ExtendedSysState::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[ExtendedSysState, MavError]fn FileTransferProtocol::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[FileTransferProtocol, MavError]fn FrameParser::push_bytes(self : FrameParser, chunk : Bytes, crc_extra_lookup : (UInt) -> Byte?, signing? : SigningContext?) -> Array[ParseStreamEvent]fn FtpPacket::from_file_transfer_protocol(ftp : FileTransferProtocol) -> Result[FtpPacket, MavError]fn FtpPacket::to_mav_message(self : FtpPacket, target_network? : Byte, target_system? : Byte, target_component? : Byte) -> Result[MavMessage, MavError]pub(all) struct FtpServer {
active_session : Byte
open_file_idx : Int
files : Array[FtpVirtualFile]
} derive(Eq, Debug)fn GlobalPositionInt::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[GlobalPositionInt, MavError]pub(all) struct HeartbeatMonitor {
timeout_ms : UInt64
nodes : Array[NodeLinkStatus]
} derive(Eq, Debug)fn HeartbeatMonitor::get_node(self : HeartbeatMonitor, sysid : Byte, compid : Byte) -> NodeLinkStatus?fn HeartbeatMonitor::is_node_alive(self : HeartbeatMonitor, sysid : Byte, compid : Byte, now_ms : UInt64) -> Boolfn HeartbeatMonitor::node_packet_loss_ratio(self : HeartbeatMonitor, sysid : Byte, compid : Byte) -> Doublepub(all) struct HighresImu {
time_usec : UInt64
xacc : Float
yacc : Float
zacc : Float
xgyro : Float
ygyro : Float
zgyro : Float
xmag : Float
ymag : Float
zmag : Float
abs_pressure : Float
diff_pressure : Float
pressure_alt : Float
temperature : Float
fields_updated : UInt
id : Byte
} derive(Eq, Debug)fn LocalPositionNed::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[LocalPositionNed, MavError]pub(all) enum MavError {
InvalidMagic(Byte)
IncompleteFrame(Int, Int)
PayloadTooLarge(Int)
PayloadTooShort(Int, Int)
UnsupportedV1MessageId(UInt)
UnsupportedIncompatFlags(Byte)
UnknownMessageId(UInt)
CrcMismatch(UInt, UInt)
SignatureMissing
SignatureInvalid(String)
InvalidEnumValue(String, UInt)
XmlParseError(String)
SchemaError(String)
} derive(Eq, Debug)pub(all) enum MavFieldType {
Scalar(MavPrimitiveType, Bool)
FixedArrayType(MavPrimitiveType, Int)
} derive(Eq, Debug)pub(all) struct MavFrame {
header : MavHeader
payload : Bytes
checksum : UInt
signature : MavSignature?
} derive(Eq, Debug)pub(all) struct MavHeader {
version : ProtocolVersion
incompat_flags : Byte
compat_flags : Byte
seq : Byte
sysid : Byte
compid : Byte
msgid : UInt
} derive(Eq, Debug)pub(all) enum MavMessage {
MsgHeartbeat(Heartbeat)
MsgSysStatus(SysStatus)
MsgSystemTime(SystemTime)
MsgPing(Ping)
MsgSetMode(SetMode)
MsgParamRequestRead(ParamRequestRead)
MsgParamRequestList(ParamRequestList)
MsgParamValue(ParamValue)
MsgParamSet(ParamSet)
MsgGpsRawInt(GpsRawInt)
MsgScaledImu(ScaledImu)
MsgRawImu(RawImu)
MsgScaledPressure(ScaledPressure)
MsgAttitude(Attitude)
MsgAttitudeQuaternion(AttitudeQuaternion)
MsgLocalPositionNed(LocalPositionNed)
MsgGlobalPositionInt(GlobalPositionInt)
MsgRcChannelsRaw(RcChannelsRaw)
MsgServoOutputRaw(ServoOutputRaw)
MsgMissionRequest(MissionRequest)
MsgMissionSetCurrent(MissionSetCurrent)
MsgMissionCurrent(MissionCurrent)
MsgMissionRequestList(MissionRequestList)
MsgMissionCount(MissionCount)
MsgMissionClearAll(MissionClearAll)
MsgMissionItemReached(MissionItemReached)
MsgMissionAck(MissionAck)
MsgMissionRequestInt(MissionRequestInt)
MsgRcChannels(RcChannels)
MsgManualControl(ManualControl)
MsgMissionItemInt(MissionItemInt)
MsgVfrHud(VfrHud)
MsgCommandInt(CommandInt)
MsgCommandLong(CommandLong)
MsgCommandAck(CommandAck)
MsgCommandCancel(CommandCancel)
MsgSetAttitudeTarget(SetAttitudeTarget)
MsgTimesync(Timesync)
MsgDistanceSensor(DistanceSensor)
MsgBatteryStatus(BatteryStatus)
MsgAutopilotVersion(AutopilotVersion)
MsgExtendedSysState(ExtendedSysState)
MsgStatustext(Statustext)
MsgMavDebug(MavDebug)
MsgLoggingAck(LoggingAck)
MsgMissionWritePartialList(MissionWritePartialList)
MsgMissionItem(MissionItem)
MsgAttitudeTarget(AttitudeTarget)
MsgSetPositionTargetLocalNed(SetPositionTargetLocalNed)
MsgPositionTargetLocalNed(PositionTargetLocalNed)
MsgOpticalFlow(OpticalFlow)
MsgHighresImu(HighresImu)
MsgFileTransferProtocol(FileTransferProtocol)
MsgHomePosition(HomePosition)
MsgLoggingData(LoggingData)
MsgParamExtRequestRead(ParamExtRequestRead)
MsgParamExtRequestList(ParamExtRequestList)
MsgParamExtValue(ParamExtValue)
MsgParamExtSet(ParamExtSet)
MsgParamExtAck(ParamExtAck)
} derive(Eq, Debug)fn MavMessage::encode_to_frame(self : MavMessage, seq~ : Byte, sysid~ : Byte, compid~ : Byte, version? : ProtocolVersion, signing? : SigningContext?) -> Result[(Bytes, MavFrame), MavError]pub(all) struct MavRouter {
ports : Array[Int]
routes : Array[RouteEntry]
unicast_forwarded : Int
broadcast_flooded : Int
} derive(Eq, Debug)fn MissionClearAll::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionClearAll, MavError]pub(all) struct MissionDownloadClient {
target_system : Byte
target_component : Byte
mission_type : Byte
timeout_ms : UInt64
max_retries : Int
state : MissionTxState
expected_count : UInt
last_action_ms : UInt64
retries : Int
downloaded_items : Array[MissionItemInt]
} derive(Eq, Debug)fn MissionDownloadClient::new(target_system : Byte, target_component : Byte, mission_type? : Byte, timeout_ms? : UInt64, max_retries? : Int) -> MissionDownloadClientfn MissionDownloadClient::on_message(self : MissionDownloadClient, msg : MavMessage, now_ms : UInt64) -> MavMessage?fn MissionDownloadClient::start_download(self : MissionDownloadClient, now_ms : UInt64) -> MavMessagefn MissionItemReached::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionItemReached, MavError]fn MissionRequestInt::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionRequestInt, MavError]fn MissionRequestList::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionRequestList, MavError]pub(all) struct MissionServer {
sysid : Byte
compid : Byte
active_seq : UInt
upload_expected : UInt
uploading : Bool
staging_items : Array[MissionItemInt]
stored_items : Array[MissionItemInt]
} derive(Eq, Debug)fn MissionServer::handle_message(self : MissionServer, sender_sysid : Byte, sender_compid : Byte, msg : MavMessage) -> MavMessage?fn MissionSetCurrent::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionSetCurrent, MavError]pub(all) enum MissionTxState {
Idle
AwaitingRequest
AwaitingCount
AwaitingItem(UInt)
Completed
Failed(MavMissionResult)
} derive(Eq, Debug)pub(all) struct MissionUploadClient {
target_system : Byte
target_component : Byte
mission_type : Byte
timeout_ms : UInt64
max_retries : Int
state : MissionTxState
last_action_ms : UInt64
retries : Int
last_requested_seq : Int
items : Array[MissionItemInt]
} derive(Eq, Debug)fn MissionUploadClient::new(target_system : Byte, target_component : Byte, mission_type? : Byte, timeout_ms? : UInt64, max_retries? : Int) -> MissionUploadClientfn MissionUploadClient::on_message(self : MissionUploadClient, msg : MavMessage, now_ms : UInt64) -> MavMessage?fn MissionUploadClient::start_upload(self : MissionUploadClient, waypoints : Array[MissionItemInt], now_ms : UInt64) -> MavMessagefn MissionWritePartialList::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[MissionWritePartialList, MavError]fn MissionWritePartialList::not_equal(x : MissionWritePartialList, y : MissionWritePartialList) -> Boolfn NoisyStreamStressReport::not_equal(x : NoisyStreamStressReport, y : NoisyStreamStressReport) -> Boolfn ParamExtRequestList::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[ParamExtRequestList, MavError]fn ParamExtRequestRead::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[ParamExtRequestRead, MavError]fn ParamRequestList::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[ParamRequestList, MavError]fn ParamRequestRead::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[ParamRequestRead, MavError]pub(all) struct ParameterClient {
target_system : Byte
target_component : Byte
timeout_ms : UInt64
max_retries : Int
state : ParamSyncState
expected_count : Int
last_action_ms : UInt64
retries : Int
params : Array[ParameterEntry]
} derive(Eq, Debug)fn ParameterClient::new(target_system : Byte, target_component : Byte, timeout_ms? : UInt64, max_retries? : Int) -> ParameterClientfn ParameterClient::on_param_value(self : ParameterClient, pv : ParamValue, now_ms : UInt64) -> Unitfn ParameterClient::start_param_set(self : ParameterClient, param_id : String, param_value : Float, param_type : Byte, now_ms : UInt64) -> MavMessagepub(all) struct ParameterServer {
sysid : Byte
compid : Byte
params : Array[ParameterEntry]
} derive(Eq, Debug)fn ParameterServer::new(sysid : Byte, compid : Byte, initial_params : Array[(String, Float, Byte)]) -> ParameterServerfn PayloadReader::read_char_array(self : PayloadReader, fixed_len : Int) -> Result[String, MavError]fn PositionTargetLocalNed::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[PositionTargetLocalNed, MavError]fn PositionTargetLocalNed::not_equal(x : PositionTargetLocalNed, y : PositionTargetLocalNed) -> Boolfn PositionTargetTypemask::not_equal(x : PositionTargetTypemask, y : PositionTargetTypemask) -> Boolfn ProtocolComparisonReport::not_equal(x : ProtocolComparisonReport, y : ProtocolComparisonReport) -> Boolpub(all) struct RcChannels {
time_boot_ms : UInt
chancount : Byte
chan1_raw : UInt
chan2_raw : UInt
chan3_raw : UInt
chan4_raw : UInt
chan5_raw : UInt
chan6_raw : UInt
chan7_raw : UInt
chan8_raw : UInt
chan9_raw : UInt
chan10_raw : UInt
chan11_raw : UInt
chan12_raw : UInt
chan13_raw : UInt
chan14_raw : UInt
chan15_raw : UInt
chan16_raw : UInt
chan17_raw : UInt
chan18_raw : UInt
rssi : Byte
} derive(Eq, Debug)pub(all) struct ServoOutputRaw {
time_usec : UInt
port : Byte
servo1_raw : UInt
servo2_raw : UInt
servo3_raw : UInt
servo4_raw : UInt
servo5_raw : UInt
servo6_raw : UInt
servo7_raw : UInt
servo8_raw : UInt
servo9_raw : UInt
servo10_raw : UInt
servo11_raw : UInt
servo12_raw : UInt
servo13_raw : UInt
servo14_raw : UInt
servo15_raw : UInt
servo16_raw : UInt
} derive(Eq, Debug)fn SetAttitudeTarget::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[SetAttitudeTarget, MavError]fn SetPositionTargetLocalNed::decode_payload(payload_ : Bytes, v2? : Bool) -> Result[SetPositionTargetLocalNed, MavError]fn SetPositionTargetLocalNed::not_equal(x : SetPositionTargetLocalNed, y : SetPositionTargetLocalNed) -> Boolfn SigningContext::new(secret_key : Bytes, link_id? : Byte, initial_timestamp? : UInt64) -> Result[SigningContext, MavError]fn SigningContext::sign_frame_bytes(self : SigningContext, unsigned_frame_bytes : Bytes) -> MavSignaturefn SigningContext::verify_frame_signature(self : SigningContext, unsigned_frame_bytes : Bytes, sig : MavSignature, enforce_replay_protection? : Bool) -> Result[Unit, MavError]fn SigningSecurityAuditReport::equal(SigningSecurityAuditReport, SigningSecurityAuditReport) -> Boolfn SigningSecurityAuditReport::not_equal(x : SigningSecurityAuditReport, y : SigningSecurityAuditReport) -> Boolpub(all) struct SysStatus {
onboard_control_sensors_present : UInt
onboard_control_sensors_enabled : UInt
onboard_control_sensors_health : UInt
load : UInt
voltage_battery : UInt
current_battery : Int
battery_remaining : Int
drop_rate_comm : UInt
errors_comm : UInt
errors_count1 : UInt
errors_count2 : UInt
errors_count3 : UInt
errors_count4 : UInt
} derive(Eq, Debug)pub(all) struct TelemetryRateTracker {
total_frames : Int
total_wire_bytes : Int
stats : Array[MessageRateStat]
} derive(Eq, Debug)fn TelemetryRateTracker::message_rate_hz(self : TelemetryRateTracker, msgid : UInt, window_ms : UInt64) -> Doublefn TelemetryRateTracker::record_frame(self : TelemetryRateTracker, frame : MavFrame, wire_len : Int) -> Unitfn TelemetryRateTracker::total_bandwidth_bytes_per_sec(self : TelemetryRateTracker, window_ms : UInt64) -> Doublefn TimesyncEstimator::create_probe(local_time_ns : Int64, target_system? : Byte, target_component? : Byte) -> MavMessagefn TimesyncEstimator::on_probe_return(self : TimesyncEstimator, incoming : Timesync, rx_time_ns : Int64) -> TimesyncSample?fn TimesyncEstimator::respond_to_probe(incoming : Timesync, local_time_ns : Int64, sender_sysid : Byte, sender_compid : Byte) -> MavMessage?fn TlogRecorder::record_message(self : TlogRecorder, timestamp_usec : UInt64, msg : MavMessage, seq~ : Byte, sysid~ : Byte, compid~ : Byte, version? : ProtocolVersion, signing? : SigningContext?) -> Result[Unit, MavError]fn TlogRecorder::record_wire_frame(self : TlogRecorder, timestamp_usec : UInt64, wire_frame : Bytes) -> Unitpub(all) struct XmlEnumDef {
name : String
bitmask : Bool
description : String
entries : Array[XmlEnumEntry]
} derive(Eq, Debug)pub(all) struct XmlFieldDef {
wire_type : String
parsed_type : MavFieldType
name : String
enum_name : String?
units : String?
description : String
is_extension : Bool
wire_offset : Int
} derive(Eq, Debug)pub(all) struct XmlMessageDef {
id : UInt
name : String
description : String
fields : Array[XmlFieldDef]
wire_ordered_fields : Array[XmlFieldDef]
base_payload_len : Int
max_payload_len : Int
crc_extra : Byte
} derive(Eq, Debug)fn ZeroTrimmingBandwidthReport::equal(ZeroTrimmingBandwidthReport, ZeroTrimmingBandwidthReport) -> Boolfn ZeroTrimmingBandwidthReport::not_equal(x : ZeroTrimmingBandwidthReport, y : ZeroTrimmingBandwidthReport) -> Boollet IFLAG_SIGNED : Bytelet MAX_PAYLOAD_LEN : Intlet V1_HEADER_LEN : Intlet V2_HEADER_LEN : Intlet V2_SIGNATURE_LEN : Intlet X25_INIT_CRC : UIntfn builtin_xml_resolver(file_name : String) -> String?fn compute_v2_signature_bytes(secret_key : FixedArray[Byte], unsigned_frame_bytes : Bytes, link_id : Byte, timestamp : UInt64) -> FixedArray[Byte]fn crc16_calculate(data : Bytes) -> UIntfn crc16_calculate_with_extra(data : Bytes, crc_extra : Byte) -> UIntfn decode_frame(wire : Bytes, crc_extra_lookup : (UInt) -> Byte?, start? : Int, signing? : SigningContext?) -> Result[(MavFrame, Int), MavError]fn decode_tlog_stream(data : Bytes, crc_extra_lookup : (UInt) -> Byte?, signing? : SigningContext?) -> Result[Array[TlogEntry], MavError]fn encode_frame(header : MavHeader, raw_payload : Bytes, crc_extra : Byte, truncate_v2_zeros? : Bool, signing? : SigningContext?) -> Result[(Bytes, MavFrame), MavError]fn encode_tlog_entry(timestamp_usec : UInt64, wire_frame : Bytes) -> Bytesfn enum_entry_variant_name(enum_name : String, entry_name : String) -> Stringfn evaluate_noisy_stream_recovery(frame_count : Int, noise_bytes_per_frame : Int, max_chunk_size : Int) -> NoisyStreamStressReportfn generate_moonbit_from_xml_with_includes(root_file_name : String, xml_resolver : (String) -> String?) -> Result[(DialectSchema, String), MavError]fn lookup_message_crc_extra(msgid : UInt) -> Byte?fn lookup_message_name(msgid : UInt) -> String?fn merge_dialect_schemas(base : DialectSchema, child : DialectSchema) -> Result[DialectSchema, MavError]let official_minimal_xml : Stringlet official_standard_xml : Stringfn parse_dialect_xml_with_includes(root_file_name : String, xml_resolver : (String) -> String?) -> Result[DialectSchema, MavError]fn resolve_message_layout(id : UInt, name : String, description : String, raw_fields : Array[XmlFieldDef]) -> Result[XmlMessageDef, MavError]fn sanitize_field_name(name : String) -> Stringfn sanitize_type_name(pascal_name : String) -> Stringfn sha256_digest(input : Bytes) -> FixedArray[Byte]fn to_pascal_case(raw : String) -> Stringfn truncate_trailing_zeros(payload : Bytes) -> BytesInstall
Download zipPure MoonBit MAVLink v2/v1 wire protocol, SHA-256 packet signing, microservice state machines, and recursive XML-to-MoonBit code generator