ble_wechat_util.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef BLE_WECHAT_UTIL
  2. #define BLE_WECHAT_UTIL
  3. #include <stdint.h>
  4. #include "_string.h"
  5. #define PRODUCT_TYPE_UNKNOWN 0
  6. #define PRODUCT_TYPE_MPBBLEDEV 1
  7. typedef void (*data_produce_func)(void *args, uint8_t **r_data, uint32_t *r_len);
  8. typedef void (*data_free_func)(uint8_t *data, uint32_t len);
  9. typedef int (*data_consume_func)(uint8_t *data, uint32_t len);
  10. typedef void (*data_error_func)(int error_code);
  11. typedef int32_t (*data_button_handler_func)(void *p_wcs, uint8_t pin_no);
  12. typedef void (*data_main_process_func)(void *p_wcs);
  13. typedef int32_t (*data_init_func)(void);
  14. typedef void (*data_on_ble_evt_func)(void *p_wcs, void * p_ble_evt);
  15. typedef struct data_handler{
  16. int m_product_type;
  17. data_produce_func m_data_produce_func;
  18. data_free_func m_data_free_func;
  19. data_consume_func m_data_consume_func;
  20. data_error_func m_data_error_func;
  21. data_on_ble_evt_func m_data_on_ble_evt_func;
  22. data_init_func m_data_init_func;
  23. data_main_process_func m_data_main_process_func;
  24. data_button_handler_func m_data_button_handler_func;
  25. void *m_data_produce_args;
  26. struct data_handler *next;
  27. } data_handler;
  28. extern data_handler first_handler;
  29. #define REGISTER(NAME) \
  30. do { \
  31. data_handler *tmp = &NAME##_data_handler; \
  32. tmp->next = first_handler.next; \
  33. first_handler.next = tmp; \
  34. } while(0)
  35. #define ARGS_ITEM_SET(ARGS_TYPE, ARGS_POINTER, ITEM_NAME, ITEM_VALUE) \
  36. do { \
  37. ARGS_TYPE *tmp = (ARGS_TYPE *)ARGS_POINTER; \
  38. tmp->ITEM_NAME = ITEM_VALUE; \
  39. } while(0)
  40. typedef struct
  41. {
  42. unsigned char bMagicNumber;
  43. unsigned char bVer;
  44. unsigned short nLength;
  45. unsigned short nCmdId;
  46. unsigned short nSeq;
  47. } BpFixHead;
  48. data_handler* get_handler_by_type(int type);
  49. unsigned short htons(unsigned short val);
  50. unsigned short ntohs(unsigned short val);
  51. unsigned long t_htonl(unsigned long h);
  52. unsigned long t_ntohl(unsigned long n);
  53. #endif