Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1baff4a
Add argv
Cantonplas Feb 28, 2025
4935f21
Works, i think
Cantonplas Feb 28, 2025
2d7a243
Fix repo name problem
Cantonplas Feb 28, 2025
f50722b
Created variable board
Cantonplas Mar 1, 2025
3285604
Merge branch 'Code_generation_fix' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Mar 3, 2025
35fc114
Some changes
Cantonplas Mar 6, 2025
5b167af
Merge branch 'Code_generation_fix' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Mar 26, 2025
b9dc5af
Merge branch 'FW-301/Execute_Code_gen_on_cmake' of https://github.com…
Cantonplas Mar 26, 2025
e0ffbc2
Changed generator.py and cmakelist, now cmakelist board needs to be m…
Cantonplas Mar 26, 2025
62bf0c4
Merge branch 'main' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Apr 9, 2025
ec302cd
Changes on cmake and some tests for making the github actions work
Cantonplas Apr 9, 2025
321ebfd
Testing to delete the results of the generation for github actions
Cantonplas Apr 9, 2025
1e1ca84
The test didnt work again
Cantonplas Apr 9, 2025
ab5ee07
Uploaded the folder so that it works
Cantonplas Apr 9, 2025
55f1c66
Merge branch 'main' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Jun 5, 2025
0e82c9f
Temporal changes
Cantonplas Aug 31, 2025
2d4eccb
Changed packet description structure and how it reads adj, works fine
Cantonplas Sep 1, 2025
b2fd7be
Deleted generated code
Cantonplas Sep 1, 2025
ff301c6
Silly change that makes it so it doesnt explode when you put a wrong …
Cantonplas Sep 1, 2025
69116f1
Merge branch 'main' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Sep 9, 2025
52814b9
Sockets are now created automatically
Cantonplas Sep 10, 2025
623bcc0
Missed a _, now working
Cantonplas Sep 10, 2025
91b8c40
Autogenerated code now creates sockets and send packets on a set peri…
Cantonplas Sep 10, 2025
789ac6e
Working version, testing to be done
Cantonplas Sep 10, 2025
f845aa5
Testing in course
Cantonplas Sep 10, 2025
ed703ab
New version now creates sockets and sends the packets correctly
Cantonplas Sep 11, 2025
85c1e62
Updated deps
Cantonplas Sep 11, 2025
4c9e8d4
Fixed Order Packets, now working
Cantonplas Sep 11, 2025
485b4fa
Deleted generated code
Cantonplas Sep 13, 2025
2bbf1e9
Update Core/Inc/Code_generation/Packet_generation/Packet_generation.py
Cantonplas Jan 20, 2026
47075b7
Merge remote-tracking branch 'origin/main' into FW-301/Execute_Code_g…
Cantonplas Jan 22, 2026
5c58756
Merge branch 'FW-301/Execute_Code_gen_on_cmake' of https://github.com…
Cantonplas Jan 22, 2026
c6aa833
6 months later maybe this time we can aprove this pr
Cantonplas Jan 22, 2026
788b26c
Deleted generated code
Cantonplas Jan 22, 2026
2833d51
Deps update and deleted comments
Cantonplas Jan 23, 2026
01cca43
Merge branch 'main' into FW-301/Execute_Code_gen_on_cmake
Cantonplas Jan 23, 2026
7cb761b
Now it works
Cantonplas Jan 23, 2026
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
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@
"utility": "cpp",
"variant": "cpp",
"atomic": "cpp",
<<<<<<< HEAD
"string": "cpp",
"string_view": "cpp",
"ranges": "cpp",
"span": "cpp",
"bitset": "cpp",
"initializer_list": "cpp",
"stacktrace": "cpp",
"regex": "cpp",
"valarray": "cpp"
=======
"bitset": "cpp",
"cstdlib": "cpp",
"mutex": "cpp",
"shared_mutex": "cpp",
"regex": "cpp"
>>>>>>> origin/main
}
}
45 changes: 42 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,51 @@ cmake_minimum_required(VERSION 3.14)
project(template-project LANGUAGES ASM C CXX)

set(EXECUTABLE ${PROJECT_NAME}.elf)
set(STLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/ST-LIB)
set(Board "VCU") # User must change the Board name
set(STLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/ST-LIB)
set(LD_SCRIPT ${STLIB_DIR}/STM32H723ZGTX_FLASH.ld)

find_package(Python3 COMPONENTS Interpreter REQUIRED)

set(GENERATOR_SCRIPT "${CMAKE_SOURCE_DIR}/Core/Inc/Code_generation/Generator.py")

add_custom_target(run_generator ALL
COMMAND ${Python3_EXECUTABLE} ${GENERATOR_SCRIPT} ${Board}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

if(CMAKE_HOST_WIN32 )
set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/Scripts/python)
else()
set(VENV_PYTHON ${CMAKE_SOURCE_DIR}/virtual/bin/python)
endif()
option(USE_ETHERNET "Enable ethernet peripheral" OFF)
option(TARGET_NUCLEO "Targets the STM32H723 Nucleo dev board" OFF)

add_custom_target(
my_custom_target_that_always_runs ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_tmp.h
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/_tmp.h # fake! ensure we run!
COMMAND ${VENV_PYTHON} ${CMAKE_SOURCE_DIR}/tools/generate_binary_metadata.py
)

option(USE_ETHERNET "Enable ethernet peripheral" OFF)
option(TARGET_NUCLEO "Targets the STM32H723 Nucleo development board" OFF)

if (PROJECT_IS_TOP_LEVEL AND (NOT CMAKE_CROSSCOMPILING))
include(FetchContent)
option(BUILD_GMOCK OFF)
option(INSTALL_GTEST OFF)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
)
FetchContent_MakeAvailable(googletest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest_main)
endif()

message(STATUS "Template project: CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}")
message(STATUS "Template project: USE_ETHERNET = ${USE_ETHERNET}")
Expand Down Expand Up @@ -129,3 +165,6 @@ else()
COMMENT "Removing BOARD build marker (NUCLEO build)"
)
endif()



30 changes: 20 additions & 10 deletions Core/Inc/Code_generation/Generator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import json
import sys
from Packet_generation.Packet_generation import *
from State_machine_generation.State_machine_generation import *

if len(sys.argv)<2:
print("Please enter a board name,exiting...")
sys.exit()

JSONpath = "Core/Inc/Code_generation/JSON_ADE"
aux = sys.argv[1]
filtered = ""
for char in aux:
if char.isalpha():
filtered += char
else:
break
board = filtered


JSONpath = "Core/Inc/Code_generation/JSON_ADE"
boards = Generate_PacketDescription(JSONpath)
board = input("Enter board name: ")
while board not in boards:
print("Board not found, select an available board")
board = input("Enter board name: ")
Generate_DataPackets_hpp(board)
Generate_OrderPackets_hpp(board)
Generate_Protections_hpp(board)
boards = Generate_PacketDescription(JSONpath, board)

if __name__ == "__main__":
Generate_DataPackets_hpp(board)
Generate_OrderPackets_hpp(board)
# Generate_Protections_hpp(board), no protections for now
with open("state_machine.json", "r") as file:
data = json.load(file)
sm = parse_state_machine(data)
Expand All @@ -26,4 +35,5 @@





2 changes: 1 addition & 1 deletion Core/Inc/Code_generation/JSON_ADE
39 changes: 28 additions & 11 deletions Core/Inc/Code_generation/Packet_generation/DataTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@

