Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c9f0992
Feat connect without elf (#65)
edras Dec 9, 2024
a0bec06
Feat unified parser (#66)
yashagarwal-314 Dec 10, 2024
a99c6e4
removed repeated variable info.
Dec 10, 2024
cc75d1a
Feat import export variable list (#68)
edras Dec 11, 2024
392afac
Merge commit '00df87dc9847536dab19dabd7512a0964b5bb80d'
MarkWendler Dec 11, 2024
65b973d
Cleaning repo
MarkWendler Dec 11, 2024
dc589e5
Add build executable github actions and pyinstaller spec
MarkWendler Dec 10, 2024
16627e4
Build executable only on manual trigger, fix of run command on shell cmd
MarkWendler Dec 10, 2024
5150fab
Testing actions withouth requirements installation only quality.
MarkWendler Dec 10, 2024
0c671de
adding requirements.txt for buildexecutables
MarkWendler Dec 10, 2024
45cac6a
Adding mchplnet local dependency checkout
MarkWendler Dec 10, 2024
973bf76
Add build executable github actions and pyinstaller spec
MarkWendler Dec 9, 2024
24c2ec0
Fix action does not show up on github
MarkWendler Dec 9, 2024
3980142
Build executable only on manual trigger, fix of run command on shell cmd
MarkWendler Dec 9, 2024
a1e7274
Testing actions withouth requirements installation only quality.
MarkWendler Dec 9, 2024
9d23e4c
Updating submodule handle, updating linux spec file
MarkWendler Dec 10, 2024
420fc4f
Cleaning repo
MarkWendler Dec 11, 2024
970867b
Update docs
MarkWendler Dec 11, 2024
6ae1620
CamelCase to sneak_case and bring examples to same naming convention …
MarkWendler Dec 12, 2024
50991fa
run buildexe action only on manual trigger
MarkWendler Dec 12, 2024
fb224c7
fix scope trigger and enumeration type (#87)
MarkWendler Feb 20, 2025
255ccba
Fix struct enum (#92)
edras May 13, 2025
e5be3f4
recovering deleted file
May 13, 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pyx2cscope"
version = "0.4.1"
version = "0.4.2"
description = "python implementation of X2Cscope"
authors = [
"Yash Agarwal <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions pyx2cscope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""This module contains the pyx2cscope package.

Version: 0.4.1
Version: 0.4.2
"""

import logging

__version__ = "0.4.1"
__version__ = "0.4.2"


def set_logger(
Expand Down
2 changes: 1 addition & 1 deletion pyx2cscope/examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

x2cscope.request_scope_data()

while(1):
while True:
if x2cscope.is_scope_data_ready():
print(x2cscope.get_scope_channel_data())
491 changes: 210 additions & 281 deletions pyx2cscope/parser/generic_parser.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyx2cscope/variable/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class VariableInfo:
name (str): The name of the variable.
type (str): The data type of the variable.
byte_size (int): The size of the variable in bytes.
bit_size (int): bit_size of variable if size is less than a byte (e.g.: union type)
bit_offset (int): bit_offset of variable if size is less than a byte (e.g.: union type)
address (int): The memory address of the variable.
array_size (int): The size of the array if the variable is an array, default is 0.
valid_values (dict): enum type of valid values
Expand All @@ -45,6 +47,8 @@ class VariableInfo:
name: str
type: str
byte_size: int
bit_size: int
bit_offset: int
address: int
array_size: int
valid_values: Dict[str, int]
Expand Down
12 changes: 7 additions & 5 deletions pyx2cscope/variable/variable_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def get_variable(self, name: str) -> Variable | None:
"""
try:
variable_info = self.parser.get_var_info(name)

return self.get_variable_raw(variable_info)
except Exception as e:
logging.error(f"Error while getting variable '{name}' : {str(e)}")
Expand Down Expand Up @@ -233,15 +232,18 @@ def get_variable_raw(self, var_info: VariableInfo) -> Variable:
"unsigned int": VariableUint16,
"unsigned long": VariableUint32,
"unsigned long long": VariableUint64,
"enum anonymousenum": VariableEnum,
"enum": VariableEnum,
}

try:

var_type: str = var_info.type.lower().replace("_", "")
if var_type == "enum anonymousenum":
return type_factory[var_type](self.l_net, var_info.address, var_info.array_size, var_info.name, var_info.valid_values)
return type_factory[var_type](self.l_net, var_info.address, var_info.array_size, var_info.name)
params = [self.l_net, var_info.address, var_info.array_size, var_info.name]
if "enum" in var_type:
var_type = "enum"
params.append(var_info.valid_values)

return type_factory[var_type](*params)
except IndexError:
raise ValueError(
f"Type {var_type} not found. Cannot select the right variable representation."
Expand Down
41 changes: 40 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,28 @@ def test_array_variable_32(self, mocker, array_size_test=255):
assert variable.is_array() == True, "variable should be an array"
assert len(variable) == array_size_test, "array has wrong length"

def test_variable_dspic33ak(self, mocker, array_size_test=4900):
def test_union_variable_16(self, mocker):
"""Given a valid 32 bit elf file, check if an array variable is read correctly."""
fake_serial(mocker, 16)
x2c_scope = X2CScope(port="COM14", elf_file=self.elf_file_16)
variable_lo = x2c_scope.get_variable("motor.vqFiltered.state.x16.lo")
variable_hi = x2c_scope.get_variable("motor.vqFiltered.state.x16.hi")
variable_union = x2c_scope.get_variable("motor.vqFiltered.state.x32")
assert variable_lo is not None, "variable name not found"
assert variable_hi is not None, "variable name not found"
assert variable_union is not None, "variable name not found"
assert variable_lo.address == variable_union.address, "variable union should have the same address as segment"
assert variable_hi.address == variable_union.address + 2, "variable high should have address + 2"

def test_variable_dspic33ak(self, mocker, array_size_test=4900, address=22122):
"""Given a valid dspic33ak elf file, check if an array variable is read correctly."""
fake_serial(mocker, 32)
x2c_scope = X2CScope(port="COM14")
x2c_scope.import_variables(self.elf_file_dspic33ak)
variable = x2c_scope.get_variable("measureInputs.current.Ia")
assert variable is not None, "variable name not found"
assert variable.is_array() == False, "variable should be an array"
assert variable.address == address, "variable has wrong address, check offset calculation"
# test array
variable_array = x2c_scope.get_variable("X2C_BUFFER")
assert variable_array is not None, "variable name not found"
Expand All @@ -77,6 +91,31 @@ def test_nested_array_variable_32(self, mocker, array_size_test=3):
assert variable.is_array() == True, "variable should be an array"
assert len(variable) == array_size_test, "array has wrong length"

def test_variable_enum_32(self, mocker, size6=6, size3=3):
"""Given a valid dspic33ck elf file, check if an enum variable is read correctly."""
fake_serial(mocker, 32)
x2c_scope = X2CScope(port="COM14", elf_file=self.elf_file_32)
# test simple variable enum
variable = x2c_scope.get_variable("nextGlobalState")
assert variable is not None, "variable name not found"
assert variable.is_array() == False, "variable should not be an array"
assert len(variable.enum_list) == size6, "enum size should be 6"
# test nested enum inside a structure
variable = x2c_scope.get_variable("mcFoc_State_mds.FocState")
assert variable is not None, "variable name not found"
assert variable.is_array() == False, "variable should not be an array"
assert len(variable.enum_list) == size3, "enum size should be 3"

def test_variable_enum_16(self, mocker, size6=6):
"""Given a valid dspic33ck elf file, check if an enum variable is read correctly."""
fake_serial(mocker, 32)
x2c_scope = X2CScope(port="COM14", elf_file=self.elf_file_16)
# test nested enum inside a structure
variable = x2c_scope.get_variable("motor.apiData.motorStatus")
assert variable is not None, "variable name not found"
assert variable.is_array() == False, "variable should not be an array"
assert len(variable.enum_list) == size6, "enum size should be 3"

def test_variable_export_import(self, mocker):
"""Given a valid 32 bit elf file, check if export and import functions for variables are working."""
fake_serial(mocker, 32)
Expand Down