disable some decoders.
Build and Release OpenMQTTGateway Firmware / Build Firmware & Publish Gitea Release (push) Canceled after 3m53s
Build and Release OpenMQTTGateway Firmware / Build Firmware & Publish Gitea Release (push) Canceled after 3m53s
This commit is contained in:
1 parent
d686cf71fc
commit
0d8a8b35f0
2 files changed
+77
-21
No files matched your search
@@ -1057,6 +1057,19 @@ extra_scripts =
|
|||||||
${env.extra_scripts}
|
${env.extra_scripts}
|
||||||
scripts/enable_rtl433_decoders.py
|
scripts/enable_rtl433_decoders.py
|
||||||
custom_rtl_433_enable_decoders = esa_energy
|
custom_rtl_433_enable_decoders = esa_energy
|
||||||
|
custom_rtl_433_disable_decoders =
|
||||||
|
skylink_motion
|
||||||
|
acurite_rain_896
|
||||||
|
acurite_th
|
||||||
|
acurite_txr
|
||||||
|
acurite_986
|
||||||
|
acurite_606
|
||||||
|
acurite_00275rm
|
||||||
|
acurite_590tx
|
||||||
|
acurite_01185m
|
||||||
|
rainpoint
|
||||||
|
rainpoint_hcs012arf
|
||||||
|
wec2103
|
||||||
|
|
||||||
[env:heltec-rtl_433-fsk]
|
[env:heltec-rtl_433-fsk]
|
||||||
platform = ${com.esp32_platform}
|
platform = ${com.esp32_platform}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Re-enable rtl_433_ESP decoders that are disabled by default in the library.
|
# Configure rtl_433_ESP decoders (enable or disable specific protocols).
|
||||||
#
|
#
|
||||||
# Newer rtl_433_ESP releases mark some decoders with `.disabled = 1` (e.g.
|
# Newer rtl_433_ESP releases mark some decoders with `.disabled = 1` (e.g.
|
||||||
# `esa_energy` since v0.6.x) and there is no build flag to turn them back on.
|
# `esa_energy` since v0.6.x) and enable many noisy OOK decoders by default.
|
||||||
# This script patches the decoder definitions inside the downloaded library in
|
# This script patches the decoder definitions inside the downloaded library in
|
||||||
# .pio/libdeps/<env>/ before compilation.
|
# .pio/libdeps/<env>/ before compilation.
|
||||||
#
|
#
|
||||||
@@ -10,6 +10,9 @@
|
|||||||
# ${env.extra_scripts}
|
# ${env.extra_scripts}
|
||||||
# scripts/enable_rtl433_decoders.py
|
# scripts/enable_rtl433_decoders.py
|
||||||
# custom_rtl_433_enable_decoders = esa_energy
|
# custom_rtl_433_enable_decoders = esa_energy
|
||||||
|
# custom_rtl_433_disable_decoders =
|
||||||
|
# skylink_motion
|
||||||
|
# acurite_rain_896
|
||||||
#
|
#
|
||||||
# Must run as a normal (post) script: lib_deps are installed while the platform
|
# Must run as a normal (post) script: lib_deps are installed while the platform
|
||||||
# builder script runs, so a "pre:" script would not find the library on a clean
|
# builder script runs, so a "pre:" script would not find the library on a clean
|
||||||
@@ -22,23 +25,23 @@ import re
|
|||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
|
|
||||||
def enable_decoders(libdeps_dir, decoders):
|
def patch_decoders(libdeps_dir, enable_decoders, disable_decoders):
|
||||||
"""Patch `.disabled = N` to `.disabled = 0` for the given r_device names.
|
"""Patch `.disabled` for the given r_device names in rtl_433_ESP."""
|
||||||
|
|
||||||
Returns a dict decoder -> status ("enabled", "already enabled", "not found").
|
|
||||||
"""
|
|
||||||
device_files = glob.glob(
|
device_files = glob.glob(
|
||||||
os.path.join(libdeps_dir, "**", "src", "rtl_433", "devices", "*.c"),
|
os.path.join(libdeps_dir, "**", "src", "rtl_433", "devices", "*.c"),
|
||||||
recursive=True,
|
recursive=True,
|
||||||
)
|
)
|
||||||
result = {name: "not found" for name in decoders}
|
enable_status = {name: "not found" for name in enable_decoders}
|
||||||
|
disable_status = {name: "not found" for name in disable_decoders}
|
||||||
|
|
||||||
for path in device_files:
|
for path in device_files:
|
||||||
with open(path, "r", encoding="utf-8", newline="") as f:
|
with open(path, "r", encoding="utf-8", newline="") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
changed = False
|
changed = False
|
||||||
for name in decoders:
|
|
||||||
|
for name in enable_decoders:
|
||||||
block_re = re.compile(
|
block_re = re.compile(
|
||||||
r"(r_device\s+const\s+" + re.escape(name) + r"\s*=\s*\{)(.*?)(\};)",
|
r"(r_device\s+(?:const\s+)?" + re.escape(name) + r"\s*=\s*\{)(.*?)(\};)",
|
||||||
re.DOTALL,
|
re.DOTALL,
|
||||||
)
|
)
|
||||||
match = block_re.search(content)
|
match = block_re.search(content)
|
||||||
@@ -49,25 +52,65 @@ def enable_decoders(libdeps_dir, decoders):
|
|||||||
r"(\.disabled\s*=\s*)[1-9]\d*", r"\g<1>0", body
|
r"(\.disabled\s*=\s*)[1-9]\d*", r"\g<1>0", body
|
||||||
)
|
)
|
||||||
if count:
|
if count:
|
||||||
content = content[: match.start(2)] + new_body + content[match.end(2):]
|
content = content[: match.start(2)] + new_body + content[match.end(2) :]
|
||||||
changed = True
|
changed = True
|
||||||
result[name] = "enabled"
|
enable_status[name] = "enabled"
|
||||||
else:
|
else:
|
||||||
result[name] = "already enabled"
|
enable_status[name] = "already enabled"
|
||||||
|
|
||||||
|
for name in disable_decoders:
|
||||||
|
block_re = re.compile(
|
||||||
|
r"(r_device\s+(?:const\s+)?" + re.escape(name) + r"\s*=\s*\{)(.*?)(\};)",
|
||||||
|
re.DOTALL,
|
||||||
|
)
|
||||||
|
match = block_re.search(content)
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
body = match.group(2)
|
||||||
|
if re.search(r"\.disabled\s*=\s*[1-9]\d*", body):
|
||||||
|
disable_status[name] = "already disabled"
|
||||||
|
continue
|
||||||
|
if re.search(r"\.disabled\s*=\s*0\b", body):
|
||||||
|
new_body = re.sub(r"(\.disabled\s*=\s*)0\b", r"\g<1>1", body)
|
||||||
|
else:
|
||||||
|
nl = "\r\n" if "\r\n" in body else "\n"
|
||||||
|
new_body, count = re.subn(
|
||||||
|
r"([ \t]*\.fields\s*=)",
|
||||||
|
r" .disabled = 1," + nl + r"\g<1>",
|
||||||
|
body,
|
||||||
|
count=1,
|
||||||
|
)
|
||||||
|
if not count:
|
||||||
|
new_body = body + " .disabled = 1," + nl
|
||||||
|
content = content[: match.start(2)] + new_body + content[match.end(2) :]
|
||||||
|
changed = True
|
||||||
|
disable_status[name] = "disabled"
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
with open(path, "w", encoding="utf-8", newline="") as f:
|
with open(path, "w", encoding="utf-8", newline="") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return result
|
|
||||||
|
return enable_status, disable_status
|
||||||
|
|
||||||
|
|
||||||
decoders = env.GetProjectOption("custom_rtl_433_enable_decoders", "").split()
|
enable_list = env.GetProjectOption("custom_rtl_433_enable_decoders", "").split()
|
||||||
if decoders:
|
disable_list = env.GetProjectOption("custom_rtl_433_disable_decoders", "").split()
|
||||||
|
|
||||||
|
if enable_list or disable_list:
|
||||||
libdeps_dir = os.path.join(env.subst("$PROJECT_LIBDEPS_DIR"), env.subst("$PIOENV"))
|
libdeps_dir = os.path.join(env.subst("$PROJECT_LIBDEPS_DIR"), env.subst("$PIOENV"))
|
||||||
status = enable_decoders(libdeps_dir, decoders)
|
enable_status, disable_status = patch_decoders(libdeps_dir, enable_list, disable_list)
|
||||||
for name, state in status.items():
|
for name, state in enable_status.items():
|
||||||
print("rtl_433_ESP decoder %s: %s" % (name, state))
|
print("rtl_433_ESP decoder %s: %s" % (name, state))
|
||||||
missing = [name for name, state in status.items() if state == "not found"]
|
for name, state in disable_status.items():
|
||||||
|
print("rtl_433_ESP decoder %s: %s" % (name, state))
|
||||||
|
missing = [
|
||||||
|
name
|
||||||
|
for name, state in list(enable_status.items()) + list(disable_status.items())
|
||||||
|
if state == "not found"
|
||||||
|
]
|
||||||
if missing:
|
if missing:
|
||||||
print("Error: rtl_433_ESP decoder(s) not found in %s: %s" % (libdeps_dir, ", ".join(missing)))
|
print(
|
||||||
|
"Error: rtl_433_ESP decoder(s) not found in %s: %s"
|
||||||
|
% (libdeps_dir, ", ".join(missing))
|
||||||
|
)
|
||||||
env.Exit(1)
|
env.Exit(1)
|
||||||
|
|
||||||
Reference in new issue
Block a user