Skip to content

Commit

Permalink
fix Mongoose J2534 cables by passing a null pointer to ioctl. add err…
Browse files Browse the repository at this point in the history
…or logging for devices that still do not work. thanks to @joeFischetti
  • Loading branch information
bri3d committed Mar 24, 2022
1 parent 418f8ca commit 012659f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
7 changes: 6 additions & 1 deletion VW_Flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
)

parser.add_argument("--dsg", help="Perform MQB-DQ250 DSG actions.", action="store_true")
parser.add_argument("--unsafe_haldex", help="Perform Haldex actions, unsafe to flash modified files!", action="store_true", dest="haldex")
parser.add_argument(
"--unsafe_haldex",
help="Perform Haldex actions, unsafe to flash modified files!",
action="store_true",
dest="haldex",
)

parser.add_argument(
"--patch-cboot",
Expand Down
22 changes: 20 additions & 2 deletions lib/connections/j2534.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class J2534:
dllPassThruWriteMsgs = None
dllPassThruStartPeriodicMsg = None
dllPassThruStopPeriodicMsg = None
dllPassThruGetLastError = None
dllPassThruReadVersion = None
dllPassThruStartMsgFilter = None
dllPassThruIoctl = None
Expand All @@ -60,6 +61,7 @@ def __init__(self, windll, rxid, txid):
global dllPassThruWriteMsgs
global dllPassThruStartPeriodicMsg
global dllPassThruStopPeriodicMsg
global dllPassThruGetLastError
global dllPassThruReadVersion
global dllPassThruStartMsgFilter
global dllPassThruIoctl
Expand Down Expand Up @@ -169,10 +171,17 @@ def __init__(self, windll, rxid, txid):
(1, "pDllVersion", 0),
(1, "pApiVersoin", 0),
)

dllPassThruReadVersion = dllPassThruReadVersionProto(
("PassThruReadVersion", self.hDLL), dllPassThruReadVersionParams
)

dllPassThruGetLastErrorProto = WINFUNCTYPE(c_long, POINTER(ctypes.c_char))
dllPassThruGetLastErrorParams = ((1, "pErrorMsg", 0),)
dllPassThruGetLastError = dllPassThruGetLastErrorProto(
("PassThruGetLastError", self.hDLL), dllPassThruGetLastErrorParams
)

dllPassThruStartMsgFilterProto = WINFUNCTYPE(
c_long,
c_ulong,
Expand Down Expand Up @@ -293,6 +302,13 @@ def PassThruStopPeriodicMsg(self, ChannelID, MsgID):

return Error_ID(result)

def PassThruGetLastError(self):
pErrorMsg = (ctypes.c_char * 80)()

dllPassThruGetLastError(pErrorMsg)

return pErrorMsg

def PassThruReadVersion(self, DeviceID):
pFirmwareVersion = (ctypes.c_char * 80)()
pDllVersion = (ctypes.c_char * 80)()
Expand All @@ -317,10 +333,12 @@ def PassThruIoctl(self, Handle, IoctlID, ioctlInput=None, ioctlOutput=None):
pInput.ConfigPtr = pointer(inputParam)

if ioctlOutput is None:
pOutput = SCONFIG()
pOutput = None
else:
pOutput = byref(ioctlOutput)

result = dllPassThruIoctl(
Handle, c_ulong(IoctlID.value), byref(pInput), byref(pOutput)
Handle, c_ulong(IoctlID.value), byref(pInput), pOutput
)

if ioctlInput:
Expand Down
12 changes: 8 additions & 4 deletions lib/connections/j2534_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ def __init__(self, windll, rxid, txid, name=None, debug=False, *args, **kwargs):
)

if self.result == Error_ID.ERR_SUCCESS:
self.logger.info("Set ISO15665_STMIN to 0xF8")
self.logger.info("Set ISO15665_STMIN to 0")
else:
self.logger.info("Failed to set ISO15765_STMIN to 0xF8")
self.logger.info("Failed to set ISO15765_STMIN to 0")
message = self.interface.PassThruGetLastError()
self.logger.info("Failure message: " + str(message.value))

blocksize = SCONFIG()
blocksize.Parameter = Ioctl_Parameters.ISO15765_BS.value
Expand All @@ -116,9 +118,11 @@ def __init__(self, windll, rxid, txid, name=None, debug=False, *args, **kwargs):
)

if self.result == Error_ID.ERR_SUCCESS:
self.logger.info("Set STMIN_TX to 0xF8")
self.logger.info("Set ISO15665_STMIN_TX to: " + str(stmin.Value))
else:
self.logger.info("Failed to set STMIN_TX to 0xF8")
self.logger.info("Failed to set ISO15765_STMIN_TX: " + str(self.result))
message = self.interface.PassThruGetLastError()
self.logger.info("Failure message: " + str(message.value))

self.rxqueue = queue.Queue()
self.exit_requested = False
Expand Down
7 changes: 6 additions & 1 deletion lib/haldex_flash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def build_blocks(flash_info: FlashInfo, input_blocks: dict[str, BlockData]):
blockname = flash_info.number_to_block_name[blocknum]

cliLogger.info(
"Haldex block passed through " + filename + " as block: " + str(blocknum) + " with name " + blockname
"Haldex block passed through "
+ filename
+ " as block: "
+ str(blocknum)
+ " with name "
+ blockname
)
output_blocks[filename] = BlockData(
input_block.block_number, binary_data, blockname
Expand Down

0 comments on commit 012659f

Please sign in to comment.