Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (71 loc) · 3.01 KB
/
Copy pathmain.py
File metadata and controls
88 lines (71 loc) · 3.01 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
import HID
import CS108FwUpgrade
import sys
import os
def main():
handle = 0
print("----------------------------")
print("CS108 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 | /R ] 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, HID.GetHidString(i)))
if NumOfConnectedDevices > 0:
print("Open the first device found...")
handle = HID.Open(0)
if handle != None:
print("Device opened: handle={}".format(handle))
else:
print("Unable to open device")
return
else:
print("No CS108 device connected")
return
if sys.argv[1].lower() == "/b":
btVersion=CS108FwUpgrade.GetBTVersion(handle)
print("Current Bluetooth firmware version: {}".format(btVersion))
fileName = sys.argv[2]
print("Upgrade 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")
else:
print("Bluetooth firmware upgrade failed")
HID.Close(handle)
elif sys.argv[1].lower() == "/n":
slVersion=CS108FwUpgrade.GetSLVersion(handle)
print("Current Silicon Labs (network processor) firmware version: {}".format(slVersion))
fileName = sys.argv[2]
print("Upgrade Silicon Labs (network 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.UpdateSilabImage(handle, stream):
print("Silicon Labs (network processor) firmware upgrade successful")
else:
print("Silicon Labs (network processor) firmware upgrade failed")
HID.Close(handle)
elif sys.argv[1].lower() == "/r":
rfidVersion=CS108FwUpgrade.GetRFIDVersion(handle)
print("Current RFID firmware version: {}".format(rfidVersion))
fileName = sys.argv[2]
print("Upgrade RFID 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.UpdateRFIDImage(handle, stream):
print("RFID firmware upgrade successful")
else:
print("RFID firmware upgrade failed")
HID.Close(handle)
if __name__ == '__main__':
main()