| Title: | Serial Communication and Data Retrieval for Axivity Devices |
|---|---|
| Description: | Serial communication and data retrieval for Axivity AX3/AX6 accelerometer devices: device discovery, status, settings, data download, and reading recorded '.cwa'/AX6 binary files. Wraps the Open Movement Project's 'OMAPI' C library (vendored in src/omapi, BSD 2-clause, Newcastle University; see src/omapi/LICENSE.TXT), rather than reimplementing the serial protocol or binary file format directly. On Linux, device discovery requires 'libudev-dev' (Debian/Ubuntu) or 'systemd-devel' (Fedora/RHEL) to be installed separately -- see SystemRequirements. macOS and Windows use OS frameworks/APIs directly, with no separate install step. Part of the Circadia Lab R ecosystem. |
| Authors: | Lucas França [aut, cre] (ORCID: <https://orcid.org/0000-0003-0853-1319>), Mario Leocadio-Miguel [aut] (ORCID: <https://orcid.org/0000-0002-7248-3529>) |
| Maintainer: | Lucas França <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-07-16 12:19:45 UTC |
| Source: | https://github.com/circadia-bio/axR |
A fallback for when axivity_discover()/OMAPI device access isn't
working, but the device's USB mass-storage volume mounts and is
visible in Finder/diskutil regardless – a common split, since the
storage side and OMAPI's own IOKit-level device discovery are
independent paths (see NEWS.md for the discovery issues hit so
far). This bypasses OMAPI and device_id entirely: it's a plain file
copy, nothing more. axR doesn't parse .cwa contents – see
mrpheus or zeitR for that.
axivity_copy_data( device_path, dest_dir, pattern = "\\.cwa$", overwrite = FALSE )axivity_copy_data( device_path, dest_dir, pattern = "\\.cwa$", overwrite = FALSE )
device_path |
Character. Path to the mounted device volume, e.g.
|
dest_dir |
Character. Destination directory for downloaded files. Created (recursively) if it doesn't already exist. |
pattern |
Character. Regex to filter which files are copied,
matched case-insensitively. Default |
overwrite |
Logical. Overwrite existing files at the
destination. Default |
Character vector of destination file paths that were successfully copied.
Wraps OMAPI's OmGetDeviceIds() plus a handful of per-device status
calls into a single data frame. Unlike serial-port probing, this uses
OMAPI's own device discovery – including its platform-specific finder
(IOKit/DiskArbitration on macOS, SetupAPI on Windows, udev on Linux) –
so it should behave the same way OmGui does on the same machine.
axivity_discover()axivity_discover()
A data frame with one row per connected device: device_id,
serial, port, path, firmware_version, hardware_version,
battery_level. Zero rows if no devices are connected.
Wraps OMAPI's OmBeginDownloading(), which runs the download on a
background thread inside the library. axR doesn't parse .cwa
contents – see mrpheus or zeitR for that.
axivity_download( device_id, dest_file, offset_blocks = 0L, length_blocks = -1L, blocking = TRUE )axivity_download( device_id, dest_file, offset_blocks = 0L, length_blocks = -1L, blocking = TRUE )
device_id |
Integer device ID, as returned by |
dest_file |
Character. Destination file path (existing files at this path are truncated). |
offset_blocks |
Integer. Start offset of the download, in blocks.
Default |
length_blocks |
Integer. Length to download, in blocks. Default
|
blocking |
Logical. If |
If blocking = TRUE, a list with status (one of "complete",
"error", "cancelled") and value (a diagnostic code if status
is "error"). If blocking = FALSE, invisibly NULL.
Cancel an in-progress download from an Axivity device
axivity_download_cancel(device_id)axivity_download_cancel(device_id)
device_id |
Integer device ID, as returned by |
Check or wait for an Axivity device's download progress
axivity_download_status(device_id) axivity_download_wait(device_id)axivity_download_status(device_id) axivity_download_wait(device_id)
device_id |
Integer device ID, as returned by |
A list with status ("none", "error", "progress",
"complete", or "cancelled") and value (percentage complete if
status is "progress", a diagnostic code if "error").
A diagnostic escape hatch for when axivity_discover() isn't finding a
device you expect it to. OMAPI logs internally via its own OmLog(),
but axR's default log target is NULL (so compiled code doesn't write
to stderr unprompted – see NEWS.md). This re-enables it.
axivity_enable_debug_log(file = NULL)axivity_enable_debug_log(file = NULL)
file |
Character path to a log file, or |
Important: this only controls where log lines go. Whether
anything is logged at all is controlled by OMAPI's debug level,
which is read from the OMDEBUG environment variable once, at
OmStartup() time – i.e. before library(axR) runs. If you're not
seeing log output after calling this, set OMDEBUG (e.g.
Sys.setenv(OMDEBUG = "3")) before loading axR, in a fresh R
session, then call this function and retry.
Invisibly, the OMAPI status code (negative indicates failure, e.g. the file couldn't be opened).
Get or set an Axivity device's accelerometer configuration
axivity_get_accel_config(device_id) axivity_set_accel_config(device_id, rate, range)axivity_get_accel_config(device_id) axivity_set_accel_config(device_id, rate, range)
device_id |
Integer device ID, as returned by |
rate |
Sampling rate in Hz (6 = 6.25, 12 = 12.5, 25, 50, 100, 200, 400, 800, 1600, 3200). Negative = low-power mode. |
range |
Sampling range in +/- G (2, 4, 8, 16). |
axivity_get_accel_config() returns a list with rate (Hz)
and range (+/- g).
Read an Axivity device's current accelerometer values
axivity_get_accelerometer(device_id)axivity_get_accelerometer(device_id)
device_id |
Integer device ID, as returned by |
A named numeric vector c(x, y, z) in units of g
(raw values are in 1/256 g, converted here).
Query an Axivity device's battery level and health
axivity_get_battery(device_id)axivity_get_battery(device_id)
device_id |
Integer device ID, as returned by |
A list with level_pct (0-99% = charging, 100% = full) and
recharge_cycles (lower is better).
Get information about an Axivity device's recorded data
axivity_get_data_info(device_id)axivity_get_data_info(device_id)
device_id |
Integer device ID, as returned by |
A list with size_bytes, filename (path on the device's own
filesystem, not yet downloaded), block_size, offset_blocks,
num_blocks, and start/end (POSIXct, the time range of the
recorded data).
Get or set an Axivity device's delayed activation window
axivity_get_delays(device_id) axivity_set_delays(device_id, start, stop)axivity_get_delays(device_id) axivity_set_delays(device_id, start, stop)
device_id |
Integer device ID, as returned by |
start, stop
|
Each either a |
axivity_get_delays() returns a list with start and stop,
each either a POSIXct, -Inf (OMAPI's "always"/zero sentinel), or
Inf (OMAPI's "never"/infinite sentinel).
Get or set an Axivity device's error-correcting code (ECC) flag
axivity_get_ecc(device_id) axivity_set_ecc(device_id, enabled)axivity_get_ecc(device_id) axivity_set_ecc(device_id, enabled)
device_id |
Integer device ID, as returned by |
enabled |
Logical. Enable or disable ECC. |
axivity_get_ecc() returns a logical.
Query an Axivity device's NAND flash memory health
axivity_get_memory_health(device_id)axivity_get_memory_health(device_id)
device_id |
Integer device ID, as returned by |
A list with spare_blocks (higher is better, 0 = unusable)
and status ("ok", "warning", or "error", using OMAPI's
documented thresholds).
Get or set an Axivity device's metadata scratch buffer
axivity_get_metadata(device_id) axivity_set_metadata(device_id, metadata)axivity_get_metadata(device_id) axivity_set_metadata(device_id, metadata)
device_id |
Integer device ID, as returned by |
metadata |
Character. Metadata to store (up to 448 bytes; longer values are truncated by the device). URL-encode first if it needs to preserve non-ASCII characters. |
axivity_get_metadata() returns a character string, trimmed of
trailing padding.
Get or set an Axivity device's session identifier
axivity_get_session_id(device_id) axivity_set_session_id(device_id, session_id)axivity_get_session_id(device_id) axivity_set_session_id(device_id, session_id)
device_id |
Integer device ID, as returned by |
session_id |
A value to set as the session ID. |
axivity_get_session_id() returns a numeric (session IDs can
exceed R's 32-bit integer range).
Get or set an Axivity device's real-time clock
axivity_get_time(device_id) axivity_set_time(device_id, time)axivity_get_time(device_id) axivity_set_time(device_id, time)
device_id |
Integer device ID, as returned by |
time |
A |
axivity_get_time() returns a POSIXct.
Check or set an Axivity device's anti-tamper lock
axivity_is_locked(device_id) axivity_set_lock(device_id, code) axivity_unlock(device_id, code)axivity_is_locked(device_id) axivity_set_lock(device_id, code) axivity_unlock(device_id, code)
device_id |
Integer device ID, as returned by |
code |
Integer lock code. |
axivity_is_locked() returns a list with locked and
has_lock_code (logicals).
Uses OMAPI's own binary file reader (omapi-reader.c, vendored from
libomapi) to parse a .cwa/AX6 recording directly, rather than
reimplementing the binary format from scratch. Returns one row per
sample – ready to hand to zeitR, or any other downstream actigraphy
analysis.
axivity_read_cwa(path)axivity_read_cwa(path)
path |
Character. Path to a |
Unlike the rest of axR, this function doesn't talk to a live device at
all – it works on a file already on disk (e.g. one retrieved with
axivity_copy_data() or axivity_download()), and doesn't require
axivity_discover() to have found anything.
A tibble (or plain data frame, if the tibble package isn't
installed) with one row per sample:
POSIXct, UTC, with sub-second precision
Accelerometer readings, in g
Gyroscope readings, raw units (only present if the recording has a gyroscope, e.g. AX6 in GA/GAM mode)
Magnetometer readings, raw units (only present if the recording has a magnetometer, e.g. AX6 in GAM mode)
Raw light sensor reading
Temperature in degrees Celsius. Unverified,
possibly wrong – OMAPI's conversion (OM_VALUE_TEMPERATURE_MC)
hardcodes a formula for one specific temperature sensor chip
(MCP9700); a comment beside it in the vendored source notes an
alternate formula for a different chip (MCP9701), suggesting
this may be hardware/revision-specific. Cross-check against
OmGui's own reading for the same file before relying on this.
Battery percentage, at the time of this block
Sampling rate in Hz, at the time of this block
with device_id, session_id, and metadata attached as
attributes. timestamp, x/y/z, and device_id have been
verified correct against a real AX3 file (cross-checked device_id
against ioreg and the Axivity config web tool); temperature_c
has not.
Wraps OMAPI's OmEraseDataAndCommit(). Staged settings changes (delays,
session ID, metadata, accelerometer config) only take full effect when
this is called.
axivity_reset(device_id, level = "quickformat")axivity_reset(device_id, level = "quickformat")
device_id |
Integer device ID, as returned by |
level |
One of |
Run an Axivity device's built-in self-test
axivity_self_test(device_id)axivity_self_test(device_id)
device_id |
Integer device ID, as returned by |
A list with passed (logical) and diagnostic_code (an
opaque, firmware-specific code; 0 means passed).
An escape hatch wrapping OMAPI's OmCommand(), for anything not
covered by axR's typed functions. Not generally recommended – OMAPI's
own docs note that incorrect use could lead to unspecified behaviour.
axivity_send_command(device_id, command, expected = "", timeout_ms = 2000L)axivity_send_command(device_id, command, expected = "", timeout_ms = 2000L)
device_id |
Integer device ID, as returned by |
command |
Character. The command string to send. |
expected |
Character. The expected response prefix, or |
timeout_ms |
Integer. Timeout in milliseconds. Default |
Character. The device's raw response.
Set an Axivity device's LED colour
axivity_set_led(device_id, colour)axivity_set_led(device_id, colour)
device_id |
Integer device ID, as returned by |
colour |
One of |