gateway_message.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "gateway_message.h"
  2. #include "string.h"
  3. #include <stdlib.h>
  4. static GATEWAY_PARAMS gateway_config_params = {0};
  5. GATEWAY_PARAMS *get_gateway_config_params()
  6. {
  7. return &gateway_config_params;
  8. }
  9. /**
  10. * @brief 向网关结构体内新增一个节点信息
  11. * @param cJSON *data_obj 网关结构体信息、const char* nodeId新增的节点ID
  12. * @retval 无
  13. */
  14. void addNode(GATEWAY_PARAMS* gateway, const char* nodeId) {
  15. // 增加节点数量
  16. NODE_PARAMS* newNode = (NODE_PARAMS*)malloc(sizeof(NODE_PARAMS));
  17. strcpy((char *)&newNode->node_address,nodeId);
  18. newNode->device_params = NULL; //先将其设备挂载为NULL
  19. newNode->nextNode = NULL; //下一个设备的挂载为NULL
  20. // 添加节点到网关链表中
  21. if (gateway->node_params == NULL) {
  22. gateway->node_params = newNode;
  23. }
  24. else
  25. {
  26. NODE_PARAMS* current = gateway->node_params;
  27. while (current->nextNode != NULL) {
  28. current = current->nextNode;
  29. }
  30. current->nextNode = newNode;
  31. }
  32. }
  33. /**
  34. * @brief 向节点下新增设备
  35. * @param NODE_PARAMS* node往那个节点中加入新的设备,const char* deviceName将设备地址当作其唯一标识
  36. * @retval 无
  37. */
  38. void addDevice(NODE_PARAMS* node,const uint8_t* deviceName)
  39. {
  40. // 创建新设备页
  41. DEVICE_PARAMS* newDevicePage = (DEVICE_PARAMS*)malloc(sizeof(DEVICE_PARAMS));
  42. newDevicePage->nextDevice = NULL;
  43. // 添加设备页到链表末尾
  44. if (node->device_params == NULL) {
  45. node->device_params = newDevicePage;
  46. } else {
  47. DEVICE_PARAMS* current = node->device_params;
  48. while (current->nextDevice != NULL) {
  49. current = current->nextDevice;
  50. }
  51. current->nextDevice = newDevicePage;
  52. }
  53. }
  54. void addParams()
  55. {
  56. }