-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (60 loc) · 2.68 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import HID
import CS108FwUpgrade
import sys
import os
import utils
def main():
handle = None
print("----------------------------")
print("CS710S Firmware Upgrade Toool")
print("----------------------------")
if (len(sys.argv) < 3) or (sys.argv[1].lower() != "/b" and sys.argv[1].lower() != "/n" and sys.argv[1].lower() != "/r"):
print("Usage: python main.py [ /B | /N ] file")
return
if not os.path.exists(sys.argv[2]):
print("File specificed ({}) not found".format(sys.argv[2]))
return
NumOfConnectedDevices = HID.GetNumHidDevices()
print("Number of USB device(s) connected: ", NumOfConnectedDevices)
for i in range(NumOfConnectedDevices):
print("Device {}: {}".format(i, str(HID.GetHidString(i))))
if NumOfConnectedDevices != 0:
handle = HID.Open()
else:
print("No CS710S device connected")
return
if sys.argv[1].lower() == "/b":
isBLMode, atVersion=CS108FwUpgrade.GetAtmelVersion(handle)
print("Current Atmel processor firmware version: {}".format(atVersion))
btVersion=CS108FwUpgrade.GetBTVersion(handle)
print("Current Bluetooth firmware version: {}".format(btVersion))
if isBLMode:
print("Reader is in bootloader mode. Please update Atmel firmware before proceeding with Bluetooth firmware.")
return
fileName = sys.argv[2]
print("\nUpgrade Bluetooth firmware with file:", fileName)
in_file = open(fileName, "rb") # opening for [r]eading as [b]inary
stream = in_file.read()
in_file.close()
if CS108FwUpgrade.UpdateBTImage(handle, stream):
print("Bluetooth firmware upgrade successful. Please reboot the reader.")
else:
print("Bluetooth firmware upgrade failed")
HID.Close(handle)
elif sys.argv[1].lower() == "/n":
isBLMode, atVersion=CS108FwUpgrade.GetAtmelVersion(handle)
print("Current Atmel processor firmware version: {}".format(atVersion))
btVersion=CS108FwUpgrade.GetBTVersion(handle)
print("Current Bluetooth firmware version: {}".format(btVersion))
fileName = sys.argv[2]
print("\nUpgrade Atmel processor firmware with file:", fileName)
in_file = open(fileName, "rb") # opening for [r]eading as [b]inary
stream = in_file.read()
in_file.close()
if CS108FwUpgrade.UpdateAtmelImage(handle, stream):
print("Atmel processor firmware upgrade successful. Please reboot the reader.")
else:
print("Atmel processor firmware upgrade failed")
HID.Close(handle)
if __name__ == '__main__':
main()