Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9502346
create complex parser
dcoutinho1328 Jul 21, 2025
cbec3a0
fixing nested structs and structs outside of type declaration
dcoutinho1328 Jul 21, 2025
2ddd246
add error prints to sys error and run formatter
dcoutinho1328 Jul 21, 2025
6f01bf6
change logic to allow all data types inside struct
dcoutinho1328 Jul 21, 2025
7c5628e
add debug.c.j2 to final build
JoaoGSP Jul 22, 2025
150175e
update build script
JoaoGSP Jul 23, 2025
55419f5
Code-Rabbit: Update ComplexParser.py
dcoutinho1328 Jul 24, 2025
f36573a
Code-rabbit: Update ComplexParser.py
dcoutinho1328 Jul 24, 2025
a601391
applying suggested changes from coderabbit
dcoutinho1328 Jul 24, 2025
649d72a
changing arguments and parsing complex also in debugging
dcoutinho1328 Jul 24, 2025
e6f1396
Merge pull request #9 from Autonomy-Logic/FIX-update-binary-build
thiagoralves Jul 24, 2025
19bcba7
Merge pull request #8 from Autonomy-Logic/RTOP-35-Add-support-for-com…
thiagoralves Jul 24, 2025
e688fba
Update build.yml to correct data paths for PyInstaller
JoaoGSP Jul 24, 2025
076744b
parsing arrays and structs
dcoutinho1328 Aug 13, 2025
9da559e
ran black formatter
dcoutinho1328 Aug 13, 2025
7c2960d
coderabbit changes
dcoutinho1328 Aug 13, 2025
147116f
fixing build pipeline to look for templates
dcoutinho1328 Aug 13, 2025
efcf9ab
Merge pull request #10 from Autonomy-Logic/FIX-update-binary-build
thiagoralves Aug 13, 2025
b5bf79b
Add MD5 checksum generation to embedded PLC debugger and update funct…
dcoutinho1328 Aug 14, 2025
ef61a48
add devcontainer name
dcoutinho1328 Aug 14, 2025
16dbda7
Added functionality to generate glueVars.c
Aug 16, 2025
b56438c
Fix buffer pointer names on GlueGenerator
thiagoralves Aug 16, 2025
313707e
Fixed glueVars.c j2 template
thiagoralves Aug 16, 2025
51e989d
Fix forward logic error of coils when connecting multiple coils in LD
thiagoralves Aug 17, 2025
d0fecb8
Merge branch 'development' into RTOP-38-Add-support-for-ARRAY-on-debug.c
thiagoralves Aug 18, 2025
fbdf3ea
adding checksum
dcoutinho1328 Aug 18, 2025
dbeaf2f
Merge pull request #12 from Autonomy-Logic/adding-checksum-to-debug
thiagoralves Aug 18, 2025
5ccca70
Merge branch 'development' into Generate-glue-vars
Aug 19, 2025
97f5fff
fix to array var declarations
dcoutinho1328 Aug 25, 2025
7c23543
Update glueVars jinja template to generate code for Arduino boards
thiagoralves Aug 27, 2025
b88005b
Merge pull request #13 from Autonomy-Logic/Generate-glue-vars
thiagoralves Aug 27, 2025
1e4298c
Fix located variables on Arduino builds
thiagoralves Aug 30, 2025
7766138
fixing variable parsing to compile correctly
dcoutinho1328 Sep 2, 2025
b349496
Merge branch 'development' into RTOP-38-Add-support-for-ARRAY-on-debug.c
dcoutinho1328 Sep 2, 2025
ac19ee2
fixing array dependant variable
dcoutinho1328 Sep 9, 2025
8cd6e6b
Merge pull request #11 from Autonomy-Logic/RTOP-38-Add-support-for-AR…
thiagoralves Sep 10, 2025
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
Prev Previous commit
Next Next commit
ran black formatter
  • Loading branch information
dcoutinho1328 committed Aug 13, 2025
commit 9da559eae43c348619dddcd52dbfa77144a0f95c
51 changes: 28 additions & 23 deletions ComplexParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

## CUSTOM CLASSES FOR BLOCK INSTANCES


class _InsertLine:
def __init__(self, index):
self.index = index
Expand Down Expand Up @@ -108,8 +109,10 @@ def AddBlock(self, block):
if self.simple and hasattr(block, "simple"):
self.simple = block.simple


## MAIN COMPLEX PARSER CLASS


class ComplexParser:

## PRIVATE METHODS AND CONSTRUCTORS
Expand Down Expand Up @@ -321,7 +324,7 @@ def __getCustomType(self, type_name):
if custom_type.name == type_name:
return custom_type
return None

