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
733f5e75
Commit
733f5e75
authored
4 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
correctly interpret CoE data
parent
1972b9a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ebpfcat/ethercat.py
+65
-48
65 additions, 48 deletions
ebpfcat/ethercat.py
with
65 additions
and
48 deletions
ebpfcat/ethercat.py
+
65
−
48
View file @
733f5e75
...
@@ -26,34 +26,41 @@ class ECCmd(Enum):
...
@@ -26,34 +26,41 @@ class ECCmd(Enum):
FRMW
=
14
# Configured Read Multiple Write
FRMW
=
14
# Configured Read Multiple Write
class
ECDatatype
(
Enum
):
class
ECDataType
(
Enum
):
BOOLEAN
=
0x1
def
__new__
(
cls
,
value
,
fmt
):
INTEGER8
=
0x2
obj
=
object
.
__new__
(
cls
)
INTEGER16
=
0x3
obj
.
_value_
=
value
INTEGER32
=
0x4
obj
.
fmt
=
fmt
UNSIGNED8
=
0x5
return
obj
UNSIGNED16
=
0x6
BOOLEAN
=
0x1
,
"
?
"
UNSIGNED32
=
0x7
INTEGER8
=
0x2
,
"
b
"
REAL32
=
0x8
INTEGER16
=
0x3
,
"
h
"
VISIBLE_STRING
=
0x9
INTEGER32
=
0x4
,
"
i
"
OCTET_STRING
=
0xA
UNSIGNED8
=
0x5
,
"
B
"
UNICODE_STRING
=
0xB
UNSIGNED16
=
0x6
,
"
H
"
TIME_OF_DAY
=
0xC
UNSIGNED32
=
0x7
,
"
I
"
TIME_DIFFERENCE
=
0xD
REAL32
=
0x8
,
"
f
"
DOMAIN
=
0xF
VISIBLE_STRING
=
0x9
,
None
INTEGER24
=
0x10
OCTET_STRING
=
0xA
,
None
REAL64
=
0x11
UNICODE_STRING
=
0xB
,
None
INTEGER64
=
0x15
TIME_OF_DAY
=
0xC
,
"
I
"
UNSIGNED24
=
0x16
TIME_DIFFERENCE
=
0xD
,
"
i
"
UNSIGNED64
=
0x1B
DOMAIN
=
0xF
,
"
i
"
BIT1
=
0x30
INTEGER24
=
0x10
,
"
i
"
BIT2
=
0x31
REAL64
=
0x11
,
"
d
"
BIT3
=
0x32
INTEGER64
=
0x15
,
"
q
"
BIT4
=
0x33
UNSIGNED24
=
0x16
,
"
i
"
BIT5
=
0x34
UNSIGNED64
=
0x1B
,
"
Q
"
BIT6
=
0x35
BIT1
=
0x30
,
"
B
"
BIT7
=
0x36
BIT2
=
0x31
,
"
B
"
BIT8
=
0x37
BIT3
=
0x32
,
"
B
"
BIT4
=
0x33
,
"
B
"
BIT5
=
0x34
,
"
B
"
BIT6
=
0x35
,
"
B
"
BIT7
=
0x36
,
"
B
"
BIT8
=
0x37
,
"
B
"
UNKNOWN1
=
2048
,
None
UNKNOWN2
=
2049
,
None
class
MBXType
(
Enum
):
class
MBXType
(
Enum
):
ERR
=
0
# Error
ERR
=
0
# Error
...
@@ -102,11 +109,23 @@ class ODCmd(Enum):
...
@@ -102,11 +109,23 @@ class ODCmd(Enum):
class
ObjectDescription
:
class
ObjectDescription
:
pass
def
__init__
(
self
,
terminal
):
self
.
terminal
=
terminal
class
ObjectEntry
:
class
ObjectEntry
:
pass
def
__init__
(
self
,
desc
):
self
.
desc
=
desc
async
def
read
(
self
):
ret
=
await
self
.
desc
.
terminal
.
sdo_read
(
self
.
desc
.
index
,
self
.
valueInfo
)
if
self
.
dataType
in
(
ECDataType
.
VISIBLE_STRING
,
ECDataType
.
UNICODE_STRING
):
return
ret
.
decode
(
"
utf8
"
)
elif
self
.
dataType
.
fmt
is
None
:
return
ret
else
:
return
unpack
(
"
<
"
+
self
.
dataType
.
fmt
,
ret
)[
0
]
def
datasize
(
args
,
data
):
def
datasize
(
args
,
data
):
...
@@ -550,9 +569,9 @@ class Terminal:
...
@@ -550,9 +569,9 @@ class Terminal:
for
index
in
idxes
:
for
index
in
idxes
:
data
=
await
self
.
coe_request
(
CoECmd
.
SDOINFO
,
ODCmd
.
OD_REQ
,
data
=
await
self
.
coe_request
(
CoECmd
.
SDOINFO
,
ODCmd
.
OD_REQ
,
"
H
"
,
index
)
"
H
"
,
index
)
dtype
,
oc
,
ms
=
unpack
(
"
<HBB
"
,
data
[:
4
])
dtype
,
ms
,
oc
=
unpack
(
"
<HBB
"
,
data
[:
4
])
od
=
ObjectDescription
()
od
=
ObjectDescription
(
self
)
od
.
index
=
index
od
.
index
=
index
od
.
dataType
=
dtype
# ECDataType(dtype)
od
.
dataType
=
dtype
# ECDataType(dtype)
od
.
maxSub
=
ms
od
.
maxSub
=
ms
...
@@ -561,16 +580,16 @@ class Terminal:
...
@@ -561,16 +580,16 @@ class Terminal:
for
od
in
ret
:
for
od
in
ret
:
od
.
entries
=
{}
od
.
entries
=
{}
for
i
in
range
(
od
.
maxSub
):
for
i
in
range
(
1
if
od
.
maxSub
>
0
else
0
,
od
.
maxSub
+
1
):
try
:
data
=
await
self
.
coe_request
(
CoECmd
.
SDOINFO
,
ODCmd
.
OE_REQ
,
data
=
await
self
.
coe_request
(
CoECmd
.
SDOINFO
,
ODCmd
.
OE_REQ
,
"
HBB
"
,
od
.
index
,
i
,
7
)
"
HBB
"
,
od
.
index
,
i
,
7
)
oe
=
ObjectEntry
(
od
)
except
RuntimeError
:
oe
.
valueInfo
,
dataType
,
oe
.
bitLength
,
oe
.
objectAccess
=
\
# many OEs just do not have more description
continue
oe
=
ObjectEntry
()
oe
.
valueInfo
,
oe
.
dataType
,
oe
.
bitLength
,
oe
.
objectAccess
=
\
unpack
(
"
<HHHH
"
,
data
[:
8
])
unpack
(
"
<HHHH
"
,
data
[:
8
])
if
dataType
==
0
:
continue
assert
i
==
oe
.
valueInfo
oe
.
dataType
=
ECDataType
(
dataType
)
oe
.
name
=
data
[
8
:].
decode
(
"
utf8
"
)
oe
.
name
=
data
[
8
:].
decode
(
"
utf8
"
)
od
.
entries
[
i
]
=
oe
od
.
entries
[
i
]
=
oe
return
ret
return
ret
...
@@ -596,14 +615,12 @@ async def main():
...
@@ -596,14 +615,12 @@ async def main():
await
tout
.
to_operational
(),
await
tout
.
to_operational
(),
odlist
=
await
tin
.
read_ODlist
()
odlist
=
await
tin
.
read_ODlist
()
for
o
in
odlist
:
for
o
in
odlist
:
print
(
o
.
index
,
o
.
name
)
print
(
hex
(
o
.
index
)
,
o
.
name
,
o
.
maxSub
)
for
i
,
p
in
o
.
entries
.
items
():
for
i
,
p
in
o
.
entries
.
items
():
print
(
"
"
,
i
,
p
.
name
,
p
.
valueInfo
,
p
.
dataType
,
p
.
bitLength
,
p
.
objectAccess
)
print
(
"
"
,
i
,
p
.
name
,
"
|
"
,
p
.
dataType
,
p
.
bitLength
,
p
.
objectAccess
)
try
:
#sdo = await tin.sdo_read(o.index, i)
sdo
=
await
tin
.
sdo_read
(
o
.
index
,
i
)
sdo
=
await
p
.
read
()
print
(
"
"
,
sdo
)
print
(
"
"
,
sdo
)
except
RuntimeError
as
e
:
print
(
"
"
,
e
)
print
(
"
tdigi
"
)
print
(
"
tdigi
"
)
print
(
"
bla
"
,
lookup_elem
(
map_fd
,
b
"
AAAA
"
,
4
))
print
(
"
bla
"
,
lookup_elem
(
map_fd
,
b
"
AAAA
"
,
4
))
await
tdigi
.
to_operational
(),
await
tdigi
.
to_operational
(),
...
...
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