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