Skip to content

Commit

Permalink
Merge pull request #167 from semuconsulting/RC-1.2.48
Browse files Browse the repository at this point in the history
RC 1.2.48
  • Loading branch information
semuadmin authored Nov 7, 2024
2 parents 4a6de31 + ac05f6d commit d79c4d8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"editor.formatOnSave": true,
"modulename": "${workspaceFolderBasename}",
"distname": "${workspaceFolderBasename}",
"moduleversion": "1.2.47",
"moduleversion": "1.2.48",
}
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# pyubx2 Release Notes

### RELEASE 1.2.48

ENHANCEMENTS:

1. Add helper methods `val2twoscomp` and `val2signmag` to convert signed integer to appropriate two's complement or sign magnitude binary representation.

### RELEASE 1.2.47

ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pyubx2"
authors = [{ name = "semuadmin", email = "[email protected]" }]
maintainers = [{ name = "semuadmin", email = "[email protected]" }]
description = "UBX protocol parser and generator"
version = "1.2.47"
version = "1.2.48"
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.9"
Expand Down
2 changes: 1 addition & 1 deletion src/pyubx2/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
:license: BSD 3-Clause
"""

__version__ = "1.2.47"
__version__ = "1.2.48"
28 changes: 28 additions & 0 deletions src/pyubx2/ubxhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,31 @@ def process_monver(msg: object) -> dict:
verdata["gnss"] = gnss_supported

return verdata


def val2twoscomp(val: int, att: str) -> int:
"""
Convert signed integer to two's complement binary representation.
:param int val: value
:param str att: attribute type e.g. "U024"
:return: two's complement representation of value
:rtype: int
"""

return val & pow(2, attsiz(att)) - 1


def val2signmag(val: int, att: str) -> int:
"""
Convert signed integer to sign magnitude binary representation.
High-order bit represents sign (0 +ve, 1 -ve).
:param int val: value
:param str att: attribute type e.g. "U024"
:return: sign magnitude representation of value
:rtype: int
"""

return (abs(val) & pow(2, attsiz(att)) - 1) | ((1 if val < 0 else 0) << attsiz(att))
14 changes: 14 additions & 0 deletions tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
utc2itow,
val2bytes,
val2sphp,
val2twoscomp,
val2signmag,
)


Expand Down Expand Up @@ -333,6 +335,18 @@ def testprocess_monver(self):
res = process_monver(msg)
self.assertEqual(res, EXPECTED_RESULT)

def testval2twoscomp(self):
res = val2twoscomp(10, "U24")
self.assertEqual(res, 0b0000000000000000000001010)
res = val2twoscomp(-10, "U24")
self.assertEqual(res, 0b111111111111111111110110)

def testval2signmag(self):
res = val2signmag(10, "U24")
self.assertEqual(res, 0b0000000000000000000001010)
res = val2signmag(-10, "U24")
self.assertEqual(res, 0b1000000000000000000001010)


if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
Expand Down

0 comments on commit d79c4d8

Please sign in to comment.