Sync parser

sync parser implementation
This commit is contained in:
Martin Girard committed 2026-09-18 19:37:46 +02:00
1 parent 96cc366595
commit d2318b6903
4 files changed
+64 -3

No files matched your search

+4
View File
@@ -9,6 +9,7 @@ authors = [
requires-python = ">=3.13"
dependencies = [
"pyserial>=3.5",
"serial-sync",
]
[project.scripts]
@@ -17,3 +18,6 @@ bench-data-connector = "bench_data_connector:main"
[build-system]
requires = ["uv_build>=0.12.12,<0.13.0"]
build-backend = "uv_build"
[tool.uv.sources]
serial-sync = { git = "https://git.h3cx.dev/Exergie/serial-sync.git", tag = "v0.1.1" }
@@ -1,6 +1,7 @@
from serial.tools import list_ports
from serial import Serial
from dataclasses import dataclass
from serial_sync import SerialSync
import struct
DATA_STRUCT = struct.Struct("<BIf")
@@ -21,13 +22,16 @@ def main() -> None:
choice = None
ports = list(list_ports.comports())
for index, port in enumerate(ports):
if len(ports) < 0:
print("No serial ports found.")
return
print(f"{index}: {port.device} {port.description}")
try:
choice = int(input("Choose a port to connect: "))
except ValueError:
pass
while choice is None or choice >= len(ports):
while choice is None or choice >= len(ports) or choice < 0:
try:
choice = int(input("Unknown port. Try again : "))
@@ -42,10 +46,13 @@ def main() -> None:
exit(0)
with Serial(selected_port,baudrate=115200,timeout=1) as ser:
sync = SerialSync(ser)
sync.calibrate_sync(30)
print(f"sync ok\nOffset:{sync._offset}\nScale:{sync._scale}")
while True:
start_sync(ser)
#print("paquet trouvé")
print(DATA_STRUCT.size)
#print(DATA_STRUCT.size)
payload = read_exactly(ser, DATA_STRUCT.size)
if not payload:
+13 -1
View File
@@ -8,10 +8,14 @@ version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "pyserial" },
{ name = "serial-sync" },
]
[package.metadata]
requires-dist = [{ name = "pyserial", specifier = ">=3.5" }]
requires-dist = [
{ name = "pyserial", specifier = ">=3.5" },
{ name = "serial-sync", git = "https://git.h3cx.dev/Exergie/serial-sync.git?tag=v0.1.1" },
]
[[package]]
name = "pyserial"
@@ -21,3 +25,11 @@ sdist = { url = "https://files.pythonhosted.org/packages/1e/7d/ae3f0a63f41e4d2f6
wheels = [
{ url = "https://files.pythonhosted.org/packages/07/bc/587a445451b253b285629263eb51c2d8e9bcea4fc97826266d186f96f558/pyserial-3.5-py2.py3-none-any.whl", hash = "sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0", size = 90585, upload-time = "2020-11-23T03:59:13.41Z" },
]
[[package]]
name = "serial-sync"
version = "0.1.1"
source = { git = "https://git.h3cx.dev/Exergie/serial-sync.git?tag=v0.1.1#cf7e5466a9ac31bf1cc83d1e9a522cbb4afb2efb" }
dependencies = [
{ name = "pyserial" },
]