pando_gateway.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*******************************************************
  2. * File name: pando_gateway.h
  3. * Author:
  4. * Versions:1.0
  5. * Description:This module is the interface of the pando gateway.
  6. * History:
  7. * 1.Date:
  8. * Author:
  9. * Modification:
  10. *********************************************************/
  11. #include "pando_gateway.h"
  12. #include "pando_device_register.h"
  13. #include "pando_device_login.h"
  14. #include "pando_cloud_access.h"
  15. #include "gateway_defs.h"
  16. #include "pando_sys.h"
  17. #include "pando_zero_device.h"
  18. #include "pando_timer.h"
  19. #include "platform_miscellaneous_interface.h"
  20. #include "pando_storage_interface.h"
  21. extern void load_data_from_flash();
  22. static GATEWAY_STATUS gateway_status;
  23. static int8_t device_connect_check(void * arg);
  24. struct pd_timer gateway_timer;
  25. /******************************************************************************
  26. * FunctionName : gateway_cb
  27. * Description : the gateway callback function.
  28. * Parameters : the gateway flow return value.
  29. * Returns : none
  30. *******************************************************************************/
  31. void FUNCTION_ATTRIBUTE
  32. gateway_cb(int8_t result)
  33. {
  34. switch(gateway_status)
  35. {
  36. case GATEWAY_LOGIN:
  37. if(result == PANDO_NOT_REGISTERED)
  38. {
  39. gateway_status = GATEWAY_REGISTER;
  40. pando_device_register(gateway_cb);
  41. }
  42. else if(result == PANDO_LOGIN_OK)
  43. {
  44. gateway_status = GATEWAY_ACCESS;
  45. pando_cloud_access(gateway_cb);
  46. }
  47. else
  48. {
  49. pando_timer_start(&gateway_timer);
  50. }
  51. break;
  52. case GATEWAY_REGISTER:
  53. if(result == PANDO_REGISTER_OK)
  54. {
  55. pando_cloud_access(gateway_cb);
  56. }
  57. else
  58. {
  59. pando_timer_start(&gateway_timer);
  60. }
  61. break;
  62. default:
  63. pando_timer_start(&gateway_timer);
  64. break;
  65. }
  66. }
  67. /******************************************************************************
  68. * FunctionName : device_connect_check
  69. * Description : check wehter the device connect the net. if device has connected the net,
  70. * start the gateway flow.
  71. * Parameters : none
  72. * Returns : none
  73. *******************************************************************************/
  74. static int8_t FUNCTION_ATTRIBUTE
  75. device_connect_check(void * arg)
  76. {
  77. if(net_connect_check() == 1)
  78. {
  79. gateway_status = GATEWAY_LOGIN;
  80. pando_timer_stop(&gateway_timer);
  81. pando_device_login(gateway_cb);
  82. }
  83. else
  84. {
  85. return 0;
  86. }
  87. }
  88. /******************************************************************************
  89. * FunctionName : pando_gateway_init
  90. * Description : initialize the gateway.
  91. * Parameters : none
  92. * Returns : none
  93. *******************************************************************************/
  94. void FUNCTION_ATTRIBUTE
  95. pando_gateway_init()
  96. {
  97. pd_printf("PANDO gateway initial....\n");
  98. gateway_status = GATEWAY_INIT;
  99. load_data_from_flash();
  100. //pando_system_time_init();
  101. pando_zero_device_init();
  102. gateway_timer.interval = 5000;
  103. gateway_timer.repeated = 1;
  104. gateway_timer.timer_cb = device_connect_check;
  105. gateway_timer.timer_no = 2;
  106. pando_timer_init(&gateway_timer);
  107. pando_timer_stop(&gateway_timer);
  108. pando_timer_start(&gateway_timer);
  109. }