|
1 | 1 | #pragma once |
2 | 2 | #include "ST-LIB.hpp" |
3 | 3 |
|
4 | | -/*Data packets for {{board}} |
| 4 | +/*Data packets for {{board}} |
5 | 5 | -AUTOGENERATED CODE, DO NOT MODIFY-*/ |
6 | | -class DataPackets { |
| 6 | +class DataPackets{ |
7 | 7 | public: |
8 | | - {% for enum in enums -% |
9 | | - } |
| 8 | + {% for enum in enums -%} |
10 | 9 | enum class {{enum.name}} : uint8_t |
11 | 10 | { |
12 | 11 | {%- for value in enum["values"] %} |
13 | 12 | {{value}} = {{loop.index0}}, |
14 | 13 | {%- endfor %} |
15 | 14 | }; |
| 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 %}) |
16 | 19 | { |
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 %}); |
55 | 21 | } |
56 | | - |
| 22 | + |
| 23 | + {% endfor -%} |
| 24 | + |
57 | 25 | 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) { |
89 | 37 | ErrorHandler("Packet {{packet.name}} not initialized"); |
90 | 38 | } |
91 | | - { |
92 | | - % endfor % |
93 | | - } |
| 39 | + {% endfor %} |
94 | 40 |
|
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 %} |
166 | 61 | } |
| 62 | + |
| 63 | + |
| 64 | + |
167 | 65 | }; |
0 commit comments