Direct-BT v3.2.3-1-g688f983
Direct-BT - Direct Bluetooth Programming.
Classes | Functions | Variables
dbt_peripheral00.cpp File Reference

This _dbt_peripheral00__ C++ peripheral ::BTRole::Slave GATT server example uses an event driven workflow. More...

#include <cstring>
#include <string>
#include <memory>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <cinttypes>
#include <pthread.h>
#include <csignal>
#include <jau/cpp_lang_util.hpp>
#include <jau/dfa_utf8_decode.hpp>
#include <jau/basic_algos.hpp>
#include <jau/darray.hpp>
#include <direct_bt/DirectBT.hpp>
#include <unistd.h>
#include "dbt_constants.hpp"
#include <cstdio>
Include dependency graph for dbt_peripheral00.cpp:

Go to the source code of this file.

Classes

class  MyAdapterStatusListener
 
class  MyGATTServerListener
 

Functions

DBGattServerRef dbGattServer (new DBGattServer(jau::make_darray(std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid16_t >(GattServiceType::GENERIC_ACCESS), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::DEVICE_NAME), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue(adapter_name.c_str(), 128), true), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::APPEARANCE), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue((uint16_t) 0)))), std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid16_t >(GattServiceType::DEVICE_INFORMATION), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::MANUFACTURER_NAME_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("Gothel Software")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::MODEL_NUMBER_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("2.4.0-pre")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::SERIAL_NUMBER_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("sn:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::HARDWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("hw:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::FIRMWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("fw:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::SOFTWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("sw:0123456789")))), std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid128_t >(DataServiceUUID), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(StaticDataUUID), BTGattChar::PropertyBitVal::Read, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("DATA_STATIC"))), make_gvalue("Proprietary Static Data 0x00010203")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(CommandUUID), BTGattChar::PropertyBitVal::WriteNoAck|BTGattChar::PropertyBitVal::WriteWithAck, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("COMMAND"))), make_gvalue(128, 64), true), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(ResponseUUID), BTGattChar::PropertyBitVal::Notify|BTGattChar::PropertyBitVal::Indicate, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("RESPONSE")), DBGattDesc::createClientCharConfig()), make_gvalue((uint16_t) 0)), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(PulseDataUUID), BTGattChar::PropertyBitVal::Notify|BTGattChar::PropertyBitVal::Indicate, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("DATA_PULSE")), DBGattDesc::createClientCharConfig()), make_gvalue("Synthethic Sensor 01")))))))
 
static BTDeviceRef getDevice ()
 
static bool initAdapter (std::shared_ptr< BTAdapter > &adapter)
 
int main (int argc, char *argv[])
 
static bool matches (const BTDeviceRef &device)
 
static void myChangedAdapterSetFunc (const bool added, std::shared_ptr< BTAdapter > &adapter)
 
static void processDisconnectedDevice (BTDeviceRef device)
 
static void setDevice (const BTDeviceRef &cd)
 
static bool startAdvertising (BTAdapter *a, std::string msg)
 
static bool stopAdvertising (BTAdapter *a, std::string msg)
 
void test ()
 

Variables

static std::string adapter_name = "TestDev001_N"
 
static SMPIOCapability adapter_sec_io_cap = SMPIOCapability::UNSET
 
static BTSecurityLevel adapter_sec_level = BTSecurityLevel::UNSET
 
static std::string adapter_short_name = "TDev001N"
 
static const uint8_t adv_chan_map =0x07
 
static const uint16_t adv_interval_max =480
 
static const uint16_t adv_interval_min =160
 
static const AD_PDU_Type adv_type =AD_PDU_Type::ADV_IND
 
static BTMode btMode = BTMode::DUAL
 
static std::shared_ptr< BTAdapterchosenAdapter = nullptr
 
static const jau::uuid128_t CommandUUID = jau::uuid128_t("d0ca6bf3-3d52-4760-98e5-fc5883e93712")
 
static BTDeviceRef connectedDevice = nullptr
 
static const jau::uuid128_t DataServiceUUID = jau::uuid128_t("d0ca6bf3-3d50-4760-98e5-fc5883e93712")
 
static const uint8_t filter_policy =0x00
 
static const jau::uuid128_t PulseDataUUID = jau::uuid128_t("d0ca6bf3-3d54-4760-98e5-fc5883e93712")
 
static const jau::uuid128_t ResponseUUID = jau::uuid128_t("d0ca6bf3-3d53-4760-98e5-fc5883e93712")
 
static bool RUN_ONLY_ONCE = false
 
static jau::relaxed_atomic_nsize_t servedConnections = 0
 
static bool SHOW_UPDATE_EVENTS = false
 
static const jau::uuid128_t StaticDataUUID = jau::uuid128_t("d0ca6bf3-3d51-4760-98e5-fc5883e93712")
 
static jau::sc_atomic_bool sync_data
 
static uint64_t timestamp_t0
 
static bool use_SC = true
 
static EUI48 useAdapter = EUI48::ALL_DEVICE
 

Detailed Description

This _dbt_peripheral00__ C++ peripheral ::BTRole::Slave GATT server example uses an event driven workflow.

dbt_peripheral00 Invocation Examples:

Using scripts/run-dbt_peripheral00.sh from dist directory:

Definition in file dbt_peripheral00.cpp.

Function Documentation

◆ startAdvertising()

static bool startAdvertising ( BTAdapter a,
std::string  msg 
)
static
Examples
dbt_peripheral00.cpp.

Definition at line 536 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ stopAdvertising()

static bool stopAdvertising ( BTAdapter a,
std::string  msg 
)
static
Examples
dbt_peripheral00.cpp.

Definition at line 586 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ processDisconnectedDevice()

static void processDisconnectedDevice ( BTDeviceRef  device)
static
Examples
dbt_peripheral00.cpp.

Definition at line 596 of file dbt_peripheral00.cpp.

◆ setDevice()

static void setDevice ( const BTDeviceRef cd)
static
Examples
dbt_peripheral00.cpp.

Definition at line 88 of file dbt_peripheral00.cpp.

◆ getDevice()

static BTDeviceRef getDevice ( )
static
Examples
dbt_peripheral00.cpp.

Definition at line 93 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ matches()

static bool matches ( const BTDeviceRef device)
static
Examples
dbt_peripheral00.cpp.

Definition at line 98 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ dbGattServer()

DBGattServerRef dbGattServer ( new   DBGattServerjau::make_darray(std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid16_t >(GattServiceType::GENERIC_ACCESS), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::DEVICE_NAME), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue(adapter_name.c_str(), 128), true), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::APPEARANCE), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue((uint16_t) 0)))), std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid16_t >(GattServiceType::DEVICE_INFORMATION), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::MANUFACTURER_NAME_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("Gothel Software")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::MODEL_NUMBER_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("2.4.0-pre")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::SERIAL_NUMBER_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("sn:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::HARDWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("hw:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::FIRMWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("fw:0123456789")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid16_t >(GattCharacteristicType::SOFTWARE_REVISION_STRING), BTGattChar::PropertyBitVal::Read, jau::darray< DBGattDescRef >(), make_gvalue("sw:0123456789")))), std::make_shared< DBGattService >(true, std::make_unique< const jau::uuid128_t >(DataServiceUUID), jau::make_darray(std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(StaticDataUUID), BTGattChar::PropertyBitVal::Read, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("DATA_STATIC"))), make_gvalue("Proprietary Static Data 0x00010203")), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(CommandUUID), BTGattChar::PropertyBitVal::WriteNoAck|BTGattChar::PropertyBitVal::WriteWithAck, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("COMMAND"))), make_gvalue(128, 64), true), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(ResponseUUID), BTGattChar::PropertyBitVal::Notify|BTGattChar::PropertyBitVal::Indicate, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("RESPONSE")), DBGattDesc::createClientCharConfig()), make_gvalue((uint16_t) 0)), std::make_shared< DBGattChar >(std::make_unique< const jau::uuid128_t >(PulseDataUUID), BTGattChar::PropertyBitVal::Notify|BTGattChar::PropertyBitVal::Indicate, jau::make_darray(std::make_shared< DBGattDesc >(BTGattDesc::TYPE_USER_DESC, make_gvalue("DATA_PULSE")), DBGattDesc::createClientCharConfig()), make_gvalue("Synthethic Sensor 01"))))))
Examples
dbt_peripheral00.cpp.
Here is the caller graph for this function:

◆ initAdapter()

static bool initAdapter ( std::shared_ptr< BTAdapter > &  adapter)
static
Examples
dbt_peripheral00.cpp.

Definition at line 613 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ myChangedAdapterSetFunc()

static void myChangedAdapterSetFunc ( const bool  added,
std::shared_ptr< BTAdapter > &  adapter 
)
static
Examples
dbt_peripheral00.cpp.

Definition at line 682 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ test()

void test ( )
Examples
dbt_peripheral00.cpp.

Definition at line 705 of file dbt_peripheral00.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
dbt_peripheral00.cpp.

Definition at line 737 of file dbt_peripheral00.cpp.

Variable Documentation

◆ timestamp_t0

uint64_t timestamp_t0
static
Examples
dbt_peripheral00.cpp.

Definition at line 67 of file dbt_peripheral00.cpp.

◆ useAdapter

EUI48 useAdapter = EUI48::ALL_DEVICE
static
Examples
dbt_peripheral00.cpp.

Definition at line 69 of file dbt_peripheral00.cpp.

◆ btMode

BTMode btMode = BTMode::DUAL
static
Examples
dbt_peripheral00.cpp.

Definition at line 70 of file dbt_peripheral00.cpp.

◆ use_SC

bool use_SC = true
static
Examples
dbt_peripheral00.cpp.

