Drone. Adapters. Crazyflie. Logging
(ex_drone v0.3.0)
View Source
Pure CRTP logging (port 5) packet builders and parsers.
Used to subscribe to battery and flight-readiness variables on a real Crazyflie via TOC download + log block create/start. Packet layouts follow the documented Bitcraze logging protocol (TOC V2 / control V2).
Typical sequence
reset = Drone.Adapters.Crazyflie.Logging.reset()
info = Drone.Adapters.Crazyflie.Logging.get_toc_info()
item = Drone.Adapters.Crazyflie.Logging.get_toc_item(0)
create = Drone.Adapters.Crazyflie.Logging.create_block_v2(0, [{1, 10}, {1, 20}])
start = Drone.Adapters.Crazyflie.Logging.start_block_v2(0, 100)Preferred variables:
pm.batteryLevel(uint8 %) — fallbackpm.vbat(float volts → %)sys.canfly(uint8) — non-zero means estimator / platform ready to fly
Summary
Types
Log block layout entry used when decoding data packets.
One TOC entry resolved from GET_ITEM_V2.
Functions
Maps battery voltage in volts to an approximate charge percent.
Log control channel (1).
True when a control result indicates success (result == 0).
Builds CREATE_BLOCK_V2.
Log data channel (2).
Default log block id used by the Crazyflie adapter (0).
Default log period in milliseconds (100).
Builds GET_INFO_V2 (TOC size / CRC / limits).
Builds GET_ITEM_V2 for TOC entry id.
Converts a layout into CREATE_BLOCK_V2 ops.
Parses a control-channel reply (<<cmd, block_id, result>>).
Parses a log-data channel payload using a known layout.
Parses GET_INFO_V2 reply payload (without CRTP header).
Parses GET_ITEM_V2 reply payload into a TOC item.
Builds RESET — deletes all log blocks.
Finds battery and can-fly TOC entries and builds a decode layout.
Builds START_BLOCK_V2 with period in milliseconds.
Log TOC channel (0).
Byte size of a log type id.
Types
@type layout_entry() :: %{ key: :battery | :estimator_ready | atom(), type: non_neg_integer(), id: non_neg_integer(), source: :battery_level | :vbat | :canfly }
Log block layout entry used when decoding data packets.
@type toc_item() :: %{ id: non_neg_integer(), type: non_neg_integer(), group: String.t(), name: String.t() }
One TOC entry resolved from GET_ITEM_V2.
Functions
@spec battery_percent_from_vbat(number()) :: 0..100
Maps battery voltage in volts to an approximate charge percent.
Crazyflie LiPo range used: 3.0 V (0%) … 4.2 V (100%).
@spec control_channel() :: 1
Log control channel (1).
True when a control result indicates success (result == 0).
@spec create_block_v2(byte(), [{byte(), non_neg_integer()}]) :: Drone.Adapters.Crazyflie.CRTP.packet()
Builds CREATE_BLOCK_V2.
ops is a list of {log_type, variable_id} tuples.
@spec data_channel() :: 2
Log data channel (2).
@spec default_block_id() :: 0
Default log block id used by the Crazyflie adapter (0).
@spec default_period_ms() :: 100
Default log period in milliseconds (100).
@spec get_toc_info() :: Drone.Adapters.Crazyflie.CRTP.packet()
Builds GET_INFO_V2 (TOC size / CRC / limits).
@spec get_toc_item(non_neg_integer()) :: Drone.Adapters.Crazyflie.CRTP.packet()
Builds GET_ITEM_V2 for TOC entry id.
@spec layout_ops([layout_entry()]) :: [{byte(), non_neg_integer()}]
Converts a layout into CREATE_BLOCK_V2 ops.
@spec parse_control_result(binary()) :: {:ok, %{command: byte(), block_id: byte(), result: byte()}} | {:error, term()}
Parses a control-channel reply (<<cmd, block_id, result>>).
@spec parse_data(binary(), [layout_entry()]) :: {:ok, map()} | {:error, term()}
Parses a log-data channel payload using a known layout.
Parses GET_INFO_V2 reply payload (without CRTP header).
Parses GET_ITEM_V2 reply payload into a TOC item.
@spec reset() :: Drone.Adapters.Crazyflie.CRTP.packet()
Builds RESET — deletes all log blocks.
@spec resolve_layout([toc_item()]) :: {:ok, [layout_entry()]} | {:error, term()}
Finds battery and can-fly TOC entries and builds a decode layout.
Prefers pm.batteryLevel, falls back to pm.vbat. Requires sys.canfly.
@spec start_block_v2(byte(), pos_integer()) :: Drone.Adapters.Crazyflie.CRTP.packet()
Builds START_BLOCK_V2 with period in milliseconds.
@spec toc_channel() :: 0
Log TOC channel (0).
@spec type_size(non_neg_integer()) :: pos_integer() | {:error, :unknown_log_type}
Byte size of a log type id.