//Data packets for {{board}} -AUTOGENERATED CODE, DO NOT MODIFY-
class DataPackets{
{% for enum in enums %}enum class {{enum.name}}:uint8_t{
public:
{% for enum in enums %}enum class {{enum.name}}:uint8_t
{
{% for value in enum["values"] %}{{value}}={{loop.index0}}{%if not loop.last%},{%endif%}
{% endfor %}};
{%endfor %}

{%endfor %}

private:
constexpr static size_t size={{size}};
uint32_t id{0};
inline static uint32_t id{0};
public:
std::array<StackPacket*,size> packets;
{%for packet in packets%}StackPacket* {{packet.name}};
{%for packet in packets%}static inline HeapPacket* {{packet.name}}{};
{% endfor %}

{% for socket in sockets %}static inline {{socket.type}}* {{socket.name}} = nullptr;
{% endfor %}

DataPackets({%for value in data %}{{value.type}} &{{value.name}}{%if not loop.last%},{%endif%}{%endfor%}}})
{
DataPackets({%for value in data %}{{value.type}} &{{value.name}}{%if not loop.last%},{%endif%}{%endfor%})
{
{% for socket in ServerSockets%}{{socket.name}} = new ServerSocket("{{socket.board_ip}}",{{socket.port}});
{% endfor %}
{% for socket in DatagramSockets%}{{socket.name}} = new DatagramSocket("{{socket.board_ip}}",{{socket.port}},"{{socket.remote_ip}}",{{socket.port}});
{% endfor %}
{% for socket in Sockets%}{{socket.name}} = new Socket("{{socket.board_ip}}",{{socket.local_port}},"{{socket.remote_ip}}",{{socket.remote_port}});
{% endfor %}
{% for packet in packets %}{{packet.name}} = new HeapPacket(static_cast<uint16_t>({{packet.id}}){% if packet.data%},{{packet.data}}{% endif%});

{% for packet in packets %}{{packet.name}} = new StackPacket({{packet.id}}{% if packet.data%},{{packet.data}}{% endif%});
packets[id]={{packet.name}};
id++;
{% endfor %}
{%for packet in sending_packets %}Scheduler::register_task({% if packet.period_type == "ms" %}{{(packet.period*1000)}}{% else %}{{packet.period}}{% endif %},+[](){
{% if packet.name is string %} DataPackets::{{packet.socket}}->send_packet(*DataPackets::{{packet.name}});
{%else%}
{%for name in packet.name%}DataPackets::{{packet.socket}}->send_packet(*{{name}});
{%endfor%}
{% endif %}
});
{%endfor%}


}
};
20 changes: 10 additions & 10 deletions Core/Inc/Code_generation/Packet_generation/OrderTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
#include "ST-LIB.hpp"

//Order packets for {{board}} -AUTOGENERATED CODE, DO NOT MODIFY-

{%for packet in packets%}extern void {{packet.name}}_cb();
{% endfor %}
class OrderPackets{
{% for enum in enums %}enum class {{enum.name}}:uint8_t{
{% for enum in enums %}enum class {{enum.name}}:uint8_t
{
{% for value in enum["values"] %}{{value}}={{loop.index0}}{%if not loop.last%},{%endif%}
{% endfor %}};
{% endfor %}

{%for packet in packets%}bool {{packet.name}}_callback();
{% endfor %}



private:
constexpr static size_t size={{size}};
uint32_t id{0};
public:
std::array<StackOrder*,size> packets;
{%for packet in packets%}StackOrder* {{packet.name}};
{%for packet in packets%}HeapOrder* {{packet.name}};
{% endfor %}

OrderPackets({%for value in data %}{{value.type}} &{{value.name}}{%if not loop.last%},{%endif%}{%endfor%}}})
OrderPackets({%for value in data %}{{value.type}} &{{value.name}}{%if not loop.last%},{%endif%}{%endfor%})
{

{% for packet in packets %}{{packet.name}}=new StackOrder({{packet.id}},{{packet.name}}_callback{% if packet.data%},{{packet.data}}{% endif%});
packets[id]={{packet.name}};
id++;
{% for packet in packets %}{{packet.name}}=new HeapOrder({{packet.id}},&{{packet.name}}_cb{% if packet.data%},{{packet.data}}{% endif%});
{% endfor %}
}
};
Loading