Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand All @@ -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<uint16_t>({{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<uint16_t>({{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");
Expand All @@ -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
}


Expand Down
6 changes: 4 additions & 2 deletions Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OrderPackets{
{% endfor %}

OrderPackets() = default;

#ifdef STLIB_ETH
{% for packet in packets -%}
inline static HeapOrder *{{packet.name}}_order{nullptr};
{% endfor %}
Expand All @@ -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");
Expand All @@ -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:
Expand Down
Loading