Metadata-Version: 2.4
Name: bc_insole_sdk
Version: 0.2.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# BC Insole SDK

Rust, Python, iOS, and Android SDK foundation for BrainCo smart pressure insoles.

The device protocol uses a short binary transport frame carrying Protobuf payloads:

```text
[BRNC][Ver][PayVer][Len LE][Protobuf Payload][CRC16 LE]
```

Core protocol support lives in `sdk/src/protocol` and implements:

- CRC16-Modbus validation over header + payload
- frame encoding
- stream parsing with magic-byte resynchronization
- Protobuf request/response payload encoding and decoding

## Build

```bash
cargo test
```

## Python

```bash
cd sdk
maturin develop --features python
```

The Python package exposes protocol constants, BLE advertisement parsing, request builders, and
an incremental stream parser. Existing parser behavior remains compatible by default. New code can
preserve calibrated and raw pressure fields separately and reject CRC-invalid frames:

```python
import bc_insole_sdk

parser = bc_insole_sdk.StreamParser(
    strict_crc=True,
    legacy_pressure_fallback=False,
)

request = bc_insole_sdk.build_sensor_stream_config_request(
    msg_id=1,
    dest_id=bc_insole_sdk.DEVICE_LEFT,
    pressure_mode="raw",
    shear_mode="calibrated",
    imu_mode="calibrated",
)
```

Use `parser.stats()` for CRC, framing, Protobuf, sequence discontinuity, and packet-loss counters.

Pressure resistance calibration and pressure-derived shear use the same Rust implementation on all
platforms. Inputs are resistance values in ohms from `raw_pressure`; outputs are calibrated normal
load and derived force vectors in newtons. Python clients call `calibrate_pressure()` and
`derive_shear()`; iOS and Android wrappers bind to `bcis_calibrate_pressure()` and
`bcis_derive_shear()`. Protocol-native `shear_data` remains reserved for future firmware use, is
disabled by default, and is not used by the derived-shear calculation.

IMU protocol fields keep calibrated LSB values (`acc_x`/`gyro_x`) and raw pre-calibration LSB values
(`raw_acc_x`/`raw_gyro_x`) separately. The SDK exposes physical accelerometer values in milli-g and
gyroscope values in degrees per second by applying `acc_scale` and `gyro_scale`. Sensor stream
configuration defaults to calibrated IMU data because the physical-value conversion uses those
calibrated LSB fields.

## Mobile

The Rust crate exports a C ABI with `staticlib`/`cdylib` outputs. iOS and Android wrappers should bind to the C surface in `sdk/src/c`.

iOS `SensorStreamConfig` and Android `SensorStreamConfig` use the same defaults as Python: raw
pressure, calibrated IMU, and protocol-native shear disabled. Pressure callbacks expose both a
compatibility `pressure` array and an explicit `rawPressure` array. When firmware sends raw pressure
only, both arrays contain resistance in ohms; when calibrated pressure is also present, `pressure`
contains calibrated protocol values while `rawPressure` remains resistance in ohms.

For iOS automated packaging and OSS release scripts, see [ios/README.md](file:///Users/brain-mini/projects/rust/bc-insole-sdk/ios/README.md).

