|
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 | | - enum class {{enum.name}} : uint8_t |
| 8 | + {% for enum in enums -% |
| 9 | + } |
| 10 | + enum class {{enum.name}} : uint8_t |
10 | 11 | { |
11 | 12 | {%- for value in enum["values"] %} |
12 | 13 | {{value}} = {{loop.index0}}, |
13 | 14 | {%- endfor %} |
14 | 15 | }; |
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 %}) |
19 | | - { |
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 %}); |
| 16 | + { % endfor % } |
| 17 | + |
| 18 | + {% for packet in packets -% |
21 | 19 | } |
22 | | - |
23 | | - {% endfor -%} |
24 | | - |
25 | | -public: |
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) { |
37 | | - ErrorHandler("Packet {{packet.name}} not initialized"); |
| 20 | + static void { |
| 21 | + { packet.name } |
| 22 | + } |
| 23 | + _init( |
| 24 | + { % for variable in packet.variables % } {{variable.type}} & |
| 25 | + { |
| 26 | + { variable.name } |
| 27 | + } { % if not loop.last % }, |
| 28 | + { % endif % } { % endfor % } |
| 29 | + ) { |
| 30 | + { |
| 31 | + { packet.name } |
38 | 32 | } |
39 | | - {% endfor %} |
| 33 | + _packet = new HeapPacket( |
| 34 | + static_cast<uint16_t>({{packet.id}}) { % if packet.variables % }, |
| 35 | + { % for variable in packet.variables % } & |
| 36 | + { |
| 37 | + { variable.name } |
| 38 | + } { % if not loop.last % }, |
| 39 | + { % endif % } { % endfor % } { % endif % } |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + { % endfor - % } |
40 | 44 |
|
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 %} |
| 45 | +public: |
| 46 | + {%for packet in packets -% |
| 47 | + } |
| 48 | + inline static HeapPacket* { |
| 49 | + { packet.name } |
| 50 | + } |
| 51 | + _packet{nullptr}; |
| 52 | + { % endfor % } |
| 53 | + {% for socket in sockets -% |
61 | 54 | } |
| 55 | + inline static {{socket.type}}* { |
| 56 | + { socket.name } |
| 57 | + } |
| 58 | + {nullptr}; |
| 59 | + { % endfor % } |
| 60 | + |
| 61 | + static void start() { |
| 62 | + {% for packet in packets -% |
| 63 | + } |
| 64 | + if ({ |
| 65 | + { packet.name } |
| 66 | + } _packet == nullptr) { |
| 67 | + ErrorHandler("Packet {{packet.name}} not initialized"); |
| 68 | + } |
| 69 | + { % endfor % } |
62 | 70 |
|
| 71 | + {% for socket in ServerSockets -% |
| 72 | + } |
| 73 | + {{socket.name}} = new ServerSocket("{{socket.board_ip}}", {{socket.port}}); |
| 74 | + { % -endfor % } |
| 75 | + {% for socket in DatagramSockets -% |
| 76 | + } |
| 77 | + {{socket.name}} = new DatagramSocket( |
| 78 | + "{{socket.board_ip}}", |
| 79 | + {{socket.port}}, |
| 80 | + "{{socket.remote_ip}}", |
| 81 | + {{socket.port}} |
| 82 | + ); |
| 83 | + { % endfor % } |
| 84 | + {% for socket in Sockets -% |
| 85 | + } |
| 86 | + {{socket.name}} = new Socket( |
| 87 | + "{{socket.board_ip}}", |
| 88 | + {{socket.local_port}}, |
| 89 | + "{{socket.remote_ip}}", |
| 90 | + {{socket.remote_port}} |
| 91 | + ); |
| 92 | + { % endfor % } |
63 | 93 |
|
64 | | - |
| 94 | + {%- for packet in sending_packets % |
| 95 | + } |
| 96 | + Scheduler::register_task( |
| 97 | + { % if packet.period_type == "ms" % } { |
| 98 | + { (packet.period * 1000) | round | int } |
| 99 | + } { % else % } { |
| 100 | + { packet.period | round | int } |
| 101 | + } { % endif % }, |
| 102 | + +[]() { |
| 103 | + { % if packet.name is string - % } |
| 104 | + DataPackets::{ |
| 105 | + { packet.socket } |
| 106 | + } -> send_packet(*DataPackets::{ |
| 107 | + { packet.name } |
| 108 | + } _packet); |
| 109 | + { % else % } |
| 110 | + {% for name in packet.name -% |
| 111 | + } |
| 112 | + DataPackets::{ |
| 113 | + { packet.socket } |
| 114 | + } -> send_packet(*DataPackets::{ |
| 115 | + { name } |
| 116 | + } _packet); |
| 117 | + { % endfor - % } |
| 118 | + { % -endif % } |
| 119 | + } |
| 120 | + ); |
| 121 | + { % -endfor % } |
| 122 | + } |
65 | 123 | }; |
0 commit comments