简介

vendor模型,即厂家自定义模型,在通用模型中没有的功能,可以在vendor模型中通过自定义的方式来添加厂家特有的功能!
vendor在SDK里面,有两种应用方法:
1.以raw的方式(透传),该方式需要填写目标地址和应用密钥
2.以publish的方式,该方式只需填写目标地址

应用层流程(raw透传的方式)

image.png

SDK代码参考

以下代码是一些代码片段,需要了解完整内容的话,可以在工程里面进行全局搜索!)

vendor模型底层传输处理

  1. vendormodel_client.c
  2. vendormodel_server.c

客户端接收处理:

  1. 初始化时,MS_vendormodel_client_init把应用层的UI_phy_model_client_cb注册到vendormodel_client_UI_cb上!
  2. 收到信息后,先进入vendormodel_client_cb处理,然后再通过vendormodel_client_UI_cb调用应用层的UI_phy_model_client_cb

服务端接收处理:

  1. 初始化时,MS_vendormodel_server_init把应用层的UI_phy_model_server_cb注册到vendormodel_server_UI_cb上!
  2. 收到信息后,先进入vendormodel_server_cb处理,然后再通过vendormodel_server_UI_cb调用应用层的UI_phy_model_server_c

vendor模型应用层处理
客户端:

  1. 注册vendor client 模型
  2. /* Register Vendor Defined model server */
  3. retval = UI_register_vendor_defined_model_client(element_handle);
  4. 绑定appkeyvendor client模型
  5. UI_config_client_appkey_binding(0,0,UI_appkey);
  6. #ifdef USE_VENDORMODEL
  7. retval=MS_access_bind_model_app(UI_vendor_defined_client_model_handle, handle);
  8. CONSOLE_OUT("BINDING App Key %04x (%04x %04x)\n",retval,UI_vendor_defined_client_model_handle,handle);
  9. #endif

设置目标地址(与publish的区别就是需要在发送时,填写目标地址)

  1. UI_vendor_model_set_raw_addr();//

填充发送数据

  1. #if 1
  2. UINT8 ttl;
  3. MS_STATE_VENDOR_EXAMPLE_TEST_STRUCT param;
  4. ACCESS_CM_GET_DEFAULT_TTL(ttl);
  5. param.total_len = test_len+7;
  6. MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.total_len);
  7. marker += 2;
  8. param.is_to_be_ack = ack_en;
  9. MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.is_to_be_ack);
  10. marker++;
  11. param.message_index = test_index;
  12. MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.message_index);
  13. marker += 2;
  14. param.osal_tick = osal_sys_tick&0xffff;
  15. MS_PACK_LE_2_BYTE_VAL(&buffer[marker], param.osal_tick);
  16. marker += 2;
  17. param.ttl = ttl;
  18. MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.ttl);
  19. marker++;
  20. param.data_len = test_len;
  21. MS_PACK_LE_1_BYTE_VAL(&buffer[marker], param.data_len);
  22. marker++;
  23. if(param.data_len)
  24. {
  25. EM_mem_set(&buffer[marker], 0, param.data_len);
  26. marker += param.data_len;
  27. }
  28. set_param.vendormodel_param = &buffer[0];

获取模型appkey

  1. MS_access_get_appkey_handle
  2. (
  3. &vendormodel_client_model_handle,
  4. &key_handle
  5. );

用MS_access_raw_data发送数据(发送raw未经加工的数据专业,类似于透传!!)

  1. retval = MS_access_raw_data
  2. (
  3. &vendormodel_client_model_handle,
  4. req_opcode,
  5. dst_addr,
  6. key_handle,
  7. pdu_ptr,
  8. marker,
  9. MS_FALSE
  10. );

服务端:

  1. 注册vendor server 模型
  2. /* Register Vendor Defined model server */
  3. retval = UI_register_vendor_defined_model_server(element_handle);
  4. 绑定appkey
  5. vm_subscriptiong_binding_cb();
  6. #ifdef USE_VENDORMODEL
  7. retval=MS_access_bind_model_app(UI_vendor_defined_server_model_handle, handle);
  8. CONSOLE_OUT("BINDING App Key %04x (%04x %04x)\n",retval,UI_vendor_defined_server_model_handle,handle);
  9. #endif

vendor回调里面的notify数据处理

  1. case MS_ACCESS_VENDORMODEL_NOTIFY_OPCODE:
  2. {
  3. uint16 message_index;
  4. uint32 osal_tick;
  5. UINT8 ack;
  6. UINT8 ttl;
  7. UINT8 len;
  8. ACCESS_CM_GET_RX_TTL(ttl);
  9. data_param = state_params->vendormodel_param;
  10. MS_UNPACK_LE_1_BYTE(&ack, data_param+marker);
  11. marker += 1;
  12. MS_UNPACK_LE_2_BYTE(&message_index, data_param+marker);
  13. marker += 2;
  14. MS_UNPACK_LE_2_BYTE(&osal_tick, data_param+marker);
  15. marker += 3;
  16. MS_UNPACK_LE_1_BYTE(&len, data_param+marker);
  17. marker += 1;
  18. marker = 0;
  19. if(ack)
  20. {
  21. MS_PACK_LE_1_BYTE_VAL(data_param+marker,++vendor_tid);
  22. marker++;
  23. MS_PACK_LE_1_BYTE_VAL(data_param+marker,0);
  24. marker++;
  25. MS_PACK_LE_2_BYTE_VAL(data_param+marker,message_index);
  26. marker += 2;
  27. MS_PACK_LE_2_BYTE_VAL(data_param+marker,osal_tick);
  28. marker += 2;
  29. MS_PACK_LE_1_BYTE_VAL(data_param+marker,ttl&0xff);
  30. marker++;
  31. MS_PACK_LE_1_BYTE_VAL(data_param+marker,len&0xff);
  32. marker++;
  33. if(len)
  34. {
  35. EM_mem_set(data_param+marker, 0, len);
  36. marker += len;
  37. }
  38. state_params->vendormodel_param = data_param;
  39. req_type->to_be_acked = 0x01;
  40. }
  41. // printf("[PDU_Rx] Pkt.INDEX:0x%04X\n",message_index);
  42. }

发送回复

  1. /* See if to be acknowledged */
  2. if (0x01 == req_type->to_be_acked)
  3. {
  4. // CONSOLE_OUT(
  5. // "[VENDOR_EXAMPLE] Sending Response.\n");
  6. /* Parameters: Request Context, Current State, Target State (NULL: to be ignored), Remaining Time (0: to be ignored), Additional Parameters (NULL: to be ignored) */
  7. retval = MS_vendormodel_server_state_update(ctx, &current_state_params, NULL, 0, NULL,marker);
  8. }

客户端:
收到回复,打印信息

  1. case MS_ACCESS_VENDORMODEL_NOTIFY_OPCODE:
  2. {
  3. uint16 message_index;
  4. UINT8 ttl;
  5. marker = 2;
  6. MS_UNPACK_LE_2_BYTE(&message_index, msg_raw->data_param+marker);
  7. marker += 4;
  8. MS_UNPACK_LE_1_BYTE(&ttl, msg_raw->data_param+marker);
  9. marker ++;
  10. CONSOLE_OUT("[PDU_Rx] Pkt.INDEX:0x%04X,SRC:0x%04X,DST:0x%04X,TTL:0x%02X,TICK:0x%08X\r\n",
  11. message_index,ctx->daddr,saddr,ttl,osal_sys_tick);
  12. }
  13. break;