BLE gattServer.write() 重载函数

BLE gattServer.write() overloaded function

我在尝试更新 MCU 运行 mbedOS v5.8.6 上 运行 的自定义 BLE 服务中的特征值时遇到问题。我正在尝试使用来自传感器的值更新此特性的值。请看下面的函数:

void onDataReadCallback(const GattReadCallbackParams *eventDataP) {
    if (eventDataP->handle == dhtServicePtr->dataStream.getValueHandle()) {

        const uint8_t data = sensorData;

        BLE::Instance().gattServer().write(eventDataP->handle, &data, sizeof(data), false);   
    }
}

我已经尝试明确说明正确的变量类型 (according to the BLE gattServer reference docs) 但无济于事。

我收到的确切错误是:

Error: No instance of overloaded function "GattServer::write" matches the argument list in "main.cpp", Line: 135, Col: 39

我相信我根据上述文档正确地执行了此操作。所以,我的问题是,我到底哪里出错了?完全有可能我刚刚犯了一个愚蠢的错误!

谢谢, 亚当

您正在尝试将指针发送到常量,尽管函数签名需要普通指针。在下面的示例中,当值为 const 时,编译器将通过错误。

#include <iostream>

    void test(int *ptr)
    {
        printf("%d",*ptr);
    }


    int main ()
    {
        //const int a = 10; //Gives error
        int a = 10;       //This works fine.

        test(&a);

        return 0;
    }