Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ebpfCAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
karaboDevices
ebpfCAT
Commits
d7d02f14
Commit
d7d02f14
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
add writer and reader for serial no
parent
7dfa08d8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ebpfcat/ethercat.py
+13
-0
13 additions, 0 deletions
ebpfcat/ethercat.py
ebpfcat/scripts.py
+54
-0
54 additions, 0 deletions
ebpfcat/scripts.py
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
with
68 additions
and
0 deletions
ebpfcat/ethercat.py
+
13
−
0
View file @
d7d02f14
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/scripts.py
+
54
−
0
View file @
d7d02f14
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
:
4
X
}
:
{
subidx
:
02
X
}
{
sm
}
{
pos
}
{
fmt
}
"
)
print
(
f
"
{
idx
:
4
X
}
:
{
subidx
:
02
X
}
{
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
:
8
X
}
{
c
:
8
X
}
{
r
==
c
}
"
)
else
:
print
(
f
"
{
r
:
8
X
}
{
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
:
8
X
}
{
w
}
"
)
if
w
is
not
None
:
await
t
.
eeprom_write_one
(
0xe
,
w
&
0xffff
)
await
t
.
eeprom_write_one
(
0xf
,
w
>>
16
)
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
0
View file @
d7d02f14
...
@@ -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"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment