Skip to content

Commit

Permalink
split Bluetooth driver over platform-specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Feb 22, 2024
1 parent 3cdda56 commit d2926c7
Show file tree
Hide file tree
Showing 8 changed files with 2,116 additions and 2,006 deletions.
1,851 changes: 1 addition & 1,850 deletions software/firmware/source/SoftRF/src/driver/Bluetooth.cpp

Large diffs are not rendered by default.

159 changes: 3 additions & 156 deletions software/firmware/source/SoftRF/src/driver/Bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,164 +32,11 @@ enum
#endif

#if defined(ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2)

#define UART_SERVICE_UUID16 ((uint16_t) 0xFFE0)
#define UART_CHARACTERISTIC_UUID16 ((uint16_t) 0xFFE1)
#define UART_SERVICE_UUID128 "0000ffe0-0000-1000-8000-00805f9b34fb"
#define UART_CHARACTERISTIC_UUID128 "0000ffe1-0000-1000-8000-00805f9b34fb"

#define MIDI_SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
#define MIDI_CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"

#define UUID16_SVC_BATTERY ((uint16_t) 0x180F)
#define UUID16_CHR_BATTERY_LEVEL ((uint16_t) 0x2A19)

#define UUID16_SVC_DEVICE_INFORMATION ((uint16_t) 0x180A)
#define UUID16_CHR_MODEL_NUMBER_STRING ((uint16_t) 0x2A24)
#define UUID16_CHR_SERIAL_NUMBER_STRING ((uint16_t) 0x2A25)
#define UUID16_CHR_FIRMWARE_REVISION_STRING ((uint16_t) 0x2A26)
#define UUID16_CHR_HARDWARE_REVISION_STRING ((uint16_t) 0x2A27)
#define UUID16_CHR_SOFTWARE_REVISION_STRING ((uint16_t) 0x2A28)
#define UUID16_CHR_MANUFACTURER_NAME_STRING ((uint16_t) 0x2A29)

#define SENSBOX_SERVICE_UUID "aba27100-143b-4b81-a444-edcd0000f020"
#define NAVIGATION_CHARACTERISTIC_UUID "aba27100-143b-4b81-a444-edcd0000f022"
#define MOVEMENT_CHARACTERISTIC_UUID "aba27100-143b-4b81-a444-edcd0000f023"
#define GPS2_CHARACTERISTIC_UUID "aba27100-143b-4b81-a444-edcd0000f024"
#define SYSTEM_CHARACTERISTIC_UUID "aba27100-143b-4b81-a444-edcd0000f025"

/* (FLAA x MAX_TRACKING_OBJECTS + GNGGA + GNRMC + FLAU) x 80 symbols */
#define BLE_FIFO_TX_SIZE 1024
#define BLE_FIFO_RX_SIZE 256

#define BLE_MAX_WRITE_CHUNK_SIZE 20

extern IODev_ops_t ESP32_Bluetooth_ops;

#include "../platform/bluetooth/Bluedroid.h"
#elif defined(ARDUINO_ARCH_NRF52)

#include "bluefruit_common.h"

#include "BLECharacteristic.h"
#include "BLEService.h"

class BLESensBox : public BLEService
{
protected:
BLECharacteristic _sensbox_nav;
BLECharacteristic _sensbox_move;
BLECharacteristic _sensbox_gps2;
BLECharacteristic _sensbox_sys;

public:
BLESensBox(void);

virtual err_t begin(void);

bool notify_nav (uint8_t);
bool notify_move(uint8_t);
bool notify_gps2(uint8_t);
bool notify_sys (uint8_t);
};

/*
* Source:
* https://github.com/flytec/SensBoxLib_iOS/blob/master/_SensBox%20Documentation/SensorBox%20BLE%20Protocol.pdf
*/
typedef struct {
uint32_t timestamp; /* Date/Time (UTC), UnixTime */
int32_t lat; /* deg * 10^7 */
int32_t lon; /* deg * 10^7 */
int16_t gnss_alt; /* GPS Hight MSL, m */
int16_t pres_alt; /* Pressure Altitude, m */
int16_t vario; /* Vario 1 Hz, cm/s */
uint8_t status; /* Status: 0..2 - GNSS, 3 - time, 4 - charge, 5 - Bat, 6 - Log */
} __attribute__((packed)) sensbox_navigation_t;

typedef struct {
int32_t pres_alt; /* Pressure Altitude, cm */
int16_t vario; /* Vario 8 Hz, cm/s */
int16_t gs; /* Ground Speed, dm/s */
int16_t cog; /* GPS Heading, deg * 10 */
int16_t pitch; /* deg * 10 */
int16_t yaw; /* deg * 10 */
int16_t roll; /* deg * 10 */
uint16_t accel; /* Acceleration, 'g' * 10 */
uint8_t status; /* Status: same as above */
} __attribute__((packed)) sensbox_movement_t;

typedef struct {
uint16_t accuracy_h; /* Horizontal Accuracy, dm */
uint16_t accuracy_v; /* Vertical Accuracy, dm */
int16_t geo_separ; /* GPS Height Ellipsoid, m */
uint8_t sats; /* Number of satellites */
uint8_t status; /* Status: same as above */
} __attribute__((packed)) sensbox_gps2_t;

typedef struct {
uint32_t timestamp; /* Date/Time (UTC), UnixTime */
uint8_t battery; /* Battery Level, % */
uint8_t log; /* Logging level, % */
int16_t temp; /* Temperature, °C * 10 */
uint8_t status; /* Status: same as above */
uint8_t status2;
uint16_t qnh; /* QNH, Pa * 10 */
int32_t pressure; /* mPa */
} __attribute__((packed)) sensbox_system_t;

#define isTimeToSensBox() (millis() - BLE_SensBox_TimeMarker > 500) /* 2 Hz */

extern IODev_ops_t nRF52_Bluetooth_ops;

#include "../platform/bluetooth/Bluefruit.h"
#elif defined(ARDUINO_ARCH_RP2040) && defined(ARDUINO_RASPBERRY_PI_PICO_W)

//
// list service handle ranges
//
#define ATT_SERVICE_GAP_SERVICE_START_HANDLE 0x0001
#define ATT_SERVICE_GAP_SERVICE_END_HANDLE 0x0003
#define ATT_SERVICE_GAP_SERVICE_01_START_HANDLE 0x0001
#define ATT_SERVICE_GAP_SERVICE_01_END_HANDLE 0x0003
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_START_HANDLE 0x0004
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_END_HANDLE 0x0007
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_01_START_HANDLE 0x0004
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_01_END_HANDLE 0x0007
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION_START_HANDLE 0x0008
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION_END_HANDLE 0x001a
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION_01_START_HANDLE 0x0008
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION_01_END_HANDLE 0x001a
#define ATT_SERVICE_FFE0_START_HANDLE 0x001b
#define ATT_SERVICE_FFE0_END_HANDLE 0x001f
#define ATT_SERVICE_FFE0_01_START_HANDLE 0x001b
#define ATT_SERVICE_FFE0_01_END_HANDLE 0x001f

//
// list mapping between characteristics and handles
//
#define ATT_CHARACTERISTIC_GAP_DEVICE_NAME_01_VALUE_HANDLE 0x0003
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_01_VALUE_HANDLE 0x0006
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_01_CLIENT_CONFIGURATION_HANDLE 0x0007
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING_01_VALUE_HANDLE 0x000a
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING_01_VALUE_HANDLE 0x000c
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_SERIAL_NUMBER_STRING_01_VALUE_HANDLE 0x000e
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_HARDWARE_REVISION_STRING_01_VALUE_HANDLE 0x0010
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_FIRMWARE_REVISION_STRING_01_VALUE_HANDLE 0x0012
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_SOFTWARE_REVISION_STRING_01_VALUE_HANDLE 0x0014
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_SYSTEM_ID_01_VALUE_HANDLE 0x0016
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST_01_VALUE_HANDLE 0x0018
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_PNP_ID_01_VALUE_HANDLE 0x001a
#define ATT_CHARACTERISTIC_FFE1_01_VALUE_HANDLE 0x001d
#define ATT_CHARACTERISTIC_FFE1_01_CLIENT_CONFIGURATION_HANDLE 0x001e
#define ATT_CHARACTERISTIC_FFE1_01_USER_DESCRIPTION_HANDLE 0x001f

/* (FLAA x MAX_TRACKING_OBJECTS + GNGGA + GNRMC + FLAU) x 80 symbols */
#define BLE_FIFO_TX_SIZE 1024
#define BLE_FIFO_RX_SIZE 256

#define BLE_MAX_WRITE_CHUNK_SIZE 20

extern IODev_ops_t CYW43_Bluetooth_ops;

#include "../platform/bluetooth/BTstack.h"
#endif /* ESP32 or ARDUINO_ARCH_NRF52 or ARDUINO_ARCH_RP2040 */

#endif /* BLUETOOTHHELPER_H */
Loading

0 comments on commit d2926c7

Please sign in to comment.