gpt4 book ai didi

c++ - 如何使用 Openthread 库编写一个简单的应用程序

转载 作者:行者123 更新时间:2023-11-30 19:25:17 24 4
gpt4 key购买 nike

即使要开发一个简单的应用程序,Openthread 中现有的示例也很难引用。任何人都可以提供使用 Openthread“mdt/fdt 库”并开发一个简单的应用程序的步骤列表,从该应用程序可以发送或接收 CoAP 消息?以下是我写的,但它运行不正常,有时会崩溃。我已链接“fdt、posix、mbedtls、libcrypto”等库并能够成功构建应用程序。

    instance = otInstanceInitSingle();
otError err = otIp6SetEnabled(instance, true);
if(err == OT_ERROR_NONE)
{
err = otCoapStart(instance, OT_DEFAULT_COAP_PORT);
pthread_t thread_id;
pthread_create(&thread_id, NULL, OTProcessThread, NULL); // To call otTaskletsProcess(instance);
return OK;
}
else{
std::cout << "Init Status: " << err << "\n";
}

该线程如下所示。我这是一个示例代码,所以我目前没有在线程中给出任何 sleep /信号。

void *OTProcessThread(void *vargp)
{
printf("\nOTProcessThread started..");
while (true)
{
otTaskletsProcess(instance);
//otSysProcessDrivers(instance);
}
}

通过这个初始化过程,我尝试发送如下消息。但之后应用程序在 Openthread 代码内的某个地方崩溃了。

     message = otCoapNewMessage(instance, NULL);
otCoapMessageInit(message, coapType, coapCode);
otCoapMessageGenerateToken(message, 8);
otCoapMessageAppendUriPathOptions(message, uri.c_str());
//otMessageAppend(message, NULL, 0);

otError status = otCoapSendRequest(instance, message, &messageInfo, &HandleResponse, this);

有人可以告诉我,我到底缺少什么吗?

最佳答案

虽然我无法在没有更大知名度的情况下讨论您的具体问题,但以下是一些您可能会觉得有用的资源:

关于c++ - 如何使用 Openthread 库编写一个简单的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59089702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com