From f9053f5df4f2a0be475d5b76c84d371f0b26b7b0 Mon Sep 17 00:00:00 2001 From: rbiasini Date: Thu, 10 Oct 2019 12:34:52 -0700 Subject: [PATCH] more Python 3 fixes, attempting to fix jenkins wifi regresison test (#295) * more Python 3 fixes, attempting to fix jenkins wifi regresison test. Not successful, but closer. --- Jenkinsfile | 15 +++++++++++++++ UPDATING.md | 12 ++++++------ examples/query_vin_and_stats.py | 12 +++++++----- examples/tesla_tester.py | 4 ++-- python/__init__.py | 2 +- python/isotp.py | 6 +++--- tests/automated/helpers.py | 8 ++++---- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7f147a2..204b5be 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,6 +46,21 @@ pipeline { } } } +/* + stage('Test Dev Build (WIFI)') { + steps { + lock(resource: "Pandas", inversePrecedence: true, quantity: 1){ + timeout(time: 60, unit: 'MINUTES') { + script { + sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; ./run_automated_tests.sh'" + sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml" + sh "docker rm ${env.DOCKER_NAME}" + } + } + } + } + } +*/ } post { failure { diff --git a/UPDATING.md b/UPDATING.md index 100acc6..ab60f88 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -1,9 +1,9 @@ # Updating your panda -Panda should update automatically via the [Chffr](http://chffr.comma.ai/) app ([apple](https://itunes.apple.com/us/app/chffr-dash-cam-that-remembers/id1146683979) and [android](https://play.google.com/store/apps/details?id=ai.comma.chffr)) +Panda should update automatically via the [openpilot](http://openpilot.comma.ai/). -If it doesn't however, you can use the following commands on linux or Mac OSX - `sudo pip install --upgrade pandacan` -` PYTHONPATH="" sudo python -c "import panda; panda.flash_release()"` - -(You'll need to have `pip` and `sudo` installed.) +On Linux or Mac OSX, you can manually update it using: +``` +sudo pip install --upgrade pandacan` +PYTHONPATH="" sudo python -c "import panda; panda.flash_release()"` +``` diff --git a/examples/query_vin_and_stats.py b/examples/query_vin_and_stats.py index 9a0df78..1dc181c 100755 --- a/examples/query_vin_and_stats.py +++ b/examples/query_vin_and_stats.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import time import struct +import binascii from panda import Panda from hexdump import hexdump from panda.python.isotp import isotp_send, isotp_recv @@ -8,9 +9,10 @@ from panda.python.isotp import isotp_send, isotp_recv # 0x7e0 = Toyota # 0x18DB33F1 for Honda? + def get_current_data_for_pid(pid): # 01 xx = Show current data - isotp_send(panda, "\x01"+chr(pid), 0x7e0) + isotp_send(panda, b"\x01"+ (chr(pid)).encode("utf8"), 0x7e0) return isotp_recv(panda, 0x7e8) def get_supported_pids(): @@ -33,15 +35,15 @@ if __name__ == "__main__": panda.can_clear(0) # 09 02 = Get VIN - isotp_send(panda, "\x09\x02", 0x7df) + isotp_send(panda, b"\x09\x02", 0x7df) ret = isotp_recv(panda, 0x7e8) hexdump(ret) - print("VIN: %s" % ret[2:]) + print("VIN: %s" % "".join(map(chr, ret[:2]))) # 03 = get DTCS - isotp_send(panda, "\x03", 0x7e0) + isotp_send(panda, b"\x03", 0x7e0) dtcs = isotp_recv(panda, 0x7e8) - print("DTCs:", dtcs[2:].encode("hex")) + print("DTCs:", "".join(map(chr, dtcs[:2]))) supported_pids = get_supported_pids() print("Supported PIDs:",supported_pids) diff --git a/examples/tesla_tester.py b/examples/tesla_tester.py index 74f19f2..9a77eb4 100644 --- a/examples/tesla_tester.py +++ b/examples/tesla_tester.py @@ -29,11 +29,11 @@ def tesla_tester(): # BDY 0x248 is the MCU_commands message, which includes folding mirrors, opening the trunk, frunk, setting the cars lock state and more. For our test, we will edit the 3rd byte, which is MCU_lockRequest. 0x01 will lock, 0x02 will unlock: print("Unlocking Tesla...") - p.can_send(0x248, "\x00\x00\x02\x00\x00\x00\x00\x00", body_bus_num) + p.can_send(0x248, b"\x00\x00\x02\x00\x00\x00\x00\x00", body_bus_num) #Or, we can set the first byte, MCU_frontHoodCommand + MCU_liftgateSwitch, to 0x01 to pop the frunk, or 0x04 to open/close the trunk (0x05 should open both) print("Opening Frunk...") - p.can_send(0x248, "\x01\x00\x00\x00\x00\x00\x00\x00", body_bus_num) + p.can_send(0x248, b"\x01\x00\x00\x00\x00\x00\x00\x00", body_bus_num) #Back to safety... print("Disabling output on Panda...") diff --git a/python/__init__.py b/python/__init__.py index deb49c3..cd2fe87 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -387,7 +387,7 @@ class Panda(object): dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20) hashsig, calc_hash = dat[0x1c:], hashlib.sha1(dat[0:0x1c]).digest()[0:4] assert(hashsig == calc_hash) - return [dat[0:0x10], dat[0x10:0x10+10]] + return [dat[0:0x10].decode("utf8"), dat[0x10:0x10+10].decode("utf8")] def get_secret(self): return self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 1, 0, 0x10) diff --git a/python/isotp.py b/python/isotp.py index 00200f8..ac0f8c4 100644 --- a/python/isotp.py +++ b/python/isotp.py @@ -6,7 +6,7 @@ def msg(x): if DEBUG: print("S:", binascii.hexlify(x)) if len(x) <= 7: - ret = chr(len(x)) + x + ret = chr(len(x)).encode("utf8") + x else: assert False return ret.ljust(8, b"\x00") @@ -68,7 +68,7 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None): if len(x) <= 7 and subaddr is None: panda.can_send(addr, msg(x), bus) elif len(x) <= 6 and subaddr is not None: - panda.can_send(addr, chr(subaddr)+msg(x)[0:7], bus) + panda.can_send(addr, chr(subaddr).encode("utf8") + msg(x)[0:7], bus) else: if subaddr: ss = (chr(subaddr) + chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:5] @@ -122,7 +122,7 @@ def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None): assert mm[0] == (0x20 | (idx&0xF)) dat += mm[1:] idx += 1 - elif msg[0]&0xf0 == 0x00: + elif msg[0] & 0xf0 == 0x00: # single tlen = msg[0] & 0xf dat = msg[1:] diff --git a/tests/automated/helpers.py b/tests/automated/helpers.py index f73a17d..e97afef 100644 --- a/tests/automated/helpers.py +++ b/tests/automated/helpers.py @@ -50,7 +50,7 @@ def connect_wifi(serial=None): FNULL = open(os.devnull, 'w') def _connect_wifi(dongle_id, pw, insecure_okay=False): - ssid = "panda-" + dongle_id.decode("utf8") + ssid = "panda-" + dongle_id r = subprocess.call(["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if not r: @@ -69,7 +69,7 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): if sys.platform == "darwin": os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw)) else: - wlan_interface = subprocess.check_output(["sh", "-c", "iw dev | awk '/Interface/ {print $2}'"]).strip() + wlan_interface = subprocess.check_output(["sh", "-c", "iw dev | awk '/Interface/ {print $2}'"]).strip().decode('utf8') cnt = 0 MAX_TRIES = 10 while cnt < MAX_TRIES: @@ -87,13 +87,13 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): if "-pair" in wifi_scan[0]: os.system("nmcli d wifi connect %s-pair" % (ssid)) connect_cnt = 0 - MAX_TRIES = 20 + MAX_TRIES = 100 while connect_cnt < MAX_TRIES: connect_cnt += 1 r = subprocess.call(["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if r: print("Waiting for panda to ping...") - time.sleep(0.1) + time.sleep(0.5) else: break if insecure_okay: