vendor/ holds the camera's 16 MB NOR dump (backup-ssc377d-nor16m.bin), the vendor update V3.6.1.3, and their unpacked trees, which the RE tools and notes read. verify.py now defaults to vendor/flash_dump_ssc377d, and the docs point at vendor/ instead of folders beside the checkout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EfVNki7giKruPunvux6dDA
43 KiB
MC-L18D on OpenIPC: technical specification
| Device | AnjoyVision MC-L18D camera module |
| SoC / sensor / flash | SigmaStar SSC377D (Infinity6C) / GalaxyCore GC5603 / 16 MB SPI NOR |
| Firmware base | OpenIPC firmware tag latest (7d213e9), Buildroot 2024.02.10, Linux 5.10.61 |
| Build target | make BOARD=ssc377d_mcl18d |
| Document status | Describes the code as it stands, uncommitted on local branches. Nothing has run on the camera. |
| Companion documents | LEARNING-GUIDE.md (how it was found and built), AF-BOARD-PROTOCOL.md (lens board wire protocol in full), MCL18D-PORT.md (short notes) |
Evidence levels. Every requirement or fact below is tagged with one of these:
| Tag | Meaning |
|---|---|
| [V] | Verified by a build, a test, or a check against the built image |
| [D] | Derived from the vendor binaries: disassembly, emulation, or data tables |
| [A] | Assumed; needs the camera to confirm |
1. Scope
1.1 In scope
- An OpenIPC image that boots on the MC-L18D with:
- the GC5603 sensor;
- the vendor's pin multiplexing;
- night mode: IR-cut, CDS light sensor, IR and white lamps;
- audio speaker enable;
- SD card;
- reset button;
- alarm input.
- ONVIF Profile S/T streaming with PTZ, served on port 85.
- Control of the external devices on connector D7 (
/dev/ttyS2):- the zoom/focus lens board: zoom, manual focus, iris;
- a Pelco-D pan/tilt head: continuous, absolute and relative moves, presets, home, position.
- A one-shot contrast autofocus,
mcl18d-af.
1.2 Out of scope / not supported
| Item | Reason |
|---|---|
| The lens board's own autofocus | Needs per-frame ISP AF statistics. The closed-source majestic doesn't export them. [D] |
| PTZ in majestic's web UI and majestic's ONVIF | The infinity6c majestic build has no "Motorized lens" settings, so majestic-af can't load. [D] |
| Lens-board firmware upgrade | The protocol is decoded (section 9.6) but not implemented. It is risky. |
| Detection-box forwarding to auto-tracking heads | Only partly decoded. [D] |
| Wi-Fi | Not addressed by this port. The lite defconfig's wireless tools stay in the image; whether the board has a Wi-Fi module was not checked. |
2. System overview
┌──────────────────────────── SSC377D ─────────────────────────────┐
GC5603 ──MIPI 2L──▶│ sensor_gc5603_mipi.ko ─▶ ISP (IQ: /etc/sensors/gc5603.bin) │
I2C1 @0x62 │ │ │
│ majestic ──RTSP :554, HTTP :80, JPEG───────┼──▶ clients
│ (night mode: GPIO 9/11/23/80, PWM0) │
│ │
│ httpd :85 ─CGI─▶ onvif_simple_server ─exec─▶ pelco-ptz ──┐ │
│ wsd_simple_server (WS-Discovery) │ │
│ mcl18d-af ──HTTP /image.jpg───────▶ majestic │ │
│ └────────────exec──────────────────────▶ pelco-ptz ──┤ │
│ ▼ │
│ mcl18d-io (GPIO 60 reset, GPIO 44 alarm) /dev/ttyS2 FUART│
└───────────────────────────────────────────────────────────┼───────┘
│ D7 TX/RX, 3.3 V,
│ 57600 8N1
┌──────────────────────┴──────┐
│ lens board (Pelco-D addr 1) │
│ optional Pelco-D PT head │
└─────────────────────────────┘
3. Hardware interface
3.1 Pins
GPIO numbers are Linux sysfs numbers and equal the pad index. The numbering is identical in the vendor kernel and OpenIPC's. [D]
| Signal | Pad | Linux | Dir | Owner in this port | Behaviour | Source |
|---|---|---|---|---|---|---|
| IR-cut A (filter open, night) | PAD_SPI0_DI | GPIO 11 | out | majestic nightMode.irCutPin1 |
Pulsed for night | [D] vendor /dev/irled + media_server |
| IR-cut B (filter closed, day) | PAD_SAR_GPIO1 | GPIO 80 | out | majestic nightMode.irCutPin2 |
Pulsed for day | [D] |
| Light board's day/night output (D5-1 CDSIN, vendor "IRDET") | PAD_PM_IRIN | GPIO 23 | in | majestic nightMode.lightSensorPin, lightMonitor true |
A digital level: 1 day, 0 night. In the vendor's "Passive" IR-cut mode, this unit's, the light board decides from its own photoresistor | [D] /dev/irled, media_server. On the camera it read 1 in a lit and an unlit room; 0 never seen |
| IR lamp | PAD_SPI0_CZ | PWM4 (mode 2), or GPIO 9 | out | majestic nightMode.backlightPin 9, high at night (irLightPwmChannel 4 is also set) |
The vendor's active modes hold PWM4 at 100% at night. This majestic brings up no PWM lamp on infinity6c. Wiring sheet labels D5-3 "PWM1" | [D] padmux, media_server |
| White lamp | PAD_PWM0 | PWM0 (mode 1) | PWM | majestic whiteLightPwmChannel 0 |
[D] padmux | |
| Speaker amp enable | PAD_SPI0_DO | GPIO 12 | out | majestic audio.speakerPin |
Polarity [A] | [D] libtools.so |
| Red/blue light IO (vendor "alarm out 1") | PAD_SPI0_CK | GPIO 10 | out | muxes.sh |
Driven 1 every boot | [D] |
Warning light (vendor IO type 12, GetLedBrGpioPort) |
PAD_SR_IO01 | GPIO 61 | out | muxes.sh |
Active low: driven 1 (off) every boot; the vendor's mainctrl pulls it low on alarm. Not a light-board enable |
[D] |
| Reset button | PAD_SR_IO00 | GPIO 60 | in | mcl18d-io |
Idle level sampled at start | [D] |
| Alarm input | PAD_FUART_CTS | GPIO 44 | in | mcl18d-io |
Idle level sampled at start | [D] |
| SD power | PAD_FUART_RTS | GPIO 45 | out | kernel (padmux SDIO1_PWR) | [D] DTS | |
| SD card detect | PAD_PM_SD_CDZ | pad 22 | in | kernel | [D] DTS | |
| Ethernet LED | PAD_PWM1 | LED1 mode 2 | — | kernel / PHY | [D] padmux | |
| Lens/PTZ UART | PAD_FUART_RX/TX | /dev/ttyS2 |
UART | pelco-ptz |
2-wire, no RTS/CTS | [D] |
| Sensor I2C | PAD_I2C1_SCL/SDA | I2C1 | I2C | sensor driver | 0x62, 320 kHz | [D] |
| Core voltage select | PAD_PM_GPIO4 | GPIO 30 | out | OpenIPC reference DTS | Switched by CPU frequency (the vendor holds it 0) | [D] |
| Audio amp | GPIO2 | pad 48 | out | kernel amp-pad |
[D] DTS |
3.2 Connectors
From the vendor wiring sheet:
| Connector | Pins used |
|---|---|
| D1 | pin 7 reset, pin 8 network LED |
| D5 | 1 CDS in, 3 IR lamp PWM, 4 white lamp PWM |
| D6 | IR-cut coil |
| D7 | TX, RX (3.3 V TTL), 4 SPKEN, 5 red/blue IO |
Requirement: a Pelco-D head with an RS-485 input needs a TTL↔RS-485 adapter on D7. [A]
3.3 Flash layout
Vendor layout (from the dump's mtdparts): [D]
0x30000(BOOT),0x200000(kernel),0xCD0000(rootfs),0x100000(DATA)
OpenIPC 16 MB NOR layout, enforced by CHECK_SIZE: [V]
- kernel slot 2048 KB;
- rootfs slot 8192 KB;
- the remainder is overlay (jffs2) and the U-Boot environment.
Requirement: flashing needs OpenIPC's U-Boot for SSC377D and a serial console. The vendor dump (backup-ssc377d-nor16m.bin, MAC F0:00:06:14:73:FF) is the only recovery image.
4. Kernel
4.1 Source and config
| Item | Value |
|---|---|
| Source | openipc/linux tarball, branch sigmastar-infinity6c (OPENIPC_KERNEL) |
| Config | br-ext-chip-sigmastar/board/infinity6c/infinity6c-ssc027a-mcl18d.config = infinity6c-ssc027a.config with CONFIG_SS_DTB_NAME="infinity6c-ssc027a-s01a-mcl18d" |
| Patch dir | br-ext-chip-sigmastar/board/infinity6c/mcl18d/linux/ (BR2_LINUX_KERNEL_PATCH) |
| Patch | 0001-arm-dts-infinity6c-add-anjvision-mc-l18d.patch: adds the DTS below |
4.2 Device tree: infinity6c-ssc027a-s01a-mcl18d.dts
#include "infinity6c-ssc027a-s01a.dts", then overrides two nodes.
/soc/padmux/schematic (complete replacement):
| Pad | Mode | Purpose |
|---|---|---|
| GPIO_NR | UNKNOWN | NA (list terminator, as in the reference) |
| PAD_PWM0 | PWM0_MODE_1 | PWM0 |
| PAD_SPI0_CZ | PWM4_MODE_2 | PWM4 |
| PAD_PWM1 | LED1_MODE_2 | ETH1_LED |
| PAD_FUART_RX / TX | FUART_2W_MODE_1 | FUART_RX / TX |
| PAD_I2C1_SCL / SDA | I2C1_MODE_1 | I2C1 |
| PAD_SD_D0..D3, CLK, CMD | SD0_MODE_1 | SDIO1_* |
| PAD_FUART_RTS | GPIO_MODE | SDIO1_PWR |
| PAD_PM_SD_CDZ | SD0_CDZ_MODE_1 | SDIO1_CDZ |
/soc/sdmmc:
slot-max-clks = 20000000×3slot-clk-driving,slot-cmd-driving,slot-data-driving = 0×3
Acceptance:
- the kernel build prints "The configuration of GPIO & PADMUX is correct!" and "PUSE check PASS!"; [V]
- the padmux table compiled into the uImage matches the vendor DTB's entry for entry. [V]
4.3 Not carried over
| Vendor feature | Disposition |
|---|---|
The vendor's built-in /dev/irled driver |
Replaced by majestic driving GPIO 11/80/23 directly |
| GPIO 30 held 0 | OpenIPC reference behaviour kept |
5. Sensor driver: sensor_gc5603_mipi.ko
5.1 Packaging
| Item | Value |
|---|---|
| Source | openipc/sensors branch gc5603-infinity6c, sigmastar/infinity6c/sensor_gc5603_mipi.c (954 lines) |
| Delivered by | general/package/sigmastar-osdrv-sensors/0001-sigmastar-infinity6c-add-gc5603-driver.patch |
| Installed as | /lib/modules/5.10.61/sigmastar/sensor_gc5603_mipi.ko [V] |
| Loaded by | load_sigmastar, gc5603) arm: insmod sensor_gc5603_mipi.ko chmap=1, chosen by the U-Boot env sensor, default BR2_OPENIPC_SNS_MODEL="gc5603" |
| Model id string | gc5603_MIPI |
5.2 Interface parameters
All [D] from gc5603_MIPI_1125.ko.
| Parameter | Value |
|---|---|
| Bus | MIPI CSI-2, 2 lanes, CSI clock 216 MHz, long packet type 0x1C00, PACKET_HEADER_EDGE1 |
| Format | RAW10, Bayer BG, CUS_SEN_10TO12_9000, ISP_EXT |
| Resolution | one mode: 2960×1666, 5–30 fps |
| MCLK | 27 MHz |
| I2C | address 0x62 (8-bit form), 320 kHz, 16-bit register / 8-bit data |
| Chip ID | 0x03F0 = 0x56, 0x03F1 = 0x03 (ID 0x5603); 3 read attempts |
| Polarities | PWDN positive, RESET negative, VSYNC/HSYNC negative, PCLK positive |
| Power-on | PWDN inactive, RESET active 1 ms, PWDN active 1 ms, RESET release 1 ms, MCLK on, wait 5 ms |
| Init | 136 register writes, including one 20 ms delay (0xFFFF entry); each write retried up to 10× at 10 ms |
| Line period | 19047 ns (HTS 0x04B0) |
| VTS at 30 fps | 1750; VTS = 1750·30 / fps (fps in 5..30, or 5000..30000 as ×1000) |
| Exposure | lines = 1000·µs / 19047 (minimum 1). Registers 0x0202 (bits 13–8, masked 0x3F), 0x0203 (bits 7–0). VTS is extended to lines + 8 when exposure exceeds VTS − 8. Registers 0x0340/0x0341. |
| Exposure range reported | 30 µs .. 200,000 µs (1/5 s); shutter step = 1 line |
| Gain | 1×..128× (×1024 units). 26-entry analog table, values 1024..63440: page 0x031D=0x2D, then 0x0614/0x0615/0x0225, then 0x031D=0x28, then 0x1467/0x1468/0x00B8/0x00B9. Digital gain = gain·64 / analog, capped at 128, written to 0x0064 = dgain>>6, 0x0065 = (dgain<<2)&0xFF. |
| Delays | AE gain delay 2 frames, shutter delay 2 frames |
| Register commit | Gain, exposure and VTS are written together on the next CUS_FRAME_ACTIVE notify, as are orientation changes (22 registers, 20 ms, then 3 post registers) |
Temperature handling (vendor logic, kept exactly):
- On every gain set, it reads a level from 0x0410 (low) / 0x0414 (high).
- By level (thresholds 5, 11, 27, 40, 51, 69, and high byte 1 with low > 32) and gain band (<16×, <32×, <64×, <80×, ≥80×), it writes a black-level trim to 0x0455/0x0456 (coarse) and 0x0451/0x0452 (fine).
- While hot, it walks the usable analog table down to 17 entries (when level > 28), then back up (when level ≤ 15).
- At level ≤ 5 it resets to the full table and trim (4, 0).
- Gain below 8× clears the hot flag.
Orientation (deliberate difference from the vendor):
| ONVIF/majestic | Vendor 0x022C | This driver 0x022C / 0x0063 / 0x0A73 |
|---|---|---|
| M0F0 | 3 | 0 / 0 / 0x60 |
| M1F0 | 2 | 1 / 1 / 0x61 |
| M0F1 | 1 | 2 / 2 / 0x62 |
| M1F1 | 0 | 3 / 3 / 0x63 |
The vendor's application inverts both mirror and flip on this board, so the vendor's displayed default is native readout. Here M0F0 is native readout. Whether that is upright is [A].
5.3 Conformance
- Differential emulation (
openipc/gc5603-difftest/) against the vendor module, same fake sensor. Covers init, ID, gain and exposure sweeps, FPS, orientation through the remap, and temperature levels:- 76,011 checks, 0 mismatches, including on the
.kobuilt into the image; [V] - 4 of 4 injected faults detected (82–928 mismatches each). [V]
- 76,011 checks, 0 mismatches, including on the
- Loads and streams on the camera: [A]
5.4 IQ file
| Item | Value |
|---|---|
| Installed as | /etc/sensors/gc5603.bin (from sigmastar-osdrv-infinity6c/files/sensor/configs/gc5603.bin) |
| Content | Byte-identical to the vendor's /config/iqfile/gc4023_day.bin, which the vendor media_server loads for this sensor on this board [D][V] |
| Night IQ | Not shipped. The vendor also has gc4023_night.bin; majestic uses one file. |
6. Board package anjvision-mcl18d
6.1 Build integration
| Item | Value |
|---|---|
| Path | general/package/anjvision-mcl18d/ |
| Symbol | BR2_PACKAGE_ANJVISION_MCL18D |
| Depends on | BR2_PACKAGE_SIGMASTAR_OSDRV_INFINITY6C |
| Selects | BR2_PACKAGE_ONVIF_SIMPLE_SERVER |
| Source | SITE = $(PKGDIR)/src, SITE_METHOD = local, license MIT |
| Build | make pelco-ptz with the target toolchain; CFLAGS -Os -Wall -Wextra, -lm |
| Registration | general/package/Config.in source line. .github/scripts/ci-matrix.py: NOT_BUILT += anjvision-mcl18d; UNBUILT_BOARDS += ssc377d_mcl18d (reason: single retail device) |
6.2 Installed files
| Target path | Mode | Source | Section |
|---|---|---|---|
/usr/share/openipc/customizer.sh |
644 | files/customizer.sh |
6.4 |
/usr/share/openipc/muxes.sh |
644 | files/muxes.sh |
6.5 |
/etc/init.d/S94mcl18d |
755 | files/S94mcl18d |
6.6 |
/usr/sbin/mcl18d-io |
755 | files/mcl18d-io |
6.7 |
/usr/sbin/pelco-ptz |
755 | built from src/ |
8 |
/usr/sbin/mcl18d-af |
755 | files/mcl18d-af |
10 |
/usr/sbin/onvif-passwd |
755 | files/onvif-passwd |
7.3 |
/etc/pelco-ptz.conf |
644 | files/pelco-ptz.conf |
8.2 |
/etc/onvif.conf.mcl18d |
600 | files/onvif.conf |
7.2 |
All shipped shell scripts:
- run under busybox
ash(CONFIG_ASH_BASH_COMPAT=y); - are comment-stripped at build time;
- call only applets and binaries present in the image. [V]
6.3 Boot sequence
| Order | Script | This port's action |
|---|---|---|
| S30 | S30customizer |
First boot only (no /etc/custom.ok): run customizer.sh, then touch /etc/custom.ok. Every boot: run muxes.sh. |
| S70 | S70vendor |
load_sigmastar -i (vendor name from ipcinfo -v): SDK modules, then sensor_gc5603_mipi.ko |
| S94 | S94mcl18d |
Start mcl18d-io; start wsd_simple_server once the ONVIF interface has IPv4 |
| S95 | S95majestic |
majestic, using the pin map written at first boot |
| S96 | S96onvifserver |
Fills firmware_ver, hardware_id, serial_num in /etc/onvif.conf; busybox httpd -p 85 serves /var/www/onvif CGI |
firstboot (sysupgrade -n) wipes the overlay, which removes custom.ok, so customizer.sh runs again on the next boot.
6.4 customizer.sh (first boot)
cli -ssets in/etc/majestic.yaml:.nightMode.irCutPin1 11.nightMode.irCutPin2 80.nightMode.lightSensorPin 23,.nightMode.lightMonitor true.nightMode.backlightPin 9.nightMode.irLightPwmChannel 4.nightMode.whiteLightPwmChannel 0.nightMode.irCut auto,.nightMode.backlight auto,.nightMode.whiteLight auto.audio.speakerPin 12.onvif.enabled false.video0.size 2560x1440.video1.enabled true,.video1.size 640x360
- Generates an 18-hex-digit random password (
hexdump -n 9 /dev/urandom). - Writes
/etc/onvif.conf=/etc/onvif.conf.mcl18dwithpassword=<random>, mode 600.
Night mode. Without lightMonitor true majestic never reads GPIO 23 and stays in day mode; with it, /metrics shows night_mode_source 1. [V] backlightPin 9 is the IR lamp's pad driven as a plain GPIO, high at night, because this majestic does not bring up PWM lamps on infinity6c; forcing night by inverting the sensor for a moment logged set_gpio(9,1). [V]
Pin roles. irCutPin1 is majestic's "opening" coil and irCutPin2 the "closing" coil. Source: majestic-webui ircut-scan.js, irCutPin1: opensWhenHigh, irCutPin2: closesWhenHigh. [D]
6.5 muxes.sh (every boot)
For (10, 1) and (61, 1): export the GPIO if needed, set direction out, write the value. GPIO 10 is the red/blue light IO (vendor alarm output 1); GPIO 61 is an active-low warning light, and 1 is off. These are the vendor's boot levels (libtools.so gpio_init_by_array). [D]
6.6 S94mcl18d
| Command | Behaviour |
|---|---|
start |
start-stop-daemon -S -b -m -p /var/run/mcl18d-io.pid -x /usr/sbin/mcl18d-io; the same for pelco-ptz keepalive with /var/run/pelco-keepalive.pid (section 8.1). Then, in the background: wait up to 60 s for an IPv4 address on ifs (from /etc/onvif.conf), then run wsd_simple_server -i <ifs> -x http://%s:<port>/onvif/device_service -m <model> -n <manufacturer> -p /var/run/wsd_simple_server.pid |
stop |
Stop all three and remove their pid files |
restart |
stop, then start |
6.7 mcl18d-io
| Item | Behaviour |
|---|---|
| Poll | Every 100 ms (usleep 100000) |
| Idle levels | Read once at start for GPIO 60 and GPIO 44 |
| Reset | GPIO 60 away from idle for 50 consecutive ticks (5 s): log RESET_BUTTON held 5 s…, run firstboot. A release before 5 s logs RESET_BUTTON released after N ms, ignored. |
| Alarm | Each change of GPIO 44: log ALARM_IN active|idle; if /etc/mcl18d/alarm-in is executable, run it in the background with active/idle |
| Start log | IO_WATCH_STARTED reset idle=<v> alarm idle=<v> (tag mcl18d) |
7. ONVIF
7.1 Server
| Item | Value |
|---|---|
| Upstream | onvif-simple-server package, roleoroleo/onvif_simple_server at 7c8672fe84a14dfdc02ba7fdb1f9f88074b2efc6 |
| Patches | Package patches 01, 02, plus this port's 03-ptz-absolute-relative-zoom-fixes.patch |
| Serving | busybox httpd on port 85, CGI under /var/www/onvif |
| Discovery | wsd_simple_server |
| majestic ONVIF | Disabled (.onvif.enabled false) so discovery shows one device |
7.2 /etc/onvif.conf (from onvif.conf.mcl18d)
| Key | Value |
|---|---|
| model / manufacturer | MC-L18D / OpenIPC |
| ifs / port | eth0 / 85 |
| scope | onvif://www.onvif.org/Profile/Streaming, …/Profile/T |
| user / password | root / random until onvif-passwd |
| Profile_0 | 2560×1440, rtsp://%s/stream=0, snapshot http://%s/image.jpg, H264 |
| Profile_1 | 640×360, rtsp://%s/stream=1, snapshot …/image.jpg?width=640&height=360, H264 |
| ptz | 1; x −1..1, y −1..1, z 0..1 |
| PTZ hooks | get_position, is_moving, move_left/right/up/down/in/out %f, move_stop, move_preset %d, goto_home_position, set_preset %s, set_home_position, remove_preset %d, jump_to_abs %f %f %f, jump_to_rel %f %f %f, get_presets, all mapped to /usr/sbin/pelco-ptz … |
Requirement: set the ONVIF password to root's password (onvif-passwd). Clients reuse the ONVIF credentials for RTSP, which majestic checks against root.
7.3 onvif-passwd [PASSWORD]
- Prompts with echo off when no argument is given.
- Refuses an empty password (exit 1).
- Rewrites
password=in/etc/onvif.confthrough a temp file, mode 600. - Logs
ONVIF_PASSWORD_CHANGED.
7.4 Patch 03: behavioural changes to ptz_service.c
| # | Request | Before | After |
|---|---|---|---|
| 1 | AbsoluteMove with PanTilt only | Zoom passed as 0, so the lens went fully wide | Missing axes passed as nan, meaning leave them |
| 2 | AbsoluteMove with Zoom only | Command never built | jump_to_abs nan nan z; range-checked (fault −7) |
| 3 | RelativeMove with Zoom only | Uninitialised buffer passed to system() |
jump_to_rel 0 0 dz; range-checked |
| 4 | RelativeMove with neither | Ran the uninitialised buffer | Refused (−4, InvalidTranslation) |
| 5 | RelativeMove Zoom without a space attribute |
strcmp(NULL), a crash |
Removed |
| 6 | FOV-space relative pan/tilt | Scaled by 360/180 | dx/180·max_step_x, dy/90·max_step_y |
| 7 | SetPreset with PresetToken | sscanf("%s") into an int: memory corruption |
%d |
Acceptance: tests/onvif_e2e.py, 23 checks. The patched build passes all 23; the unpatched build fails 7. [V]
8. pelco-ptz
8.1 Command line
One command per process. Exit status: 0 OK, 1 usage or argument error, 2 port, lock, write or preset-store failure.
| Command | Effect | Port needed |
|---|---|---|
move left|right|up|down|in|out [SPEED] |
Continuous motion. SPEED 0..1, default 0.5. Pan/tilt speed 0 stops that axis. | yes |
focus near|far |
Focus motor runs until stop |
yes |
iris open|close |
Iris runs until stop |
yes |
stop |
Clears all motion and sends the stop frame | yes |
abs X Y Z |
Absolute move in generic space; nan leaves an axis |
yes |
rel DX DY DZ |
Query position, add the deltas, then absolute move. A delta of 0 or nan leaves the axis. |
yes |
position |
Prints x,y,z (4 decimals), from head replies or the last commanded position |
yes |
moving |
Prints 1 while any axis moves or within settle_ms of an abs/preset/home move, else 0 |
no |
home / sethome |
Go to / set preset home_preset |
yes |
preset list |
Prints N=name,x,y,z lines |
no |
preset set NAME |
Allocates the lowest free N in 2..max_preset (≠ home); stores the queried position |
yes |
preset goto N / preset remove N |
N in 1..255 | yes |
keepalive |
Sends pelco_af_frame() every keepalive_ms until killed; takes no lock; reopens the port after a write error. Started by S94mcl18d. |
yes |
On this camera's head abs and rel do nothing (section 9.5); they stay for a head that implements the extended commands. [V]
Preset names:
- 1–64 bytes;
- no whitespace, control characters,
,,=or DEL.
8.2 Configuration: /etc/pelco-ptz.conf
Format: key=value; # comments.
| Key | Default (file / built-in) | Meaning |
|---|---|---|
port |
/dev/ttyS2 |
Serial device |
baud |
57600 / 57600 |
One of 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200; anything else is refused (PTZ_CONF_BAUD) |
address |
1 |
Pelco address 0..255; out of range logs PTZ_CONF_ADDRESS and falls back to 1 |
pan_invert, tilt_invert |
0 |
Mirror the axis (ceiling mount) |
tilt_min, tilt_max |
-90, 90 |
Head's tilt travel in degrees, up positive |
home_preset |
1 |
Preset used as ONVIF home |
max_preset |
32 |
Highest preset for ONVIF, capped at 255 |
settle_ms |
3000 |
How long abs/preset/home counts as "moving" |
query_timeout_ms |
300 |
Wait for a position reply |
keepalive_ms |
100 |
Interval of keepalive's frames; 0 makes keepalive exit at once |
57600 baud: the vendor comm_server sets the port to 57600 whenever /opt/ch/af.flag exists, as it does on this camera, overriding its PTZ setting of 2400. [D] A pan/tilt head sharing D7 must also run at 57600.
8.3 Serial line
| Setting | Value |
|---|---|
| Mode | O_RDWR|O_NOCTTY|O_NONBLOCK, cfmakeraw, 8N1, CLOCAL|CREAD, no RTS/CTS |
| Write | One 7-byte write, then tcdrain; a short write is an error |
| Read | Only for position queries: tcflush input, send, poll/read until a valid reply or query_timeout_ms |
keepalive |
Same setup, then O_NONBLOCK cleared so each 18-byte write() lands whole; the tty's write lock keeps it from splitting a command frame from another process |
8.4 Frames (Pelco-D)
FF addr c1 c2 d1 d2 sum, where sum = (addr + c1 + c2 + d1 + d2) mod 256.
Motion frame (one frame carries the whole motion state):
| Bit | Field |
|---|---|
| c2 0x02 / 0x04 | right / left (after pan_invert) |
| c2 0x08 / 0x10 | up / down (after tilt_invert) |
| c2 0x20 / 0x40 | zoom tele / wide |
| c2 0x80 | focus far |
| c1 0x01 | focus near |
| c1 0x02 / 0x04 | iris open / close |
| d1 | pan speed when panning |
| d2 | tilt speed when tilting |
When neither pan nor tilt moves but the lens does, d1 = d2 = the zoom speed (if zooming and non-zero), else 0x30. This matches the vendor's frames to the lens board. [D][V]
Speed mapping:
pelco_speed(v)= 0 for v ≤ 0 or NaN;- 0x3F for v ≥ 1;
- else
round(v·63), minimum 1.
Reference frames (byte-checked by make test):
| Command | Frame |
|---|---|
| stop | FF 01 00 00 00 00 01 |
| left 0.5 | FF 01 00 04 20 00 25 |
| zoom in 0.5 | FF 01 00 20 20 20 61 |
| focus near | FF 01 01 00 30 30 62 (vendor FocusNearAutoOff) |
| focus far | FF 01 00 80 30 30 E1 (vendor FocusFarAutoOff) |
| iris open | FF 01 02 00 30 30 63 |
| iris close | FF 01 04 00 30 30 65 |
| preset set / goto / clear n | FF 01 00 03 00 nn / 07 / 05 (+ sum) |
| set pan / tilt / zoom | FF 01 00 4B/4D/4F vH vL (+ sum) |
| query pan / tilt / zoom | FF 01 00 51/53/55 00 00 (+ sum) |
| replies accepted | FF addr 00 59/5B/5D vH vL sum, with noise before it skipped and the checksum checked |
8.5 Generic coordinate space
| Axis | Generic | Pelco value |
|---|---|---|
| Pan | x −1..1 = −180..180° (pan_invert negates) |
hundredths of a degree 0..35999, wrapped |
| Tilt | y −1..1 = −90..90°, up positive, clamped to tilt_min..tilt_max |
Pelco counts down from the horizon: hundredths(−up) |
| Zoom | z 0..1 | round(z·65535) |
Relative-move arithmetic:
- pan wraps in (−1, 1];
- tilt clamps to
tilt_min/90 .. tilt_max/90; - zoom clamps to 0..1.
8.6 Continuous-move combining
- ONVIF sends a diagonal as separate per-axis calls.
- Each axis (pan, tilt, zoom, focus, iris) keeps the time it was last set.
- On each
move/focus/iris:- an axis set more than 300 ms earlier is cleared (it belongs to an earlier request);
- the new axis is set;
- one frame carrying all live axes is sent.
8.7 State, locking, persistence
| File | Content |
|---|---|
/tmp/pelco-ptz.lock |
flock(LOCK_EX) for the whole run, so frames never interleave |
/tmp/pelco-ptz.state |
17 fields: pan dir/speed/ms, tilt dir/speed/ms, zoom dir/speed/ms, focus dir/ms, iris dir/ms, x, y, z, busy-until-ms. Written via .tmp + rename. A malformed file resets the state. |
/etc/pelco-ptz.presets |
N=name,x,y,z per line. Written via .tmp + rename. |
Negative zero is normalised before output.
8.8 Logging
syslog, ident pelco-ptz, LOG_USER. Tags:
PTZ_ABSOLUTEPTZ_CONF_ADDRESS,PTZ_CONF_BAUDPTZ_HOME_SETPTZ_LOCK_FAILEDPTZ_PORT_OPEN_FAILED,PTZ_PORT_SETUP_FAILEDPTZ_PRESET_FULL,PTZ_PRESET_REMOVED,PTZ_PRESET_SAVE_FAILED,PTZ_PRESET_SETPTZ_WRITE_FAILED
9. Lens board interface
Summary; the full detail is in AF-BOARD-PROTOCOL.md. Everything in this section is [D] from the vendor comm_server/media_server, confirmed by emulating the vendor code: af-board-re/verify.py, 40/40. [V]
9.1 Link
| Item | Value |
|---|---|
| Port | /dev/ttyS2, shared with any pan/tilt head |
| Line | 57600 8N1 when /opt/ch/af.flag exists (true on this camera). _WTD builds use 115200; /opt/ch/diy_baudrate overrides. |
| Address | Pelco address 1 |
9.2 Commands the board accepts
Plain Pelco-D, as in section 8.4: zoom, focus, iris, stop, presets, and pan/tilt for the head behind the board, but only while the board is awake (9.5). [V]
In the vendor firmware, focus and iris always carry 30 30, and zoom carries the speed level mapped 0..10 → 0x05..0x37.
9.3 AF data stream (produced here only as a keep-alive)
- One frame per ISP frame, with focus values FV0 (whole frame) and FV1 (centre):
FV = Σ stat[a][w] >> 6over arrays {0,1,3,4};- sent as
(FV>>11)&FF, (FV>>3)&FF.
- This camera's setting (
AfConfig type=1) usesCAfV2, 18 bytes:51 01 04 78 01 11 | FV0 | FV1 | gain | class<<4|night | stat bytes | ircut | IR% | white% | sum. - The factory default
type=2usesCAfV3, 16 bytes. pelco-ptz keepalivesends one CAfV2 frame with constant values every 100 ms:51 01 04 78 01 11 12 34 08 00 01 30 12 34 00 00 00 a5. [V]
9.4 Version query (vendor, at boot)
- Camera sends:
END D7×8 at 60 ms intervals, thenVER ED. - Board reply: byte 3 = lens code (01–15, 20/21), byte 4 = variant, bytes 5–8 = BCD date.
- Fallback:
EXVER 8A.
Not implemented here.
9.5 Behaviour with no AF data
Measured on the camera, 2026-10-28/29. [V]
| Condition | Result |
|---|---|
| No AF frames since boot | Nothing on D7 moves; no byte comes back (rx 0); no version reply. Same at every baud 2400–115200, Pelco-D address 0/1 and Pelco-P |
| One AF frame, then a command | Ignored |
| Five AF frames 33 ms apart, then a command | Obeyed: pan, tilt, zoom, focus |
| 3 s silence after a burst | Still obeyed |
| 40 s silence | Asleep again |
| One frame every 100 ms | Awake throughout |
| First stream after sleep | About 20 s of large focus moves before it settles |
| Pelco-D 0x4B/0x4D/0x4F (also after 0x49) | Ignored |
| Pelco-D 0x51/0x53/0x55 | Never answered |
| Presets 0x03/0x07 | Work: go to returns to the stored view |
| Board to camera | 51 01 04 78 01 0a … sum while something moves; byte 10 tracks zoom (INFERRED); silent when idle |
9.6 Upgrade (vendor; not implemented)
- Camera sends
END×15, thenSTART+ BE32 size + sum. - Board requests
DATA+ BE32 address +80+ sum. - Camera answers with 138-byte blocks.
- Board ends with
OK 9A.
10. mcl18d-af: one-shot contrast autofocus
10.1 Command line
mcl18d-af [-u USER:PASS] [-c XxYxWxH|full] [-s STEP_MS] [-b BACK_MS] [-n SAMPLES]
[-w SETTLE_MS] [-g PERMILLE] [-t SWEEP_S] [-a URL] [-h]
| Option | Default | Meaning |
|---|---|---|
-u |
user:password from /etc/onvif.conf |
majestic HTTP login (curl --anyauth) |
-c |
middle third of cli -g .video0.size; full if unreadable |
Judged region, in snapshot pixels. majestic refuses it on this SoC, so in practice the full frame |
-s |
150 | Approach step, ms of motor run time |
-b |
1000 | Extra back-off past the best snapshot before the approach, ms |
-n |
2 | Snapshots averaged per approach measurement |
-w |
300 | Wait after each motor stop before measuring, ms |
-g |
5 | An approach step is better or worse only if sharpness changes by more than g/1000 |
-t |
45 | Longest sweep one way, seconds of motor time |
-a |
http://127.0.0.1/image.jpg |
Snapshot URL (?crop= appended unless full) |
-s, -b, -n, -w, -g, -t must be non-negative integers; -n and -s at least 1.
Fixed in the script: a sweep has found focus once the picture rose 50/1000 above its start and then fell 30/1000 below its best on two snapshots running; it turns round if, after at least 1.5 s and 3 snapshots, it has not risen 50/1000 and is 30/1000 below its start. At most 3 back-offs.
10.2 Sharpness measure
S = byte size of a JPEG snapshot, read with curl -s -f -w %{size_download}: one snapshot per point during a sweep, the mean of n during the approach. At a fixed quality, finer detail compresses less.
Measured on the camera, 2026-10-29 [V]:
- a sharp snapshot of the bench was about 338 KB and a blurred one about 126 KB;
- two snapshots of a still scene differ by 0.1–0.6%;
?crop=answers HTTP 501; the script logsAF_CROP_REFUSEDand judges the full frame.
10.3 What the lens is like
| Fact | Consequence | Source |
|---|---|---|
| The motor reports no position | Positions are motor run time, measured with /proc/uptime (centiseconds) |
[D] |
| Focus lay up to 19 s of motor time from the start; the sharp band is about 1.5 s wide | Short steps from a blurred start change the picture less than the noise, so the search is a continuous sweep first | [V] |
| A snapshot shows the lens a little after the fact | Just after a reversal the picture goes on getting worse; the second sweep never turns | [V] once made a second sweep give up at once |
| Each reversal loses travel to gear backlash | The finish approaches focus from one side only | [A]; a back-and-forth climb ended short of focus |
10.4 Algorithm
- Start. Measure. If that fails or returns 0 with a crop set, retry the full frame (
AF_CROP_REFUSED); if that fails too,AF_SNAPSHOT_FAILED, exit 2. LogAF_START. - Sweep
far, allowed to turn, for up to-ts. Take one snapshot as the base, start the motor, then loop:- snapshot; its time is the midpoint of the request, from the motor start;
- better than the best so far: it becomes the best, and its time is
peak; - once the best has risen past the found threshold, two snapshots running below it by the drop threshold: stop, focus passed (
AF_SWEEP <dir> found); - the turn rule of 10.1 met: stop (
AF_SWEEP <dir> getting worse); - time out: stop (
AF_SWEEP <dir> no focus).
- Second sweep,
near, never turning: for the first sweep's run plus-ts if it turned, plus 2×-ts if it timed out. - Neither found focus:
AF_NO_DETAIL, exit 3. - Back off the other way for (run − peak) +
-bms (AF_BACK). - Approach in the sweep's direction: measure, then repeat pulse
-sms, wait-w, measure:- better (by
g): keep going (AF_STEP … better); - same: keep going (
… same); - worse after something was better: done; the lens rests one step past the sharpest point (
… worse); - worse before anything was better: the back-off was too short. Back off another
-bms and approach again; after 3 back-offs,AF_LOST, exit 2; - at most 2×
-b/-s+ 10 steps, then done.
- better (by
- Measure once more and log
AF_DONE sharpness=<S> best_seen=<S> steps=<n>.
10.5 Outputs
| Item | Value |
|---|---|
stdout and syslog (tag mcl18d-af) |
AF_START sharpness=<S> region=<crop>, AF_SWEEP <dir> found best=<S> at <ms>ms, ran <ms>ms / getting worse after <ms>ms, turning / no focus in <ms>ms, AF_BACK <dir> <ms>ms, AF_STEP <dir> <ms>ms sharpness=<S> better|same|worse, AF_DONE …, AF_CROP_REFUSED, AF_SNAPSHOT_FAILED, AF_NO_DETAIL, AF_LOST |
| Exit 0 | Focus found |
| Exit 1 | Usage error |
| Exit 2 | Snapshot or pelco-ptz failure, or focus not found again (AF_LOST) |
| Exit 3 | No detail to focus on |
| Exit 130 | Interrupted |
| Safety | trap stop EXIT: the focus motor is always stopped on exit |
10.6 Conformance
make af BUSYBOX=<host busybox> runs the comment-stripped script under busybox ash built from the tree's own source, against a simulated lens:
- 0..1500 ms of travel, with end stops;
- 15 ms backlash per reversal;
- ±0.5% noise on a Gaussian sharpness curve of width 250;
- optionally, snapshots that show the lens some ms late.
The simulated travel is far shorter than the camera's, so it runs with -w 20 -t 3 -b 150 -s 30.
| Case | Required | Result |
|---|---|---|
| Start below, above and at focus, and far out (4 cases) | Ends within 100 ms of focus; motor stopped | pass [V] |
| Default region | Middle-third crop URL | pass [V] |
| Snapshots 150 ms late, focus behind the start | Still found | pass [V] |
| Crop refused | Falls back to the full frame and still converges | pass [V] |
| Wrong login | Exit 2, motor untouched | pass [V] |
| Featureless scene | Exit 3 AF_NO_DETAIL |
pass [V] |
| Non-numeric option | Exit 1 | pass [V] |
On the camera, 2026-10-29, with the defaults [V]: from either side of focus, 12–27 s, ending at 99.4–99.6% of the best snapshot seen.
11. Build
11.1 Defconfig ssc377d_mcl18d_defconfig
ssc377d_lite_defconfig plus:
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=".../infinity6c-ssc027a-mcl18d.config"
BR2_LINUX_KERNEL_PATCH=".../board/infinity6c/mcl18d/linux"
BR2_OPENIPC_FLASH_SIZE="16"
BR2_OPENIPC_SNS_MODEL="gc5603"
BR2_PACKAGE_ANJVISION_MCL18D=y
BR2_PACKAGE_ONVIF_SIMPLE_SERVER=y
11.2 Build environment
| Item | Value |
|---|---|
| Container | Ubuntu 24.04 (openipc-builder:24.04): build-essential, bc, bison, flex, cpio, rsync, unzip, wget, python3, cmake, u-boot-tools, bsdextrautils (hexdump, which the kernel's padmux check needs) |
| Command | docker run --rm --user $(id -u):$(id -g) -e HOME=$O/home -e BR2_DL_DIR=$O/dl -e PWD=$F -v $F:$F -v $O:$O -w $F openipc-builder:24.04 make BOARD=ssc377d_mcl18d TARGET=$O/output |
PWD |
Must be passed; the Makefile reads it from the environment |
| Output | $O/output/images/openipc.ssc377d-nor-lite.tgz, uImage.ssc377d, rootfs.squashfs.ssc377d (copied to openipc/images/) |
11.3 Size budget [V]
| Image | Used | Cap |
|---|---|---|
| uImage | 1991 KB | 2048 KB (57 KB headroom) |
| rootfs (squashfs xz) | 5264 KB | 8192 KB |
12. Verification matrix
| ID | Requirement | Method | Status |
|---|---|---|---|
| V1 | Image builds and fits flash | Container build, CHECK_SIZE |
[V] |
| V2 | Padmux and pin use consistent | Kernel's padmux/PUSE checks | [V] |
| V3 | Padmux equals the vendor's | DTB diff from the built uImage | [V] |
| V4 | Sensor driver register-equivalent to the vendor's | gc5603-difftest: 76,011 checks plus fault injection |
[V] |
| V5 | Rootfs contains the driver, IQ, scripts, tools | Rootfs listing | [V] |
| V6 | Pelco-D frames byte-exact | make test |
[V] |
| V7 | pelco-ptz end to end on a serial line |
make e2e (pty head) |
[V] |
| V8 | ONVIF PTZ end to end | tests/onvif_e2e.py: 23/23; unpatched fails 7 |
[V] |
| V9 | mcl18d-af converges, also with late snapshots |
make af simulation (10.6) |
[V] |
| V10 | Shell scripts parse before and after stripping | test_shell_parse.sh, test_strip_shell_comments.sh (STRICT) |
[V] |
| V11 | CI selector consistent | ci-matrix.py --self-test |
[V] |
| V12 | Lens protocol facts | af-board-re/verify.py: 40/40 |
[V] (against vendor code) |
| V13 | keepalive frames whole and on time; commands intact between them |
make e2e |
[V] |
| H1 | Boots; sensor detected; video streams | Camera | [V] 2026-10-28 |
| H2 | Orientation upright at M0F0 | Camera | [V] |
| H3 | Day/night polarity, IR-cut direction, lamps | Camera | In part: majestic follows GPIO 23 and, at night, opens the IR-cut, goes grey and drives GPIO 9 [V]. GPIO 23 never seen at 0, IR LEDs never seen lit [A] |
| H4 | GPIO 10/61 boot levels correct | Camera | [A]; GPIO 61's role corrected from vendor code [D] |
| H5 | SD card, microphone, speaker polarity, reset button, alarm input | Camera | [A] |
| H6 | Lens board obeys zoom/focus/iris at 57600 | Camera + lens board | [V] zoom and focus, with the keep-alive only; iris not checked |
| H7 | /image.jpg?crop= works; snapshot noise < 0.5% |
Camera | crop: no, HTTP 501. Noise: 0.1–0.6% in a still scene [V] |
| H8 | mcl18d-af finds focus on the real lens |
Camera | [V] 12–27 s, 99.4–99.6% of the best snapshot |
| H9 | Pan/tilt head at 57600: moves, presets, position replies | Camera + head | [V] moves (shell and ONVIF) and presets work, with the keep-alive; no position replies |
13. Risks and open issues
| # | Risk / issue | Impact | Mitigation |
|---|---|---|---|
| R1 | Only part of it has run on hardware (H1, H2, H6–H9, H3 in part) | IR LEDs, GPIO 10/61, SD, audio unchecked | Do H3–H5 next |
| R2 | IQ file is GC4023's, as the vendor uses | Colour/noise tuning not specific to GC5603 | Same as the vendor; tune later |
| R3 | The board sleeps without AF frames, and wakes into a ~20 s focus sweep | Nothing on D7 works without pelco-ptz keepalive; if it dies, PTZ stops |
S94mcl18d starts it; ps/logread show PTZ_KEEPALIVE_START |
| R4 | A pan/tilt head and the lens board share one UART at 57600 | A head that can't do 57600 cannot be used with the lens board | Separate port or an adapter (none on this board) |
| R5 | JPEG size as the focus metric | Noise at night or high gain; scene motion | -n, -g; run in a still scene |
| R6 | pelco-ptz process start-up inside the focus pulse |
Pulse length jitter of a few ms | Approach steps of 150 ms; sweeps time themselves from /proc/uptime |
| R7 | Not upstreamable as is | Vendor register tables and a factory IQ blob | Keep local; see LEARNING-GUIDE §15 |
| R8 | ONVIF password random until set | NVR can't log in | Run onvif-passwd with root's password |
| R9 | video0.size 2560×1440, below the sensor's 2960×1666 output |
Lower resolution than the sensor delivers | Matches the vendor: this camera's saved config streams 2560X1440, and the spec sheet lists 2560×1440 as its 30 fps main stream. Full size is untested. |
| R10 | No absolute pan/tilt positions and no position feedback from this head | ONVIF AbsoluteMove/RelativeMove not offered; GetStatus shows the last commanded position | Presets are the head's absolute positions |
| R11 | Heat: with the heat sink loose the SoC reached 76 °C | Resets, failed memory self-test, kernel oops on corrupted memory, colour flares every 5–15 s | Heat sink refitted 2026-10-28: 63 °C steady, no resets; flares rarer but not gone (R12) |
| R12 | Colour flares: now and then a frame turns to random noise below a random row, mostly within seconds of a large lighting change | Visible glitches in the stream | Cause open. Ruled out: UART traffic, black-level writes, motors, mid-frame writes of frame length, gain index or analog gain page, VIF FIFO errors |
| R13 | The light board's day/night output (GPIO 23) and its IR LEDs never seen to change | Night vision unconfirmed | Cover the board's photoresistor in a dark room; check the light board's supply on D5 |
| R14 | set_gpio(12, 0) error at every majestic start |
Speaker enable may not work | Not investigated |
14. Source locations
| Component | Location |
|---|---|
| Board files, package, patches | openipc/firmware branch mcl18d-port (uncommitted) |
| Sensor driver source | openipc/sensors branch gc5603-infinity6c |
| Device tree source | openipc/linux-infinity6c branch mcl18d |
| onvif-simple-server fix source | openipc/onvif_simple_server branch ptz-fixes |
| Sensor differential test | openipc/gc5603-difftest/ |
| Lens protocol emulation and checks | openipc/af-board-re/ |
| Built images | openipc/images/ |
| Vendor references | vendor/flash_dump_ssc377d/ (authoritative), vendor/firmware_MCL18D_V3.6.1.3/ (update file; see LEARNING-GUIDE §18 for two files of unknown origin there) |