From 0b5fe4ea2d4f9980e33fff497f825de0cd7a88cb Mon Sep 17 00:00:00 2001 From: Cantonplas Date: Thu, 21 May 2026 19:07:31 +0200 Subject: [PATCH] Add round robin and Stack Packet to DataTemplate. Now DataPackets and OrderPackets work without ethernet --- .../Packet_generation/DataTemplate.hpp | 29 ++++++++++++++----- .../Packet_generation/OrderTemplate.hpp | 6 ++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp b/Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp index 81dae9d1..865bf7f7 100644 --- a/Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp +++ b/Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp @@ -3,6 +3,10 @@ /*Data packets for {{board}} -AUTOGENERATED CODE, DO NOT MODIFY-*/ + +#ifndef ARRAY_LEN +#define ARRAY_LEN(Arr) (sizeof(Arr)/sizeof(Arr[0])) +#endif class DataPackets{ public: {% for enum in enums -%} @@ -13,25 +17,35 @@ class DataPackets{ {%- endfor %} }; {% endfor %} - +#ifdef STLIB_ETH {% for packet in packets -%} static void {{packet.name}}_init({% for variable in packet.variables %}{{variable.type}} &{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %}) { - {{packet.name}}_packet = new HeapPacket(static_cast({{packet.id}}){% if packet.variables %}, {% for variable in packet.variables %}&{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}); + {{packet.name}}_packet = new StackPacket(static_cast({{packet.id}}){% if packet.variables %}, {% for variable in packet.variables %}&{{variable.name}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}); } {% endfor -%} +#endif public: +#ifdef STLIB_ETH {%for packet in packets -%} - inline static HeapPacket *{{packet.name}}_packet{nullptr}; + inline static Packet *{{packet.name}}_packet{nullptr}; {% endfor %} + + {% for group in sending_packets -%} + inline static uint32_t group_{{loop.index0}}_idx = 0; + inline static Packet **group_{{loop.index0}}[] = { {% for packet in group.packets %}&{{packet.name}}_packet{% if not loop.last %}, {% endif %}{% endfor %} }; + {% endfor %} + {% for socket in DatagramSockets -%} inline static {{socket.type}} *{{socket.name}}{nullptr}; {% endfor %} +#endif static void start() { +#ifdef STLIB_ETH {% for packet in packets -%} if ({{packet.name}}_packet == nullptr) { PANIC("Packet {{packet.name}} not initialized"); @@ -43,12 +57,13 @@ class DataPackets{ {% endfor %} {%- for group in sending_packets %} - Scheduler::register_task({% if group.period_type == "ms" %}{{ (group.period*1000)|round|int }}{% else %}{{ group.period|round|int }}{% endif %}, +[](){ - {% for packet in group.packets -%} - DataPackets::{{packet.socket}}->send_packet(*DataPackets::{{packet.name}}_packet); - {% endfor -%} + Scheduler::register_task({% if group.period_type == "ms" %}{{ (group.period*1000)|round|int }}{% else %}{{ group.period|round|int }}{% endif %} / ARRAY_LEN(DataPackets::group_{{loop.index0}}), +[](){ + Packet *packet = *DataPackets::group_{{loop.index0}}[DataPackets::group_{{loop.index0}}_idx]; + DataPackets::{{group.packets[0].socket}}->send_packet(*packet); + DataPackets::group_{{loop.index0}}_idx = (DataPackets::group_{{loop.index0}}_idx + 1) % ARRAY_LEN(DataPackets::group_{{loop.index0}}); }); {%- endfor %} +#endif } diff --git a/Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp b/Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp index 6911008e..122b087a 100644 --- a/Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp +++ b/Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp @@ -21,7 +21,7 @@ class OrderPackets{ {% endfor %} OrderPackets() = default; - +#ifdef STLIB_ETH {% for packet in packets -%} inline static HeapOrder *{{packet.name}}_order{nullptr}; {% endfor %} @@ -39,9 +39,10 @@ class OrderPackets{ {% for socket in ServerSockets -%} inline static {{socket.type}} *{{socket.name}}{nullptr}; {% endfor %} - +#endif static void start() { +#ifdef STLIB_ETH {% for packet in packets -%} if ({{packet.name}}_order == nullptr) { PANIC("Order {{packet.name}} not initialized"); @@ -54,6 +55,7 @@ class OrderPackets{ {% for socket in Sockets -%} {{socket.name}} = new Socket("{{socket.board_ip}}",{{socket.local_port}},"{{socket.remote_ip}}",{{socket.remote_port}}); {% endfor %} +#endif } private: