gagent_cloud_demo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * File : gagent_tool.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-01-03 flyingcys first version
  23. */
  24. #include <rtthread.h>
  25. #include "gagent_cloud.h"
  26. #ifdef RT_USING_FINSH
  27. #include <finsh.h>
  28. #endif
  29. #define DEMO_PRODUCT_KEY "1371df627fa64e849f32fe17ebd5fd38"
  30. #define DEMO_PRODUCT_KEY_SECRET "067a83b650544d979bb3d4d147f32034"
  31. #define DEMO_MAC "\xBC\x12\x34\x56\x78\x23"
  32. static gagent_cloud_param gagent_param;
  33. int gagent_read_param(void *param, rt_uint32_t len)
  34. {
  35. /* read param */
  36. return RT_EOK;
  37. }
  38. int gagent_write_param(void *param, rt_uint32_t len)
  39. {
  40. /* write param */
  41. return RT_EOK;
  42. }
  43. int gagent_recv_packet(rt_uint8_t from, rt_uint8_t action, rt_uint8_t *kv, rt_uint16_t kv_len)
  44. {
  45. /* please read product protocol */
  46. uint8_t power;
  47. switch(action)
  48. {
  49. case ACTION_CONTROL:
  50. rt_kprintf("ACTION_CONTROL\r\n");
  51. power = *(kv + 1);
  52. rt_kprintf("power:%d\n", power);
  53. gagent_cloud_send_packet(ACTION_REPORT_STATUS, &power, 1);
  54. break;
  55. case ACTION_READ_STATUS:
  56. rt_kprintf("ACTION_READ_STATUS\r\n");
  57. // gagent_cloud_send_packet(ACTION_READ_STATUS_ACK, buf, buf_len);
  58. break;
  59. case ACTION_TRANS_RECV:
  60. rt_kprintf("this is your raw data from app\r\n");
  61. break;
  62. case ACTION_PUSH_OTA:
  63. rt_kprintf("ACTION_PUSH_OTA\r\n");
  64. break;
  65. }
  66. return RT_EOK;
  67. }
  68. int gagent_cloud(void)
  69. {
  70. int rc = RT_EOK;
  71. rt_memset(&gagent_param, 0, sizeof(gagent_param));
  72. //
  73. strcpy(gagent_param.product_key, DEMO_PRODUCT_KEY);
  74. strcpy(gagent_param.product_secret, DEMO_PRODUCT_KEY_SECRET);
  75. strcpy(gagent_param.mac, DEMO_MAC);
  76. gagent_param.read_param_callback = gagent_read_param;
  77. gagent_param.write_param_callback = gagent_write_param;
  78. gagent_param.recv_packet_callback = gagent_recv_packet;
  79. //
  80. gagent_cloud_start(&gagent_param);
  81. return rc;
  82. }
  83. #ifdef RT_USING_FINSH
  84. MSH_CMD_EXPORT(gagent_cloud, gagent cloud demo);
  85. FINSH_FUNCTION_EXPORT(gagent_cloud, "gagent cloud test");
  86. #endif