main.c 中的 Openthread SRP 客户端

问题描述

您好,我正在尝试在 main.c 中启动 SRP(服务注册协议)客户端。我在 openthread/srp_client.h 中找到了以下描述"

 * This function starts the SRP client operation.
SRP client will prepare and send "SRP Update" message to the SRP server once all the following 
conditions are met:

- The SRP client is started - `otSrpClientStart()` is called.
- Host name is set - `otSrpClientSetHostName()` is called.
- At least one host IPv6 address is set - `otSrpClientSetHostName()` is called.
- At least one service is added - `otSrpClientAddService()` is called.

It does not matter in which order these functions are called. When all conditions are met,the 
SRP client will wait for a short delay before preparing an "SRP Update" message and sending to 
server. 

* @param[in] aInstance        A pointer to the OpenThread instance.
* @param[in] aServerSockAddr  The socket address (IPv6 address and port number) of the SRP 
* server.
*
* @retval OT_ERROR_NONE       SRP client operation started successfully or it is already 
running with same server
*                             socket address and callback.
* @retval OT_ERROR_BUSY       SRP client is busy running with a different socket address.
* @retval OT_ERROR_Failed     Failed to open/connect the client's UDP socket.
*/
otError otSrpClientStart(otInstance *aInstance,const otSockAddr *aServerSockAddr);

srp_client.h

otError otSrpClientStart(otInstance *aInstance,const otSockAddr *aServerSockAddr)
otError otSrpClientSetHostName(otInstance *aInstance,const char *aName)
otError otSrpClientAddService(otInstance *aInstance,otSrpClientService *aService)

我的 Main.c

#include <openthread/srp_client.h>

static void SrpClientinit(void){

otSrpClientStart(**What comes in here?**,**How can i Use the EUI64 as IP?**)
otSrpClientSetHostName(**What comes in here?**,'SrpTest')
otSrpClientAddService(**What comes in here?**,**What comes in here?**)

}


int main(int argc,char *argv[]){
....
SrpClientinit();
....
}

谁能解释我如何定义函数的参数?

解决方法

这是我的代码,我可以刷入固件,但 Thread 设备不再连接到 Thread 网络。

void SrpClientInit(void)
{  

otSockAddr SRP_1;
SRP_1.mAddress.mFields.mComponents.mIid.mFields.m8[0] = 0xff;
SRP_1.mPort = 0xff;
otSockAddr *SRP_1_pointer = &SRP_1;

otIp6Address SRPaddr;
SRPaddr.mFields.m16[0] = 0xfff;
otIp6Address *SRPaddr_pointer = &SRPaddr;


otSrpClientService SRPclient;
SRPclient.mName = "_knx._udp";
SRPclient.mInstanceName = "fancy-service";
//SRPclient.mTxtEntries->mKey = NULL;
SRPclient.mPort = 12356;
SRPclient.mPriority = 1;
SRPclient.mWeight = 1;
SRPclient.mNumTxtEntries = 1;
otSrpClientService *SRPclient_pointer = &SRPclient;

otSrpClientSetHostName(sInstance,"SRPtest");
otSrpClientSetHostAddresses(sInstance,SRPaddr_pointer,0x0f);
otSrpClientAddService(sInstance,SRPclient_pointer);
otSrpClientStart(sInstance,SRP_1_pointer);
} 

srp_client.h

#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1
#define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE 1