Skip to content

Commit

Permalink
SimpleBLE v0.0.2
Browse files Browse the repository at this point in the history
SimpleBLE v0.0.2
  • Loading branch information
kdewald authored Oct 10, 2021
2 parents 6233922 + 92eb42a commit 229196f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - 2021-XX-XX
## [0.0.2] - 2021-10-09

### Added
- Safe implementation of `SimpleBLE::Adapter` and `SimpleBLE::Peripheral` classes.
Expand All @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `SimpleBLE::Adapter` would fail to stop scanning. _(Thanks PatrykSajdok!)_
- Switched WinRT initialization to single-threaded.

### Changed
- SimpleDBus dependency not migrated to OpenBluetoothToolbox.

## [0.0.1] - 2021-09-06

### Added
Expand Down
23 changes: 11 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ else()
endif()

# Load default parameters passed in through the command line.
if(NOT SIMPLEDBUS_GIT_REPOSITORY)
set(SIMPLEDBUS_GIT_REPOSITORY "https://github.com/kdewald/SimpleDBus.git")
if(NOT SIMPLEBLUEZ_GIT_REPOSITORY)
set(SIMPLEBLUEZ_GIT_REPOSITORY "https://github.com/OpenBluetoothToolbox/SimpleBluez.git")
endif()
if(NOT SIMPLEDBUS_GIT_TAG)
set(SIMPLEDBUS_GIT_TAG "feature/simpleble")
if(NOT SIMPLEBLUEZ_GIT_TAG)
set(SIMPLEBLUEZ_GIT_TAG "master")
endif()

# Perform some overall CMake configurations
Expand Down Expand Up @@ -57,20 +57,20 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
message("-- [INFO] Linux Host Detected")

FetchContent_Declare(
simpledbus
GIT_REPOSITORY ${SIMPLEDBUS_GIT_REPOSITORY}
GIT_TAG ${SIMPLEDBUS_GIT_TAG}
simplebluez
GIT_REPOSITORY ${SIMPLEBLUEZ_GIT_REPOSITORY}
GIT_TAG ${SIMPLEBLUEZ_GIT_TAG}
)
FetchContent_MakeAvailable(simpledbus)
FetchContent_MakeAvailable(simplebluez)

set(
EXTERNAL_LIBRARIES
bluezdbus-static
simplebluez-static
pthread
)
set(
EXTERNAL_INCLUDE_DIRS
${SIMPLEDBUS_INCLUDES}
${SIMPLEBLUEZ_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/src/linux
)
set(
Expand All @@ -90,7 +90,6 @@ elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")

set(
EXTERNAL_INCLUDE_DIRS
${SIMPLEDBUS_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/src/windows
)
set(
Expand Down Expand Up @@ -203,4 +202,4 @@ endif()
# Export the variables needed by the parent project
if(NOT ${STANDALONE})
set(SIMPLEBLE_INCLUDES ${SIMPLEBLE_USER_INCLUDE_DIR} PARENT_SCOPE)
endif()
endif()
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ from internal or secure sources without the risk of those getting compromised.
This is done by specifying the additional command line arguments to
the `cmake` command:

- `SIMPLEBLUEZ_GIT_REPOSITORY`
Call CMake with `-DSIMPLEBLUEZ_GIT_REPOSITORY=<path>` to override the
default location of the SimpleBluez repository.
- `SIMPLEBLUEZ_GIT_TAG`
Call CMake with `-DSIMPLEBLUEZ_GIT_TAG=<tag>` to override the default
tag of the SimpleBluez repository.

- `SIMPLEDBUS_GIT_REPOSITORY`
Call CMake with `-DSIMPLEDBUS_GIT_REPOSITORY=<path>` to override the
default location of the SimpleDBus repository.
Expand Down Expand Up @@ -136,10 +143,10 @@ or just be ignored.
| `SimpleBLE::Peripheral::connect` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::disconnect` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::is_connected` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::is_connectable` | No | Yes | Yes |
| `SimpleBLE::Peripheral::is_connectable` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::services` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::manufacturer_data` | No | Yes | Yes |
| `SimpleBLE::Peripheral::read` | No | Yes | Yes |
| `SimpleBLE::Peripheral::manufacturer_data` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::read` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::write_request` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::write_command` | Yes | Yes | Yes |
| `SimpleBLE::Peripheral::notify` | Yes | Yes | Yes |
Expand All @@ -150,7 +157,6 @@ or just be ignored.

## Known Issues / To-Do's
- [Linux] Fork safety is not guaranteed.
- [Linux] `SimpleBLE::Peripheral::read` does not work.
- [MacOS] Only the main system adapter can be detected.
- [MacOS] Implementation has incomplete error handling and might crash if invalid parameters are passed.
- [MacOS] Timeout logic can be DRYed up.
Expand Down
2 changes: 1 addition & 1 deletion src/linux/AdapterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <simpleble/Peripheral.h>
#include <simpleble/Types.h>

#include <bluezdbus/BluezAdapter.h>
#include <BluezAdapter.h>

namespace SimpleBLE {

Expand Down
4 changes: 2 additions & 2 deletions src/linux/Bluez.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <atomic>
#include <thread>
#include "bluezdbus/BluezService.h"
#include "BluezService.h"

namespace SimpleBLE {

Expand All @@ -23,4 +23,4 @@ class Bluez {
void async_thread_function();
};

} // namespace SimpleBLE
} // namespace SimpleBLE
25 changes: 11 additions & 14 deletions src/linux/PeripheralBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ bool PeripheralBase::is_connected() {
return device->Property_Connected() && device->Property_ServicesResolved();
}

bool PeripheralBase::is_connectable() {
// TODO its a stub, replace with real implementation
if (is_connected()) {
return false;
}
return true;
}
bool PeripheralBase::is_connectable() { return identifier_ != ""; }

std::vector<BluetoothService> PeripheralBase::services() {
auto device = _get_device();
Expand All @@ -80,19 +74,22 @@ std::vector<BluetoothService> PeripheralBase::services() {
}

std::map<uint16_t, ByteArray> PeripheralBase::manufacturer_data() {
// TODO: Implement
return {};
auto device = _get_device();

std::map<uint16_t, ByteArray> manufacturer_data;
for (auto& [manufacturer_id, value_array] : device->get_manufacturer_data()) {
manufacturer_data[manufacturer_id] = ByteArray((const char*)value_array.data(), value_array.size());
}

return manufacturer_data;
}

ByteArray PeripheralBase::read(BluetoothUUID service, BluetoothUUID characteristic) {
// TODO: Check if the characteristic is readable.
auto characteristic_object = _get_characteristic(service, characteristic);

// FIXME: SimpleDBus does not have this feature yet.
// std::vector<uint8_t> value = characteristic_object->get_value();
// return ByteArray((const char*)value.data(), value.size());

return ByteArray();
std::vector<uint8_t> value = characteristic_object->Property_Value();
return ByteArray((const char*)value.data(), value.size());
}

void PeripheralBase::write_request(BluetoothUUID service, BluetoothUUID characteristic, ByteArray data) {
Expand Down
2 changes: 1 addition & 1 deletion src/linux/PeripheralBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <simpleble/Exceptions.h>
#include <simpleble/Types.h>

#include <bluezdbus/BluezDevice.h>
#include <BluezDevice.h>

#include <condition_variable>

Expand Down

0 comments on commit 229196f

Please sign in to comment.