File: createTestMatrix.py

package info (click to toggle)
python-canmatrix 1.2~github-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,012 kB
  • sloc: xml: 30,201; python: 14,631; makefile: 31; sh: 7
file content (78 lines) | stat: -rw-r--r-- 2,049 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# coding=utf-8
import codecs
import sys
sys.path.append('..')

import canmatrix.formats
from canmatrix.canmatrix import *
#
# create target Matrix
#

db = CanMatrix()

db.ecus.add(Ecu("testBU"))
db.ecus.add(Ecu("recBU"))

myFrame = Frame("testFrame1", Id=0x123, dlc=8, transmitter="testBU")

unit = "specialCharUnit°$"
comment = "Multi \n Line \n Signal comment with a-umlaut: ä"

mySignal = Signal("someTestSignal",
                  signalSize=11,
                  is_little_endian=False,
                  is_signed=False,
                  factor=5.0,
                  offset=1.0,
                  min=0,
                  max=500,
                  unit=u"specialCharUnit°$", #.decode("utf-8"),
                  receiver=["recBU"])
mySignal.set_startbit(9, bitNumbering=1, startLittle=True)
mySignal2 = Signal("Signal",
                   startBit=20,
                   signalSize=3,
                   is_little_endian=True,
                   is_signed=False,
                   factor=1.0,
                   offset=0.0,
                   min=0,
                   max=6,
                   unit="someUnit",
                   receiver=["recBU"])

mySignal2.add_values(1, "one")
mySignal2.add_values(2, "two")
mySignal2.add_values(3, "three")

mySignal.add_comment(comment)
myFrame.add_comment("Multi \n Line \n Frame comment")

myFrame.add_signal(mySignal)
myFrame.add_signal(mySignal2)

myFrame2 = Frame("extendedFrame", Id=0x12,  dlc=8, transmitter="testBU")
myFrame2.extended = 1

db.frames.add_frame(myFrame)
db.frames.add_frame(myFrame2)

db.ecu_by_name("testBU").add_comment("sender ECU")
db.ecu_by_name("testBU").add_attribute("NetworkNode", 0x111)
db.ecu_by_name("recBU").add_comment("receiver ECU")

db.frame_by_name("testFrame1").cycle_time = 100


db.add_ecu_defines("NetworkNode", 'INT 0 65535')


#
#
# export the new (target)-Matrix for example as .dbc:
#

canmatrix.formats.dumpp({"myMatrix": db}, "test.dbc", dbcExportEncoding='iso-8859-1',
             dbcExportCommentEncoding='iso-8859-1')