-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d78e2f
commit 613f8b2
Showing
4 changed files
with
189 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__copyright__=""" | ||
pySART - Simplified AUTOSAR-Toolkit for Python. | ||
(C) 2009-2018 by Christoph Schueler <cpu12.gems@googlemail.com> | ||
All Rights Reserved | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
""" | ||
|
||
import sys | ||
|
||
version = sys.version_info | ||
PRE35 = version.major >= 3 and version.minor < 5 # We need some pre-3.5 fixes, e.g. flatten() function. | ||
|
||
if PRE35: | ||
from pyxcp.master.pre35 import Master | ||
else: | ||
from pyxcp.master.py35 import Master | ||
|
||
|
||
def unlock(client, privilege): | ||
length, seed = client.getSeed(0, privilege) | ||
#print("SEED: ", hexDump(seed), flush = True) | ||
_, kee = dllif.getKey(b"SeedNKeyXcp.dll", privilege, seed) | ||
print("KEE:", kee) | ||
# res = client.unlock(len(kee), kee) | ||
#print(res) | ||
|
||
|
||
def verify(client, addr, length): | ||
client.setMta(addr) | ||
cs = client.buildChecksum(length) | ||
print("CS: {:08X}".format(cs.checksum)) | ||
client.setMta(addr) | ||
data = client.upload(length) | ||
cc = checksum.check(data, cs.checksumType) | ||
print("CS: {:08X}".format(cc)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__copyright__=""" | ||
pySART - Simplified AUTOSAR-Toolkit for Python. | ||
(C) 2009-2018 by Christoph Schueler <cpu12.gems@googlemail.com> | ||
All Rights Reserved | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
""" | ||
|
||
from pyxcp.master.base import MasterBaseType | ||
from pyxcp.utils import flatten | ||
|
||
class Master(MasterBaseType): | ||
## | ||
## Python <= 3.4 requires nasty hack (flatten) to unpack tuples. | ||
## | ||
|
||
def shortDownload(self, address, addressExt, *data): | ||
length = len(data) | ||
addr = struct.pack("<I", address) | ||
response = self.transport.request(types.Command.SHORT_DOWNLOAD, length, 0, addressExt, flatten(addr, data)) | ||
return response | ||
|
||
def modifyBits(self, shiftValue, andMask, xorMask): | ||
# A = ( (A) & ((~((dword)(((word)~MA)<<S))) )^((dword)(MX<<S)) ) | ||
am = struct.pack("<H", andMask) | ||
xm = struct.pack("<H", xorMask) | ||
response = self.transport.request(types.Command.MODIFY_BITS, shiftValue, flatten(am, xm)) | ||
return response | ||
|
||
def setDaqPtr(self, daqListNumber, odtNumber, odtEntryNumber): | ||
daqList = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.SET_DAQ_PTR, 0, flatten(daqList), odtNumber, odtEntryNumber) | ||
return response | ||
|
||
def setDaqListMode(self, mode, daqListNumber, eventChannelNumber, prescaler, priority): | ||
dln = struct.pack("<H", daqListNumber) | ||
ecn = struct.pack("<H", eventChannelNumber) | ||
response = self.transport.request(types.Command.SET_DAQ_LIST_MODE, mode, flatten(dln, ecn), prescaler, priority) | ||
return response | ||
|
||
def allocOdt(self, daqListNumber, odtCount): | ||
dln = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.ALLOC_ODT, 0, flatten(dln), odtCount) | ||
return response | ||
|
||
def allocOdtEntry(self, daqListNumber, odtNumber, odtEntriesCount): | ||
dln = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.ALLOC_ODT_ENTRY, 0, flatten(dln), odtNumber, odtEntriesCount) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__copyright__=""" | ||
pySART - Simplified AUTOSAR-Toolkit for Python. | ||
(C) 2009-2018 by Christoph Schueler <cpu12.gems@googlemail.com> | ||
All Rights Reserved | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
""" | ||
|
||
from pyxcp.master.base import MasterBaseType | ||
|
||
|
||
class Master(MasterBaseType): | ||
## | ||
## Python >= 3.5 permits nice unpacking syntax (PEP448). | ||
## | ||
|
||
def shortDownload(self, address, addressExt, *data): | ||
length = len(data) | ||
addr = struct.pack("<I", address) | ||
response = self.transport.request(types.Command.SHORT_DOWNLOAD, length, 0, addressExt, *addr, *data) | ||
return response | ||
|
||
def modifyBits(self, shiftValue, andMask, xorMask): | ||
# A = ( (A) & ((~((dword)(((word)~MA)<<S))) )^((dword)(MX<<S)) ) | ||
am = struct.pack("<H", andMask) | ||
xm = struct.pack("<H", xorMask) | ||
response = self.transport.request(types.Command.MODIFY_BITS, shiftValue, *am, *xm) | ||
return response | ||
|
||
def setDaqPtr(self, daqListNumber, odtNumber, odtEntryNumber): | ||
daqList = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.SET_DAQ_PTR, 0, *daqList, odtNumber, odtEntryNumber) | ||
return response | ||
|
||
def setDaqListMode(self, mode, daqListNumber, eventChannelNumber, prescaler, priority): | ||
dln = struct.pack("<H", daqListNumber) | ||
ecn = struct.pack("<H", eventChannelNumber) | ||
response = self.transport.request(types.Command.SET_DAQ_LIST_MODE, mode, *dln, *ecn, prescaler, priority) | ||
return response | ||
|
||
def allocOdt(self, daqListNumber, odtCount): | ||
dln = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.ALLOC_ODT, 0, *dln, odtCount) | ||
return response | ||
|
||
def allocOdtEntry(self, daqListNumber, odtNumber, odtEntriesCount): | ||
dln = struct.pack("<H", daqListNumber) | ||
response = self.transport.request(types.Command.ALLOC_ODT_ENTRY, 0, *dln, odtNumber, odtEntriesCount) | ||
return response | ||
|