Files
utun2/lib/ble/ble_identity.h
T

32 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Объявление VibeChat: VC, версия 4, node_id BE64, имя UTF-8 до 13 байт.
* encode возвращает размер 11..24 либо -1; decode возвращает ble_identity_result.
* Имя сокращается по целому символу; decode отклоняет неверный UTF-8 и нулевой ID. */
#ifndef VIBECHAT_BLE_IDENTITY_H
#define VIBECHAT_BLE_IDENTITY_H
#include <stdint.h>
#include <stddef.h>
#define BLE_IDENTITY_VERSION 4 /* DATA с 16-bit flow ID; ACK использует Without Response/Notify. */
#ifdef __cplusplus
extern "C" {
#endif
struct ble_identity { uint64_t node_id; char name[14]; };
/* Причины отказа: вызывающий код логирует их с endpoint/RSSI и ограничивает повторы. */
enum ble_identity_result {
BLE_IDENTITY_OK = 0,
BLE_IDENTITY_ERR_ARGUMENT = -1,
BLE_IDENTITY_ERR_LENGTH = -2,
BLE_IDENTITY_ERR_MAGIC = -3,
BLE_IDENTITY_ERR_VERSION = -4,
BLE_IDENTITY_ERR_NODE = -5,
BLE_IDENTITY_ERR_UTF8 = -6
};
int ble_identity_encode(uint8_t output[24], uint64_t node_id, const char* name);
/* Разбирает data[size]; output меняется только при успехе. Ошибка — отрицательный код. */
int ble_identity_decode(struct ble_identity* output, const uint8_t* data, size_t size);
/* Короткое имя результата decode для диагностики; возвращает статическую строку. */
const char* ble_identity_result_name(int result);
#ifdef __cplusplus
}
#endif
#endif