Skip to content

Commit

Permalink
Split generated crazyflie code into public header and private impleme…
Browse files Browse the repository at this point in the history
…ntation
  • Loading branch information
jeguzzi committed Jul 28, 2020
1 parent 2d24050 commit 3ca9ffd
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
6 changes: 3 additions & 3 deletions crazyflie/aideck_protocol.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
This file was autogenerate on 07/15/20 from the following Python config:
This file was autogenerate on 07/28/20 from the following Python config:
from base import config, c_uint8, c_uint16 # type: ignore
Expand All @@ -25,10 +25,10 @@
*/

#include "aideck_protocol.h"

#define HEADER_LENGTH 4
#define BUFFER_LENGTH 13
#define VERBOSE_RX
#define VERBOSE_TX

#ifdef VERBOSE_RX
static uint8_t verbose_rx = 0;
Expand Down
29 changes: 29 additions & 0 deletions crazyflie/aideck_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
This file was autogenerate on 07/28/20 from the following Python config:
from base import config, c_uint8, c_uint16 # type: ignore
@config(name='camera', group='aideck_HIMAX', header="!CAM")
class Camera:
marginTop: c_uint16
marginRight: c_uint16
marginBottom: c_uint16
marginLeft: c_uint16
format: c_uint8 # noqa
step: c_uint8
target_value: c_uint8
ae: c_uint8
fps: c_uint8
@config(name='stream', group='aideck_stream', header="!STR")
class Stream:
on: c_uint8
format: c_uint8 # noqa
transport: c_uint8
*/

#define VERBOSE_RX
#define VERBOSE_TX
4 changes: 2 additions & 2 deletions protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ PARAM_GROUP_STOP(my_config)

An input is a structured message from the GAP to the Crazyflie. For every input, the user has to implement a callback, which get triggered every time a new message is received. For the above example, the user has to define the callback
```
static void my_input_callback(my_input_t *);
void my_input_callback(my_input_t *);
```
which is defined in the generate file.


## Building

The generated files should be included in the building tree:
- files in `build/crazyflie/` have to be copied in `<crazyflie_firmware>/src/deck/driver/src`
- implementation and header files in `build/crazyflie/` have to be copied in `<crazyflie_firmware>/src/deck/driver/src` and `<crazyflie_firmware>/src/deck/driver/interface` respectively
- files in `build/gap` in `<gap_app>/src`

The generate files are not meant to be modified or compiled as standalone file, but included in other files that implement the rest of the UART communication:
Expand Down
8 changes: 7 additions & 1 deletion protocol/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def main(config_path: str) -> None:
os.makedirs(cf_build_folder, exist_ok=True)
gap_build_folder = os.path.join(build_folder, 'gap')
os.makedirs(gap_build_folder, exist_ok=True)
template = e.get_template('crazyflie.aideck_p.h.j2')
template = e.get_template('crazyflie.aideck_protocol.c.j2')
with open(os.path.join(cf_build_folder, 'aideck_protocol.c'), 'w') as f:
f.write(template.render(
configs=configurations, inputs=inputs,
header_length=header_length, buffer_length=buffer_length,
source=source, date=date))
template = e.get_template('crazyflie.aideck_protocol.h.j2')
with open(os.path.join(cf_build_folder, 'aideck_protocol.h'), 'w') as f:
f.write(template.render(
configs=configurations, inputs=inputs,
header_length=header_length, buffer_length=buffer_length,
source=source, date=date))
template = e.get_template('gap.protocol.h.j2')
with open(os.path.join(gap_build_folder, 'uart_protocol.h'), 'w') as f:
f.write(template.render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
{{source | indent(2)}}
*/

#include "aideck_protocol.h"

#define HEADER_LENGTH {{header_length}}
#define BUFFER_LENGTH {{buffer_length}}
#define VERBOSE_RX
#define VERBOSE_TX

#ifdef VERBOSE_RX
static uint8_t verbose_rx = 0;
Expand Down Expand Up @@ -41,10 +41,7 @@ typedef struct {

{%- for data_t in inputs %}
// --- input {{data_t.name}}
{{ typedef(data_t) }}
{{ log(data_t) }}
// To be implemented
static void {{data_t.set_cb}}({{data_t.typename}} *);
{{- cb(data_t) -}}
{% endfor %}
{%if inputs or configs %}
Expand Down
16 changes: 16 additions & 0 deletions protocol/templates/crazyflie.aideck_protocol.h.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{%- from "macros.j2" import typedef -%}
/*
This file was autogenerate on {{date}} from the following Python config:

{{source | indent(2)}}
*/

#define VERBOSE_RX
#define VERBOSE_TX

{%- for data_t in inputs %}
// --- input {{data_t.name}}
{{ typedef(data_t) }}
// To be implemented
void {{data_t.set_cb}}({{data_t.typename}} *);
{% endfor %}

0 comments on commit 3ca9ffd

Please sign in to comment.