简介

config模型,专门用来给节点做“配置”用的,例如,订阅、发布、绑定appkey等配置。

应用流程(端对端直接控制方式)

image.png

SDK代码参考

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

客户端:
初始化

  1. 注册config client模型
  2. /* Register Configuration model client */
  3. retval = UI_register_config_model_client(element_handle);

设置config client发布地址和devicekey

  1. /* Set the Publish address for Config Client */
  2. UI_set_publish_address(UI_prov_data.uaddr, UI_config_client_model_handle,MS_TRUE);

发送获取Composition数据命令

  1. /* Get the Composition data */
  2. UI_config_client_get_composition_data(0x00);

服务端:
初始化

  1. 注册config server模型
  2. /* Register foundation model servers */
  3. retval = UI_register_foundation_model_servers(element_handle);
  4. APP_config_server_CB_init(UI_app_config_server_callback);
  5. 获取devicekey
  6. UI_sample_get_device_key();

不处理Composition命令,返回Composition状态

  1. null

客户端:
发送添加appkey命令

  1. /* Add Appkey */
  2. UI_config_client_appkey_add(0, 0, UI_appkey);

服务端:
绑定appkey到各个模型

  1. case MS_ACCESS_CONFIG_APPKEY_ADD_OPCODE:
  2. #ifdef EASY_BOUNDING
  3. blebrr_scan_pl(FALSE);
  4. ms_provisioner_addr = saddr;
  5. vm_subscriptiong_binding_cb();//重要
  6. // ms_provisioner_addr = saddr;
  7. #if (CFG_HEARTBEAT_MODE)
  8. UI_trn_set_heartbeat_subscription(saddr);
  9. #endif
  10. #else
  11. // CONSOLE_OUT("Stop timer\n");
  12. ms_provisioner_addr = saddr;
  13. // EM_stop_timer(&procfg_timer_handle);
  14. blebrr_prov_started = MS_FALSE;
  15. #endif
  16. break;

客户端:
处理appkey添加完成响应回调

  1. case MS_ACCESS_CONFIG_APPKEY_STATUS_OPCODE:
  2. {
  3. CONSOLE_OUT(
  4. "MS_ACCESS_CONFIG_APPKEY_STATUS_OPCODE\n");
  5. #ifdef EASY_BOUNDING
  6. UI_SET_RAW_DATA_DST_ADDR(UI_prov_data.uaddr);
  7. MS_access_cm_set_transmit_state(MS_NETWORK_TX_STATE, (0<<3)|0);
  8. /* Set provision started */
  9. blebrr_prov_started = MS_FALSE;
  10. EM_stop_timer(&procfg_timer_handle);
  11. CONSOLE_OUT(
  12. "PROVISION AND CONFIG DONE!!!\n");
  13. // UI_config_proxy_set(0);
  14. /* Send a Generic ON */
  15. #else
  16. /* Bind the model to Appkey */
  17. UI_config_client_model_app_bind(UI_prov_data.uaddr, 0, MS_ACCESS_MODEL_TYPE_SIG, MS_MODEL_ID_GENERIC_ONOFF_SERVER);
  18. #endif
  19. }