def __getFunctionBlock(self, name):
"""
Get the function block by its name.
Expand All @@ -330,7 +333,7 @@ def __getFunctionBlock(self, name):
if block.name == name:
return block
return None

def __spreadDeclarations(self, block, prefix="", write_base_types=True):
"""
Spread the declarations of the block.
Expand All @@ -339,7 +342,9 @@ def __spreadDeclarations(self, block, prefix="", write_base_types=True):
for i in range(block.start, block.end + 1):
index_prefix = f"{prefix}.table[{i}]"
if block.data_type in BASE_TYPES:
self.csv_vars.append({"name": index_prefix, "type": block.data_type})
self.csv_vars.append(
{"name": index_prefix, "type": block.data_type}
)
else:
type = self.__getCustomType(block.data_type)
if type:
Expand All @@ -356,30 +361,34 @@ def __spreadDeclarations(self, block, prefix="", write_base_types=True):
function_block = self.__getFunctionBlock(block.data_type)
if function_block:
for inner_block in function_block.inner_blocks:
self.__spreadDeclarations(inner_block, prefix=prefix, write_base_types=False)
self.__spreadDeclarations(
inner_block, prefix=prefix, write_base_types=False
)
elif block.type == STRUCT.name:
for inner_block in block.inner_blocks:
if isinstance(inner_block, _VariableInstance):
self.__spreadDeclarations(inner_block, prefix=prefix)

def __addVarDeclarations(self, program, prefix=""):
program_block = next(
(p for p in self.programs if p.name == program), None
)
program_block = next((p for p in self.programs if p.name == program), None)
if program_block:
for block in program_block.inner_blocks:
if isinstance(block, _VariableInstance):
self.__spreadDeclarations(block, prefix)

def __findProgramInstances(self):
"""
Find program instances in the ST file.
"""
for block in self.blocks:
if block.type == CONFIGURATION.name:
for resource in filter(lambda x: x.type == RESOURCE.name, block.inner_blocks):
for resource in filter(
lambda x: x.type == RESOURCE.name, block.inner_blocks
):
program_instances = [
PROGRAM_DEFINITION.GetInfo(line) for line in resource.lines if PROGRAM_DEFINITION.GetInfo(line)
PROGRAM_DEFINITION.GetInfo(line)
for line in resource.lines
if PROGRAM_DEFINITION.GetInfo(line)
]
for program_instance in program_instances:
prefix = f"{block.name.upper()}.{resource.name.upper()}.{program_instance['instance'].upper()}"
Expand All @@ -388,10 +397,6 @@ def __findProgramInstances(self):
def __appendVarsToCSV(self, csv_file):
"""
Append new variable lines before the Ticktime section using regex matching.

:param content: Original file content as a string.
:param new_vars: List of variable lines (strings) to append.
:return: Modified file content with new variables inserted before Ticktime.
"""

content = []
Expand All @@ -410,30 +415,30 @@ def __appendVarsToCSV(self, csv_file):

if ticktime_idx is None:
raise ValueError("Ticktime section not found in lines.")

while ticktime_idx >= 1 and EMPTY_LINE.match(content[ticktime_idx - 1]):
ticktime_idx -= 1

last_var_number = -1

if ticktime_idx > 0:
extracted_var_number = var_number_pattern.match(content[ticktime_idx - 1]).group(1)
extracted_var_number = var_number_pattern.match(
content[ticktime_idx - 1]
).group(1)
if extracted_var_number:
last_var_number = int(extracted_var_number)

template = Environment(loader=self.__loader).get_template(
CSV_VARS_TEMPLATE
)
template = Environment(loader=self.__loader).get_template(CSV_VARS_TEMPLATE)

formatted_vars = []
for var in self.csv_vars:
last_var_number += 1
formatted_vars.append(
f"{template.render(i=last_var_number, var=var)}\n"
)
formatted_vars.append(f"{template.render(i=last_var_number, var=var)}\n")

with open(csv_file, "w") as f:
f.writelines(content[:ticktime_idx] + formatted_vars + [""] + content[ticktime_idx:])
f.writelines(
content[:ticktime_idx] + formatted_vars + [""] + content[ticktime_idx:]
)

return content[:ticktime_idx] + formatted_vars + [""] + content[ticktime_idx:]

Expand Down
1 change: 1 addition & 0 deletions STParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def GetInfo(self, line):
}
return None


class _ProgramDefinition(_NamedBlock):
def __init__(self):
super().__init__("program_definition")
Expand Down
4 changes: 3 additions & 1 deletion xml2st.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def main():
elif args.generate_debug and len(args.generate_debug) == 2:
try:
complex_parser = ComplexParser()
complex_parser.AddComplexVars(args.generate_debug[0], args.generate_debug[1])
complex_parser.AddComplexVars(
args.generate_debug[0], args.generate_debug[1]
)

debug_text = generate_debugger_file(args.generate_debug[1])

Expand Down
Loading