Skip to content
Snippets Groups Projects
Commit 4a4494e9 authored by Claudiu MILEA (95030)'s avatar Claudiu MILEA (95030)
Browse files

Update setup in order to measure message count

parent 4e640683
No related branches found
No related tags found
No related merge requests found
from enum import Enum, IntEnum
DEBUG_FREQ_MULTIPLIER: int = 100
DEBUG_FREQ_MULTIPLIER: int = 1
class VehicleSegment(Enum):
......
......@@ -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')
......
......@@ -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}')
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment