aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPetre Eftime <[email protected]>2016-09-09 17:29:38 +0300
committerPetre Eftime <[email protected]>2016-09-16 14:13:47 +0300
commit22c1af1c7f1a47207668ba61ceccea2143500069 (patch)
tree3fce0058fdff26951df516d362b7e0adf205b63b /examples
parent80e1f741597aec0d2874904f28cce3352bd95d64 (diff)
Add missing BluetoothDevice properties
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt6
-rw-r--r--examples/list_mfg.cpp109
2 files changed, 115 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 271b5905..52352bdc 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -35,6 +35,11 @@ set_target_properties(uuid
PROPERTIES
CXX_STANDARD 11)
+add_executable (list_mfg list_mfg.cpp)
+set_target_properties(list_mfg
+ PROPERTIES
+ CXX_STANDARD 11)
+
include_directories(${PROJECT_SOURCE_DIR}/api)
target_link_libraries (hellotinyb tinyb)
@@ -43,3 +48,4 @@ target_link_libraries (asynctinyb tinyb)
target_link_libraries (esstinyb tinyb)
target_link_libraries (notifications tinyb)
target_link_libraries (uuid tinyb)
+target_link_libraries (list_mfg tinyb)
diff --git a/examples/list_mfg.cpp b/examples/list_mfg.cpp
new file mode 100644
index 00000000..b554f7cb
--- /dev/null
+++ b/examples/list_mfg.cpp
@@ -0,0 +1,109 @@
+/*
+ * Author: Petre Eftime <[email protected]>
+ * Copyright (c) 2015 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <tinyb.hpp>
+
+#include <vector>
+#include <iostream>
+#include <thread>
+#include <atomic>
+#include <csignal>
+
+using namespace tinyb;
+
+/** Converts a raw temperature read from the sensor to a Celsius value.
+ * @param[in] raw_temp The temperature read from the sensor (two bytes)
+ * @return The Celsius value of the temperature
+ */
+static float celsius_temp(uint16_t raw_temp)
+{
+ const float SCALE_LSB = 0.03125;
+ return ((float)(raw_temp >> 2)) * SCALE_LSB;
+}
+
+
+std::atomic<bool> running(true);
+
+void signal_handler(int signum)
+{
+ if (signum == SIGINT) {
+ running = false;
+ }
+}
+
+/** This program reads the temperature from a
+ * TI Sensor Tag(http://www.ti.com/ww/en/wireless_connectivity/sensortag2015/?INTC=SensorTag&HQS=sensortag)
+ * Pass the MAC address of the sensor as the first parameter of the program.
+ */
+int main(int argc, char **argv)
+{
+ BluetoothManager *manager = nullptr;
+ try {
+ manager = BluetoothManager::get_bluetooth_manager();
+ } catch(const std::runtime_error& e) {
+ std::cerr << "Error while initializing libtinyb: " << e.what() << std::endl;
+ exit(1);
+ }
+
+ /* Start the discovery of devices */
+ bool ret = manager->start_discovery();
+ std::cout << "Started = " << (ret ? "true" : "false") << std::endl;
+
+ BluetoothDevice *sensor_tag = NULL;
+ BluetoothGattService *temperature_service = NULL;
+
+ for (;;) {
+ std::cout << "Discovered devices: " << std::endl;
+ /* Get the list of devices */
+ auto list = manager->get_devices();
+
+ for (auto it = list.begin(); it != list.end(); ++it) {
+
+ std::cout << "Class = " << (*it)->get_class_name() << " ";
+ std::cout << "Path = " << (*it)->get_object_path() << " ";
+ std::cout << "Name = " << (*it)->get_name() << " ";
+ std::cout << "Connected = " << (*it)->get_connected() << " ";
+ std::cout << std::endl;
+
+ auto mfg = (*it)->get_manufacturer_data();
+
+ if (mfg.empty())
+ continue;
+
+ std::cout << "MFG" << std::endl;
+ for(auto it: mfg) {
+ std::cout << "\t" << it.first << " = [ ";
+ for (auto arr_it: it.second) {
+ std::cout << (int) arr_it << ", ";
+ }
+ std::cout << "]" << std::endl;
+ }
+
+ }
+
+ /* If not, wait and try again */
+ std::this_thread::sleep_for(std::chrono::seconds(4));
+ std::cout << std::endl;
+ }
+}