用adv_vendor_self_provison中,
?//?檢查命令執(zhí)行狀態(tài),如果超時(shí)未收到應(yīng)答則打印提示信息 ????if(val->vendor_model_srv_Hdr.status) ????{ ????????APP_DBG("Timeout?opcode?0x%02x",?val->vendor_model_srv_Hdr.opcode); ????????return; ????} ????//?根據(jù)操作碼執(zhí)行相應(yīng)的操作 ????if(val->vendor_model_srv_Hdr.opcode?==?OP_VENDOR_MESSAGE_TRANSPARENT_MSG) ????{ ????????//?接收
其中這段代碼val->vendor_model_srv_Hdr.opcode?==?OP_VENDOR_MESSAGE_TRANSPARENT_MSG
和下面這段代碼中return vendor_message_srv_send_trans(¶m, pData, len); 是對(duì)應(yīng)的用于發(fā)送透?jìng)餍畔?/p>
static?int?vendor_model_srv_send(uint16_t?addr,?uint8_t?*pData,?uint16_t?len) { ????//?發(fā)送參數(shù)的設(shè)定 ????struct?send_param?param?=?{ ????????.app_idx?=?vnd_models[0].keys[0],?//?使用的應(yīng)用密鑰索引 ????????.addr?=?addr,??????????????????????//?發(fā)往的目標(biāo)地址 ????????.trans_cnt?=?0x01,?????????????????//?用戶層發(fā)送次數(shù) ????????.period?=?K_MSEC(400),?????????????//?消息重傳的間隔 ????????.rand?=?(0),???????????????????????//?發(fā)送的隨機(jī)延時(shí) ????????.tid?=?vendor_srv_tid_get(),???????//?消息的事務(wù)標(biāo)識(shí) ????????.send_ttl?=?BLE_MESH_TTL_DEFAULT,??//?消息的TTL值 ????}; ????//?發(fā)送應(yīng)答指示消息或透?jìng)飨? ????//return?vendor_message_srv_indicate(¶m,?pData,?len);??//?發(fā)送應(yīng)答指示消息,超時(shí)默認(rèn)為2秒 ????return?vendor_message_srv_send_trans(¶m,?pData,?len);?//?發(fā)送透?jìng)飨ⅲ瑹o應(yīng)答機(jī)制 }
由于透?jìng)靼l(fā)送信息是無應(yīng)答機(jī)制的,我現(xiàn)在想用應(yīng)答指示消息vendor_message_srv_indicate(¶m, pData, len);來發(fā)送透?jìng)飨ⅰ?span>我想實(shí)現(xiàn)的效果是:AB兩個(gè)點(diǎn),當(dāng)A點(diǎn)給B點(diǎn)發(fā)送消息,B點(diǎn)返回一個(gè)確認(rèn)碼給A,A收到確認(rèn)碼之后發(fā)送信息給節(jié)點(diǎn)B。
我具體應(yīng)該如何修改下面的代碼呢?
節(jié)點(diǎn)A發(fā)送部分代碼利用一個(gè)測(cè)試事件來執(zhí)行,代碼如下:
if?(events?&?APP_NODE_TEST_EVT)?{ ????????uint8_t?status; ????????uint8_t?data[4]?=?{?0,?1,?2,?3?};?//?準(zhǔn)備要發(fā)送的測(cè)試數(shù)據(jù) ????????status?=?vendor_model_srv_send(0x0002,?data,?sizeof(data)); ????????if?(status)?//?如果發(fā)送失敗,打印錯(cuò)誤狀態(tài) ????????????APP_DBG("trans?failed?%d",?status); ????????tmos_start_task(App_TaskID,?APP_NODE_TEST_EVT,?4800); ????????}
節(jié)點(diǎn)A的接收部分,當(dāng)節(jié)點(diǎn)A接收到節(jié)點(diǎn)B發(fā)送的信息后,打印兩節(jié)點(diǎn)之間的RSSI值,然后再定義一個(gè)數(shù)據(jù)發(fā)送給節(jié)點(diǎn)B。
if?(val->vendor_model_srv_Hdr.opcode?==?OP_VENDOR_MESSAGE_TRANSPARENT_MSG)?{ ????????//?接收 ????????struct?bt_mesh_msg_ctx?*ctx?=?(struct?bt_mesh_msg_ctx?*)?val->mydata; //????????if(ctx->addr==self_prov_addr) //????????????return; ????????if?(ctx->addr?==?0x0002)?{ ????????APP_DBG("DATA---src:0x%04x?self_addr:0x%04x?rssi:%d",?ctx->addr,?self_prov_addr,?ctx->recv_rssi);? ????????//?發(fā)送 ????????????int?status; ????????????//?準(zhǔn)備發(fā)送的數(shù)據(jù)數(shù)組 ????????????uint8_t?data[8]?=?{?0,?1,?2,?3,?4,?5,?6,?7?}; ????????????//?通過自定義模型發(fā)送數(shù)據(jù)到訂閱地址 ????????????status?=?vendor_model_srv_send(0x0002,?data,?8); ????????????if?(status)?{ ????????????????//?如果發(fā)送失敗,打印失敗信息 ????????????????APP_DBG("send?failed?%d",?status); ????????????} ???????? ????????} ????????}
節(jié)點(diǎn)B的接收部分,當(dāng)節(jié)點(diǎn)B接收到節(jié)點(diǎn)A發(fā)送的信息后,打印兩節(jié)點(diǎn)之間的RSSI值,然后再定義一個(gè)數(shù)據(jù)發(fā)送給節(jié)點(diǎn)A。
if?(val->vendor_model_srv_Hdr.opcode?==?OP_VENDOR_MESSAGE_TRANSPARENT_MSG)?{ ????????//?接收 ????????struct?bt_mesh_msg_ctx?*ctx?=?(struct?bt_mesh_msg_ctx?*)?val->mydata; //????????if(ctx->addr==self_prov_addr) //????????????return; ????????if?(ctx->addr?==?0x0001)?{ ????????APP_DBG("DATA---src:0x%04x?self_addr:0x%04x?rssi:%d",?ctx->addr,?self_prov_addr,?ctx->recv_rssi);? ????????//?發(fā)送 ????????????int?status; ????????????//?準(zhǔn)備發(fā)送的數(shù)據(jù)數(shù)組 ????????????uint8_t?data[8]?=?{?0,?1,?2,?3,?4,?5,?6,?7?}; ????????????//?通過自定義模型發(fā)送數(shù)據(jù)到訂閱地址 ????????????status?=?vendor_model_srv_send(0x0001,?data,?8); ????????????if?(status)?{ ????????????????//?如果發(fā)送失敗,打印失敗信息 ????????????????APP_DBG("send?failed?%d",?status); ????????????} ???????? ????????} ????????}