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 sys
import os
import subprocess
import time
CAMERA_NAMES = {
"qhy367c": {
"image": "QHY367.img",
"device_id": "1618:c367",
"active_id": "1618:c368"
},
"qhy600m": {
"image": "QHY600.img",
"device_id": "1618:c600",
"active_id": "1618:c601"
},
}
PARAMETERS = CAMERA_NAMES["qhy600m"]
def get_path(dev_id):
if len(dev_id) != 9:
raise Exception("Invalid device id: {}. Expected a string 9 characters long (ex: aaaa:bbbb)".format(dev_id))
for line in subprocess.check_output("lsusb").split('\n'):
if dev_id in line:
parts = line.split(' ')
bus = parts[1]
device = parts[3][:-1]
path = "/dev/bus/usb/{}/{}".format(bus, device)
# path = "/sys/bus/usb/devices/{}-{}".format(bus.replace('0', ''), device.replace('0', ''))
print("Found {} at {}".format(dev_id, path))
return path
return None
def fix_perms(camera_path):
me = os.getuid()
camera_perms = os.stat(camera_path).st_uid
if camera_perms != me:
print("Fixing permissions..")
os.system("sudo chown iximeow:iximeow {}".format(camera_path))
camera_path = get_path(PARAMETERS["device_id"])
if camera_path == None:
print("couldn't find the camera, firmware may have been loaded already?")
sys.exit(1)
fix_perms(camera_path)
# fxload_binary = "./sdks/LINUX_X64_qhyccd_V20190628_0/sbin/fxload"
fxload_binary = "./sdks/sdk_linux64_20.07.26/sbin/fxload"
fw_cmd = "{} -t fx3 -I firmware/qhy/{} -D {}".format(
fxload_binary,
PARAMETERS["image"],
camera_path
)
print(fw_cmd)
fw_load = subprocess.check_output([
fxload_binary, '-t', 'fx3', '-I', 'firmware/qhy/{}'.format(PARAMETERS["image"]), '-D', camera_path])
print(fw_load)
time.sleep(1)
path = get_path(PARAMETERS["active_id"])
if path == None:
print("couldn't find camera id after loading firmware. did the camera die?")
sys.exit(1)
fix_perms(path)
|