OpenCyphal / pydsdl

Cyphal DSDL processing front end implemented in Python
https://opencyphal.org
MIT License
11 stars 9 forks source link

Automatically detect zero-cost types #48

Open pavel-kirienko opened 4 years ago

pavel-kirienko commented 4 years ago

On a little-endian IEEE 754-compliant machine the following definition (comments removed) can be (de-)serialized in C/C++ using memcpy (possibly DMA-assisted). In Python, serialization can be delegated to the standard struct module.

truncated uint64 unique_id

uavcan.si.unit.mass.Scalar.1.0 mass

uavcan.si.unit.electric_charge.Scalar.1.0 design_capacity

uavcan.si.unit.voltage.Scalar.1.0[2] design_cell_voltage_min_max

uavcan.si.unit.electric_current.Scalar.1.0 discharge_current
uavcan.si.unit.electric_current.Scalar.1.0 discharge_current_burst
uavcan.si.unit.electric_current.Scalar.1.0 charge_current
uavcan.si.unit.electric_current.Scalar.1.0 charge_current_fast
uavcan.si.unit.electric_current.Scalar.1.0 charge_termination_treshold
uavcan.si.unit.voltage.Scalar.1.0          charge_voltage

uint16 cycle_count

void8
uint8 series_cell_count

uint7 state_of_health_pct
void1

Technology.0.1 technology  # This is an enumeration

This is based on https://forum.uavcan.org/t/future-zero-cost-serialization-constraint/469, but this capability is just an implementation detail that does not require any support from the Specification.

PyDSDL should detect such zero-cost types automatically. Probably it makes sense to express the availability of zero-cost (de-)serialization as a function of platform properties: