
| Current Path : /var/www/web-klick.de/dsh/50_1/1330__canpy/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_1/1330__canpy/testmodes.py |
# -*- coding: utf-8 -*-
import os
import re
import sys
import time
import random
#************************************************************************
class CAN (object):
def __init__ (self,communication_matrix={}):
pass
#*************************************************************************
def t_make_communication_matrix (self,msgcount=10):
"""
Sets an arbitrary communication matrix by random,
msgcount: the count of messages in the matrix
"""
communication_matrix = {}
rand = random.Random()
zaehler = 0
while zaehler < msgcount:
msg_signals = ""
msg_bits = 0
msg_bytes = rand.randint(1,8)
msg_name = "%03x" % rand.randint(1,2047)
while (0 == 0):
signal_name = rand.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
zaehler1 = 0
zaehlmax = rand.randint(3,7)
while (zaehler1 < zaehlmax):
signal_name = signal_name + rand.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789______")
zaehler1 = zaehler1 + 1
signal_len = rand.choice([1,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,28,19,20])
msg_bits = msg_bits + signal_len
if msg_bits > msg_bytes * 8:
break
msg_signals = msg_signals + "," + signal_name + "," + str(signal_len)
if not msg_signals == "":
communication_matrix[msg_name] = msg_signals[1:]
zaehler = zaehler + 1
return(communication_matrix)
#****************************************************************
def t_get_signals (self,communication_matrix):
"""
Gets all signals from
the given communication matrix
"""
signal_list = {}
for msg in communication_matrix.keys():
sig_str = communication_matrix[msg].split(",")
zaehler = 0
while (0 == 0):
try:
signal_list[sig_str[zaehler]] = sig_str[zaehler+1]
except:
break
zaehler = zaehler + 2
return(signal_list)