Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Fix use 0x prefix to identify hex values (#75)
Browse files Browse the repository at this point in the history
closes #74

Co-authored-by: Brian ONeill <[email protected]>
  • Loading branch information
Boneill3 and Boneill3 authored Aug 29, 2021
1 parent d7e7550 commit 5500868
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion canopen_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MAJOR = 4
MINOR = 0
PATCH = 1
PATCH = 2

APP_NAME = 'canopen-monitor'
APP_DESCRIPTION = 'An NCurses-based TUI application for tracking activity' \
Expand Down
8 changes: 5 additions & 3 deletions canopen_monitor/parse/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ def __len__(self) -> int:
def convert_value(value: str) -> Union[int, str]:
# Turn number-like objects into numbers
if (value != ''):
if (all(c in string.hexdigits for c in value)):
return int(value, 16)
elif (all(c in string.digits for c in value)):
if value.startswith("0x") and all(c in string.hexdigits for c in value):
return int(value[2:], 16)
if (all(c in string.digits for c in value)):
return int(value, 10)
elif (all(c in string.hexdigits for c in value)):
return int(value, 16)
else:
return value

Expand Down
4 changes: 2 additions & 2 deletions tests/spec_eds_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_get_node_id(self):
"""
DCF Parsing set node id attribute
"""
self.assertEqual(0x10,
self.assertEqual(10,
self.eds.node_id,
"Error parsing node id")

Expand Down Expand Up @@ -163,7 +163,7 @@ def test_invalid_subindex_when_no_subindices(self):
class TestExtendedPDODefinition(unittest.TestCase):
def setUp(self):
# node id defined in file
self.node_id = 0x10
self.node_id = 10
with patch('builtins.open', mock_open(read_data=TEST_DCF)) as _:
with patch('os.listdir') as mocked_listdir:
mocked_listdir.return_value = ["battery.dcf"]
Expand Down

0 comments on commit 5500868

Please sign in to comment.