forked from cedricp/ddtplugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vin_crc.py
57 lines (45 loc) · 1.45 KB
/
vin_crc.py
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
# -*- coding: utf-8 -*-
# Plugin to compute CRC from VIN
# (c) 2017
import crcmod
from binascii import unhexlify
import PyQt4.QtGui as gui
import PyQt4.QtCore as core
import options
_ = options.translator('ddt4all')
plugin_name = _("CRC calculator")
category = _("VIN")
# We need an ELM to work
need_hw = False
def calc_crc(vin=None):
VIN=vin.encode("hex")
VININT=unhexlify(VIN)
crc16 = crcmod.predefined.Crc('x-25')
crc16.update(VININT)
crcle = crc16.hexdigest()
# Seems that computed CRC is returned in little endian way
# Convert it to big endian
return crcle[2:4] + crcle[0:2]
class CrcWidget(gui.QDialog):
def __init__(self):
super(CrcWidget, self).__init__(None)
layout = gui.QVBoxLayout()
self.input = gui.QLineEdit()
self.output = gui.QLineEdit()
self.output.setStyleSheet("QLineEdit { color: rgb(255, 0, 0); }")
info = gui.QLabel(_("CRC CALCULATOR"))
info.setAlignment(core.Qt.AlignHCenter)
self.output.setAlignment(core.Qt.AlignHCenter)
layout.addWidget(info)
layout.addWidget(self.input)
layout.addWidget(self.output)
self.input.textChanged.connect(self.recalc)
self.setLayout(layout)
self.output.setReadOnly(True)
def recalc(self):
vin = str(self.input.text().toAscii()).upper()
crc = calc_crc(vin)
self.output.setText('%s' % crc)
def plugin_entry():
a = CrcWidget()
a.exec_()