genmsg: add a template for generating flight side serializers.
Signed-off-by: Michael Hope <mlhx@google.com>
This commit is contained in:
parent
889ed7c04e
commit
6fc3926cd8
1 changed files with 40 additions and 0 deletions
40
src/main/io/msg.h.template
Normal file
40
src/main/io/msg.h.template
Normal file
|
@ -0,0 +1,40 @@
|
|||
@# MSP encoder generator for Clearflight.
|
||||
@# EmPy format. See http://www.alcyone.com/software/empy/ for more.
|
||||
@#
|
||||
// Generated by gencpp from file @(spec.package)/@(spec.short_name).msg
|
||||
// DO NOT EDIT!
|
||||
|
||||
@{
|
||||
import genmsp
|
||||
env = genmsp.make_env(spec, msg_context, search_path)
|
||||
}@
|
||||
|
||||
@# Generate the serializer for a message.
|
||||
@[def serialize(spec, prefix='', indent='')]@
|
||||
@[for field in spec.parsed_fields()]@
|
||||
@{ctype = genmsp.get_type(field.type)}@
|
||||
@[if ctype is None]@
|
||||
@{child = genmsp.load_spec(field.base_type, spec, env)}@
|
||||
@[if field.is_array]@
|
||||
for (int i = 0; i < @genmsp.get_count(field); i++) {
|
||||
@serialize(child, '{}[i].'.format(field.name), ' '*4)@
|
||||
}
|
||||
@[else]@
|
||||
@serialize(child, '{}->'.format(field.name))@
|
||||
@[end if]@
|
||||
@[else]@
|
||||
@[if field.is_array]@
|
||||
@(indent)serialize@(ctype.encoder)s((const uint@(ctype.encoder)_t *)@prefix@field.name, @genmsp.get_count(field));
|
||||
@[else]@
|
||||
@(indent)serialize@(ctype.encoder)(@prefix@field.name);
|
||||
@[end if]@
|
||||
@[end if]@
|
||||
@[end for]@
|
||||
@[end def]@
|
||||
|
||||
// Respond to a @spec.short_name / MSP_@genmsp.to_caps(spec.short_name) command.
|
||||
static void send@(spec.short_name)(@(', '.join(genmsp.generate_encoder_args(spec, env)))) {
|
||||
uint8_t len = @(' + '.join(str(genmsp.get_length(x, spec, env)) for x in spec.parsed_fields()));
|
||||
headSerialReply(len);
|
||||
@serialize(spec)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue