gotelem/py/templates/c/skylab.h.jinja2
2023-06-19 21:26:08 -05:00

40 lines
1 KiB
Django/Jinja

// Generated by skylab2.py
#pragma once
#include "skylab2_types.h"
namespace umnsvp::skylab2 {
typedef union {
uint8_t b[4];
uint32_t i;
float f;
} can_float_union_t;
///@brief enumeration for CAN packet IDs
enum class CANPacketId : uint32_t {
{% for p in packets %}
/// {{p.description}} {# '%#x' is a python format string.#}
CAN_PACKET_{{ p.name | upper }} = {{ '%#x' % p.id}},
{% endfor %}
};
{% for p in packets %}
///@brief {{p.description}}
struct can_packet_{{ p.name | lower }} {
{% for field in p.data %}
{% if field.__class__.__name__ == "CANMessageBitfieldDef" %}
struct {
{% for subfield in field.bits %}
uint8_t {{subfield.name}}:1;
{% endfor %}
} {{ field.name | lower }};
{% else %}{{ field.data_type }} {{field.name}};{% endif %}
{% endfor %}
};
/// the length of the {{p.name | lower}} packet
constexpr size_t CAN_LENGTH_{{ p.name | upper }} = sizeof(can_packet_{{p.name | lower}});
{% endfor %}
} // namespace umnsvp::skylab2