Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generated/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ add_library(open_earable_protocols STATIC
"src/audio_configuration_protocol.c"
"src/audio_response_protocol.c"
"src/button_protocol.c"
"src/imu_protocol.c"
"src/led_protocol.c"
"src/ppg_protocol.c"
"src/wireless_audio_configuration_protocol.c"
)
add_library(OpenEarable::Protocols ALIAS open_earable_protocols)
Expand Down
44 changes: 44 additions & 0 deletions generated/c/include/imu_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Generated from schemas/imu/protocol.yml. Do not edit by hand.
#pragma once

#include "protocol_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* BLE only from firmware 2.3.0; six signed raw motion readings followed by three unchanged
* compensated magnetometer floats. See README for exact scales and firmware selection.
*/
typedef struct imu_compact_sample_t imu_compact_sample_t;
struct imu_compact_sample_t {
int16_t accel_x;
int16_t accel_y;
int16_t accel_z;
int16_t gyro_x;
int16_t gyro_y;
int16_t gyro_z;
float mag_x;
float mag_y;
float mag_z;
};


/**
* Encode a binary representation of this message. BLE only from firmware 2.3.0; six signed
* raw motion readings followed by three unchanged compensated magnetometer floats. See
* README for exact scales and firmware selection.
*/
protocol_status_t imu_compact_sample_encode(const imu_compact_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written);
/**
* Decode a binary representation into this message. BLE only from firmware 2.3.0; six
* signed raw motion readings followed by three unchanged compensated magnetometer floats.
* See README for exact scales and firmware selection.
*/
protocol_status_t imu_compact_sample_decode(imu_compact_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read);

#ifdef __cplusplus
}
#endif

65 changes: 65 additions & 0 deletions generated/c/include/ppg_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Generated from schemas/ppg/protocol.yml. Do not edit by hand.
#pragma once

#include "protocol_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Unchanged SD/.oe sample and BLE sample before firmware 2.3.0. Channel order is red,
* infrared, green, ambient.
*/
typedef struct ppg_legacy_sample_t ppg_legacy_sample_t;
struct ppg_legacy_sample_t {
uint32_t red;
uint32_t infrared;
uint32_t green;
uint32_t ambient;
};


/**
* BLE only from firmware 2.3.0. Concatenate red, infrared, green, ambient as four unsigned
* 19-bit values, least significant bit first. The high four bits of bits_64_79 are zero.
* See README for bit extraction and firmware selection.
*/
typedef struct ppg_compact_sample_t ppg_compact_sample_t;
struct ppg_compact_sample_t {
uint32_t bits_0_31;
uint32_t bits_32_63;
uint16_t bits_64_79;
};


/**
* Encode a binary representation of this message. Unchanged SD/.oe sample and BLE sample
* before firmware 2.3.0. Channel order is red, infrared, green, ambient.
*/
protocol_status_t ppg_legacy_sample_encode(const ppg_legacy_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written);
/**
* Decode a binary representation into this message. Unchanged SD/.oe sample and BLE sample
* before firmware 2.3.0. Channel order is red, infrared, green, ambient.
*/
protocol_status_t ppg_legacy_sample_decode(ppg_legacy_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read);

/**
* Encode a binary representation of this message. BLE only from firmware 2.3.0.
* Concatenate red, infrared, green, ambient as four unsigned 19-bit values, least
* significant bit first. The high four bits of bits_64_79 are zero. See README for bit
* extraction and firmware selection.
*/
protocol_status_t ppg_compact_sample_encode(const ppg_compact_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written);
/**
* Decode a binary representation into this message. BLE only from firmware 2.3.0.
* Concatenate red, infrared, green, ambient as four unsigned 19-bit values, least
* significant bit first. The high four bits of bits_64_79 are zero. See README for bit
* extraction and firmware selection.
*/
protocol_status_t ppg_compact_sample_decode(ppg_compact_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read);

#ifdef __cplusplus
}
#endif

73 changes: 73 additions & 0 deletions generated/c/src/imu_protocol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Generated from schemas/imu/protocol.yml. Do not edit by hand.
#include "imu_protocol.h"

