Skip to content

Typed setters: set_language (227), set_motion (822) - #12

Merged
widgetii merged 1 commit into
masterfrom
setters-language-motion
Sep 22, 2026
Merged

widgetii merged 1 commit into
masterfrom
setters-language-motion

Conversation

@widgetii

Copy link
Copy Markdown
Member

What

Two more typed wrappers over set_config_section, extending PR #11. Section codes were recovered from libtools.so disassembly (each MsgSet*Config wrapper loads the wire code into r0 before MsgSetModuleConfig(code, xml); MsgSetVideoOSDConfig=525 matches the earlier live capture) and confirmed live on an MTF45-4G_AF.

  • set_language(language, confirm=True) — code 227 = SystemConfig/MiscConfig. Verified live (zh_cnen).
  • set_motion(enable, sensitivity=None, alarm_threshold=None, confirm=True) — code 822 = AlarmConfig/MotionDetectAlarm. Read-modify-write of the full element (captured from "Batch Motion Detection"), so the detection grid (BlockConfig), day/night thresholds, arming schedule and alarm actions are preserved. Verified live (Enable 0↔1, children preserved).

Notes

  • const.CFG_MISC="227", CFG_MOTION="822".
  • Two sections that are not straight writes are documented for later: TimeConfig (222) did not acknowledge a full-element write (its NTPConfig child likely triggers a blocking NTP re-sync), and AjDevTools' "Batch Sync Time" clock-sync uses a non-8091 (ONVIF/HTTP) channel.

Changes

  • anjoy/comm.py: set_language, set_motion (RMW).
  • anjoy/const.py: CFG_MISC, CFG_MOTION.
  • tests/test_comm.py: frame/confirm-gate for language; RMW round-trip preserving children, confirm-gate and no-section error for motion (84 tests pass).
  • docs/devices.md: code-recovery method + the new codes/setters + the deferred-sections note.

Two more section setters, codes recovered from libtools.so disassembly
(MsgSet*Config wrappers load the wire code into r0 before MsgSetModuleConfig)
and confirmed live on MTF45-4G_AF:

- set_language(language, confirm=True): code 227 = SystemConfig/MiscConfig.
  Verified live (zh_cn <-> en).
- set_motion(enable, sensitivity=None, alarm_threshold=None, confirm=True):
  code 822 = AlarmConfig/MotionDetectAlarm. Read-modify-write of the full
  element (captured from "Batch Motion Detection") so the detection grid,
  day/night thresholds, arming schedule and alarm actions are preserved.
  Verified live (Enable 0<->1, children preserved).

const.CFG_MISC="227", CFG_MOTION="822". Tests: frame/confirm-gate for language;
RMW round-trip preserving children, confirm-gate and no-section error for motion.
Docs: the code-recovery method, the two new codes/setters, and notes that
TimeConfig (222) needs a dedicated capture and clock-sync is off-8091.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add typed language and motion configuration setters

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds confirmed typed setters for device language and motion detection.
• Preserves motion grids, schedules, and alarm actions through read-modify-write.
• Documents recovered section codes and validates protocol frames and write safeguards.
Diagram

graph TD
  A["API caller"] --> B{"Write confirmed?"} -- "No" --> C["Raise AnjoyError"]
  B -- "Language" --> D["Build MiscConfig"] --> F["Section writer"] --> G["Camera config"]
  B -- "Motion" --> E["Preserve motion XML"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Send partial motion updates
  • ➕ Avoids downloading and reserializing the full motion section
  • ➕ Reduces network traffic and implementation complexity
  • ➖ Relies on undocumented device-side merge semantics for a complex section
  • ➖ Could reset grids, schedules, thresholds, or alarm actions on some firmware
  • ➖ Does not match the vendor tool's captured full-element write behavior

Recommendation: Keep the read-modify-write approach for motion configuration because it follows observed vendor behavior and explicitly preserves opaque child settings. A partial write would be preferable only after live validation across supported firmware confirms that motion sections are safely merged.

Files changed (4) +114 / -3

Enhancement (2) +43 / -0
comm.pyAdd confirmed language and motion setters +41/-0

Add confirmed language and motion setters

• Adds a direct language section setter using code 227. Adds a motion setter using code 822 that downloads the current section, changes requested attributes, preserves nested configuration, and rejects missing sections or unconfirmed writes.

anjoy/comm.py

const.pyDefine language and motion section codes +2/-0

Define language and motion section codes

• Adds protocol constants for SystemConfig/MiscConfig code 227 and AlarmConfig/MotionDetectAlarm code 822.

anjoy/const.py

Tests (1) +52 / -0
test_comm.pyTest language frames and motion preservation +52/-0

Test language frames and motion preservation

• Verifies language message framing and confirmation gating. Exercises motion read-modify-write behavior, nested child preservation, confirmation gating, and missing-section errors.

tests/test_comm.py

Documentation (1) +19 / -3
devices.mdDocument recovered configuration codes and setter behavior +19/-3

Document recovered configuration codes and setter behavior

• Explains how section codes were recovered and cross-checked, documents the new typed setters, and records deferred time synchronization sections requiring dedicated investigation.

docs/devices.md

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@widgetii
widgetii merged commit 1be57f2 into master Sep 22, 2026
6 checks passed
@widgetii
widgetii deleted the setters-language-motion branch September 22, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant