我正在编写一个 android 应用程序,它通过 BLE(具有特征和描述符)读取从 arm 处理器发送的数据。在硬件部分,我使用以下功能:
tBleStatus aci_gatt_add_char_desc ( uint16_t serviceHandle,
uint16_t charHandle,
uint8_t descUuidType, //16 or 128 bit
const uint8_t * uuid, //descriptor uuid
uint8_t descValueMaxLen,
uint8_t descValueLen,
const void * descValue, //actual data
uint8_t secPermissions,
uint8_t accPermissions,
uint8_t gattEvtMask,
uint8_t encryKeySize,
uint8_t isVariable,
uint16_t * descHandle
)
如果我们descValue
作为字符串或众所周知的类型值传递,我们可以轻松地在 android 端提取值,如下所示:
byte[] descValue = Descriptor.getValue();
String DescString = new String(descValue, "ISO_8859_1");
或者对于浮动我使用:
float wrapped = ByteBuffer.wrap(descValue).order(ByteOrder.LITTLE_ENDIAN).getFloat();
但是,我想在 C 中发送一个结构,而不是字符串或任何单一数据类型(例如特征表示格式(0x2904 UUID):
typedef __packed struct _charactFormat {
uint8_t format;
int8_t exp;
uint16_t unit;
uint8_t name_space;
uint16_t desc;
} PACKED charactFormat;
但问题是当我们调用getValue()
在 Android 中调用函数时,它返回一个字节数组,我不知道如何解释这个字节数组并从中提取数据
我正在寻找一种发送方式struct
而不是严格寻找 Char Pres。形式。(这是可能的,因为 nRF 连接应用程序可以读取数据结构但源代码不可用(即使在他们的 nRF 工具箱中)
任何帮助,将不胜感激