parse

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package parse contains pure parsers for the textual output of the Raspberry Pi 5 firmware tools (vcgencmd, pmic_read_adc) and the kernel sysfs/hwmon files. Everything here is I/O-free: callers pass in the raw command output as a string and receive a typed result or an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseClockHertz

func ParseClockHertz(s string) (float64, error)

ParseClockHertz parses `vcgencmd measure_clock` output of the form "frequency(0)=1600020224" and returns the frequency in hertz. A reported frequency of 0 (e.g. for an idle h264 block) is valid and returns 0.

func ParseResetStatus

func ParseResetStatus(s string) (uint32, error)

ParseResetStatus parses `vcgencmd get_rsts` output of the form "get_rsts=1020" and returns the reset-status word. The right-hand side is parsed with base 0 so a 0x-prefixed value would also be accepted.

func ParseSysfsInt

func ParseSysfsInt(s string) (int64, error)

ParseSysfsInt parses an integer from a sysfs/hwmon file, trimming any surrounding whitespace and trailing newline first. Values are base-10.

func ParseTempCelsius

func ParseTempCelsius(s string) (float64, error)

ParseTempCelsius parses `vcgencmd measure_temp` output of the form "temp=46.6'C" and returns the temperature in degrees Celsius.

func ParseVolts

func ParseVolts(s string) (float64, error)

ParseVolts parses `vcgencmd measure_volts` output of the form "volt=0.8749V" and returns the voltage in volts. Command-level error bodies such as "bad argument" do not match and produce an error.

Types

type Rail

type Rail struct {
	Name     string
	Volts    float64
	Amps     float64
	HasVolts bool
	HasAmps  bool
}

Rail is a single PMIC power rail as reported by `pmic_read_adc`. The firmware emits two lines per rail (a "_A" current line and a "_V" voltage line) which are not adjacent; ParsePMIC merges them into one Rail. Volt-only rails such as EXT5V and BATT have no current channel, so HasAmps stays false.

func ParsePMIC

func ParsePMIC(s string) ([]Rail, error)

ParsePMIC parses the full output of `pmic_read_adc`. Each non-blank line is matched against pmicLineRe; the _A/_V suffix is stripped to derive the rail Name, and the current/voltage lines for the same Name are merged into a single Rail. Rails are returned in order of first appearance. Empty input returns (nil, nil); any line that fails to match is reported as an error.

type RingOsc

type RingOsc struct {
	Hertz   float64
	Volts   float64
	Celsius float64
}

RingOsc is the decoded form of `vcgencmd read_ring_osc`.

func ParseRingOsc

func ParseRingOsc(s string) (RingOsc, error)

ParseRingOsc parses a `vcgencmd read_ring_osc` line, converting the MHz frequency to hertz.

type Throttled

type Throttled struct {
	Raw uint32

	// Live bits (0..3): the condition is happening right now.
	UnderVoltageNow  bool
	ArmFreqCappedNow bool
	ThrottledNow     bool
	SoftTempLimitNow bool

	// Sticky-since-boot bits (16..19): the condition has occurred at least
	// once since the last boot.
	UnderVoltageSince  bool
	ArmFreqCappedSince bool
	ThrottledSince     bool
	SoftTempLimitSince bool
}

Throttled is the decoded form of `vcgencmd get_throttled`.

The firmware reports a 32-bit bitmask. The low nibble (bits 0..3) describes the *current* (live) state and the bits at 16..19 are sticky flags that latch if the condition has occurred at any point since boot. The exact bit assignments are documented by the Raspberry Pi firmware and reproduced here:

bit 0  / 16  under-voltage detected
bit 1  / 17  arm frequency capped
bit 2  / 18  currently throttled
bit 3  / 19  soft temperature limit active

func ParseThrottled

func ParseThrottled(s string) (Throttled, error)

ParseThrottled parses a line of the form "throttled=0x<hex>" into a Throttled. Input that does not begin with the "throttled=" prefix, or whose right-hand side is not a valid 32-bit integer, is rejected with an error.

type Version

type Version struct {
	// FirmwareDate is the first line of the block if it looks like a
	// timestamp, otherwise empty.
	FirmwareDate string
	Hash         string
	Variant      string
	Build        string
}

Version is the decoded form of the `vcgencmd version` block.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses the multi-line `vcgencmd version` block. The last non-empty line is expected to be "version <hash> (<variant>) (<build>)". FirmwareDate is taken from the first non-empty line when it looks like a timestamp, otherwise it is left empty.

Jump to

Keyboard shortcuts

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