From 4a4494e9b4b8675532efa0430b82a2b8ab09dbe5 Mon Sep 17 00:00:00 2001 From: Claudiu Milea <claudiu.milea@stud.acs.upb.ro> Date: Tue, 29 Aug 2023 22:49:24 +0300 Subject: [PATCH] Update setup in order to measure message count --- chassis-powertrain-body-setup/can_id_sheet.py | 2 +- chassis-powertrain-body-setup/ecu_coordinator.py | 4 +++- chassis-powertrain-body-setup/ecu_process.py | 7 +++++-- chassis-powertrain-body-setup/periodic_send_thread.py | 7 ++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/chassis-powertrain-body-setup/can_id_sheet.py b/chassis-powertrain-body-setup/can_id_sheet.py index 6e51326..cf9edb2 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 58216ae..53ae946 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 37c0688..25417e4 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 920abab..4a986ae 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 -- GitLab