Exemplo n.º 1
0
 def do_connect(self, cmdLine):
     'Connect to an XCP slave: connect'
     parser = ShellArgParser(prog='connect', description=__doc__)
     args = parser.parse_args(shlex.split(cmdLine))
     slave = CANInterface.XCPSlaveCANAddr(args.commandId, args.responseId)
     self.interface.connect(slave)
     self.connection = XCPConnection.Connection(self.interface)
Exemplo n.º 2
0
 def do_download32(self, cmdLine):
     'write 32 bits from an XCP slave'
     try:
         args = self._parseDownload(cmdLine, prog='download32', description=__doc__)
         pointer = XCPConnection.Pointer(args.address)
         print(self.connection.download32(pointer, args.data))
     except ShellArgParserExit:
         return
     except Exception as e:
         print(e)
Exemplo n.º 3
0
 def do_upload16(self, cmdLine):
     'read 16 bits from an XCP slave'
     try:
         args = self._parseUpload(cmdLine, prog='upload16', description=__doc__)
         pointer = XCPConnection.Pointer(args.address)
         print(self.connection.upload16(pointer))
     except ShellArgParserExit:
         return
     except Exception as e:
         print(e)
Exemplo n.º 4
0
def ReadScalar(param, paramSpec, conn):
    slot = paramSpec['slots'][param['slots'][-1]]
    addr = param['addr']
    addrext = 0 if not 'addrext' in param else param['addrext']
    ptr = XCPConnection.Pointer(addr, addrext)
    if casts.sizeof(param['type']) == 4:
        raw = conn.upload32(ptr)
    elif casts.sizeof(param['type']) == 2:
        raw = conn.upload16(ptr)
    elif casts.sizeof(param['type']) == 1:
        raw = conn.upload8(ptr)
    else:
        raise ValueError
    castRaw = casts.poly(casts.uintTypeFor(param['type']), param['type'], raw)
    return float(castRaw) * SLOTScaleFactor(slot)
Exemplo n.º 5
0
def WriteScalar(value, param, paramSpec, conn):
    slot = paramSpec['slots'][param['slots'][-1]]
    addr = param['addr']
    addrext = 0 if not 'addrext' in param else param['addrext']
    ptr = XCPConnection.Pointer(addr, addrext)
    unscaledFloat = value / SLOTScaleFactor(slot)
    raw = casts.poly(param['type'], casts.uintTypeFor(param['type']),
                     unscaledFloat)
    if casts.sizeof(param['type']) == 4:
        conn.download32(ptr, raw)
    elif casts.sizeof(param['type']) == 2:
        conn.download16(ptr, raw)
    elif casts.sizeof(param['type']) == 1:
        conn.download8(ptr, raw)
    else:
        raise ValueError
Exemplo n.º 6
0
            sys.stderr.write('Connecting to target addr ' +
                             targetSlave[0].description() + ', ID ' +
                             str(targetSlave[1]) + '\n')
        else:
            sys.stderr.write('Connecting to target addr ' +
                             targetSlave[0].description() + '\n')

        # Connect to the target and read out its old configuration
        for attempt in range(1, maxAttempts + 1):
            try:
                conn = boardType.Connect(interface, targetSlave,
                                         args.dumpTraffic)

                conn.set_cal_page(structSegment, 0)
                oldBuffer = conn.upload(
                    XCPConnection.Pointer(structBaseaddr, 0),
                    ctypes.sizeof(OldConfigType))
                oldStruct = OldConfigType.from_buffer_copy(oldBuffer)
                oldDict = ctypesdict.getdict(oldStruct)

                outFile = OpenOutFile(args.outputFile, targetSlave[1])
                outFile.write(
                    json.dumps(oldDict,
                               sort_keys=True,
                               indent=4,
                               separators=(',', ': ')))
                outFile.write('\n')
                if outFile != sys.stdout:
                    outFile.close()
                try:
                    conn.close()
Exemplo n.º 7
0
        else:
            print('Connecting to target addr ' + targetSlave[0].description())

        for attempt in range(1, args.maxAttempts + 1):
            try:
                inFile = OpenInFile(args.inputFile, targetSlave[1])
                inDict = json.loads(inFile.read())
                inFile.close()

                conn = boardType.Connect(interface, targetSlave,
                                         args.dumpTraffic)

                # Read the existing data from the board - in case the dict we have loaded does not cover the entire struct
                conn.set_cal_page(structSegment, 0)
                dataBuffer = conn.upload(
                    XCPConnection.Pointer(structBaseaddr, 0),
                    ctypes.sizeof(ConfigType))
                dataStruct = ConfigType.from_buffer_copy(dataBuffer)

                # Set the data in the struct from the existing one
                writeDataStruct = dataStruct

                # Merge in data from the loaded dictionary
                ctypesdict.setfromdict(writeDataStruct, inDict)

                writeDataBuffer = bytes(memoryview(writeDataStruct))

                # Write the new buffer to the board
                conn.download(XCPConnection.Pointer(structBaseaddr, 0),
                              writeDataBuffer)
                conn.nvwrite()
Exemplo n.º 8
0
        if targetSlave[1] != None:
            sys.stderr.write('Connecting to target addr ' +
                             targetSlave[0].description() + ', ID ' +
                             str(targetSlave[1]) + '\n')
        else:
            sys.stderr.write('Connecting to target addr ' +
                             targetSlave[0].description() + '\n')

        for attempt in range(1, args.maxAttempts + 1):
            try:
                conn = boardType.Connect(interface, targetSlave,
                                         args.dumpTraffic)

                conn.set_cal_page(structSegment, 0)
                dataBuffer = conn.upload(
                    XCPConnection.Pointer(structBaseaddr, 0),
                    ctypes.sizeof(ConfigType))
                dataStruct = ConfigType.from_buffer_copy(dataBuffer)
                data = ctypesdict.getdict(dataStruct)

                outFile.write(
                    json.dumps(data,
                               sort_keys=True,
                               indent=4,
                               separators=(',', ': ')))
                outFile.write('\n')
                if outFile != sys.stdout:
                    outFile.close()
                try:
                    conn.close()
                except XCPConnection.Error:
Exemplo n.º 9
0
                    type=hexInt,
                    default=1)
args = parser.parse_args()

if args.size == 1:
    uploadDelegate = UploadDelegate8()
elif args.size == 2:
    uploadDelegate = UploadDelegate16()
elif args.size == 4:
    uploadDelegate = UploadDelegate32()

try:
    with CANInterface.MakeInterface(args.deviceURI) as interface:
        slave = CANInterface.XCPSlaveCANAddr(args.commandId, args.responseId)
        interface.connect(slave)
        connection = XCPConnection.Connection(interface, readTimeout,
                                              writeTimeout)

        for address in range(args.address, args.address + args.words):
            pointer = XCPConnection.Pointer(address, args.extension)
            print(uploadDelegate.upload(connection, pointer))
        connection.close()

except (OSError, CANInterface.ConnectFailed):
    try:
        interface.close()
    except NameError:
        pass
    raise
except:
    interface.close()
    raise
Exemplo n.º 10
0
     if index >= len(slaves):
         exit
     targetSlaves = [slaves[index]]
             
 for targetSlave in targetSlaves:
     if targetSlave[1] != None:
         print('Programming target addr ' + targetSlave[0].description() + ', ID ' + str(targetSlave[1]))
     else:
         print('Programming target addr ' + targetSlave[0].description())
     
     for attempt in range(1, maxAttempts + 1):
         try:
             conn = boardType.Connect(interface, targetSlave, args.dumpTraffic)
             conn.program_start()
             
             if not args.ignoreCRCMatch and conn.program_check(XCPConnection.Pointer(dataSingleBlock.baseaddr, 0), len(dataSingleBlock.data), dataCRC):
                 print('CRC matched flash contents')
                 # Success, don't need to do anything further with this slave
             else:
                 # Either CRC check was not done or it didn't match
                 conn.program_clear(XCPConnection.Pointer(dataSingleBlock.baseaddr, 0), len(dataSingleBlock.data))
                 for block in dataBlocks:
                     conn.program_range(XCPConnection.Pointer(block.baseaddr, 0), block.data)
                 # MTA should now be one past the end of the last block
                 conn.program_verify(dataCRC)
             conn.program_reset()
             print('Program OK')
             programOK = True
             break
         except XCPConnection.Error as err:
             print('Program failure (' + str(err) + '), attempt #' + str(attempt))