diff --git a/chassis-powertrain-body-setup/can_id_sheet.py b/chassis-powertrain-body-setup/can_id_sheet.py index 6e51326f6bf30887ca6b63878ad6632e3f51ba95..cf9edb288b451f4f6ed6fac75521ba77f9cde844 100644 --- a/chassis-powertrain-body-setup/can_id_sheet.py +++ b/chassis-powertrain-body-setup/can_id_sheet.py @@ -1,6 +1,6 @@ from enum import Enum, IntEnum -DEBUG_FREQ_MULTIPLIER: int = 100 +DEBUG_FREQ_MULTIPLIER: int = 1 class VehicleSegment(Enum): diff --git a/chassis-powertrain-body-setup/ecu_coordinator.py b/chassis-powertrain-body-setup/ecu_coordinator.py index 58216aeb530ce4112d03823642b518b60321674e..53ae946d6ac732340c0726f88f7dedf660335f29 100644 --- a/chassis-powertrain-body-setup/ecu_coordinator.py +++ b/chassis-powertrain-body-setup/ecu_coordinator.py @@ -8,7 +8,7 @@ from scapy.config import conf from scapy.contrib.cansocket import CANSocket from scapy.main import load_contrib import multiprocessing as mp - +import os def get_filtered_can_socket(vehicle_segment: VehicleSegment): filters = [{'can_id': f.value, 'can_mask': 0x7FF} for f in CANFrame if @@ -42,6 +42,8 @@ if __name__ == '__main__': interface = arg if protocol == "can": + bashCommand = "/bin/bash -c 'sudo modprobe vcan; sudo ip link add name vcan0 type vcan; sudo ip link set dev vcan0 up'" + os.system(bashCommand) conf.contribs['CANSocket'] = {'use-python-can': True} load_contrib('cansocket') socket = CANSocket(channel='vcan0') diff --git a/chassis-powertrain-body-setup/ecu_process.py b/chassis-powertrain-body-setup/ecu_process.py index 37c0688e20229628abe8654b8bf1c65246a56d6a..25417e43aeff8957bd116c53414c12f6f5f7d081 100644 --- a/chassis-powertrain-body-setup/ecu_process.py +++ b/chassis-powertrain-body-setup/ecu_process.py @@ -3,7 +3,6 @@ from periodic_send_thread import PeriodicSendingTask from multiprocessing import Process from scapy.sendrecv import * - class GenericECU(Process): def __init__(self, protocol: str, @@ -12,8 +11,10 @@ class GenericECU(Process): rx_socket, # type: SuperSocket vehicle_segment: VehicleSegment ): + self.msg_count = 0 def sniff_function(pkt): - print(pkt.__repr__()) + self.msg_count += 1 + # print(pkt.show()) Process.__init__(self) self.protocol = protocol self.interface = interface @@ -52,3 +53,5 @@ class GenericECU(Process): for t in self.tasks: t.join(timeout=5) + + print(f'Message count {self.msg_count} from ECU with segment: {self.name}') diff --git a/chassis-powertrain-body-setup/periodic_send_thread.py b/chassis-powertrain-body-setup/periodic_send_thread.py index 920abab319123de26f18c30fb9069bcea6004b7e..4a986ae167b3b237eaa53e3be29b2c7e4d720e9f 100644 --- a/chassis-powertrain-body-setup/periodic_send_thread.py +++ b/chassis-powertrain-body-setup/periodic_send_thread.py @@ -1,6 +1,7 @@ from can_id_sheet import CANFrame from scapy.layers.can import * +from scapy.layers.l2 import Ether from scapy.all import * from scapy.sendrecv import send import time @@ -36,14 +37,14 @@ class PeriodicSendingTask(Thread): if self.protocol == "can": # CAN packet sending send(self.packets, verbose=0, socket=self.socket) - print(f'Sent {len(self.packets)} CAN packets at {time.time()}, frequency = {self.interval_s}s') + # print(f'Sent {len(self.packets)} CAN packets at {time.time()}, frequency = {self.interval_s}s') elif self.protocol == "eth": # ethernet packet sending - sendp(self.packets, iface=self.socket.iface) + sendp(self.packets, verbose=0, iface=self.socket.iface) # For debug # for p in self.packets: # p.show() - print(f'Sent {len(self.packets)} Ethernet packets at {time.time()}, frequency = {self.interval_s}s') + # print(f'Sent {len(self.packets)} Ethernet packets at {time.time()}, frequency = {self.interval_s}s') msg_due_time_ns += self.interval_ns # Compensate for the time it takes to send the message