diff --git a/crypto/getcertheader.py b/crypto/getcertheader.py index 0623881d..f0820c20 100755 --- a/crypto/getcertheader.py +++ b/crypto/getcertheader.py @@ -36,11 +36,11 @@ for fn in sys.argv[1:]: cname = fn.split("/")[-1].split(".")[0] + "_rsa_key" - print 'RSAPublicKey '+cname+' = {.len = 0x20,' - print ' .n0inv = %dU,' % n0inv - print ' .n = %s,' % to_c_uint32(rsa.n) - print ' .rr = %s,' % to_c_uint32(rr) - print ' .exponent = %d,' % rsa.e - print '};' + print('RSAPublicKey '+cname+' = {.len = 0x20,') + print(' .n0inv = %dU,' % n0inv) + print(' .n = %s,' % to_c_uint32(rsa.n)) + print(' .rr = %s,' % to_c_uint32(rr)) + print(' .exponent = %d,' % rsa.e) + print('};') diff --git a/crypto/sign.py b/crypto/sign.py index e856c9c2..b5000cfa 100755 --- a/crypto/sign.py +++ b/crypto/sign.py @@ -10,7 +10,7 @@ rsa = RSA.importKey(open(sys.argv[3]).read()) with open(sys.argv[1]) as f: dat = f.read() -print "signing", len(dat), "bytes" +print("signing", len(dat), "bytes") with open(sys.argv[2], "wb") as f: if os.getenv("SETLEN") is not None: @@ -20,7 +20,7 @@ with open(sys.argv[2], "wb") as f: else: x = dat dd = hashlib.sha1(dat).digest() - print "hash:",dd.encode("hex") + print("hash:",dd.encode("hex")) dd = "\x00\x01" + "\xff"*0x69 + "\x00" + dd rsa_out = pow(int(dd.encode("hex"), 16), rsa.d, rsa.n) sig = (hex(rsa_out)[2:-1].rjust(0x100, '0')).decode("hex") diff --git a/examples/can_bit_transition.py b/examples/can_bit_transition.py index d33b4d25..9a54d6ff 100755 --- a/examples/can_bit_transition.py +++ b/examples/can_bit_transition.py @@ -16,10 +16,10 @@ class Message(): for i in range(len(self.ones)): zero_to_one = other.zeros[i] & self.ones[i] if zero_to_one: - print 'id %s 0 -> 1 at byte %d bitmask %d' % (self.message_id, i, zero_to_one) + print('id %s 0 -> 1 at byte %d bitmask %d' % (self.message_id, i, zero_to_one)) one_to_zero = other.ones[i] & self.zeros[i] if one_to_zero: - print 'id %s 1 -> 0 at byte %d bitmask %d' % (self.message_id, i, one_to_zero) + print('id %s 1 -> 0 at byte %d bitmask %d' % (self.message_id, i, one_to_zero)) class Info(): @@ -78,10 +78,10 @@ def PrintUnique(log_file, low_range, high_range): if message_id in low.messages: high.messages[message_id].printBitDiff(low.messages[message_id]) found = True - if not found: print 'No messages that transition from always low to always high found!' + if not found: print('No messages that transition from always low to always high found!') if __name__ == "__main__": if len(sys.argv) < 4: - print 'Usage:\n%s log.csv - -' % sys.argv[0] + print('Usage:\n%s log.csv - -' % sys.argv[0]) sys.exit(0) PrintUnique(sys.argv[1], sys.argv[2], sys.argv[3]) diff --git a/examples/can_unique.py b/examples/can_unique.py index eb2feffa..05f24a7d 100755 --- a/examples/can_unique.py +++ b/examples/can_unique.py @@ -31,12 +31,12 @@ class Message(): for i in range(len(self.ones)): new_ones = ((~other.ones[i]) & 0xff) & self.ones[i] if new_ones: - print 'id %s new one at byte %d bitmask %d' % ( - self.message_id, i, new_ones) + print('id %s new one at byte %d bitmask %d' % ( + self.message_id, i, new_ones)) new_zeros = ((~other.zeros[i]) & 0xff) & self.zeros[i] if new_zeros: - print 'id %s new zero at byte %d bitmask %d' % ( - self.message_id, i, new_zeros) + print('id %s new zero at byte %d bitmask %d' % ( + self.message_id, i, new_zeros)) class Info(): @@ -80,7 +80,7 @@ def PrintUnique(interesting_file, background_files): interesting.load(interesting_file) for message_id in sorted(interesting.messages): if message_id not in background.messages: - print 'New message_id: %s' % message_id + print('New message_id: %s' % message_id) else: interesting.messages[message_id].printBitDiff( background.messages[message_id]) @@ -88,6 +88,6 @@ def PrintUnique(interesting_file, background_files): if __name__ == "__main__": if len(sys.argv) < 3: - print 'Usage:\n%s interesting.csv background*.csv' % sys.argv[0] + print('Usage:\n%s interesting.csv background*.csv' % sys.argv[0]) sys.exit(0) PrintUnique(sys.argv[1], sys.argv[2:]) diff --git a/examples/get_panda_password.py b/examples/get_panda_password.py index 0abbc052..b8ec3d94 100644 --- a/examples/get_panda_password.py +++ b/examples/get_panda_password.py @@ -13,8 +13,8 @@ def get_panda_password(): wifi = p.get_serial() #print('[%s]' % ', '.join(map(str, wifi))) - print("SSID: " + wifi[0]) - print("Password: " + wifi[1]) + print(("SSID: " + wifi[0])) + print(("Password: " + wifi[1])) if __name__ == "__main__": get_panda_password() \ No newline at end of file diff --git a/examples/query_vin_and_stats.py b/examples/query_vin_and_stats.py index 26fd2a1a..9a0df78e 100755 --- a/examples/query_vin_and_stats.py +++ b/examples/query_vin_and_stats.py @@ -36,15 +36,15 @@ if __name__ == "__main__": isotp_send(panda, "\x09\x02", 0x7df) ret = isotp_recv(panda, 0x7e8) hexdump(ret) - print "VIN: %s" % ret[2:] + print("VIN: %s" % ret[2:]) # 03 = get DTCS isotp_send(panda, "\x03", 0x7e0) dtcs = isotp_recv(panda, 0x7e8) - print "DTCs:", dtcs[2:].encode("hex") + print("DTCs:", dtcs[2:].encode("hex")) supported_pids = get_supported_pids() - print "Supported PIDs:",supported_pids + print("Supported PIDs:",supported_pids) while 1: speed = struct.unpack(">B", get_current_data_for_pid(13)[2:])[0] # kph @@ -52,7 +52,7 @@ if __name__ == "__main__": throttle = struct.unpack(">B", get_current_data_for_pid(17)[2:])[0]/255.0 * 100 # percent temp = struct.unpack(">B", get_current_data_for_pid(5)[2:])[0] - 40 # degrees C load = struct.unpack(">B", get_current_data_for_pid(4)[2:])[0]/255.0 * 100 # percent - print "%d KPH, %d RPM, %.1f%% Throttle, %d deg C, %.1f%% load" % (speed, rpm, throttle, temp, load) + print("%d KPH, %d RPM, %.1f%% Throttle, %d deg C, %.1f%% load" % (speed, rpm, throttle, temp, load)) time.sleep(0.2) diff --git a/examples/tesla_tester.py b/examples/tesla_tester.py index 74f19f25..0c484b07 100644 --- a/examples/tesla_tester.py +++ b/examples/tesla_tester.py @@ -51,10 +51,10 @@ def tesla_tester(): vin_index = int(binascii.hexlify(dat)[:2]) #first byte is the index, 00, 01, 02 vin_string = binascii.hexlify(dat)[2:] #rest of the string is the actual VIN data vin[vin_index] = vin_string.decode("hex") - print("Got VIN index " + str(vin_index) + " data " + vin[vin_index]) + print(("Got VIN index " + str(vin_index) + " data " + vin[vin_index])) #if we have all 3 parts of the VIN, print it and break out of our while loop if 0 in vin and 1 in vin and 2 in vin: - print("VIN: " + vin[0] + vin[1] + vin[2][:3]) + print(("VIN: " + vin[0] + vin[1] + vin[2][:3])) break if __name__ == "__main__": diff --git a/python/esptool.py b/python/esptool.py index 3bfb3915..053a4c69 100755 --- a/python/esptool.py +++ b/python/esptool.py @@ -48,7 +48,7 @@ class FakePort(object): @baudrate.setter def baudrate(self, x): - print "set baud to", x + print("set baud to", x) self.panda.set_uart_baud(1, x) def write(self, buf): @@ -161,7 +161,7 @@ class ESPROM(object): """ Try connecting repeatedly until successful, or giving up """ def connect(self): - print 'Connecting...' + print('Connecting...') for _ in range(4): # issue reset-to-bootloader: @@ -250,7 +250,7 @@ class ESPROM(object): result = self.command(ESPROM.ESP_FLASH_BEGIN, struct.pack(' 16: raise FatalError('Invalid V2 second header magic=%d segments=%d' % (magic, segments)) @@ -543,13 +543,13 @@ class ELFFile(object): tool_nm = "xt-nm" proc = subprocess.Popen([tool_nm, self.name], stdout=subprocess.PIPE) except OSError: - print "Error calling %s, do you have Xtensa toolchain in PATH?" % tool_nm + print("Error calling %s, do you have Xtensa toolchain in PATH?" % tool_nm) sys.exit(1) for l in proc.stdout: fields = l.strip().split() try: if fields[0] == "U": - print "Warning: ELF binary has undefined symbol %s" % fields[1] + print("Warning: ELF binary has undefined symbol %s" % fields[1]) continue if fields[0] == "w": continue # can skip weak symbols @@ -568,7 +568,7 @@ class ELFFile(object): try: proc = subprocess.Popen([tool_readelf, "-h", self.name], stdout=subprocess.PIPE) except OSError: - print "Error calling %s, do you have Xtensa toolchain in PATH?" % tool_readelf + print("Error calling %s, do you have Xtensa toolchain in PATH?" % tool_readelf) sys.exit(1) for l in proc.stdout: fields = l.strip().split() @@ -599,7 +599,7 @@ class CesantaFlasher(object): CMD_BOOT_FW = 6 def __init__(self, esp, baud_rate=0): - print 'Running Cesanta flasher stub...' + print('Running Cesanta flasher stub...') if baud_rate <= ESPROM.ESP_ROM_BAUD: # don't change baud rates if we already synced at that rate baud_rate = 0 self._esp = esp @@ -640,7 +640,7 @@ class CesantaFlasher(object): raise FatalError('Expected digest, got: %s' % hexify(p)) digest = hexify(p).upper() expected_digest = hashlib.md5(data).hexdigest().upper() - print + print() if digest != expected_digest: raise FatalError('Digest mismatch: expected %s, got %s' % (expected_digest, digest)) p = self._esp.read() @@ -679,7 +679,7 @@ class CesantaFlasher(object): raise FatalError('Expected digest, got: %s' % hexify(p)) expected_digest = hexify(p).upper() digest = hashlib.md5(data).hexdigest().upper() - print + print() if digest != expected_digest: raise FatalError('Digest mismatch: expected %s, got %s' % (expected_digest, digest)) p = self._esp.read() @@ -791,7 +791,7 @@ def binutils_safe_path(p): try: return subprocess.check_output(["cygpath", "-w", p]).rstrip('\n') except subprocess.CalledProcessError: - print "WARNING: Failed to call cygpath to sanitise Cygwin path." + print("WARNING: Failed to call cygpath to sanitise Cygwin path.") return p @@ -837,9 +837,9 @@ class FatalError(RuntimeError): def load_ram(esp, args): image = LoadFirmwareImage(args.filename) - print 'RAM boot...' + print('RAM boot...') for (offset, size, data) in image.segments: - print 'Downloading %d bytes at %08x...' % (size, offset), + print('Downloading %d bytes at %08x...' % (size, offset), end=' ') sys.stdout.flush() esp.mem_begin(size, div_roundup(size, esp.ESP_RAM_BLOCK), esp.ESP_RAM_BLOCK, offset) @@ -848,19 +848,19 @@ def load_ram(esp, args): esp.mem_block(data[0:esp.ESP_RAM_BLOCK], seq) data = data[esp.ESP_RAM_BLOCK:] seq += 1 - print 'done!' + print('done!') - print 'All segments done, executing at %08x' % image.entrypoint + print('All segments done, executing at %08x' % image.entrypoint) esp.mem_finish(image.entrypoint) def read_mem(esp, args): - print '0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address)) + print('0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address))) def write_mem(esp, args): esp.write_reg(args.address, args.value, args.mask, 0) - print 'Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address) + print('Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address)) def dump_mem(esp, args): @@ -869,10 +869,10 @@ def dump_mem(esp, args): d = esp.read_reg(args.address + (i * 4)) f.write(struct.pack('> 16 args.flash_size = {18: '2m', 19: '4m', 20: '8m', 21: '16m', 22: '32m'}.get(size_id) if args.flash_size is None: - print 'Warning: Could not auto-detect Flash size (FlashID=0x%x, SizeID=0x%x), defaulting to 4m' % (flash_id, size_id) + print('Warning: Could not auto-detect Flash size (FlashID=0x%x, SizeID=0x%x), defaulting to 4m' % (flash_id, size_id)) args.flash_size = '4m' else: - print 'Auto-detected Flash size:', args.flash_size + print('Auto-detected Flash size:', args.flash_size) def write_flash(esp, args): @@ -900,10 +900,10 @@ def write_flash(esp, args): image = argfile.read() argfile.seek(0) # rewind in case we need it again if address + len(image) > int(args.flash_size.split('m')[0]) * (1 << 17): - print 'WARNING: Unlikely to work as data goes beyond end of flash. Hint: Use --flash_size' + print('WARNING: Unlikely to work as data goes beyond end of flash. Hint: Use --flash_size') # Fix sflash config data. if address == 0 and image[0] == '\xe9': - print 'Flash params set to 0x%02x%02x' % (flash_mode, flash_size_freq) + print('Flash params set to 0x%02x%02x' % (flash_mode, flash_size_freq)) image = image[0:2] + flash_params + image[4:] # Pad to sector size, which is the minimum unit of writing (erasing really). if len(image) % esp.ESP_FLASH_SECTOR != 0: @@ -911,30 +911,30 @@ def write_flash(esp, args): t = time.time() flasher.flash_write(address, image, not args.no_progress) t = time.time() - t - print ('\rWrote %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' - % (len(image), address, t, len(image) / t * 8 / 1000)) - print 'Leaving...' + print(('\rWrote %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' + % (len(image), address, t, len(image) / t * 8 / 1000))) + print('Leaving...') if args.verify: - print 'Verifying just-written flash...' + print('Verifying just-written flash...') _verify_flash(flasher, args, flash_params) flasher.boot_fw() def image_info(args): image = LoadFirmwareImage(args.filename) - print('Image version: %d' % image.version) - print('Entry point: %08x' % image.entrypoint) if image.entrypoint != 0 else 'Entry point not set' - print '%d segments' % len(image.segments) - print + print(('Image version: %d' % image.version)) + print(('Entry point: %08x' % image.entrypoint) if image.entrypoint != 0 else 'Entry point not set') + print('%d segments' % len(image.segments)) + print() checksum = ESPROM.ESP_CHECKSUM_MAGIC for (idx, (offset, size, data)) in enumerate(image.segments): if image.version == 2 and idx == 0: - print 'Segment 1: %d bytes IROM0 (no load address)' % size + print('Segment 1: %d bytes IROM0 (no load address)' % size) else: - print 'Segment %d: %5d bytes at %08x' % (idx + 1, size, offset) + print('Segment %d: %5d bytes at %08x' % (idx + 1, size, offset)) checksum = ESPROM.checksum(data, checksum) - print - print 'Checksum: %02x (%s)' % (image.checksum, 'valid' if image.checksum == checksum else 'invalid!') + print() + print('Checksum: %02x (%s)' % (image.checksum, 'valid' if image.checksum == checksum else 'invalid!')) def make_image(args): @@ -979,7 +979,7 @@ def elf2image(args): if irom_offs < 0: raise FatalError('Address of symbol _irom0_text_start in ELF is located before flash mapping address. Bad linker script?') if (irom_offs & 0xFFF) != 0: # irom0 isn't flash sector aligned - print "WARNING: irom0 section offset is 0x%08x. ELF is probably linked for 'elf2image --version=2'" % irom_offs + print("WARNING: irom0 section offset is 0x%08x. ELF is probably linked for 'elf2image --version=2'" % irom_offs) with open(args.output + "0x%05x.bin" % irom_offs, "wb") as f: f.write(data) f.close() @@ -991,21 +991,21 @@ def elf2image(args): def read_mac(esp, args): mac = esp.read_mac() - print 'MAC: %s' % ':'.join(map(lambda x: '%02x' % x, mac)) + print('MAC: %s' % ':'.join(map(lambda x: '%02x' % x, mac))) def chip_id(esp, args): chipid = esp.chip_id() - print 'Chip ID: 0x%08x' % chipid + print('Chip ID: 0x%08x' % chipid) def erase_flash(esp, args): flasher = CesantaFlasher(esp, args.baud) - print 'Erasing flash (this may take a while)...' + print('Erasing flash (this may take a while)...') t = time.time() flasher.flash_erase_chip() t = time.time() - t - print 'Erase took %.1f seconds' % t + print('Erase took %.1f seconds' % t) def run(esp, args): @@ -1015,8 +1015,8 @@ def run(esp, args): def flash_id(esp, args): flash_id = esp.flash_id() esp.flash_finish(False) - print 'Manufacturer: %02x' % (flash_id & 0xff) - print 'Device: %02x%02x' % ((flash_id >> 8) & 0xff, (flash_id >> 16) & 0xff) + print('Manufacturer: %02x' % (flash_id & 0xff)) + print('Device: %02x%02x' % ((flash_id >> 8) & 0xff, (flash_id >> 16) & 0xff)) def read_flash(esp, args): @@ -1024,8 +1024,8 @@ def read_flash(esp, args): t = time.time() data = flasher.flash_read(args.address, args.size, not args.no_progress) t = time.time() - t - print ('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' - % (len(data), args.address, t, len(data) / t * 8 / 1000)) + print(('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' + % (len(data), args.address, t, len(data) / t * 8 / 1000))) file(args.filename, 'wb').write(data) @@ -1037,26 +1037,26 @@ def _verify_flash(flasher, args, flash_params=None): if address == 0 and image[0] == '\xe9' and flash_params is not None: image = image[0:2] + flash_params + image[4:] image_size = len(image) - print 'Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name) + print('Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name)) # Try digest first, only read if there are differences. digest, _ = flasher.flash_digest(address, image_size) digest = hexify(digest).upper() expected_digest = hashlib.md5(image).hexdigest().upper() if digest == expected_digest: - print '-- verify OK (digest matched)' + print('-- verify OK (digest matched)') continue else: differences = True if getattr(args, 'diff', 'no') != 'yes': - print '-- verify FAILED (digest mismatch)' + print('-- verify FAILED (digest mismatch)') continue flash = flasher.flash_read(address, image_size) assert flash != image diff = [i for i in range(image_size) if flash[i] != image[i]] - print '-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0]) + print('-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0])) for d in diff: - print ' %08x %02x %02x' % (address + d, ord(flash[d]), ord(image[d])) + print(' %08x %02x %02x' % (address + d, ord(flash[d]), ord(image[d]))) if differences: raise FatalError("Verify failed.") @@ -1067,7 +1067,7 @@ def verify_flash(esp, args, flash_params=None): def version(args): - print __version__ + print(__version__) # # End of operations functions @@ -1208,7 +1208,7 @@ def main(): args = parser.parse_args() - print 'esptool.py v%s' % __version__ + print('esptool.py v%s' % __version__) # operation function can take 1 arg (args), 2 args (esp, arg) # or be a member function of the ESPROM class. @@ -1310,5 +1310,5 @@ if __name__ == '__main__': try: main() except FatalError as e: - print '\nA fatal error occurred: %s' % e + print('\nA fatal error occurred: %s' % e) sys.exit(2) diff --git a/python/isotp.py b/python/isotp.py index 97182700..09ee180b 100644 --- a/python/isotp.py +++ b/python/isotp.py @@ -2,7 +2,7 @@ DEBUG = False def msg(x): if DEBUG: - print "S:",x.encode("hex") + print("S:",x.encode("hex")) if len(x) <= 7: ret = chr(len(x)) + x else: @@ -52,7 +52,7 @@ def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr): tlen = ord(msg[1]) & 0xf dat = msg[2:] else: - print msg.encode("hex") + print(msg.encode("hex")) assert False return dat[0:tlen] @@ -129,7 +129,7 @@ def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None): dat = dat[0:tlen] if DEBUG: - print "R:",dat.encode("hex") + print("R:",dat.encode("hex")) return dat diff --git a/python/update.py b/python/update.py index c711ffba..a82bbc6a 100755 --- a/python/update.py +++ b/python/update.py @@ -27,7 +27,7 @@ def ensure_st_up_to_date(): panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() - print "waiting for board..." + print("waiting for board...") time.sleep(1) if panda.bootstub or not panda.get_version().startswith(repo_version): @@ -38,7 +38,7 @@ def ensure_st_up_to_date(): assert(not panda.bootstub) version = str(panda.get_version()) - print("%s should be %s" % (version, repo_version)) + print(("%s should be %s" % (version, repo_version))) assert(version.startswith(repo_version)) if __name__ == "__main__": diff --git a/tests/all_wifi_test.py b/tests/all_wifi_test.py index 602ce96d..2c92cd90 100755 --- a/tests/all_wifi_test.py +++ b/tests/all_wifi_test.py @@ -12,12 +12,12 @@ if __name__ == "__main__": for p in Panda.list(): dongle_id, pw = Panda(p).get_serial() - print dongle_id, pw + print(dongle_id, pw) assert(dongle_id.isalnum()) _connect_wifi(dongle_id, pw) r = requests.get("http://192.168.0.10/") - print r.text + print(r.text) wifi_dongle_id = r.text.split("ssid: panda-")[1].split("
")[0] st_version = r.text.split("st version:")[1].strip().split("
")[0] esp_version = r.text.split("esp version:")[1].strip().split("
")[0] diff --git a/tests/automated/helpers.py b/tests/automated/helpers.py index c9e0c676..d902b085 100644 --- a/tests/automated/helpers.py +++ b/tests/automated/helpers.py @@ -62,7 +62,7 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): except: pass - print("WIFI: connecting to %s" % ssid) + print(("WIFI: connecting to %s" % ssid)) while 1: if sys.platform == "darwin": @@ -72,7 +72,7 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): cnt = 0 MAX_TRIES = 10 while cnt < MAX_TRIES: - print("WIFI: scanning %d" % cnt) + print(("WIFI: scanning %d" % cnt)) os.system("iwlist %s scanning > /dev/null" % wlan_interface) os.system("nmcli device wifi rescan") wifi_scan = filter(lambda x: ssid in x, subprocess.check_output(["nmcli","dev", "wifi", "list"]).split("\n")) @@ -256,5 +256,5 @@ def clear_can_buffers(panda): r = panda.can_recv() time.sleep(0.05) if (time.time() - st) > 10: - print("Unable to clear can buffers for panda ", panda.get_serial()) + print(("Unable to clear can buffers for panda ", panda.get_serial())) assert False \ No newline at end of file diff --git a/tests/get_version.py b/tests/get_version.py index 73e51e1f..c505806c 100755 --- a/tests/get_version.py +++ b/tests/get_version.py @@ -4,6 +4,6 @@ from panda import Panda if __name__ == "__main__": for p in Panda.list(): pp = Panda(p) - print("%s: %s" % (pp.get_serial()[0], pp.get_version())) + print(("%s: %s" % (pp.get_serial()[0], pp.get_version()))) diff --git a/tests/gmbitbang/recv.py b/tests/gmbitbang/recv.py index 0e9cc4cb..92111ed7 100755 --- a/tests/gmbitbang/recv.py +++ b/tests/gmbitbang/recv.py @@ -12,6 +12,6 @@ while 1: if len(ret) > 0: add = ret[0][0] if last_add is not None and add != last_add+1: - print "MISS %d %d" % (last_add, add) + print("MISS %d %d" % (last_add, add)) last_add = add - print ret + print(ret) diff --git a/tests/gmbitbang/rigol.py b/tests/gmbitbang/rigol.py index cd2164a1..7118b9cf 100755 --- a/tests/gmbitbang/rigol.py +++ b/tests/gmbitbang/rigol.py @@ -4,10 +4,10 @@ import visa import matplotlib.pyplot as plt resources = visa.ResourceManager() -print resources.list_resources() +print(resources.list_resources()) scope = resources.open_resource('USB0::0x1AB1::0x04CE::DS1ZA184652242::INSTR', timeout=2000, chunk_size=1024000) -print(scope.query('*IDN?').strip()) +print((scope.query('*IDN?').strip())) #voltscale = scope.ask_for_values(':CHAN1:SCAL?')[0] #voltoffset = scope.ask_for_values(":CHAN1:OFFS?")[0] @@ -17,7 +17,7 @@ scope.write(":WAV:POIN:MODE RAW") scope.write(":WAV:DATA? CHAN1")[10:] rawdata = scope.read_raw() data = np.frombuffer(rawdata, 'B') -print data.shape +print(data.shape) s1 = data[0:650] s2 = data[650:] @@ -31,5 +31,5 @@ plt.plot(s2) plt.show() #data = (data - 130.0 - voltoffset/voltscale*25) / 25 * voltscale -print data +print(data) diff --git a/tests/gmbitbang/test.py b/tests/gmbitbang/test.py index 24227f1a..321165f8 100755 --- a/tests/gmbitbang/test.py +++ b/tests/gmbitbang/test.py @@ -10,8 +10,8 @@ p1.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p2.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # get versions -print(p1.get_version()) -print(p2.get_version()) +print((p1.get_version())) +print((p2.get_version())) # this sets bus 2 to actually be GMLAN p2.set_gmlan(bus=2) @@ -28,6 +28,6 @@ while 1: #p1.set_gmlan(bus=2) #p1.can_send(iden, dat, bus=3) time.sleep(0.01) - print p2.can_recv() + print(p2.can_recv()) #exit(0) diff --git a/tests/gmbitbang/test_one.py b/tests/gmbitbang/test_one.py index 210041a0..635cd2c9 100755 --- a/tests/gmbitbang/test_one.py +++ b/tests/gmbitbang/test_one.py @@ -9,9 +9,9 @@ p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p.set_gmlan(bus=2) time.sleep(0.1) while len(p.can_recv()) > 0: - print "clearing" + print("clearing") time.sleep(0.1) -print "cleared" +print("cleared") p.set_gmlan(bus=None) iden = 18000 diff --git a/tests/health_test.py b/tests/health_test.py index c9321678..bf502fda 100755 --- a/tests/health_test.py +++ b/tests/health_test.py @@ -13,7 +13,7 @@ if __name__ == "__main__": while True: for panda in pandas: - print(panda.health()) + print((panda.health())) print("\n") time.sleep(0.5) diff --git a/tests/language/test_language.py b/tests/language/test_language.py index 908eeeca..353f37e8 100755 --- a/tests/language/test_language.py +++ b/tests/language/test_language.py @@ -18,11 +18,11 @@ if __name__ == "__main__": try: cmd = "cd ../../; grep -R -i -w " + suffix_cmd + " '" + line + "'" res = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) - print res + print(res) found_bad_language = True except subprocess.CalledProcessError as e: pass if found_bad_language: sys.exit("Failed: found bad language") else: - print "Success" + print("Success") diff --git a/tests/location_listener.py b/tests/location_listener.py index d7e37bf8..16be9233 100755 --- a/tests/location_listener.py +++ b/tests/location_listener.py @@ -18,20 +18,20 @@ if __name__ == "__main__": ser = PandaSerial(panda, 1, 9600) # power cycle by toggling reset - print "resetting" + print("resetting") panda.set_esp_power(0) time.sleep(0.5) panda.set_esp_power(1) time.sleep(0.5) - print "done" - print ser.read(1024) + print("done") + print(ser.read(1024)) # upping baud rate baudrate = 460800 - print "upping baud rate" + print("upping baud rate") msg = add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % baudrate)+"\r\n" - print msg + print(msg) ser.write(msg) time.sleep(0.1) # needs a wait for it to actually send diff --git a/tests/pedal/enter_canloader.py b/tests/pedal/enter_canloader.py index fc35dddb..2f7f9bc7 100755 --- a/tests/pedal/enter_canloader.py +++ b/tests/pedal/enter_canloader.py @@ -67,10 +67,10 @@ if __name__ == "__main__": if args.fn: time.sleep(0.1) - print "flashing", args.fn + print("flashing", args.fn) code = open(args.fn).read() Panda.flash_static(CanHandle(p), code) - print "can flash done" + print("can flash done") diff --git a/tests/read_winusb_descriptors.py b/tests/read_winusb_descriptors.py index a786197f..ea5e93f3 100644 --- a/tests/read_winusb_descriptors.py +++ b/tests/read_winusb_descriptors.py @@ -8,22 +8,22 @@ if __name__ == "__main__": p = Panda() len = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, 1) - print 'Microsoft OS String Descriptor' + print('Microsoft OS String Descriptor') dat = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, len[0]) - if DEBUG: print 'LEN: {}'.format(hex(len[0])) + if DEBUG: print('LEN: {}'.format(hex(len[0]))) hexdump("".join(map(chr, dat))) ms_vendor_code = dat[16] - if DEBUG: print 'MS_VENDOR_CODE: {}'.format(hex(len[0])) + if DEBUG: print('MS_VENDOR_CODE: {}'.format(hex(len[0]))) - print '\nMicrosoft Compatible ID Feature Descriptor' + print('\nMicrosoft Compatible ID Feature Descriptor') len = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, 1) - if DEBUG: print 'LEN: {}'.format(hex(len[0])) + if DEBUG: print('LEN: {}'.format(hex(len[0]))) dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, len[0]) hexdump("".join(map(chr, dat))) - print '\nMicrosoft Extended Properties Feature Descriptor' + print('\nMicrosoft Extended Properties Feature Descriptor') len = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, 1) - if DEBUG: print 'LEN: {}'.format(hex(len[0])) + if DEBUG: print('LEN: {}'.format(hex(len[0]))) dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, len[0]) hexdump("".join(map(chr, dat))) diff --git a/tests/safety_replay/replay_drive.py b/tests/safety_replay/replay_drive.py index ca643fc9..03f05011 100755 --- a/tests/safety_replay/replay_drive.py +++ b/tests/safety_replay/replay_drive.py @@ -37,7 +37,7 @@ def replay_drive(lr, safety_mode, param): blocked_addrs.add(canmsg.address) if "DEBUG" in os.environ: - print "blocked %d at %f" % (canmsg.address, (msg.logMonoTime - start_t)/(1e9)) + print("blocked %d at %f" % (canmsg.address, (msg.logMonoTime - start_t)/(1e9))) tx_controls += safety.get_controls_allowed() tx_tot += 1 elif msg.which() == 'can': @@ -48,11 +48,11 @@ def replay_drive(lr, safety_mode, param): to_push = package_can_msg(canmsg) safety.safety_rx_hook(to_push) - print "total openpilot msgs:", tx_tot - print "total msgs with controls allowed:", tx_controls - print "blocked msgs:", tx_blocked - print "blocked with controls allowed:", tx_controls_blocked - print "blocked addrs:", blocked_addrs + print("total openpilot msgs:", tx_tot) + print("total msgs with controls allowed:", tx_controls) + print("blocked msgs:", tx_blocked) + print("blocked with controls allowed:", tx_controls_blocked) + print("blocked addrs:", blocked_addrs) return tx_controls_blocked == 0 @@ -64,7 +64,7 @@ if __name__ == "__main__": param = 0 if len(sys.argv) < 4 else int(sys.argv[3]) lr = LogReader(sys.argv[1]) - print "replaying drive %s with safety mode %d and param %d" % (sys.argv[1], mode, param) + print("replaying drive %s with safety mode %d and param %d" % (sys.argv[1], mode, param)) replay_drive(lr, mode, param) diff --git a/tests/safety_replay/test_safety_replay.py b/tests/safety_replay/test_safety_replay.py index 620f3db7..ff23e016 100755 --- a/tests/safety_replay/test_safety_replay.py +++ b/tests/safety_replay/test_safety_replay.py @@ -31,11 +31,11 @@ if __name__ == "__main__": lr = LogReader(route) m = safety_modes.get(mode, mode) - print "\nreplaying %s with safety mode %d and param %s" % (route, m, param) + print("\nreplaying %s with safety mode %d and param %s" % (route, m, param)) if not replay_drive(lr, m, int(param)): failed.append(route) for f in failed: - print "\n**** failed on %s ****" % f + print("\n**** failed on %s ****" % f) assert len(failed) == 0, "\nfailed on %d logs" % len(failed) diff --git a/tests/standalone_test.py b/tests/standalone_test.py index 9e181d8f..a7f93278 100755 --- a/tests/standalone_test.py +++ b/tests/standalone_test.py @@ -12,14 +12,14 @@ if __name__ == "__main__": p = Panda("WIFI") else: p = Panda() - print(p.get_serial()) - print(p.health()) + print((p.get_serial())) + print((p.health())) t1 = time.time() for i in range(100): p.get_serial() t2 = time.time() - print("100 requests took %.2f ms" % ((t2-t1)*1000)) + print(("100 requests took %.2f ms" % ((t2-t1)*1000))) p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)