From 3ae54c3c66a456c975ee5b27003e6d0e8a48a7e8 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Thu, 6 Jun 2019 13:48:02 +0200
Subject: [PATCH] fix(crc_patch.py): Update for Python3 compatibility

---
 Hello_World/build_image          |  2 +-
 Hello_World_FreeRTOS/build_image |  2 +-
 ble/build_image                  |  2 +-
 bmatest/build_image              |  2 +-
 bmetest/build_image              |  2 +-
 bootloader/crc_patch.py          | 11 ++++++-----
 ecgtest/build_image              |  2 +-
 imutest/build_image              |  2 +-
 ips/build_image                  |  2 +-
 9 files changed, 14 insertions(+), 13 deletions(-)
 mode change 100644 => 100755 bootloader/crc_patch.py

diff --git a/Hello_World/build_image b/Hello_World/build_image
index efcda785..5feeda9e 100755
--- a/Hello_World/build_image
+++ b/Hello_World/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/Hello_World_FreeRTOS/build_image b/Hello_World_FreeRTOS/build_image
index efcda785..5feeda9e 100755
--- a/Hello_World_FreeRTOS/build_image
+++ b/Hello_World_FreeRTOS/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/ble/build_image b/ble/build_image
index efcda785..5feeda9e 100755
--- a/ble/build_image
+++ b/ble/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/bmatest/build_image b/bmatest/build_image
index efcda785..5feeda9e 100755
--- a/bmatest/build_image
+++ b/bmatest/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/bmetest/build_image b/bmetest/build_image
index efcda785..5feeda9e 100755
--- a/bmetest/build_image
+++ b/bmetest/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/bootloader/crc_patch.py b/bootloader/crc_patch.py
old mode 100644
new mode 100755
index 16394463..21eeb57a
--- a/bootloader/crc_patch.py
+++ b/bootloader/crc_patch.py
@@ -1,16 +1,17 @@
+#!/usr/bin/env python3
 import sys
 import crc16
 
 crc = 0
 
-data = open(sys.argv[1]).read()
+data = open(sys.argv[1], 'rb').read()
 crc = crc16.crc16xmodem(data)
-print crc
+print(crc)
 
-padded = data + chr(crc >> 8) + chr(crc & 0xFF)
+padded = data + bytes([crc >> 8, crc & 0xFF])
 
 crc = 0
 crc = crc16.crc16xmodem(padded)
-print crc
+print(crc)
 
-open(sys.argv[1], 'w').write(padded)
+open(sys.argv[1], 'wb').write(padded)
diff --git a/ecgtest/build_image b/ecgtest/build_image
index efcda785..5feeda9e 100755
--- a/ecgtest/build_image
+++ b/ecgtest/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/imutest/build_image b/imutest/build_image
index efcda785..5feeda9e 100755
--- a/imutest/build_image
+++ b/imutest/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
diff --git a/ips/build_image b/ips/build_image
index efcda785..5feeda9e 100755
--- a/ips/build_image
+++ b/ips/build_image
@@ -2,4 +2,4 @@ make clean
 make APP=1
 make build/max32665.bin
 cp build/max32665.bin card10.bin
-python ../bootloader/crc_patch.py card10.bin
+../bootloader/crc_patch.py card10.bin
-- 
GitLab