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)
...@@ -33,6 +33,7 @@ from contextlib import asynccontextmanager ...@@ -33,6 +33,7 @@ from contextlib import asynccontextmanager
from enum import Enum, IntEnum from enum import Enum, IntEnum
from itertools import count from itertools import count
import logging import logging
import operator
from random import randint from random import randint
from socket import socket, AF_PACKET, SOCK_DGRAM from socket import socket, AF_PACKET, SOCK_DGRAM
from struct import pack, unpack, unpack_from, calcsize from struct import pack, unpack, unpack_from, calcsize
...@@ -355,7 +356,10 @@ class EtherCat(Protocol): ...@@ -355,7 +356,10 @@ class EtherCat(Protocol):
logging.info("future already done, dropped datagram") logging.info("future already done, dropped datagram")
except CancelledError: except CancelledError:
raise raise
except Exception: except Exception as e:
for _, _, future in dgrams:
if not future.done():
future.set_exception(e)
logging.exception("process_packet failed") logging.exception("process_packet failed")
raise raise
...@@ -408,9 +412,8 @@ class EtherCat(Protocol): ...@@ -408,9 +412,8 @@ class EtherCat(Protocol):
out += b"\0" * data out += b"\0" * data
elif data is not None: elif data is not None:
out += data out += data
assert isinstance(pos, int) and isinstance(offset, int), \ self.send_queue.put_nowait((cmd, out, idx, operator.index(pos),
f"pos: {pos} offset: {offset}" operator.index(offset), future))
self.send_queue.put_nowait((cmd, out, idx, pos, offset, future))
ret = await future ret = await future
if data is None: if data is None:
return unpack(fmt, ret) return unpack(fmt, ret)
......
...@@ -29,7 +29,7 @@ class Skip(EBPFTerminal): ...@@ -29,7 +29,7 @@ class Skip(EBPFTerminal):
class EL1808(EBPFTerminal): class EL1808(EBPFTerminal):
compatibility = {(2, 118501458)} compatibility = {(2, 118501458), (2, 0x3F03052)}
channel1 = ProcessDesc(0x6000, 1) channel1 = ProcessDesc(0x6000, 1)
channel2 = ProcessDesc(0x6010, 1) channel2 = ProcessDesc(0x6010, 1)
...@@ -41,6 +41,27 @@ class EL1808(EBPFTerminal): ...@@ -41,6 +41,27 @@ class EL1808(EBPFTerminal):
channel8 = ProcessDesc(0x6070, 1) channel8 = ProcessDesc(0x6070, 1)
class EL2212(EBPFTerminal):
compatibility = {(2, 0x8A43052)}
class Channel(Struct):
output = ProcessDesc(0x7000, 2)
boost_current = ServiceDesc(0x8000, 1)
hold_current = ServiceDesc(0x8000, 2)
supply_voltage = ServiceDesc(0x8000, 3)
coil_resistance = ServiceDesc(0x8000, 5)
booster_on_time = ServiceDesc(0x8000, 6)
booster_off_time = ServiceDesc(0x8000, 7)
switch_off_threshold = ServiceDesc(0x8000, 8)
enable_booster_on = ServiceDesc(0x8002, 1)
enable_booster_off = ServiceDesc(0x8002, 2)
enable_off_threshold = ServiceDesc(0x8002, 3)
channel1 = Channel(0)
channel2 = Channel(0x10)
class EL2808(EBPFTerminal): class EL2808(EBPFTerminal):
compatibility = {(2, 184037458), (2, 0x7D83052)} compatibility = {(2, 184037458), (2, 0x7D83052)}
......
...@@ -25,7 +25,7 @@ from contextlib import asynccontextmanager, contextmanager ...@@ -25,7 +25,7 @@ from contextlib import asynccontextmanager, contextmanager
import os import os
from socket import AF_NETLINK, NETLINK_ROUTE, if_nametoindex from socket import AF_NETLINK, NETLINK_ROUTE, if_nametoindex
import socket import socket
from struct import pack, unpack from struct import pack, unpack_from
from .ebpf import EBPF, MemoryDesc from .ebpf import EBPF, MemoryDesc
from .bpf import ProgType from .bpf import ProgType
...@@ -86,21 +86,28 @@ class XDRFD(DatagramProtocol): ...@@ -86,21 +86,28 @@ class XDRFD(DatagramProtocol):
transport.sendto(p, (0, 0)) transport.sendto(p, (0, 0))
def datagram_received(self, data, addr): def datagram_received(self, data, addr):
pos = 0 try:
while (pos < len(data)): pos = 0
ln, type, flags, seq, pid = unpack("IHHII", data[pos : pos+16]) while (pos < len(data)):
if type == 3: # DONE ln, type, flags, seq, pid = unpack_from("IHHII", data, pos)
self.future.set_result(0) if type == 3: # DONE
return self.future.set_result(0)
elif type == 2: # ERROR return
errno, *args = unpack("iIHHII", data[pos+16 : pos+36]) elif type == 2: # ERROR
if errno != 0: errno, *args = unpack_from("iIHHII", data, pos + 16)
self.future.set_exception(OSError(errno, os.strerror(-errno))) if errno != 0:
self.future.set_exception(
OSError(errno, os.strerror(-errno)))
return
if flags & 2 == 0: # not a multipart message
self.future.set_result(0)
return return
if flags & 2 == 0: # not a multipart message pos += ln
self.future.set_result(0) self.future.set_exception(
return RuntimeError("Netlink response not understood"))
pos += ln except Exception as e:
self.future.set_exception(e)
raise
class PacketArray: class PacketArray:
......