医美代码重构
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /*
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. /*
  8. 1.
  9. 2.()
  10. 3.
  11. */
  12. #pragma once
  13. #include <stdbool.h>
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. /*
  19. * DEFINES
  20. ****************************************************************************************
  21. */
  22. //#define SUPPORT_HEARTBEAT
  23. //#define SPP_DEBUG_MODE
  24. #define spp_sprintf(s, ...) sprintf((char *)(s), ##__VA_ARGS__)
  25. #define SPP_DATA_MAX_LEN (512)
  26. #define SPP_CMD_MAX_LEN (20)
  27. #define SPP_STATUS_MAX_LEN (20)
  28. #define SPP_DATA_BUFF_MAX_LEN (2 * 1024)
  29. /// Attributes State Machine
  30. enum {
  31. SPP_IDX_SVC,
  32. SPP_IDX_SPP_DATA_NOTIFY_CHAR,
  33. SPP_IDX_SPP_DATA_NTY_VAL,
  34. SPP_IDX_SPP_DATA_NTF_CFG,
  35. SPP_IDX_SPP_DATA_RECV_CHAR,
  36. SPP_IDX_SPP_DATA_RECV_VAL,
  37. // SPP_IDX_SPP_COMMAND_CHAR,
  38. // SPP_IDX_SPP_COMMAND_VAL,
  39. // SPP_IDX_SPP_STATUS_CHAR,
  40. // SPP_IDX_SPP_STATUS_VAL,
  41. // SPP_IDX_SPP_STATUS_CFG,
  42. #ifdef SUPPORT_HEARTBEAT
  43. SPP_IDX_SPP_HEARTBEAT_CHAR,
  44. SPP_IDX_SPP_HEARTBEAT_VAL,
  45. SPP_IDX_SPP_HEARTBEAT_CFG,
  46. #endif
  47. SPP_IDX_NB,
  48. };
  49. typedef struct {
  50. uint8_t *rxbuf;
  51. size_t rxbufsize;
  52. uint8_t *txbuf;
  53. size_t txbufsize;
  54. size_t rxpacketReceiveOvertime;
  55. bool receive_data_processing_flag;
  56. int has_rx_size;
  57. int maxClientNum;
  58. const char *bleName;
  59. int last_rx_ticket;
  60. bool ble_connect_flag;
  61. } bleuart_t;
  62. /*接收完整JSON*/
  63. typedef void (*blerxcb_t)(uint8_t *rx, size_t rxsize);
  64. typedef uint8_t (*blesetmotorcb_t)(int rotation_direction, double position, int speed_level);
  65. void bleuart_init(bleuart_t *bleuart);
  66. void bleuart_reg_cb(blerxcb_t cb);
  67. void ble_set_motor_reg_cb(blesetmotorcb_t cb);
  68. void bleuart_send_packet(uint8_t *tx, size_t txsize);
  69. /**
  70. * @brief
  71. */
  72. void bleuart_schedule();
  73. void bleuart_notify_send(uint8_t *buffer, uint8_t buffer_size);