2023-12-09 10:48:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0])))
|
|
|
|
|
|
|
|
from draw_memory_map import memory_table # noqa: E402
|
|
|
|
|
|
|
|
from srnemqtt.config import get_config, get_interface # noqa: E402
|
2023-12-09 15:35:45 +00:00
|
|
|
from srnemqtt.interfaces import BaseInterface # noqa: E402
|
2023-12-09 10:48:53 +00:00
|
|
|
from srnemqtt.protocol import readMemory # noqa: E402
|
|
|
|
|
|
|
|
|
2023-12-09 15:35:45 +00:00
|
|
|
def get_device_name(iface: BaseInterface) -> str | None:
|
2023-12-09 10:48:53 +00:00
|
|
|
data = readMemory(iface, 0x0C, 8)
|
|
|
|
if data is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return data.decode("utf-8").strip()
|
|
|
|
|
|
|
|
|
2023-12-09 15:35:45 +00:00
|
|
|
def get_device_version(iface: BaseInterface) -> str | None:
|
2023-12-09 10:48:53 +00:00
|
|
|
data = readMemory(iface, 0x14, 4)
|
|
|
|
if data is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
major = (data[0] << 8) + data[1]
|
|
|
|
minor = data[2]
|
|
|
|
patch = data[3]
|
|
|
|
|
|
|
|
return f"{major}.{minor}.{patch}"
|
|
|
|
|
|
|
|
|
2023-12-09 15:35:45 +00:00
|
|
|
def get_device_serial(iface: BaseInterface) -> str | None:
|
2023-12-09 10:48:53 +00:00
|
|
|
data = readMemory(iface, 0x18, 3)
|
|
|
|
if data is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
p1 = data[0]
|
|
|
|
p2 = data[1]
|
|
|
|
p3 = (data[2] << 8) + data[3]
|
|
|
|
return f"{p1}-{p2}-{p3}"
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
conf = get_config()
|
|
|
|
iface = get_interface(conf)
|
|
|
|
|
|
|
|
print(get_device_name(iface))
|
|
|
|
print(get_device_version(iface))
|
|
|
|
print(get_device_serial(iface))
|
|
|
|
|
|
|
|
data: List[int] = []
|
|
|
|
for i in range(0, 0xFFFF, 16):
|
|
|
|
newdata = readMemory(iface, i, 16)
|
|
|
|
if newdata:
|
|
|
|
data.extend(newdata)
|
|
|
|
# !!! FIXME: Naively assumes all queries return the exact words requested
|
|
|
|
print(
|
|
|
|
memory_table(
|
|
|
|
data,
|
|
|
|
wordsize=2,
|
|
|
|
skip_nullrows=True,
|
|
|
|
)
|
|
|
|
)
|