Skip to content

Commit 7274d9f

Browse files
authored
Merge pull request #484 from TheCacophonyProject/test-firmware-sim
Test firmware sim
2 parents 9d6cafd + 1f9d781 commit 7274d9f

File tree

14 files changed

+258
-13
lines changed

14 files changed

+258
-13
lines changed

_modules/cacophony.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import glob
2+
import os
3+
import re
4+
5+
16
def continuous_recording(on):
27
args = ["cacophony-config", "--write"]
38
if on:
@@ -24,3 +29,41 @@ def continuous_recording(on):
2429
output = __salt__["cmd.run"](" ".join(args), raise_err=True)
2530
__salt__["service.restart"]("thermal-recorder")
2631
return output
32+
33+
34+
def has_usb_device(device_ids):
35+
"""Return True when a matching USB vendor:product ID is present."""
36+
37+
if not device_ids:
38+
return False
39+
40+
if isinstance(device_ids, str):
41+
targets = {device_ids.lower()}
42+
else:
43+
try:
44+
targets = {item.lower() for item in device_ids if isinstance(item, str)}
45+
except TypeError:
46+
targets = set()
47+
48+
if not targets:
49+
return False
50+
51+
for path in glob.glob("/sys/bus/usb/devices/*"):
52+
if ":" in os.path.basename(path):
53+
continue
54+
55+
try:
56+
with open(os.path.join(path, "idVendor"), encoding="utf-8") as vendor_file:
57+
vendor = vendor_file.read().strip().lower()
58+
with open(os.path.join(path, "idProduct"), encoding="utf-8") as product_file:
59+
product = product_file.read().strip().lower()
60+
except FileNotFoundError:
61+
continue
62+
63+
if not vendor or not product:
64+
continue
65+
66+
if f"{vendor}:{product}" in targets:
67+
return True
68+
69+
return False

