简介
vendor模型,即厂家自定义模型,在通用模型中没有的功能,可以在vendor模型中通过自定义的方式来添加厂家特有的功能!
vendor在SDK里面,有两种应用方法:
1.以raw的方式(透传),该方式需要填写目标地址和应用密钥
2.以publish的方式,该方式只需填写目标地址
应用层流程(raw透传的方式)
SDK代码参考
(以下代码是一些代码片段,需要了解完整内容的话,可以在工程里面进行全局搜索!)
vendor模型底层传输处理
vendormodel_client.c
vendormodel_server.c
客户端接收处理:
初始化时,MS_vendormodel_client_init把应用层的UI_phy_model_client_cb注册到vendormodel_client_UI_cb上!
收到信息后,先进入vendormodel_client_cb处理,然后再通过vendormodel_client_UI_cb调用应用层的UI_phy_model_client_cb!
服务端接收处理:
初始化时,MS_vendormodel_server_init把应用层的UI_phy_model_server_cb注册到vendormodel_server_UI_cb上!
收到信息后,先进入vendormodel_server_cb处理,然后再通过vendormodel_server_UI_cb调用应用层的UI_phy_model_server_c
vendor模型应用层处理
客户端:
注册vendor client 模型
/* Register Vendor Defined model server */
retval = UI_register_vendor_defined_model_client(element_handle);
绑定appkey到vendor client模型
UI_config_client_appkey_binding(0,0,UI_appkey);
#ifdef USE_VENDORMODEL
retval=MS_access_bind_model_app(UI_vendor_defined_client_model_handle, handle);
CONSOLE_OUT("BINDING App Key %04x (%04x %04x)\n",retval,UI_vendor_defined_client_model_handle,handle);
#endif
设置目标地址(与publish的区别就是需要在发送时,填写目标地址)
UI_vendor_model_set_raw_addr();//
填充发送数据
#if 1
UINT8 ttl;
MS_STATE_VENDOR_EXAMPLE_TEST_STRUCT param;
ACCESS_CM_GET_DEFAULT_TTL(ttl);
param.total_len = test_len+7;
MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.total_len);
marker += 2;
param.is_to_be_ack = ack_en;
MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.is_to_be_ack);
marker++;
param.message_index = test_index;
MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.message_index);
marker += 2;
param.osal_tick = osal_sys_tick&0xffff;
MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.osal_tick);
marker += 2;
param.ttl = ttl;
MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.ttl);
marker++;
param.data_len = test_len;
MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.data_len);
marker++;
if(param.data_len)
{
EM_mem_set(&buffer[marker], 0, param.data_len);
marker += param.data_len;
}
set_param.vendormodel_param = &buffer[0];
获取模型appkey
MS_access_get_appkey_handle
(
&vendormodel_client_model_handle,
&key_handle
);
用MS_access_raw_data发送数据(发送raw未经加工的数据专业,类似于透传!!)
retval = MS_access_raw_data
(
&vendormodel_client_model_handle,
req_opcode,
dst_addr,
key_handle,
pdu_ptr,
marker,
MS_FALSE
);
服务端:
注册vendor server 模型
/* Register Vendor Defined model server */
retval = UI_register_vendor_defined_model_server(element_handle);
绑定appkey
vm_subscriptiong_binding_cb();
#ifdef USE_VENDORMODEL
retval=MS_access_bind_model_app(UI_vendor_defined_server_model_handle, handle);
CONSOLE_OUT("BINDING App Key %04x (%04x %04x)\n",retval,UI_vendor_defined_server_model_handle,handle);
#endif
vendor回调里面的notify数据处理
case MS_ACCESS_VENDORMODEL_NOTIFY_OPCODE:
{
uint16 message_index;
uint32 osal_tick;
UINT8 ack;
UINT8 ttl;
UINT8 len;
ACCESS_CM_GET_RX_TTL(ttl);
data_param = state_params->vendormodel_param;
MS_UNPACK_LE_1_BYTE(&ack, data_param+marker);
marker += 1;
MS_UNPACK_LE_2_BYTE(&message_index, data_param+marker);
marker += 2;
MS_UNPACK_LE_2_BYTE(&osal_tick, data_param+marker);
marker += 3;
MS_UNPACK_LE_1_BYTE(&len, data_param+marker);
marker += 1;
marker = 0;
if(ack)
{
MS_PACK_LE_1_BYTE_VAL(data_param+marker,++vendor_tid);
marker++;
MS_PACK_LE_1_BYTE_VAL(data_param+marker,0);
marker++;
MS_PACK_LE_2_BYTE_VAL(data_param+marker,message_index);
marker += 2;
MS_PACK_LE_2_BYTE_VAL(data_param+marker,osal_tick);
marker += 2;
MS_PACK_LE_1_BYTE_VAL(data_param+marker,ttl&0xff);
marker++;
MS_PACK_LE_1_BYTE_VAL(data_param+marker,len&0xff);
marker++;
if(len)
{
EM_mem_set(data_param+marker, 0, len);
marker += len;
}
state_params->vendormodel_param = data_param;
req_type->to_be_acked = 0x01;
}
// printf("[PDU_Rx] Pkt.INDEX:0x%04X\n",message_index);
}
发送回复
/* See if to be acknowledged */
if (0x01 == req_type->to_be_acked)
{
// CONSOLE_OUT(
// "[VENDOR_EXAMPLE] Sending Response.\n");
/* Parameters: Request Context, Current State, Target State (NULL: to be ignored), Remaining Time (0: to be ignored), Additional Parameters (NULL: to be ignored) */
retval = MS_vendormodel_server_state_update(ctx, ¤t_state_params, NULL, 0, NULL,marker);
}
客户端:
收到回复,打印信息
case MS_ACCESS_VENDORMODEL_NOTIFY_OPCODE:
{
uint16 message_index;
UINT8 ttl;
marker = 2;
MS_UNPACK_LE_2_BYTE(&message_index, msg_raw->data_param+marker);
marker += 4;
MS_UNPACK_LE_1_BYTE(&ttl, msg_raw->data_param+marker);
marker ++;
CONSOLE_OUT("[PDU_Rx] Pkt.INDEX:0x%04X,SRC:0x%04X,DST:0x%04X,TTL:0x%02X,TICK:0x%08X\r\n",
message_index,ctx->daddr,saddr,ttl,osal_sys_tick);
}
break;