qcloud_iot_device.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "qcloud_iot_device.h"
  22. #include <stdbool.h>
  23. #include <string.h>
  24. #include "qcloud_iot_export.h"
  25. int iot_device_info_set(DeviceInfo *device_info, const char *product_id, const char *device_name)
  26. {
  27. memset(device_info, 0x0, sizeof(DeviceInfo));
  28. if ((MAX_SIZE_OF_PRODUCT_ID) < strlen(product_id)) {
  29. Log_e("product name(%s) length:(%lu) exceeding limitation", product_id, strlen(product_id));
  30. return QCLOUD_ERR_FAILURE;
  31. }
  32. if ((MAX_SIZE_OF_DEVICE_NAME) < strlen(device_name)) {
  33. Log_e("device name(%s) length:(%lu) exceeding limitation", device_name, strlen(device_name));
  34. return QCLOUD_ERR_FAILURE;
  35. }
  36. strncpy(device_info->product_id, product_id, MAX_SIZE_OF_PRODUCT_ID);
  37. strncpy(device_info->device_name, device_name, MAX_SIZE_OF_DEVICE_NAME);
  38. /* construct device-id(@product_id+@device_name) */
  39. memset(device_info->client_id, 0x0, MAX_SIZE_OF_CLIENT_ID);
  40. int ret = HAL_Snprintf(device_info->client_id, MAX_SIZE_OF_CLIENT_ID, "%s%s", product_id, device_name);
  41. if ((ret < 0) || (ret >= MAX_SIZE_OF_CLIENT_ID)) {
  42. Log_e("set device info failed");
  43. return QCLOUD_ERR_FAILURE;
  44. }
  45. Log_i("SDK_Ver: %s, Product_ID: %s, Device_Name: %s", QCLOUD_IOT_DEVICE_SDK_VERSION, device_info->product_id,
  46. device_info->device_name);
  47. return QCLOUD_RET_SUCCESS;
  48. }
  49. #ifdef __cplusplus
  50. }
  51. #endif