- C 95.6%
- Makefile 4.4%
The previous code could not talk to the device: it opened the hidraw node twice (once to write, once to read), wrote sizeof(int) instead of a full 64-byte HID report, returned 1 from open_device() while callers checked fd < 0 (so errors landed on stdout), and passed unterminated strncpy slices to atof(). Rewrite the device layer around a single non-blocking fd with poll() and a deadline, discard replies that do not echo the request byte, and parse fixed-width fields safely (including the -.--- placeholders the firmware sends while the output is off). Protocol was verified against the original Smart Power V31 firmware source: ProcessIO() reads the command from ReceivedDataBuffer[0] and builds replies from the two 16-byte LCD line buffers. Also: - split the CLI (src/main.c) from the device/parsing code - auto-detect the device by USB ID 04d8:003f, keep the old positional device argument, add --device - add status/data/version output, dump command, help, exit codes - add Makefile, udev rule, README and parser/I-O tests (make check) |
||
|---|---|---|
| build | ||
| src | ||
| tests | ||
| udev | ||
| .gitignore | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
CLI Program for Odroid Smart Power V1
A command line interface for the ODROID Smart Power V1.
This is a discontinued product, but I've had one laying around for a decade and I wanted an easy way to interface with it through a Linux terminal.
No external libraries are needed: the program talks to the kernel's hidraw interface directly.
Building
make # builds build/smartpowercli
make check # runs the parser unit tests (no hardware needed)
sudo make install
The only build requirement is a C11 compiler and make.
Usage
smartpowercli [--device /dev/hidrawN] <command>
If --device is omitted the Smart Power is located automatically by its USB
IDs (04d8:003f). The older two-argument form still works:
smartpowercli /dev/hidraw0 data
Commands
| Command | Description |
|---|---|
data |
Voltage, current, power and consumed energy |
status |
Power output and energy logging state |
onoff |
Toggle the power output |
startstop |
Start/stop watt-hour logging |
version |
Firmware version |
dump |
Hex dump the raw reply, for debugging |
help |
Show usage |
Example:
$ smartpowercli data
Voltage: 5.001 V
Current: 0.123 A
Power: 0.615 W
Energy: 1.234 Wh
While the output is switched off the device reports dashes for current, power
and energy; the CLI prints n/a for those fields.
Exit codes: 0 success, 1 usage error, 2 device or I/O error.
Device permissions
/dev/hidrawN is root-only by default. Either run the tool with sudo, or
install the included udev rule so your logged-in user gets access:
sudo make install-udev
or manually:
sudo cp udev/99-odroid-smartpower.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger --subsystem-match=hidraw
Unplug and replug the device afterwards.
Protocol notes
The Smart Power is a vendor-defined HID device (usage page 0xFF00) with one
unnumbered 64-byte input and one 64-byte output report. A command is a 64-byte
output report whose first byte is the request; the device replies with a
64-byte input report whose first byte echoes the request:
| Request | Meaning |
|---|---|
0x37 |
Read measurements |
0x80 |
Toggle watt-hour logging |
0x81 |
Read status |
0x82 |
Toggle power output |
0x83 |
Read firmware version |
The status reply contains the logging flag at byte 1 and the power flag at
byte 2. The data reply is fixed-width ASCII with the measurements at byte
offsets 2, 10, 17 and 24 (voltage, current, power, watt-hours). Version text
starts at byte 1 and is 16 bytes long. See src/smartpowercli.c for details.
License
MIT, see LICENSE.