forked from tallis/J2735-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ2735Decoders.py
More file actions
82 lines (57 loc) · 2.42 KB
/
J2735Decoders.py
File metadata and controls
82 lines (57 loc) · 2.42 KB
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
79
80
81
82
from pyasn1.type import univ
from pyasn1.codec.der import encoder as DERencoder, decoder as DERdecoder
from j2735 import *
from Plausability import nmea2deg
from J2735Encoders import *
import datetime
BSMcounter = 0
def decodeJ2735BSM(encodedJ2735):
decoded = DERdecoder.decode(encodedJ2735, asn1Spec=BasicSafetyMessage())
return decoded[0]
def decodeJ2735ALC(encodedALC):
decoded = DERdecoder.decode(encodedALC, asn1Spec=ALaCarte())
return decoded[0]
##
## GETTERS AND SETTERS
##
def getMessageType(encodedJ2735):
try:
decoded = DERdecoder.decode(encodedJ2735)
if(str(decoded[0].getComponentByPosition(0))=="2"):
return "BSM"
elif(str(decoded[0].getComponentByPosition(0))=="1"):
return "ALC"
except Exception, err:
# print "GETMESSAGETYPE: REBENTEI COM EXCEPCAO: " + str(err)
return "STDMSG"
# ALC Getters
def ALCget_appID(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(1))
def ALCget_initTS(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(2))
def ALCget_recvTS(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(3))
def ALCget_source(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(4))
def ALCget_destination(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(5))
def ALCget_destport(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(6))
def ALCget_appData(encodedALC):
decodedALC = decodeJ2735ALC(encodedALC)
return str(decodedALC.getComponentByPosition(7))
# ALC SETTERS
def ALCset_source(encodedALC, sourceIP):
decodedALC = decodeJ2735ALC(encodedALC)
encodedALC = createALaCarte(decodedALC.getComponentByPosition(1),decodedALC.getComponentByPosition(2), decodedALC.getComponentByPosition(3), sourceIP, decodedALC.getComponentByPosition(5), decodedALC.getComponentByPosition(6), decodedALC.getComponentByPosition(7))
return encodedALC
def ALCset_recvTS(encodedALC, recvTS):
decodedALC = decodeJ2735ALC(encodedALC)
encodedALC = createALaCarte(decodedALC.getComponentByPosition(1),decodedALC.getComponentByPosition(2), recvTS, decodedALC.getComponentByPosition(4), decodedALC.getComponentByPosition(5), decodedALC.getComponentByPosition(6), decodedALC.getComponentByPosition(7))
return encodedALC