Skip to content
Snippets Groups Projects
Commit d7d02f14 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

add writer and reader for serial no

parent 7dfa08d8
No related branches found
No related tags found
No related merge requests found
...@@ -565,6 +565,19 @@ class Terminal: ...@@ -565,6 +565,19 @@ class Terminal:
busy, data = await self.read(0x502, "H4x8s") busy, data = await self.read(0x502, "H4x8s")
return data return data
async def eeprom_write_one(self, start, data):
"""read 2 bytes from the eeprom at `start`"""
while (await self.read(0x502, "H"))[0] & 0x8000:
pass
busy = 0x1000
while busy & 0xff00:
await self.write(0x502, "HIH", 0x201, start, data)
busy = 0x8000
while busy & 0x8000:
busy, = await self.read(0x502, "H")
print(f"busy {busy:X}")
await self.write(0x502, "H", 0)
async def read_eeprom(self): async def read_eeprom(self):
"""read the entire eeprom""" """read the entire eeprom"""
async def get_data(size): async def get_data(size):
......
from argparse import ArgumentParser from argparse import ArgumentParser
import asyncio import asyncio
from functools import wraps from functools import wraps
from hashlib import sha1
from struct import unpack from struct import unpack
import sys import sys
...@@ -84,3 +85,56 @@ async def info(): ...@@ -84,3 +85,56 @@ async def info():
await t.parse_pdos() await t.parse_pdos()
for (idx, subidx), (sm, pos, fmt) in t.pdos.items(): for (idx, subidx), (sm, pos, fmt) in t.pdos.items():
print(f"{idx:4X}:{subidx:02X} {sm} {pos} {fmt}") print(f"{idx:4X}:{subidx:02X} {sm} {pos} {fmt}")
def encode(name):
r = int.from_bytes(sha1(name.encode("ascii")).digest(), "little")
return r % 0xffffffff + 1
@entrypoint
async def eeprom():
parser = ArgumentParser(
prog = "ec-eeprom",
description = "Read and write the eeprom")
parser.add_argument("interface")
parser.add_argument("-t", "--terminal", type=int)
parser.add_argument("-r", "--read", action="store_true")
parser.add_argument("-w", "--write", type=int)
parser.add_argument("-n", "--name", type=str)
parser.add_argument("-c", "--check", type=str)
args = parser.parse_args()
ec = EtherCat(args.interface)
await ec.connect()
if args.terminal is None:
return
terminals = range(await ec.count())
else:
# former terminal: don't listen!
# this does not work with all terminals, dunno why
await ec.roundtrip(ECCmd.FPRW, 7, 0x10, "H", 0)
terminals = [args.terminal]
t = Terminal()
t.ec = ec
await t.initialize(-args.terminal, 7)
if args.read or args.check is not None:
r, = unpack("<4xI", await t.eeprom_read_one(0xc))
if args.check is not None:
c = encode(args.check)
print(f"{r:8X} {c:8X} {r == c}")
else:
print(f"{r:8X} {r}")
w = None
if args.write is not None:
w = args.write
elif args.name is not None:
w = encode(args.name)
print(f"{w:8X} {w}")
if w is not None:
await t.eeprom_write_one(0xe, w & 0xffff)
await t.eeprom_write_one(0xf, w >> 16)
...@@ -6,3 +6,4 @@ dependencies = [] ...@@ -6,3 +6,4 @@ dependencies = []
[project.scripts] [project.scripts]
ec-scanbus = "ebpfcat.scripts:scanbus" ec-scanbus = "ebpfcat.scripts:scanbus"
ec-info = "ebpfcat.scripts:info" ec-info = "ebpfcat.scripts:info"
ec-eeprom = "ebpfcat.scripts:eeprom"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment