|
5 | 5 |
|
6 | 6 | class BTSerialInterface |
7 | 7 | { |
8 | | - public: |
9 | | - virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0; |
10 | | - virtual void disconnect() = 0; |
11 | | - virtual void end() = 0; |
12 | | - virtual esp_err_t register_callback(esp_spp_cb_t * callback) = 0; |
13 | | - virtual void setTimeout(unsigned long timeout) = 0; |
14 | | - |
15 | | - virtual int available() = 0; |
16 | | - virtual size_t readBytes(uint8_t *buffer, size_t bufferSize) = 0; |
17 | | - |
18 | | - virtual bool isCongested() = 0; |
19 | | - virtual size_t write(const uint8_t *buffer, size_t size) = 0; |
20 | | - virtual void flush() = 0; |
| 8 | + public: |
| 9 | + virtual bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) = 0; |
| 10 | + virtual void disconnect() = 0; |
| 11 | + virtual void end() = 0; |
| 12 | + virtual esp_err_t register_callback(esp_spp_cb_t * callback) = 0; |
| 13 | + virtual void setTimeout(unsigned long timeout) = 0; |
| 14 | + |
| 15 | + virtual int available() = 0; |
| 16 | + virtual size_t readBytes(uint8_t *buffer, size_t bufferSize) = 0; |
| 17 | + |
| 18 | + virtual bool isCongested() = 0; |
| 19 | + virtual size_t write(const uint8_t *buffer, size_t size) = 0; |
| 20 | + virtual void flush() = 0; |
21 | 21 | }; |
22 | 22 |
|
23 | 23 |
|
24 | 24 | class BTClassicSerial : public virtual BTSerialInterface, public BluetoothSerial |
25 | 25 | { |
26 | 26 | // Everything is already implemented in BluetoothSerial since the code was |
27 | 27 | // originally written using that class |
28 | | - public: |
29 | | - bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) |
30 | | - { |
31 | | - return BluetoothSerial::begin(deviceName, isMaster, rxQueueSize, txQueueSize); |
32 | | - } |
33 | | - |
34 | | - void disconnect() |
35 | | - { |
36 | | - BluetoothSerial::disconnect(); |
37 | | - } |
38 | | - |
39 | | - void end() |
40 | | - { |
41 | | - BluetoothSerial::end(); |
42 | | - } |
43 | | - |
44 | | - esp_err_t register_callback(esp_spp_cb_t * callback) |
45 | | - { |
46 | | - return BluetoothSerial::register_callback(callback); |
47 | | - } |
48 | | - |
49 | | - void setTimeout(unsigned long timeout) |
50 | | - { |
51 | | - BluetoothSerial::setTimeout(timeout); |
52 | | - } |
53 | | - |
54 | | - int available() |
55 | | - { |
56 | | - return BluetoothSerial::available(); |
57 | | - } |
58 | | - |
59 | | - size_t readBytes(uint8_t *buffer, size_t bufferSize) |
60 | | - { |
61 | | - return BluetoothSerial::readBytes(buffer, bufferSize); |
62 | | - } |
63 | | - |
64 | | - bool isCongested() |
65 | | - { |
66 | | - return BluetoothSerial::isCongested(); |
67 | | - } |
68 | | - |
69 | | - size_t write(const uint8_t *buffer, size_t size) |
70 | | - { |
71 | | - return BluetoothSerial::write(buffer, size); |
72 | | - } |
73 | | - |
74 | | - void flush() |
75 | | - { |
76 | | - BluetoothSerial::flush(); |
77 | | - } |
| 28 | + public: |
| 29 | + bool begin(String deviceName, bool isMaster, uint16_t rxQueueSize, uint16_t txQueueSize) |
| 30 | + { |
| 31 | + return BluetoothSerial::begin(deviceName, isMaster, rxQueueSize, txQueueSize); |
| 32 | + } |
| 33 | + |
| 34 | + void disconnect() |
| 35 | + { |
| 36 | + BluetoothSerial::disconnect(); |
| 37 | + } |
| 38 | + |
| 39 | + void end() |
| 40 | + { |
| 41 | + BluetoothSerial::end(); |
| 42 | + } |
| 43 | + |
| 44 | + esp_err_t register_callback(esp_spp_cb_t * callback) |
| 45 | + { |
| 46 | + return BluetoothSerial::register_callback(callback); |
| 47 | + } |
| 48 | + |
| 49 | + void setTimeout(unsigned long timeout) |
| 50 | + { |
| 51 | + BluetoothSerial::setTimeout(timeout); |
| 52 | + } |
| 53 | + |
| 54 | + int available() |
| 55 | + { |
| 56 | + return BluetoothSerial::available(); |
| 57 | + } |
| 58 | + |
| 59 | + size_t readBytes(uint8_t *buffer, size_t bufferSize) |
| 60 | + { |
| 61 | + return BluetoothSerial::readBytes(buffer, bufferSize); |
| 62 | + } |
| 63 | + |
| 64 | + bool isCongested() |
| 65 | + { |
| 66 | + return BluetoothSerial::isCongested(); |
| 67 | + } |
| 68 | + |
| 69 | + size_t write(const uint8_t *buffer, size_t size) |
| 70 | + { |
| 71 | + return BluetoothSerial::write(buffer, size); |
| 72 | + } |
| 73 | + |
| 74 | + void flush() |
| 75 | + { |
| 76 | + BluetoothSerial::flush(); |
| 77 | + } |
78 | 78 | }; |
79 | 79 |
|
80 | 80 |
|
81 | 81 | class BTLESerial: public virtual BTSerialInterface, public BleSerial |
82 | 82 | { |
83 | | - public: |
84 | | - // Missing from BleSerial |
85 | | - bool begin(String deviceName, bool isMaster, uint16_t rxQueueSuze, uint16_t txQueueSize) |
86 | | - { |
87 | | - // Curretnly ignoring rxQueueSize |
88 | | - // transmitBufferLength = txQueueSize; |
89 | | - BleSerial::begin(deviceName.c_str()); |
90 | | - return true; |
91 | | - } |
92 | | - |
93 | | - void disconnect() |
94 | | - { |
95 | | - Server->disconnect(Server->getConnId()); |
96 | | - } |
97 | | - |
98 | | - void end() |
99 | | - { |
100 | | - BleSerial::end(); |
101 | | - } |
102 | | - |
103 | | - esp_err_t register_callback(esp_spp_cb_t * callback) |
104 | | - { |
105 | | - connectionCallback = callback; |
106 | | - return ESP_OK; |
107 | | - } |
108 | | - |
109 | | - void setTimeout(unsigned long timeout) |
110 | | - { |
111 | | - BleSerial::setTimeout(timeout); |
112 | | - } |
113 | | - |
114 | | - int available() |
115 | | - { |
116 | | - return BleSerial::available(); |
117 | | - } |
118 | | - |
119 | | - size_t readBytes(uint8_t *buffer, size_t bufferSize) |
120 | | - { |
121 | | - return BleSerial::readBytes(buffer, bufferSize); |
122 | | - } |
123 | | - |
124 | | - bool isCongested() |
125 | | - { |
126 | | - // not currently supported in this implementation |
127 | | - return false; |
128 | | - } |
129 | | - |
130 | | - size_t write(const uint8_t *buffer, size_t size) |
131 | | - { |
132 | | - return BleSerial::write(buffer, size); |
133 | | - } |
134 | | - |
135 | | - void flush() |
136 | | - { |
137 | | - BleSerial::flush(); |
138 | | - } |
139 | | - |
140 | | - // override BLEServerCallbacks |
141 | | - void onConnect(BLEServer *pServer) |
142 | | - { |
143 | | - bleConnected = true; |
144 | | - connectionCallback(ESP_SPP_SRV_OPEN_EVT, nullptr); |
145 | | - } |
146 | | - |
147 | | - void onDisconnect(BLEServer *pServer) |
148 | | - { |
149 | | - bleConnected = false; |
150 | | - connectionCallback(ESP_SPP_CLOSE_EVT, nullptr); |
151 | | - Server->startAdvertising(); |
152 | | - } |
153 | | - |
154 | | - private: |
155 | | - esp_spp_cb_t * connectionCallback; |
| 83 | + public: |
| 84 | + // Missing from BleSerial |
| 85 | + bool begin(String deviceName, bool isMaster, uint16_t rxQueueSuze, uint16_t txQueueSize) |
| 86 | + { |
| 87 | + // Curretnly ignoring rxQueueSize |
| 88 | + // transmitBufferLength = txQueueSize; |
| 89 | + BleSerial::begin(deviceName.c_str()); |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + void disconnect() |
| 94 | + { |
| 95 | + Server->disconnect(Server->getConnId()); |
| 96 | + } |
| 97 | + |
| 98 | + void end() |
| 99 | + { |
| 100 | + BleSerial::end(); |
| 101 | + } |
| 102 | + |
| 103 | + esp_err_t register_callback(esp_spp_cb_t * callback) |
| 104 | + { |
| 105 | + connectionCallback = callback; |
| 106 | + return ESP_OK; |
| 107 | + } |
| 108 | + |
| 109 | + void setTimeout(unsigned long timeout) |
| 110 | + { |
| 111 | + BleSerial::setTimeout(timeout); |
| 112 | + } |
| 113 | + |
| 114 | + int available() |
| 115 | + { |
| 116 | + return BleSerial::available(); |
| 117 | + } |
| 118 | + |
| 119 | + size_t readBytes(uint8_t *buffer, size_t bufferSize) |
| 120 | + { |
| 121 | + return BleSerial::readBytes(buffer, bufferSize); |
| 122 | + } |
| 123 | + |
| 124 | + bool isCongested() |
| 125 | + { |
| 126 | + // not currently supported in this implementation |
| 127 | + return false; |
| 128 | + } |
| 129 | + |
| 130 | + size_t write(const uint8_t *buffer, size_t size) |
| 131 | + { |
| 132 | + return BleSerial::write(buffer, size); |
| 133 | + } |
| 134 | + |
| 135 | + void flush() |
| 136 | + { |
| 137 | + BleSerial::flush(); |
| 138 | + } |
| 139 | + |
| 140 | + // override BLEServerCallbacks |
| 141 | + void onConnect(BLEServer *pServer) |
| 142 | + { |
| 143 | + bleConnected = true; |
| 144 | + connectionCallback(ESP_SPP_SRV_OPEN_EVT, nullptr); |
| 145 | + } |
| 146 | + |
| 147 | + void onDisconnect(BLEServer *pServer) |
| 148 | + { |
| 149 | + bleConnected = false; |
| 150 | + connectionCallback(ESP_SPP_CLOSE_EVT, nullptr); |
| 151 | + Server->startAdvertising(); |
| 152 | + } |
| 153 | + |
| 154 | + private: |
| 155 | + esp_spp_cb_t * connectionCallback; |
156 | 156 |
|
157 | 157 | }; |
158 | 158 |
|
|
0 commit comments