_states/cacophony.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def pkg_installed_from_github(
9292
pkg_name = name
9393

9494
installed_version_cmd = f"dpkg-query --showformat='${{Version}}' --show {pkg_name}"
95-
installed_version_ret = __salt__["cmd.run_all"](installed_version_cmd, python_shell=False)
95+
installed_version_ret = __salt__["cmd.run_all"](
96+
installed_version_cmd, python_shell=False
97+
)
9698

9799
installed_version = ""
98100
if installed_version_ret["retcode"] == 0:
@@ -124,7 +126,7 @@ def pkg_installed_from_github(
124126
download_start_time = time.time()
125127
source_url = f"https://github.com/TheCacophonyProject/{name}/releases/download/v{version}/{pkg_name}_{version}_{architecture}.deb"
126128
download_ret = __salt__["cp.get_url"](source_url, deb_path, makedirs=True)
127-
download_duration = time.time() - download_start_time
129+
download_duration = time.time() - download_start_time
128130
if not download_ret:
129131
ret["comment"] = f"Failed to download package from {source_url}"
130132
return ret
@@ -136,10 +138,14 @@ def pkg_installed_from_github(
136138

137139
if install_ret["retcode"] != 0:
138140
ret["result"] = False
139-
ret["comment"] = "dpkg failed to install {}. Stderr: {}".format(deb_path, install_ret["stderr"])
141+
ret["comment"] = "dpkg failed to install {}. Stderr: {}".format(
142+
deb_path, install_ret["stderr"]
143+
)
140144
else:
141145
ret["result"] = True
142-
ret["comment"] = f"Package {pkg_name} version {version} installed successfully in {(time.time() - start_time):.2f}. (download: {download_duration:.2f}s, install: {install_duration:.2f}s)."
146+
ret["comment"] = (
147+
f"Package {pkg_name} version {version} installed successfully in {(time.time() - start_time):.2f}. (download: {download_duration:.2f}s, install: {install_duration:.2f}s)."
148+
)
143149
ret["changes"] = {
144150
"old": installed_version,
145151
"new": version,
@@ -150,9 +156,10 @@ def pkg_installed_from_github(
150156
if os.path.exists(package_tmp_dir):
151157
os.remove(deb_path)
152158
os.rmdir(package_tmp_dir)
153-
159+
154160
return ret
155161

162+
156163
def init_alsa(name):
157164
"""Ensure that the built-in audio hardware is correctly initialised."""
158165
if _is_audio_setup():

tc2-top.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ base:
88
- tc2/auth
99
- tc2/salt-minion
1010
- tc2/network-manager
11+
- tc2/rtl8821au
1112
- tc2/watchdog
1213
- tc2/event-reporter
1314
- tc2/thermal-uploader

tc2/management-interface/init.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
management-interface-pkg:
22
cacophony.pkg_installed_from_github:
33
- name: management-interface
4-
- version: "1.43.0"
4+
- version: "1.45.0"
55
- architecture: "arm64"
66
- branch: tc2
77

tc2/modemd/init.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ stop_modem_manager:
1010
modemd-pkg:
1111
cacophony.pkg_installed_from_github:
1212
- name: modemd
13-
- version: "1.15.1"
13+
- version: "1.16.0"
1414
- architecture: "arm64"
1515
- branch: "tc2"
1616

tc2/rpi-net-manager/init.sls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
rpi-net-manager-pkg:
22
cacophony.pkg_installed_from_github:
33
- name: rpi-net-manager
4-
- version: "0.6.2"
4+
- version: "0.7.1"
55
- architecture: "arm64"
66

77
rpi-net-manager-service:
88
service.running:
99
- name: rpi-net-manager
1010
- enable: True
11+
12+
hostapd:
13+
pkg.installed
14+

tc2/rtl8821au/init.sls

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{% from "tc2/rtl8821au/map.jinja" import rtl8821au with context %}
2+
{% set device_present = salt['cacophony.has_usb_device'](rtl8821au['device_ids']) %}
3+
{% set install_marker = rtl8821au['install_marker'] %}
4+
{% set already_installed = salt['file.file_exists'](install_marker) %}
5+
{% set should_install = rtl8821au['auto_update'] or not already_installed %}
6+
{% set install_command = "./install-driver.sh" %}
7+
{% if rtl8821au['install_args'] %}
8+
{% set install_command = install_command + " " + " ".join(rtl8821au['install_args']) %}
9+
{% endif %}
10+
11+
{% if device_present %}
12+
13+
{% if rtl8821au['packages'] %}
14+
rtl8821au-deps:
15+
pkg.installed:
16+
- pkgs: {{ rtl8821au['packages'] }}
17+
{% endif %}
18+
19+
{% if should_install %}
20+
rtl8821au-source:
21+
git.latest:
22+
- name: {{ rtl8821au['repo'] }}
23+
- target: {{ rtl8821au['source_dir'] }}
24+
- depth: 1
25+
- rev: {{ rtl8821au['branch'] }}
26+
- require:
27+
{% if rtl8821au['packages'] %}
28+
- pkg: rtl8821au-deps
29+
{% endif %}
30+
- user: root
31+
{% if not rtl8821au['auto_update'] %}
32+
- unless: test -f "{{ install_marker }}"
33+
{% endif %}
34+
35+
rtl8821au-install:
36+
cmd.run:
37+
- name: {{ install_command }}
38+
- cwd: {{ rtl8821au['source_dir'] }}
39+
- unless: modinfo 8821au
40+
- require:
41+
- git: rtl8821au-source
42+
43+
rtl8821au-reinstall:
44+
cmd.run:
45+
- name: {{ install_command }}
46+
- cwd: {{ rtl8821au['source_dir'] }}
47+
- onlyif: modinfo 8821au
48+
- onchanges:
49+
- git: rtl8821au-source
50+
- require:
51+
- git: rtl8821au-source
52+
53+
rtl8821au-marker:
54+
file.managed:
55+
- name: {{ install_marker }}
56+
- contents: installed
57+
- makedirs: True
58+
- onlyif: modinfo 8821au
59+
- require:
60+
- git: rtl8821au-source
61+
- unless: test -f "{{ install_marker }}"
62+
{% else %}
63+
rtl8821au-installed:
64+
test.nop:
65+
- name: rtl8821au
66+
- comment: Driver already installed ({{ install_marker }})
67+
{% endif %}
68+
69+
rtl8821au-modprobe-options:
70+
file.line:
71+
- name: /etc/modprobe.d/8821au.conf
72+
- mode: replace
73+
- match: ^options 8821au
74+
- content: options 8821au rtw_led_ctrl=1 rtw_vht_enable=2 rtw_power_mgnt=0 rtw_dfs_region_domain=3
75+
- onlyif: test -f /etc/modprobe.d/8821au.conf
76+
{% if should_install %}
77+
- require:
78+
- cmd: rtl8821au-install
79+
{% endif %}
80+
81+
{% else %}
82+
rtl8821au-not-required:
83+
test.nop:
84+
- name: rtl8821au
85+
- comment: Driver not installed. device_present={{ device_present }}
86+
{% endif %}

tc2/rtl8821au/map.jinja

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{% set supported_device_ids = [
2+
"0bda:0811",
3+
"0bda:0821",
4+
"0bda:8822",
5+
"0bda:a811",
6+
"0bda:0820",
7+
"0bda:0823",
8+
"0411:0242",
9+
"0411:029b",
10+
"04bb:0953",
11+
"056e:4007",
12+
"056e:400e",
13+
"056e:400f",
14+
"0846:9052",
15+
"0e66:0023",
16+
"2001:3314",
17+
"2001:3318",
18+
"2019:ab32",
19+
"20f4:804b",
20+
"2357:011e",
21+
"2357:011f",
22+
"2357:0120",
23+
"3823:6249",
24+
"7392:a811",
25+
"7392:a812",
26+
"7392:a813",
27+
"7392:b611",
28+
] %}
29+
30+
{% set packages = ["dkms", "git", "hostapd"] %}
31+
{% if salt['grains.get']('os_family') == 'Debian' %}
32+
{% set packages = packages + ["build-essential", "bc", "iw"] %}
33+
{% set os_name = salt['grains.get']('os') %}
34+
{% set os_fullname = salt['grains.get']('osfullname') %}
35+
{% if os_name in ['Raspbian', 'Raspberry Pi OS'] or os_fullname.startswith('Raspberry Pi OS') %}
36+
{% set packages = packages + ["raspberrypi-kernel-headers"] %}
37+
{% else %}
38+
{% set packages = packages + ["linux-headers-" ~ salt['grains.get']('kernelrelease')] %}
39+
{% endif %}
40+
{% endif %}
41+
42+
{% set branch = salt['pillar.get']('rtl8821au:branch', 'main') %}
43+
{% set source_dir = salt['pillar.get']('rtl8821au:source_dir', '/usr/local/src/8821au-20210708') %}
44+
{% set install_marker = salt['pillar.get']('rtl8821au:install_marker', source_dir ~ '/.salt-driver-installed') %}
45+
{% set auto_update = salt['pillar.get']('rtl8821au:auto_update', False) %}
46+
47+
{% set rtl8821au = {
48+
'device_ids': salt['pillar.get']('rtl8821au:device_ids', supported_device_ids),
49+
'packages': salt['pillar.get']('rtl8821au:packages', packages),
50+
'repo': salt['pillar.get']('rtl8821au:repo', 'https://github.com/morrownr/8821au-20210708.git'),
51+
'branch': branch,
52+
'source_dir': source_dir,
53+
'install_marker': install_marker,
54+
'auto_update': auto_update,
55+
'install_args': salt['pillar.get']('rtl8821au:install_args', ['NoPrompt']),
56+
} %}

tc2/tc2-agent/init.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tc2-agent-pkg:
22
cacophony.pkg_installed_from_github:
33
- name: tc2-agent
4-
- version: "0.5.30"
4+
- version: "0.5.31"
55
- architecture: "arm64"
66
- branch: "main"
77

tc2/tc2-hat-controller/init.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tc2-hat-controller-pkg:
22
cacophony.pkg_installed_from_github:
33
- name: tc2-hat-controller
4-
- version: "0.20.7"
4+
- version: "0.21.1"
55
- architecture: "arm64"
66
- branch: "main"
77

0 commit comments

Comments
 (0)