bcudp

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bcudp carries a Baichuan byte stream over the UDP transport that battery cameras speak instead of TCP port 9000. See docs/udp.md.

Index

Constants

View Source
const ReplyPortEnv = "REOSTREAM_BATTERY_UDP_PORT"

ReplyPortEnv names the environment variable that sets the reply port when SetReplyPort has not.

Variables

View Source
var ErrSilent = errors.New("bcudp: camera stopped answering")

ErrSilent means the camera sent nothing for silenceLimit.

Functions

func Ours added in v0.2.4

func Ours(ip net.IP, d time.Duration) bool

Ours reports whether this process has a session with the camera at ip open, or had one within the last d: anything else that wakes the camera is someone else (the Reolink app) or the camera itself (motion).

func SetReplyPort added in v0.2.7

func SetReplyPort(port int)

SetReplyPort makes every later search and session use port for the camera's replies; 0 goes back to each socket's own port.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is one UDP session with a battery camera, as a reliable ordered byte stream. It implements net.Conn.

func Dial

func Dial(ctx context.Context, host, uid string) (*Conn, error)

Dial wakes the battery camera at host, opens a session with it, and returns the session as a byte stream carrying Baichuan.

func (*Conn) Close

func (c *Conn) Close() error

Close ends the session, telling the camera so it can go back to sleep.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read reads the camera's byte stream. A D2C_DISC from the camera reads as io.EOF once everything before it has been read.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(time.Time) error

SetWriteDeadline is accepted and ignored: Write never blocks on the camera.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write queues b for the camera, split into packets, and sends them. It does not wait for acks.

type Event

type Event struct {
	Seq  uint32
	UID  string
	Body []byte
}

Event is one decrypted cloud event report. Body is the JSON the camera sent, for example {"event":3} for motion. Seq is the sequence number, which is also the key the body was encrypted under.

func DecodeEvent

func DecodeEvent(b []byte) (Event, error)

DecodeEvent parses and decrypts a cf31 event packet. It verifies the checksum against the ciphertext exactly as the camera computes it, and rejects a truncated or corrupt packet rather than returning half an event.

type Info

type Info struct {
	Addr    net.IP
	UID     string
	Asleep  bool // the reply carried a battery block, which only a sleeping camera sends
	Battery int  // percent, or -1 when the reply carried none
}

Info is a battery camera's answer to a search.

func Discover

func Discover(ctx context.Context) ([]Info, error)

Discover broadcasts a search until ctx ends and returns every battery camera that answered, one entry per address.

func Search(ctx context.Context, host string) (Info, error)

Search asks the camera at host for its UID and sleep state. It does not wake the camera.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL