Add reliable Android BLE ride recorder
This commit is contained in:
@@ -15,6 +15,12 @@ static uint32_t get_u32_le(const uint8_t *input)
|
||||
((uint32_t)input[2] << 16) | ((uint32_t)input[3] << 24);
|
||||
}
|
||||
|
||||
static uint64_t get_u64_le(const uint8_t *input)
|
||||
{
|
||||
return (uint64_t)get_u32_le(input) |
|
||||
((uint64_t)get_u32_le(input + 4) << 32);
|
||||
}
|
||||
|
||||
static void put_u16_le(uint8_t *output, uint16_t value)
|
||||
{
|
||||
output[0] = (uint8_t)value;
|
||||
@@ -89,3 +95,31 @@ bool trikke_ble_decode_ack(
|
||||
*packet_sequence = get_u32_le(ack + 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool trikke_ble_decode_begin_session(
|
||||
const uint8_t *command,
|
||||
size_t command_size,
|
||||
uint64_t *session_token)
|
||||
{
|
||||
if (command == NULL || session_token == NULL ||
|
||||
command_size != TRIKKE_BLE_BEGIN_SESSION_SIZE ||
|
||||
memcmp(command, "BGN1", 4) != 0) {
|
||||
return false;
|
||||
}
|
||||
*session_token = get_u64_le(command + 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool trikke_ble_update_subscription(
|
||||
bool notify_enabled,
|
||||
bool session_connection_ready,
|
||||
bool *subscribed)
|
||||
{
|
||||
if (subscribed == NULL) {
|
||||
return false;
|
||||
}
|
||||
const bool effective = notify_enabled && session_connection_ready;
|
||||
const bool changed = effective != *subscribed;
|
||||
*subscribed = effective;
|
||||
return changed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user