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
cd579568
Commit
cd579568
authored
4 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
support an analog output
parent
c10bf540
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
devices.py
+14
-0
14 additions, 0 deletions
devices.py
ebpfcat.py
+13
-5
13 additions, 5 deletions
ebpfcat.py
terminals.py
+7
-0
7 additions, 0 deletions
terminals.py
testsystem.py
+11
-7
11 additions, 7 deletions
testsystem.py
with
45 additions
and
12 deletions
devices.py
+
14
−
0
View file @
cd579568
...
...
@@ -13,3 +13,17 @@ class AnalogInput(Device):
def
update
(
self
):
self
.
value
=
self
.
data
class
AnalogOutput
(
Device
):
value
=
DeviceVar
()
data
=
TerminalVar
()
def
__init__
(
self
,
data
):
self
.
data
=
data
def
program
(
self
):
self
.
data
=
self
.
value
def
update
(
self
):
self
.
data
=
self
.
value
This diff is collapsed.
Click to expand it.
ebpfcat.py
+
13
−
5
View file @
cd579568
from
asyncio
import
ensure_future
,
gather
,
sleep
from
struct
import
pack
,
unpack
,
calcsize
from
struct
import
pack
,
unpack
,
calcsize
,
pack_into
,
unpack_from
from
time
import
time
from
.arraymap
import
ArrayMap
,
ArrayGlobalVarDesc
from
.ethercat
import
ECCmd
,
EtherCat
,
Packet
,
Terminal
...
...
@@ -38,8 +38,14 @@ class TerminalVar(MemoryDesc):
self
.
terminal
=
value
.
terminal
self
.
position
=
value
.
desc
.
position
instance
.
__dict__
[
self
.
name
]
=
value
el
s
e
:
el
if
instance
.
sync_group
.
current_data
is
Non
e
:
super
().
__set__
(
instance
.
sync_group
,
value
)
else
:
pv
=
instance
.
__dict__
.
get
(
self
.
name
)
data
=
instance
.
sync_group
.
current_data
start
=
self
.
terminal
.
bases
[
self
.
position
[
0
]]
+
self
.
position
[
1
]
fmt
=
"
<
"
+
pv
.
desc
.
size
pack_into
(
fmt
,
data
,
start
,
value
)
def
__get__
(
self
,
instance
,
owner
):
if
instance
is
None
:
...
...
@@ -53,7 +59,7 @@ class TerminalVar(MemoryDesc):
data
=
instance
.
sync_group
.
current_data
start
=
self
.
terminal
.
bases
[
self
.
position
[
0
]]
+
self
.
position
[
1
]
fmt
=
"
<
"
+
pv
.
desc
.
size
return
unpack
(
fmt
,
data
[
start
:
start
+
calcsize
(
fmt
)]
)[
0
]
return
unpack
_from
(
fmt
,
data
,
start
)[
0
]
def
__set_name__
(
self
,
name
,
owner
):
self
.
name
=
name
...
...
@@ -203,9 +209,11 @@ class SyncGroup:
async
def
run
(
self
):
await
gather
(
*
[
t
.
to_operational
()
for
t
in
self
.
terminals
])
self
.
current_data
=
self
.
asm_packet
while
True
:
self
.
ec
.
send_packet
(
self
.
asm_packet
)
self
.
current_data
=
await
self
.
ec
.
receive_index
(
self
.
packet_index
)
self
.
ec
.
send_packet
(
self
.
current_data
)
data
=
await
self
.
ec
.
receive_index
(
self
.
packet_index
)
self
.
current_data
=
bytearray
(
data
)
for
dev
in
self
.
devices
:
dev
.
update
()
...
...
This diff is collapsed.
Click to expand it.
terminals.py
+
7
−
0
View file @
cd579568
...
...
@@ -5,6 +5,13 @@ class Generic(EBPFTerminal):
pass
class
EL4104
(
EBPFTerminal
):
ch1_value
=
PacketDesc
((
1
,
0
),
'
H
'
)
ch2_value
=
PacketDesc
((
1
,
2
),
'
H
'
)
ch3_value
=
PacketDesc
((
1
,
4
),
'
H
'
)
ch4_value
=
PacketDesc
((
1
,
6
),
'
H
'
)
class
EL3164
(
EBPFTerminal
):
ch1_attrs
=
PacketDesc
((
0
,
0
),
'
H
'
)
ch2_attrs
=
PacketDesc
((
0
,
4
),
'
H
'
)
...
...
This diff is collapsed.
Click to expand it.
testsystem.py
+
11
−
7
View file @
cd579568
from
asyncio
import
gather
,
sleep
,
ensure_future
from
.terminals
import
EL3164
,
Generic
from
.devices
import
AnalogInput
from
.terminals
import
EL3164
,
EL4104
,
Generic
from
.devices
import
AnalogInput
,
AnalogOutput
from
.ebpfcat
import
FastEtherCat
,
FastSyncGroup
,
SyncGroup
tdigi
=
Generic
()
tout
=
Generic
()
tout
=
EL4104
()
tin
=
EL3164
()
ec
=
FastEtherCat
(
"
eth0
"
,
[
tdigi
,
tin
,
tout
])
...
...
@@ -22,15 +22,19 @@ async def main():
#ensure_future(monitor(ec))
ai
=
AnalogInput
(
tin
.
ch1_value
)
fsg
=
FastSyncGroup
(
ec
,
[
ai
])
#fsg = SyncGroup(ec, [ai])
ao
=
AnalogOutput
(
tout
.
ch1_value
)
#fsg = FastSyncGroup(ec, [ai])
fsg
=
SyncGroup
(
ec
,
[
ai
,
ao
])
ao
.
value
=
0
fsg
.
start
()
for
i
in
range
(
10
):
await
sleep
(
0.1
)
fsg
.
properties
.
read
()
print
(
i
,
ai
.
value
,
ec
.
ebpf
.
count
,
ec
.
ebpf
.
allcount
)
#fsg.properties.read()
ao
.
value
=
3000
*
i
print
(
i
,
ai
.
value
,
ao
.
data
,
await
tout
.
get_state
())
if
__name__
==
"
__main__
"
:
from
asyncio
import
get_event_loop
...
...
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