Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • teichman/ebpfcat
1 result
Show changes
Commits on Source (3)
...@@ -24,7 +24,7 @@ from enum import Enum ...@@ -24,7 +24,7 @@ from enum import Enum
import logging import logging
import os import os
from struct import pack, unpack, calcsize, pack_into, unpack_from from struct import pack, unpack, calcsize, pack_into, unpack_from
from time import time from time import monotonic
from .arraymap import ArrayMap, ArrayGlobalVarDesc from .arraymap import ArrayMap, ArrayGlobalVarDesc
from .ethercat import ( from .ethercat import (
ECCmd, EtherCat, MachineState, Packet, Terminal, EtherCatError, ECCmd, EtherCat, MachineState, Packet, Terminal, EtherCatError,
...@@ -502,6 +502,8 @@ class BaseType(Enum): ...@@ -502,6 +502,8 @@ class BaseType(Enum):
class SyncGroupBase: class SyncGroupBase:
missed_counter = 0 missed_counter = 0
cycletime = 0.01 # cycle time of the PLC loop
task = None
current_data = None current_data = None
logical_in = logical_out = None logical_in = logical_out = None
...@@ -543,12 +545,13 @@ class SyncGroupBase: ...@@ -543,12 +545,13 @@ class SyncGroupBase:
async with self.map_fmmu(): async with self.map_fmmu():
task = ensure_future(self.to_operational()) task = ensure_future(self.to_operational())
try: try:
lasttime = monotonic()
while True: while True:
self.ec.send_packet(data) self.ec.send_packet(data)
try: try:
data = await wait_for( data = await wait_for(
self.ec.receive_index(self.packet_index), self.ec.receive_index(self.packet_index),
timeout=0.1) timeout=0.05)
except TimeoutError: except TimeoutError:
self.missed_counter += 1 self.missed_counter += 1
logging.warning( logging.warning(
...@@ -556,6 +559,9 @@ class SyncGroupBase: ...@@ -556,6 +559,9 @@ class SyncGroupBase:
self.missed_counter) self.missed_counter)
continue continue
data = self.update_devices(data) data = self.update_devices(data)
newtime = monotonic()
await sleep(self.cycletime - (newtime - lasttime))
lasttime = monotonic()
finally: finally:
task.cancel() task.cancel()
try: try:
...@@ -617,6 +623,7 @@ class SyncGroup(SyncGroupBase): ...@@ -617,6 +623,7 @@ class SyncGroup(SyncGroupBase):
raise raise
def start(self): def start(self):
assert self.task is None or self.task.done()
self.allocate() self.allocate()
self.packet_index = SyncGroup.packet_index self.packet_index = SyncGroup.packet_index
SyncGroup.packet_index += 1 SyncGroup.packet_index += 1
......
...@@ -467,7 +467,6 @@ class EtherCat(Protocol): ...@@ -467,7 +467,6 @@ class EtherCat(Protocol):
def connection_made(self, transport): def connection_made(self, transport):
"""start the send loop once the connection is made""" """start the send loop once the connection is made"""
transport.get_extra_info("socket").bind(self.addr)
self.transport = transport self.transport = transport
ensure_future(self.sendloop()) ensure_future(self.sendloop())
......
...@@ -58,7 +58,6 @@ class XDRFD(DatagramProtocol): ...@@ -58,7 +58,6 @@ class XDRFD(DatagramProtocol):
def connection_made(self, transport): def connection_made(self, transport):
sock = transport.get_extra_info("socket") sock = transport.get_extra_info("socket")
sock.setsockopt(270, 11, 1) sock.setsockopt(270, 11, 1)
sock.bind((0, 0))
self.transport = transport self.transport = transport
# this was adopted from xdp1_user.c # this was adopted from xdp1_user.c
p = pack("IHHIIBxHiIiHHHHiHHI", p = pack("IHHIIBxHiIiHHHHiHHI",
......