Skip to content

Commit 55c3ecd

Browse files
committed
fix: keep jinja templates intact and pin clang-format hook
1 parent d878c71 commit 55c3ecd

4 files changed

Lines changed: 85 additions & 250 deletions

File tree

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ default_install_hook_types:
33
- pre-commit
44
- pre-push
55
repos:
6-
- repo: local
6+
- repo: https://github.com/pre-commit/mirrors-clang-format
7+
rev: v17.0.6
78
hooks:
89
- id: clang-format
9-
name: clang-format
10-
entry: clang-format -i
11-
language: system
10+
files: ^(Core/|tools/).*
1211
types_or:
1312
- c
1413
- c++
15-
files: ^(Core/|tools/).*
14+
exclude: ^Core/Inc/Code_generation/Packet_generation/.*Template\.hpp$|^tools/binary_metadata_template\.cpp$
Lines changed: 46 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,65 @@
11
#pragma once
22
#include "ST-LIB.hpp"
33

4-
/*Data packets for {{board}}
4+
/*Data packets for {{board}}
55
-AUTOGENERATED CODE, DO NOT MODIFY-*/
6-
class DataPackets {
6+
class DataPackets{
77
public:
8-
{% for enum in enums -%
9-
}
8+
{% for enum in enums -%}
109
enum class {{enum.name}} : uint8_t
1110
{
1211
{%- for value in enum["values"] %}
1312
{{value}} = {{loop.index0}},
1413
{%- endfor %}
1514
};
15+
{% endfor %}
16+
17+
{% for packet in packets -%}
18+
static void {{packet.name}}_init({% for variable in packet.variables %}{{variable.type}} &{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %})
1619
{
17-
% endfor %
18-
}
19-
20-
{% for packet in packets -%
21-
}
22-
static void {
23-
{
24-
packet.name
25-
}
26-
}
27-
_init(
28-
{ % for variable in packet.variables % } {{variable.type}} &
29-
{
30-
{
31-
variable.name
32-
}
33-
} { % if not loop.last % },
34-
{ % endif % } { % endfor % }
35-
) {
36-
{
37-
{
38-
packet.name
39-
}
40-
}
41-
_packet = new HeapPacket(
42-
static_cast<uint16_t>({{packet.id}}) { % if packet.variables % },
43-
{ % for variable in packet.variables % } &
44-
{
45-
{
46-
variable.name
47-
}
48-
} { % if not loop.last % },
49-
{ % endif % } { % endfor % } { % endif % }
50-
);
51-
}
52-
53-
{
54-
% endfor - %
20+
{{packet.name}}_packet = new HeapPacket(static_cast<uint16_t>({{packet.id}}){% if packet.variables %}, {% for variable in packet.variables %}&{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %});
5521
}
56-
22+
23+
{% endfor -%}
24+
5725
public:
58-
{%for packet in packets -%
59-
}
60-
inline static HeapPacket* {
61-
{
62-
packet.name
63-
}
64-
}
65-
_packet{nullptr};
66-
{
67-
% endfor %
68-
}
69-
{% for socket in sockets -%
70-
}
71-
inline static {{socket.type}}* {
72-
{
73-
socket.name
74-
}
75-
}
76-
{nullptr};
77-
{
78-
% endfor %
79-
}
80-
81-
static void start() {
82-
{% for packet in packets -%
83-
}
84-
if ({
85-
{
86-
packet.name
87-
}
88-
} _packet == nullptr) {
26+
{%for packet in packets -%}
27+
inline static HeapPacket *{{packet.name}}_packet{nullptr};
28+
{% endfor %}
29+
{% for socket in sockets -%}
30+
inline static {{socket.type}} *{{socket.name}}{nullptr};
31+
{% endfor %}
32+
33+
static void start()
34+
{
35+
{% for packet in packets -%}
36+
if ({{packet.name}}_packet == nullptr) {
8937
ErrorHandler("Packet {{packet.name}} not initialized");
9038
}
91-
{
92-
% endfor %
93-
}
39+
{% endfor %}
9440

95-
{% for socket in ServerSockets -%
96-
}
97-
{{socket.name}} = new ServerSocket("{{socket.board_ip}}", {{socket.port}});
98-
{
99-
% -endfor %
100-
}
101-
{% for socket in DatagramSockets -%
102-
}
103-
{{socket.name}} = new DatagramSocket(
104-
"{{socket.board_ip}}",
105-
{{socket.port}},
106-
"{{socket.remote_ip}}",
107-
{{socket.port}}
108-
);
109-
{
110-
% endfor %
111-
}
112-
{% for socket in Sockets -%
113-
}
114-
{{socket.name}} = new Socket(
115-
"{{socket.board_ip}}",
116-
{{socket.local_port}},
117-
"{{socket.remote_ip}}",
118-
{{socket.remote_port}}
119-
);
120-
{
121-
% endfor %
122-
}
123-
124-
{%- for packet in sending_packets %
125-
}
126-
Scheduler::register_task(
127-
{ % if packet.period_type == "ms" % } {
128-
{
129-
(packet.period * 1000) | round | int
130-
}
131-
} { % else % } {
132-
{
133-
packet.period | round | int
134-
}
135-
} { % endif % },
136-
+[]() {
137-
{
138-
% if packet.name is string - %
139-
}
140-
DataPackets::{{packet.socket}}->send_packet(*DataPackets::{
141-
{
142-
packet.name
143-
}
144-
} _packet);
145-
{
146-
% else %
147-
}
148-
{% for name in packet.name -%
149-
}
150-
DataPackets::{{packet.socket}}->send_packet(*DataPackets::{
151-
{
152-
name
153-
}
154-
} _packet);
155-
{
156-
% endfor - %
157-
}
158-
{
159-
% -endif %
160-
}
161-
}
162-
);
163-
{
164-
% -endfor %
165-
}
41+
{% for socket in ServerSockets -%}
42+
{{socket.name}} = new ServerSocket("{{socket.board_ip}}",{{socket.port}});
43+
{%- endfor %}
44+
{% for socket in DatagramSockets -%}
45+
{{socket.name}} = new DatagramSocket("{{socket.board_ip}}",{{socket.port}},"{{socket.remote_ip}}",{{socket.port}});
46+
{% endfor %}
47+
{% for socket in Sockets -%}
48+
{{socket.name}} = new Socket("{{socket.board_ip}}",{{socket.local_port}},"{{socket.remote_ip}}",{{socket.remote_port}});
49+
{% endfor %}
50+
51+
{%- for packet in sending_packets %}
52+
Scheduler::register_task({% if packet.period_type == "ms" %}{{ (packet.period*1000)|round|int }}{% else %}{{ packet.period|round|int }}{% endif %}, +[](){
53+
{% if packet.name is string -%}
54+
DataPackets::{{packet.socket}}->send_packet(*DataPackets::{{packet.name}}_packet);
55+
{% else %}
56+
{% for name in packet.name -%}
57+
DataPackets::{{packet.socket}}->send_packet(*DataPackets::{{name}}_packet);
58+
{% endfor -%}
59+
{%- endif %}
60+
}); {%- endfor %}
16661
}
62+
63+
64+
16765
};
Lines changed: 20 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,43 @@
11
#pragma once
22
#include "ST-LIB.hpp"
33

4-
/*Order packets for {{board}}
4+
/*Order packets for {{board}}
55
-AUTOGENERATED CODE, DO NOT MODIFY- */
66

7-
class OrderPackets {
7+
8+
class OrderPackets{
89
public:
9-
{% for enum in enums -%
10-
}
10+
{% for enum in enums -%}
1111
enum class {{enum.name}} : uint8_t
1212
{
1313
{%- for value in enum["values"] %}
1414
{{value}} = {{loop.index0}},
1515
{%- endfor %}
1616
};
17-
{
18-
% endfor %
19-
}
17+
{% endfor %}
2018

21-
{% for packet in packets -%
22-
}
23-
inline static bool {
24-
{
25-
packet.name
26-
}
27-
}
28-
_flag{false};
29-
{ % endfor % }
19+
{% for packet in packets -%}
20+
inline static bool {{packet.name}}_flag{false};
21+
{% endfor %}
3022

3123
OrderPackets() = default;
3224

33-
{% for packet in packets -%
34-
}
35-
inline static HeapOrder* {
36-
{
37-
packet.name
38-
}
39-
}
40-
_order{nullptr};
25+
{% for packet in packets -%}
26+
inline static HeapOrder *{{packet.name}}_order{nullptr};
27+
{% endfor %}
28+
29+
{% for packet in packets -%}
30+
static void {{packet.name}}_init({% for variable in packet.variables %}{{variable.type}} &{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %})
4131
{
42-
% endfor %
43-
}
44-
45-
{% for packet in packets -%
46-
}
47-
static void {
48-
{
49-
packet.name
50-
}
51-
}
52-
_init(
53-
{ % for variable in packet.variables % } {{variable.type}} &
54-
{
55-
{
56-
variable.name
57-
}
58-
} { % if not loop.last % },
59-
{ % endif % } { % endfor % }
60-
) {
61-
{
62-
{
63-
packet.name
64-
}
65-
}
66-
_order = new HeapOrder(
67-
{{packet.id}},
68-
&{
69-
{
70-
packet.name
71-
}
72-
} _cb { % if packet.variables % },
73-
{ % for variable in packet.variables % } &
74-
{
75-
{
76-
variable.name
77-
}
78-
} { % if not loop.last % },
79-
{ % endif % } { % endfor % } { % endif % }
80-
);
81-
}
82-
{
83-
% endfor %
32+
{{packet.name}}_order = new HeapOrder({{packet.id}}, &{{packet.name}}_cb{% if packet.variables %}, {% for variable in packet.variables %}&{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %});
8433
}
34+
{% endfor %}
8535

8636
private:
87-
{% for packet in packets -%
88-
}
89-
static void {
90-
{
91-
packet.name
92-
}
93-
}
94-
_cb() {
95-
{
96-
{
97-
packet.name
98-
}
99-
}
100-
_flag = true;
101-
}
37+
{% for packet in packets -%}
38+
static void {{packet.name}}_cb()
10239
{
103-
% endfor %
40+
{{packet.name}}_flag = true;
10441
}
42+
{% endfor %}
10543
};

tools/binary_metadata_template.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* AUTOGENERATED FILE
3-
* DO NOT MODIFY MANUALLY!!!
4-
*/
5-
extern "C" {
6-
const char DESCRIPTION[255] __attribute__((section(".metadata_pool"))) =
7-
"****************" // placeholder for beggining
8-
"{{ DateTimeISO8601 }}" // DateTime using ISO-8601 format
9-
" " // alignment
10-
"{{ STLIB_COMMIT }}" // STLIB commit
11-
"{{ ADJ_COMMIT}}" // ADJ commit
12-
"{{ BOARD_COMMIT }}" // Board commit
13-
// the '=' is used for unparsing
14-
{% for var_pair in variables -%
15-
}
16-
"{{var_pair.name}}={{var_pair.value}}" { % endfor % };
2+
* AUTOGENERATED FILE
3+
* DO NOT MODIFY MANUALLY!!!
4+
*/
5+
extern "C"{
6+
const char DESCRIPTION[255] __attribute__((section(".metadata_pool")))=
7+
"****************" // placeholder for beggining
8+
"{{ DateTimeISO8601 }}" // DateTime using ISO-8601 format
9+
" " // alignment
10+
"{{ STLIB_COMMIT }}" // STLIB commit
11+
"{{ ADJ_COMMIT}}" // ADJ commit
12+
"{{ BOARD_COMMIT }}" // Board commit
13+
// the '=' is used for unparsing
14+
{% for var_pair in variables -%}
15+
"{{var_pair.name}}={{var_pair.value}}"
16+
{% endfor %};
1717
}

0 commit comments

Comments
 (0)