Baichuan commands as data: an id, the firmware's name, and the parameter elements its bodies carry.

The firmware dispatches each command id to a handler that reads and writes a fixed set of parameter elements. Which of them appear in a request and which in a reply depends on the command (a GET sends nothing and gets the parameters back, a SET sends them and gets an empty reply), so both directions are typed as the same partial record of those parameters.

command(37, "GET_NETPORT_CFG_V20", [serverPort, rtspPort])
  body type  { ServerPort?: { serverPort: number; enable: number }; RtspPort?: … }

Examples

Encode and decode a command body

import { assertEquals } from "@std/assert";
import {
  command,
  decodeCommandBody,
  encodeCommandBody,
} from "@hertzg/reolink-api/protocol/command";
import { int, xmlParam } from "@hertzg/reolink-api/protocol/xml";

const rtspPort = xmlParam("RtspPort", { rtspPort: int(), enable: int() });
const setPorts = command(36, "SET_NETPORT_CFG_V20", [rtspPort]);

const xml = encodeCommandBody(setPorts, {
  RtspPort: { rtspPort: 554, enable: 1 },
});

assertEquals(decodeCommandBody(setPorts, xml), {
  RtspPort: { rtspPort: 554, enable: 1 },
});

Functions

f
decodeCommandBody<C extends Command>(
command: C,
xml: string
): CommandBody<C>

Reads a command body. Elements that are not among the command's parameters are ignored.

f
encodeCommandBody<C extends Command>(
command: C,
body: CommandBody<C>
): string

Writes a command body as XML. Parameters missing from body are left out; an empty body gives an empty string, which the firmware treats as "use the current values" rather than as an empty <body/>.

Type Aliases

T
Command<P extends readonly AnyXmlParam[] = readonly AnyXmlParam[]> = { id: number; name: string; params: P; firmware: readonly Firmware[]; }

A Baichuan command: its id, firmware name, and parameter elements.

  • firmware: readonly Firmware[]

    The firmware builds known to register the command, empty when unknown. Registration does not promise that a given device answers it.

  • id: number

    The command id sent in the message header.

  • name: string

    The name the firmware's dispatch table gives the command.

  • params: P

    The parameter elements the command's bodies may carry.

T
CommandBody<C extends Command> = [P in C["params"][number] in keyof P["name"]]?: XmlParamValue<P>

The body of a Command, request or reply: each of its parameters by element name, all optional.

T
Firmware = "RLC-823A" | "Video Doorbell PoE"

A firmware build whose command table this package was derived from.