pando_zero_device.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*******************************************************
  2. * File name: pando_zero_device.c
  3. * Author: Chongguang Li
  4. * Versions: 1.0
  5. * Description:This module is used to process the gateway business.
  6. * History:
  7. * 1.Date:
  8. * Author:
  9. * Modification:
  10. *********************************************************/
  11. #include "pando_channel.h"
  12. #include "pando_types.h"
  13. #include "sub_device_protocol.h"
  14. //#include "pando_system_time.h"
  15. #include "pando_zero_device.h"
  16. #include "pando_sys.h"
  17. #define COMMON_COMMAND_UPGRADE 65529
  18. #define COMMON_COMMAND_REBOOT 65535
  19. #define COMMON_COMMAND_SYN_TIME 65531
  20. /******************************************************************************
  21. * FunctionName : zero_device_data_process.
  22. * Description : process the received data of zero device(zero device is the gateway itself).
  23. * Parameters : uint.
  24. * Returns : none.
  25. *******************************************************************************/
  26. static void FUNCTION_ATTRIBUTE
  27. zero_device_data_process(uint8_t * buffer, uint16_t length)
  28. {
  29. struct pando_command cmd_body;
  30. uint16_t type = 0;
  31. uint16_t len = 0;
  32. struct sub_device_buffer * device_buffer = (struct sub_device_buffer *)pd_malloc(sizeof(struct sub_device_buffer));
  33. if(device_buffer == NULL)
  34. {
  35. pd_printf("%s:malloc error!\n", __func__);
  36. return;
  37. }
  38. device_buffer->buffer = (uint8_t*)pd_malloc(length);
  39. if(device_buffer->buffer == NULL)
  40. {
  41. pd_printf("%s:malloc error!\n", __func__);
  42. pd_free(device_buffer);
  43. return;
  44. }
  45. pd_memcpy(device_buffer->buffer, buffer, length);
  46. device_buffer->buffer_length = length;
  47. struct TLVs *cmd_param = get_sub_device_command(device_buffer, &cmd_body);
  48. if(COMMON_COMMAND_SYN_TIME == cmd_body.command_num )
  49. {
  50. pd_printf("PANDO: synchronize time\n");
  51. uint64_t time = get_next_uint64(cmd_param);
  52. show_package((uint8_t*)(&time), sizeof(time));
  53. // pando_set_system_time(time);
  54. }
  55. if( device_buffer->buffer != NULL)
  56. {
  57. pd_free( device_buffer->buffer);
  58. device_buffer->buffer = NULL;
  59. }
  60. if(device_buffer != NULL)
  61. {
  62. pd_free(device_buffer);
  63. device_buffer = NULL;
  64. }
  65. }
  66. /******************************************************************************
  67. * FunctionName : ipando_zero_device_init
  68. * Description : initialize the zero device(zero device is the gateway itself).
  69. * Parameters : none.
  70. * Returns : none.
  71. *******************************************************************************/
  72. void FUNCTION_ATTRIBUTE
  73. pando_zero_device_init(void)
  74. {
  75. on_subdevice_channel_recv(PANDO_CHANNEL_PORT_0, zero_device_data_process);
  76. }