Definition at line 71 of file dbt_peripheral00.cpp.

◆ adapter_name

std::string adapter_name = "TestDev001_N"
static
Examples
dbt_peripheral00.cpp.

Definition at line 72 of file dbt_peripheral00.cpp.

◆ adapter_short_name

std::string adapter_short_name = "TDev001N"
static
Examples
dbt_peripheral00.cpp.

Definition at line 73 of file dbt_peripheral00.cpp.

◆ chosenAdapter

std::shared_ptr<BTAdapter> chosenAdapter = nullptr
static
Examples
dbt_peripheral00.cpp.

Definition at line 74 of file dbt_peripheral00.cpp.

◆ adapter_sec_level

BTSecurityLevel adapter_sec_level = BTSecurityLevel::UNSET
static
Examples
dbt_peripheral00.cpp.

Definition at line 75 of file dbt_peripheral00.cpp.

◆ adapter_sec_io_cap

SMPIOCapability adapter_sec_io_cap = SMPIOCapability::UNSET
static
Examples
dbt_peripheral00.cpp.

Definition at line 76 of file dbt_peripheral00.cpp.

◆ SHOW_UPDATE_EVENTS

bool SHOW_UPDATE_EVENTS = false
static
Examples
dbt_peripheral00.cpp.

Definition at line 77 of file dbt_peripheral00.cpp.

◆ RUN_ONLY_ONCE

bool RUN_ONLY_ONCE = false
static
Examples
dbt_peripheral00.cpp.

Definition at line 78 of file dbt_peripheral00.cpp.

◆ sync_data

jau::sc_atomic_bool sync_data
static
Examples
dbt_peripheral00.cpp.

Definition at line 79 of file dbt_peripheral00.cpp.

◆ connectedDevice

BTDeviceRef connectedDevice = nullptr
static
Examples
dbt_peripheral00.cpp.

Definition at line 80 of file dbt_peripheral00.cpp.

◆ servedConnections

jau::relaxed_atomic_nsize_t servedConnections = 0
static
Examples
dbt_peripheral00.cpp.

Definition at line 82 of file dbt_peripheral00.cpp.

◆ DataServiceUUID

const jau::uuid128_t DataServiceUUID = jau::uuid128_t("d0ca6bf3-3d50-4760-98e5-fc5883e93712")
static
Examples
dbt_peripheral00.cpp.

Definition at line 103 of file dbt_peripheral00.cpp.

◆ StaticDataUUID

const jau::uuid128_t StaticDataUUID = jau::uuid128_t("d0ca6bf3-3d51-4760-98e5-fc5883e93712")
static
Examples
dbt_peripheral00.cpp.

Definition at line 104 of file dbt_peripheral00.cpp.

◆ CommandUUID

const jau::uuid128_t CommandUUID = jau::uuid128_t("d0ca6bf3-3d52-4760-98e5-fc5883e93712")
static
Examples
dbt_peripheral00.cpp.

Definition at line 105 of file dbt_peripheral00.cpp.

◆ ResponseUUID

const jau::uuid128_t ResponseUUID = jau::uuid128_t("d0ca6bf3-3d53-4760-98e5-fc5883e93712")
static
Examples
dbt_peripheral00.cpp.

Definition at line 106 of file dbt_peripheral00.cpp.

◆ PulseDataUUID

const jau::uuid128_t PulseDataUUID = jau::uuid128_t("d0ca6bf3-3d54-4760-98e5-fc5883e93712")
static
Examples
dbt_peripheral00.cpp.

Definition at line 107 of file dbt_peripheral00.cpp.

◆ adv_interval_min

const uint16_t adv_interval_min =160
static
Examples
dbt_peripheral00.cpp.

Definition at line 530 of file dbt_peripheral00.cpp.

◆ adv_interval_max

const uint16_t adv_interval_max =480
static
Examples
dbt_peripheral00.cpp.

Definition at line 531 of file dbt_peripheral00.cpp.

◆ adv_type

const AD_PDU_Type adv_type =AD_PDU_Type::ADV_IND
static
Examples
dbt_peripheral00.cpp.

Definition at line 532 of file dbt_peripheral00.cpp.

◆ adv_chan_map

const uint8_t adv_chan_map =0x07
static
Examples
dbt_peripheral00.cpp.

Definition at line 533 of file dbt_peripheral00.cpp.

◆ filter_policy

const uint8_t filter_policy =0x00
static
Examples
dbt_peripheral00.cpp.

Definition at line 534 of file dbt_peripheral00.cpp.