static protocol_status_t imu_compact_sample_write(protocol_writer_t *writer, const imu_compact_sample_t *message) {
protocol_status_t status;
status = protocol_write_int16(writer, message->accel_x);
if (status != PROTOCOL_OK) return status;
status = protocol_write_int16(writer, message->accel_y);
if (status != PROTOCOL_OK) return status;
status = protocol_write_int16(writer, message->accel_z);
if (status != PROTOCOL_OK) return status;
status = protocol_write_int16(writer, message->gyro_x);
if (status != PROTOCOL_OK) return status;
status = protocol_write_int16(writer, message->gyro_y);
if (status != PROTOCOL_OK) return status;
status = protocol_write_int16(writer, message->gyro_z);
if (status != PROTOCOL_OK) return status;
status = protocol_write_float(writer, message->mag_x);
if (status != PROTOCOL_OK) return status;
status = protocol_write_float(writer, message->mag_y);
if (status != PROTOCOL_OK) return status;
status = protocol_write_float(writer, message->mag_z);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

static protocol_status_t imu_compact_sample_read(protocol_reader_t *reader, imu_compact_sample_t *message) {
protocol_status_t status;
status = protocol_read_int16(reader, &message->accel_x);
if (status != PROTOCOL_OK) return status;
status = protocol_read_int16(reader, &message->accel_y);
if (status != PROTOCOL_OK) return status;
status = protocol_read_int16(reader, &message->accel_z);
if (status != PROTOCOL_OK) return status;
status = protocol_read_int16(reader, &message->gyro_x);
if (status != PROTOCOL_OK) return status;
status = protocol_read_int16(reader, &message->gyro_y);
if (status != PROTOCOL_OK) return status;
status = protocol_read_int16(reader, &message->gyro_z);
if (status != PROTOCOL_OK) return status;
status = protocol_read_float(reader, &message->mag_x);
if (status != PROTOCOL_OK) return status;
status = protocol_read_float(reader, &message->mag_y);
if (status != PROTOCOL_OK) return status;
status = protocol_read_float(reader, &message->mag_z);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

protocol_status_t imu_compact_sample_encode(const imu_compact_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written) {
protocol_writer_t writer = { buffer, buffer_size, 0 };
protocol_status_t status = imu_compact_sample_write(&writer, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_written != NULL) {
*bytes_written = writer.offset;
}
return PROTOCOL_OK;
}

protocol_status_t imu_compact_sample_decode(imu_compact_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read) {
protocol_reader_t reader = { buffer, buffer_size, 0 };
protocol_status_t status = imu_compact_sample_read(&reader, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_read != NULL) {
*bytes_read = reader.offset;
}
return PROTOCOL_OK;
}

99 changes: 99 additions & 0 deletions generated/c/src/ppg_protocol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Generated from schemas/ppg/protocol.yml. Do not edit by hand.
#include "ppg_protocol.h"

static protocol_status_t ppg_legacy_sample_write(protocol_writer_t *writer, const ppg_legacy_sample_t *message) {
protocol_status_t status;
status = protocol_write_uint32(writer, message->red);
if (status != PROTOCOL_OK) return status;
status = protocol_write_uint32(writer, message->infrared);
if (status != PROTOCOL_OK) return status;
status = protocol_write_uint32(writer, message->green);
if (status != PROTOCOL_OK) return status;
status = protocol_write_uint32(writer, message->ambient);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

static protocol_status_t ppg_legacy_sample_read(protocol_reader_t *reader, ppg_legacy_sample_t *message) {
protocol_status_t status;
status = protocol_read_uint32(reader, &message->red);
if (status != PROTOCOL_OK) return status;
status = protocol_read_uint32(reader, &message->infrared);
if (status != PROTOCOL_OK) return status;
status = protocol_read_uint32(reader, &message->green);
if (status != PROTOCOL_OK) return status;
status = protocol_read_uint32(reader, &message->ambient);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

protocol_status_t ppg_legacy_sample_encode(const ppg_legacy_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written) {
protocol_writer_t writer = { buffer, buffer_size, 0 };
protocol_status_t status = ppg_legacy_sample_write(&writer, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_written != NULL) {
*bytes_written = writer.offset;
}
return PROTOCOL_OK;
}

protocol_status_t ppg_legacy_sample_decode(ppg_legacy_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read) {
protocol_reader_t reader = { buffer, buffer_size, 0 };
protocol_status_t status = ppg_legacy_sample_read(&reader, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_read != NULL) {
*bytes_read = reader.offset;
}
return PROTOCOL_OK;
}

static protocol_status_t ppg_compact_sample_write(protocol_writer_t *writer, const ppg_compact_sample_t *message) {
protocol_status_t status;
status = protocol_write_uint32(writer, message->bits_0_31);
if (status != PROTOCOL_OK) return status;
status = protocol_write_uint32(writer, message->bits_32_63);
if (status != PROTOCOL_OK) return status;
status = protocol_write_uint16(writer, message->bits_64_79);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

static protocol_status_t ppg_compact_sample_read(protocol_reader_t *reader, ppg_compact_sample_t *message) {
protocol_status_t status;
status = protocol_read_uint32(reader, &message->bits_0_31);
if (status != PROTOCOL_OK) return status;
status = protocol_read_uint32(reader, &message->bits_32_63);
if (status != PROTOCOL_OK) return status;
status = protocol_read_uint16(reader, &message->bits_64_79);
if (status != PROTOCOL_OK) return status;
return PROTOCOL_OK;
}

protocol_status_t ppg_compact_sample_encode(const ppg_compact_sample_t *message, uint8_t *buffer, size_t buffer_size, size_t *bytes_written) {
protocol_writer_t writer = { buffer, buffer_size, 0 };
protocol_status_t status = ppg_compact_sample_write(&writer, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_written != NULL) {
*bytes_written = writer.offset;
}
return PROTOCOL_OK;
}

protocol_status_t ppg_compact_sample_decode(ppg_compact_sample_t *message, const uint8_t *buffer, size_t buffer_size, size_t *bytes_read) {
protocol_reader_t reader = { buffer, buffer_size, 0 };
protocol_status_t status = ppg_compact_sample_read(&reader, message);
if (status != PROTOCOL_OK) {
return status;
}
if (bytes_read != NULL) {
*bytes_read = reader.offset;
}
return PROTOCOL_OK;
}

5 changes: 5 additions & 0 deletions generated/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.4

- Define 24-byte BLE IMU samples for firmware 2.3.x; retain float values/units and the 36-byte SD layout.
- Define lossless 10-byte BLE PPG samples for firmware 2.3.x alongside the unchanged 16-byte legacy/SD layout.

## 0.0.3

* added wireless-audio-configuration protocol
Expand Down
2 changes: 2 additions & 0 deletions generated/dart/lib/open_earable_protocols.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export 'src/protocol_runtime.dart'
export 'src/audio_configuration_protocol.dart';
export 'src/audio_response_protocol.dart';
export 'src/button_protocol.dart';
export 'src/imu_protocol.dart';
export 'src/led_protocol.dart';
export 'src/ppg_protocol.dart';
export 'src/wireless_audio_configuration_protocol.dart';
61 changes: 61 additions & 0 deletions generated/dart/lib/src/imu_protocol.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Generated from schemas/imu/protocol.yml. Do not edit by hand.
import 'dart:typed_data';
import 'protocol_runtime.dart';

/// BLE only from firmware 2.3.0; six signed raw motion readings followed by three unchanged
/// compensated magnetometer floats. See README for exact scales and firmware selection.
class ImuCompactSample {
/// Creates a ImuCompactSample value.
ImuCompactSample({required this.accel_x, required this.accel_y, required this.accel_z, required this.gyro_x, required this.gyro_y, required this.gyro_z, required this.mag_x, required this.mag_y, required this.mag_z});

final int accel_x;
final int accel_y;
final int accel_z;
final int gyro_x;
final int gyro_y;
final int gyro_z;
final double mag_x;
final double mag_y;
final double mag_z;

/// Decodes a complete ImuCompactSample value from [bytes].
factory ImuCompactSample.fromBytes(Uint8List bytes) {
final reader = ProtocolReader(bytes);
final value = ImuCompactSample._read(reader);
reader.finish();
return value;
}

static ImuCompactSample _read(ProtocolReader reader) {
final accel_x = reader.int16();
final accel_y = reader.int16();
final accel_z = reader.int16();
final gyro_x = reader.int16();
final gyro_y = reader.int16();
final gyro_z = reader.int16();
final mag_x = reader.float32();
final mag_y = reader.float32();
final mag_z = reader.float32();
return ImuCompactSample(accel_x: accel_x, accel_y: accel_y, accel_z: accel_z, gyro_x: gyro_x, gyro_y: gyro_y, gyro_z: gyro_z, mag_x: mag_x, mag_y: mag_y, mag_z: mag_z);
}

/// Encodes this value to the protocol binary representation.
Uint8List toBytes() {
final writer = ProtocolWriter();
_write(writer);
return writer.takeBytes();
}

void _write(ProtocolWriter writer) {
writer.int16(accel_x);
writer.int16(accel_y);
writer.int16(accel_z);
writer.int16(gyro_x);
writer.int16(gyro_y);
writer.int16(gyro_z);
writer.float32(mag_x);
writer.float32(mag_y);
writer.float32(mag_z);
}
}

Loading
Loading