mirror of
https://github.com/pelgraine/Meck.git
synced 2026-05-15 22:05:53 +02:00
595f0073f9
SerialBLEInterface.cpp — added esp_bt.h include and three esp_ble_tx_power_set calls at +9 dBm after BLEDevice::init(), covering default, advertising, and scan power types. MyMesh.h — FIRMWARE_VER_CODE bumped from 10 → 11. MyMesh.cpp — The RESP_CODE_DEVICE_INFO frame construction now: Byte 2: sends 0xFF (sentinel) when MAX_CONTACTS > 510, otherwise the normal MAX_CONTACTS / 2. Older apps interpret 0xFF as 510 contacts — completely harmless. Bytes 80-81 (new, appended after the version string): uint16_t little-endian with the true MAX_CONTACTS value. Apps that understand v11+ read it here. Apps < v11 ignore trailing bytes — the BLE/serial frame protocol is length-delimited, so extra bytes at the tail are safe. platformio.ini — Both BLE builds (meck_audio_ble, meck_4g_ble) bumped from 510 → 2000. mymesh.cpp: writeContactRespFrame return type change (return _serial->writeFrame() result) checkSerialInterface() batch-fill loop.
93 lines
2.8 KiB
C++
93 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "../BaseSerialInterface.h"
|
|
#include <BLEDevice.h>
|
|
#include <BLEServer.h>
|
|
#include <BLEUtils.h>
|
|
#include <BLE2902.h>
|
|
|
|
class SerialBLEInterface : public BaseSerialInterface, BLESecurityCallbacks, BLEServerCallbacks, BLECharacteristicCallbacks {
|
|
BLEServer *pServer;
|
|
BLEService *pService;
|
|
BLECharacteristic * pTxCharacteristic;
|
|
bool deviceConnected;
|
|
bool oldDeviceConnected;
|
|
bool _isEnabled;
|
|
uint16_t last_conn_id;
|
|
uint8_t _remote_bda[6]; // peer BDA, stored in onConnect for conn param updates
|
|
uint32_t _pin_code;
|
|
unsigned long _last_write;
|
|
unsigned long adv_restart_time;
|
|
|
|
struct Frame {
|
|
uint8_t len;
|
|
uint8_t buf[MAX_FRAME_SIZE];
|
|
};
|
|
|
|
#define FRAME_QUEUE_SIZE 16
|
|
int recv_queue_len;
|
|
Frame recv_queue[FRAME_QUEUE_SIZE];
|
|
int send_queue_len;
|
|
Frame send_queue[FRAME_QUEUE_SIZE];
|
|
|
|
void clearBuffers() { recv_queue_len = 0; send_queue_len = 0; }
|
|
|
|
protected:
|
|
// BLESecurityCallbacks methods
|
|
uint32_t onPassKeyRequest() override;
|
|
void onPassKeyNotify(uint32_t pass_key) override;
|
|
bool onConfirmPIN(uint32_t pass_key) override;
|
|
bool onSecurityRequest() override;
|
|
void onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl) override;
|
|
|
|
// BLEServerCallbacks methods
|
|
void onConnect(BLEServer* pServer) override;
|
|
void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) override;
|
|
void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) override;
|
|
void onDisconnect(BLEServer* pServer) override;
|
|
|
|
// BLECharacteristicCallbacks methods
|
|
void onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param) override;
|
|
|
|
public:
|
|
SerialBLEInterface() {
|
|
pServer = NULL;
|
|
pService = NULL;
|
|
deviceConnected = false;
|
|
oldDeviceConnected = false;
|
|
adv_restart_time = 0;
|
|
_isEnabled = false;
|
|
_last_write = 0;
|
|
last_conn_id = 0;
|
|
memset(_remote_bda, 0, 6);
|
|
send_queue_len = recv_queue_len = 0;
|
|
}
|
|
|
|
/**
|
|
* init the BLE interface.
|
|
* @param prefix a prefix for the device name
|
|
* @param name IN/OUT - a name for the device (combined with prefix). If "@@MAC", is modified and returned
|
|
* @param pin_code the BLE security pin
|
|
*/
|
|
void begin(const char* prefix, char* name, uint32_t pin_code);
|
|
|
|
// BaseSerialInterface methods
|
|
void enable() override;
|
|
void disable() override;
|
|
bool isEnabled() const override { return _isEnabled; }
|
|
|
|
bool isConnected() const override;
|
|
|
|
bool isWriteBusy() const override;
|
|
size_t writeFrame(const uint8_t src[], size_t len) override;
|
|
size_t checkRecvFrame(uint8_t dest[]) override;
|
|
};
|
|
|
|
#if BLE_DEBUG_LOGGING && ARDUINO
|
|
#include <Arduino.h>
|
|
#define BLE_DEBUG_PRINT(F, ...) Serial.printf("BLE: " F, ##__VA_ARGS__)
|
|
#define BLE_DEBUG_PRINTLN(F, ...) Serial.printf("BLE: " F "\n", ##__VA_ARGS__)
|
|
#else
|
|
#define BLE_DEBUG_PRINT(...) {}
|
|
#define BLE_DEBUG_PRINTLN(...) {}
|
|
#endif |