一、定义回调指针
typedef void (*pRpcRxBtCallBack)(char len, char *buf);
typedef void (*pRpcPreSleepNotifyCallback)(uint8_t sleepmode);
typedef void (*pRpcWakeupNotifyCallback)( char wakeUpSource);
typedef void (*pRpcTimeCalcNotifyCallback)(TimeInfo *pTimeInfo, TimeCalcFlag type);
typedef void (*pRpcEcallNotifyCallback)( char ecallType);
typedef void (*pRpcRxTboxDtcCallback)( short len, char *buf);
typedef void (*pRpcRxAirBagInfoCallback)( short len, char *buf);
typedef void (*pRpcClientConnetNotify)( RpcConnectStatus connectStatus);
二、定义结构体指针
typedef struct rpcRxCallBack
{
pRpcRxBtCallBack rpcRxBtCallBack;
pRpcPreSleepNotifyCallback rpcPreSleepNotifyCallback;
pRpcWakeupNotifyCallback rpcWakeupNotifyCallback;
pRpcTimeCalcNotifyCallback rpcTimeCalcNotifyCallback;
pRpcEcallNotifyCallback rpcEcallNotifyCallback;
pRpcRxTboxDtcCallback rpcRxTboxDtcCallback;
pRpcRxAirBagInfoCallback rpcRxAirBagInfoCallback;
}RpcCallBack;
三、定义全局结构体
RpcCallBack g_rpcCallBack;
static RpcCallBack *RpcGetClientCallback(void)
{
return &g_rpcCallBack;
}
三、注册函数
void RpcRegisterCallback (RpcCallBack rpcCallBack)
{
RpcCallBack *pRpcCallBack = RpcGetClientCallback();
if(NULL != rpcCallBack.rpcRxBtCallBack)
{
pRpcCallBack->rpcRxBtCallBack = rpcCallBack.rpcRxBtCallBack;
}
else
{
pRpcCallBack->rpcRxBtCallBack = NULL;
}
}
四、实例
void BytonDidDemoConnetNotify(RpcConnectStatus connectStatus)
{
}
void BytonEcallClientReister(void)
{
RpcCallBack rpcCallBack;
rpcCallBack.rpcRxBtCallBack = NULL;
rpcCallBack.rpcCanCallBack = NULL;
rpcCallBack.rpcRxCantpFrameData = NULL;
rpcCallBack.prpcRxdidInfo = BytonDidDemoRxDidInfo;
rpcCallBack.rpcClientConnetNotify = BytonDidDemoConnetNotify;
RpcRegisterCallback(rpcCallBack);
}