Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows scan fix #5

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ endif()
list(APPEND PLUGIN_SOURCES
"src/universal_ble_plugin.cpp"
"src/universal_ble_plugin.h"
"src/helper/universal_enum.h"
"src/helper/universal_ble_base.h"
"src/helper/utils.cpp"
"src/helper/utils.h"
Expand Down
43 changes: 43 additions & 0 deletions windows/src/helper/universal_ble_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,47 @@ namespace universal_ble
using namespace winrt::Windows::Devices::Bluetooth::Advertisement;
using namespace winrt::Windows::Devices::Bluetooth::GenericAttributeProfile;
using namespace Windows::Devices::Enumeration;

// Define all enums
enum class ConnectionState : int
{
connected = 0,
disconnected = 1,
};

enum class CharacteristicProperty : int
{
broadcast = 0,
read = 1,
writeWithoutResponse = 2,
write = 3,
notify = 4,
indicate = 5,
authenticatedSignedWrites = 6,
extendedProperties = 7,
};

enum class BleInputProperty : int
{
disabled = 0,
notification = 1,
indication = 2,
};

enum class BleOutputProperty : int
{
withResponse = 0,
withoutResponse = 1,
};

enum class AvailabilityState : int
{
unknown = 0,
resetting = 1,
unsupported = 2,
unauthorized = 3,
poweredOff = 4,
poweredOn = 5,
};

}
47 changes: 0 additions & 47 deletions windows/src/helper/universal_enum.h

This file was deleted.

10 changes: 1 addition & 9 deletions windows/src/helper/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#if WDK_NTDDI_VERSION < NTDDI_WIN10_VB
#error "Windows SDK version before 10.0.19041.0 is not supported"
#elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
// For Windows SDK version before 10.0.19041.0, remap functions to post-10.0.19041.0 versions
#define WINRT_IMPL_CoGetApartmentType WINRT_CoGetApartmentType
#endif

#define MAC_ADDRESS_STR_LENGTH (size_t)17 // Two chars per byte, 5 chars for colon
#define MAC_ADDRESS_STR_LENGTH (size_t)17

namespace universal_ble
{
Expand All @@ -29,7 +28,6 @@ namespace universal_ble

uint64_t _str_to_mac_address(std::string mac_str)
{
// TODO: Validate input - Expected Format: XX:XX:XX:XX:XX:XX
uint64_t mac_address_number = 0;
uint8_t *mac_ptr = (uint8_t *)&mac_address_number;
sscanf_s(mac_str.c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac_ptr[5], &mac_ptr[4], &mac_ptr[3],
Expand All @@ -39,7 +37,6 @@ namespace universal_ble

winrt::guid uuid_to_guid(const std::string &uuid)
{
// TODO: Add proper cleanup / validation
std::stringstream helper;
for (int i = 0; i < uuid.length(); i++)
{
Expand All @@ -63,23 +60,18 @@ namespace universal_ble
std::string guid_to_uuid(const winrt::guid &guid)
{
std::stringstream helper;
// TODO: It might be cleaner to use snprintf instead of string streams.

for (uint32_t i = 0; i < 4; i++)
{
// * NOTE: We're performing a byte swap!
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t *)&guid.Data1)[3 - i];
}
helper << '-';
for (uint32_t i = 0; i < 2; i++)
{
// * NOTE: We're performing a byte swap!
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t *)&guid.Data2)[1 - i];
}
helper << '-';
for (uint32_t i = 0; i < 2; i++)
{
// * NOTE: We're performing a byte swap!
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t *)&guid.Data3)[1 - i];
}
helper << '-';
Expand Down
30 changes: 2 additions & 28 deletions windows/src/helper/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,16 @@ namespace universal_ble
std::string _mac_address_to_str(uint64_t mac_address);
uint64_t _str_to_mac_address(std::string mac_address);

winrt::guid uuid_to_guid(const std::string &uuid);
std::string guid_to_uuid(const winrt::guid &guid);

std::vector<uint8_t> to_bytevc(IBuffer buffer);
IBuffer from_bytevc(std::vector<uint8_t> bytes);

winrt::guid uuid_to_guid(const std::string &uuid);
std::string to_hexstring(std::vector<uint8_t> bytes);

std::string to_uuidstr(winrt::guid guid);

/// Structs for passing data between background to ui thread
struct ConnectionStateStruct
{
std::string deviceId;
int64_t connectionState;
ConnectionStateStruct(std::string deviceId, int64_t connectionState)
: deviceId(deviceId), connectionState(connectionState) {}
};

struct PairStateStruct
{
std::string deviceId;
bool isPaired;
std::string errorMessage;
PairStateStruct(std::string deviceId, bool isPaired, std::string errorMessage)
: deviceId(deviceId), isPaired(isPaired), errorMessage(errorMessage) {}
};

struct ValueChangeStruct
{
std::string deviceId;
std::string characteristicId;
std::vector<uint8_t> value;
ValueChangeStruct(std::string deviceId, std::string characteristicId, std::vector<uint8_t> value)
: deviceId(deviceId), characteristicId(characteristicId), value(value) {}
};

/// To call async functions synchronously
template <typename async_t>
static auto async_get(async_t const &async)
Expand Down