Skip to content

Commit 9fde208

Browse files
Fix/code gen improvement 2.0.1.0 (#69)
* Added improved error handeling for python autogenerator script * Eliminated state machine generation and protection * La blcu funciona va chavales, ahora si que si apuntito de caramelo V2 * La blcu funciona va chavales, ahora si que si apuntito de caramelo V2 --------- Co-authored-by: Jorge Sáez <jorgeesg82@gmail.com>
1 parent 9c01e69 commit 9fde208

3 files changed

Lines changed: 66 additions & 18 deletions

File tree

Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DataPackets{
2626
{%for packet in packets -%}
2727
inline static HeapPacket *{{packet.name}}_packet{nullptr};
2828
{% endfor %}
29-
{% for socket in sockets -%}
29+
{% for socket in DatagramSockets -%}
3030
inline static {{socket.type}} *{{socket.name}}{nullptr};
3131
{% endfor %}
3232

@@ -38,26 +38,17 @@ class DataPackets{
3838
}
3939
{% endfor %}
4040

41-
{% for socket in ServerSockets -%}
42-
{{socket.name}} = new ServerSocket("{{socket.board_ip}}",{{socket.port}});
43-
{%- endfor %}
4441
{% for socket in DatagramSockets -%}
4542
{{socket.name}} = new DatagramSocket("{{socket.board_ip}}",{{socket.port}},"{{socket.remote_ip}}",{{socket.port}});
4643
{% 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 %}
5044

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 -%}
45+
{%- for group in sending_packets %}
46+
Scheduler::register_task({% if group.period_type == "ms" %}{{ (group.period*1000)|round|int }}{% else %}{{ group.period|round|int }}{% endif %}, +[](){
47+
{% for packet in group.packets -%}
5448
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);
5849
{% endfor -%}
59-
{%- endif %}
60-
}); {%- endfor %}
50+
});
51+
{%- endfor %}
6152
}
6253

6354

Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ class OrderPackets{
3333
}
3434
{% endfor %}
3535

36+
{% for socket in Sockets -%}
37+
inline static {{socket.type}} *{{socket.name}}{nullptr};
38+
{% endfor %}
39+
{% for socket in ServerSockets -%}
40+
inline static {{socket.type}} *{{socket.name}}{nullptr};
41+
{% endfor %}
42+
43+
static void start()
44+
{
45+
{% for packet in packets -%}
46+
if ({{packet.name}}_order == nullptr) {
47+
ErrorHandler("Order {{packet.name}} not initialized");
48+
}
49+
{% endfor %}
50+
51+
{% for socket in ServerSockets -%}
52+
{{socket.name}} = new ServerSocket("{{socket.board_ip}}",{{socket.port}});
53+
{%- endfor %}
54+
{% for socket in Sockets -%}
55+
{{socket.name}} = new Socket("{{socket.board_ip}}",{{socket.local_port}},"{{socket.remote_ip}}",{{socket.remote_port}});
56+
{% endfor %}
57+
}
58+
3659
private:
3760
{% for packet in packets -%}
3861
static void {{packet.name}}_cb()

Core/Inc/Code_generation/Packet_generation/Packet_generation.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,49 @@ def GenerateDataPackets(board:BoardDescription):
7171
return Packets,totaldata
7272

7373
packets,data = GenerateDataPackets(board)
74+
75+
def GenerateGroupedSendingPackets(board: BoardDescription):
76+
datagram_sockets = [s["name"] for s in board.sockets.DatagramSockets]
77+
grouped_lookup = {}
78+
79+
for packet in board.sending_packets:
80+
socket_name = packet["socket"]
81+
if socket_name not in datagram_sockets:
82+
continue
83+
84+
period = packet["period"]
85+
period_type = packet["period_type"]
86+
names = packet["name"]
87+
88+
key = (period, period_type)
89+
if key not in grouped_lookup:
90+
grouped_lookup[key] = []
91+
92+
if isinstance(names, list):
93+
for name in names:
94+
grouped_lookup[key].append({"socket": socket_name, "name": name})
95+
else:
96+
grouped_lookup[key].append({"socket": socket_name, "name": names})
97+
98+
grouped_list = []
99+
for (period, period_type), items in grouped_lookup.items():
100+
grouped_list.append({
101+
"period": period,
102+
"period_type": period_type,
103+
"packets": items
104+
})
105+
return grouped_list
106+
74107
context = {
75108
"board": board.name,
76109
"enums": GenerateDataEnum(board),
77110
"packets" : packets,
78111
"data": data,
79112
"size": board.order_size,
80-
"sockets":board.sockets.allSockets,
81-
"ServerSockets":board.sockets.ServerSockets,
82113
"Sockets":board.sockets.Sockets,
83114
"DatagramSockets":board.sockets.DatagramSockets,
84-
"sending_packets": board.sending_packets,
115+
"DatagramSocketNames": [s["name"] for s in board.sockets.DatagramSockets],
116+
"sending_packets": GenerateGroupedSendingPackets(board),
85117
}
86118
return context
87119

@@ -154,6 +186,8 @@ def GenerateOrderPackets(board:BoardDescription):
154186
"packets" : packets,
155187
"data": data,
156188
"size": board.order_size,
189+
"ServerSockets":board.sockets.ServerSockets,
190+
"Sockets":board.sockets.Sockets,
157191
}
158192
return context
159193

0 commit comments

Comments
 (0)