mpbledev.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef MPBLEDEV
  2. #define MPBLEDEV
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include "_string.h"
  7. #include "nrf_gpio.h"
  8. #include "epb_MmBp.h"
  9. #include "ble_wechat_util.h"
  10. #include "ble_wechat.h"
  11. #include "app_error.h"
  12. #include "nrf_log.h"
  13. #include "nrf_log_ctrl.h"
  14. #include "nrf_log_default_backends.h"
  15. #define CMD_NULL 0
  16. #define CMD_AUTH 1
  17. #define CMD_INIT 2
  18. #define CMD_SENDDAT 3
  19. #define DEVICE_TYPE "WeChatDev"
  20. #define DEVICE_ID "WeChatBluetoothDevice"
  21. #define PROTO_VERSION 0x010004
  22. #define AUTH_PROTO 1
  23. #define MAC_ADDRESS_LENGTH 6
  24. //#define EAM_md5AndNoEnrypt 1 //认证方式只能定义其中的一种
  25. #define EAM_md5AndAesEnrypt 1
  26. //#define EAM_macNoEncrypt 2
  27. #define DEVICE_KEY {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
  28. #ifdef EAM_macNoEncrypt
  29. #define AUTH_METHOD EAM_macNoEncrypt
  30. #define MD5_TYPE_AND_ID_LENGTH 0
  31. #define CIPHER_TEXT_LENGTH 0
  32. #endif
  33. #ifdef EAM_md5AndAesEnrypt
  34. #define AUTH_METHOD EAM_md5AndAesEnrypt
  35. #define MD5_TYPE_AND_ID_LENGTH 16
  36. #define CIPHER_TEXT_LENGTH 16
  37. #endif
  38. #ifdef EAM_md5AndNoEnrypt
  39. #define AUTH_METHOD EAM_md5AndNoEnrypt
  40. #define MD5_TYPE_AND_ID_LENGTH 16
  41. #define CIPHER_TEXT_LENGTH 0
  42. #endif
  43. #define CHALLENAGE_LENGTH 4
  44. #define mpbledev_MAGICCODE_H 0xfe
  45. #define mpbledev_MAGICCODE_L 0xcf
  46. #define mpbledev_VERSION 0x01
  47. //#define SEND_HELLO_WECHAT "Hello, WeChat!"
  48. #define SEND_HELLO_WECHAT "Hello, WeChat!"
  49. /* Hardware Resources define */
  50. #define mpbledev_LIGHT 19
  51. #define mpbledev_BUTTON_1 17
  52. typedef enum
  53. {
  54. errorCodeUnpackAuthResp = 0x9990,
  55. errorCodeUnpackInitResp = 0x9991,
  56. errorCodeUnpackSendDataResp = 0x9992,
  57. errorCodeUnpackCtlCmdResp = 0x9993,
  58. errorCodeUnpackRecvDataPush = 0x9994,
  59. errorCodeUnpackSwitchViewPush = 0x9995,
  60. errorCodeUnpackSwitchBackgroundPush = 0x9996,
  61. errorCodeUnpackErrorDecode = 0x9997,
  62. }mpbledevUnpackErrorCode;
  63. typedef enum
  64. {
  65. errorCodeProduce = 0x9980,
  66. }mpbledevPackErrorCode;
  67. typedef enum
  68. {
  69. sendTextReq = 0x01,
  70. sendTextResp = 0x1001,
  71. openLightPush = 0x2001,
  72. closeLightPush = 0x2002,
  73. }BleDemo2CmdID;
  74. typedef struct
  75. {
  76. uint8_t m_magicCode[2];
  77. uint16_t m_version;
  78. uint16_t m_totalLength;
  79. uint16_t m_cmdid;
  80. uint16_t m_seq;
  81. uint16_t m_errorCode;
  82. }BlueDemoHead;
  83. typedef struct
  84. {
  85. int cmd;
  86. CString send_msg;
  87. } mpbledev_info;
  88. typedef struct
  89. {
  90. bool wechats_switch_state; //公众账号切换到前台的状态
  91. bool indication_state;
  92. bool auth_state;
  93. bool init_state;
  94. bool auth_send;
  95. bool init_send;
  96. unsigned short send_data_seq;
  97. unsigned short push_data_seq;
  98. unsigned short seq;
  99. }mpbledev_state;
  100. void ble_mpbledev_on_ble_evt(void *p_wcs, void *p_ble_evt);
  101. extern data_handler *m_mpbledev_handler;
  102. extern data_handler mpbledev_data_handler;
  103. #endif