configurable bt adapter 19/2319/1
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 24 Oct 2012 22:47:17 +0000 (15:47 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 24 Oct 2012 22:47:17 +0000 (15:47 -0700)
TODO
examples/obdsourceconfig
plugins/obd2plugin/bluetooth.hpp
plugins/obd2plugin/obd2source.cpp

diff --git a/TODO b/TODO
index 5693335..e1001f0 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,3 +5,4 @@
 - historic data "get" interface in routing engine
 - sqlite database storage plugin
 - connect/disconnect on first/last subscription in obd2source
+- improve obd2source speed via Physical Addressing and Fast polling (see https://www.scantool.net/forum/index.php?topic=6661.msg25024#msg25024)
index d8b685e..f7403bd 100644 (file)
@@ -4,7 +4,8 @@
                        "name" : "OBD2Source",
                        "path" : "/usr/lib/automotive-message-broker/obd2sourceplugin.so",
                        "device" : "/dev/ttyUSB0",
-                       "baud" : "115200"
+                       "baud" : "115200",
+                       "bluetoothAdapter" : ""
                }
        ],
        "sinks": [
index f88491a..0e889c5 100644 (file)
@@ -10,9 +10,9 @@
 class ObdBluetoothDevice
 {
 public:
-       std::string getDeviceForAddress(std::string address)
-       {
 
+       std::string getDeviceForAddress( std::string address,std::string adapterAddy = "")
+       {
                GError* error = NULL;
                OrgBluezManager* manager = org_bluez_manager_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
                                                                                                                                                                 G_DBUS_PROXY_FLAGS_NONE,
@@ -28,14 +28,30 @@ public:
                error = NULL;
 
                gchar* adapterPath;
-               if(!org_bluez_manager_call_default_adapter_sync(manager,&adapterPath,NULL,&error))
+
+               if(adapterAddy != "")
                {
-                       DebugOut(0)<<"Error getting bluetooth default adapter: "<<error->message<<endl;
-                       g_error_free(error);
-                       return "";
+                       if(!org_bluez_manager_call_find_adapter_sync(manager,adapterAddy.c_str(), &adapterPath, NULL, &error))
+                       {
+                               DebugOut(0)<<"Error getting bluetooth adapter ("<<adapterAddy<<"): "<<error->message<<endl;
+                               g_error_free(error);
+                               return "";
+                       }
+
+                       error = NULL;
                }
 
-               error = NULL;
+               else
+               {
+                       if(!org_bluez_manager_call_default_adapter_sync(manager,&adapterPath, NULL, &error))
+                       {
+                               DebugOut(0)<<"Error getting bluetooth default adapter: "<<error->message<<endl;
+                               g_error_free(error);
+                               return "";
+                       }
+
+                       error = NULL;
+               }
 
                OrgBluezAdapter* adapter = org_bluez_adapter_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
                                                                                                                                                                 G_DBUS_PROXY_FLAGS_NONE,
@@ -81,6 +97,7 @@ public:
 
                return serialDeviceName;
        }
+
 };
 
 
index 2ec40b6..d40315f 100644 (file)
@@ -388,6 +388,7 @@ void OBD2Source::setConfiguration(map<string, string> config)
        //Default values
        std::string port = "/dev/ttyUSB0";
        std::string baud = "115200";
+       std::string btadapter = "";
        
        //Try to load config
        //printf("OBD2Source::setConfiguration\n");
@@ -399,10 +400,15 @@ void OBD2Source::setConfiguration(map<string, string> config)
                {
                        port = (*i).second;
                }
-               if ((*i).first == "baud")
+               else if ((*i).first == "baud")
                {
                        baud = (*i).second;
                }
+
+               else if ((*i).first == "bluetoothAdapter")
+               {
+                       btadapter = (*i).second;
+               }
        }
 
        if(port.find(":") != string::npos)
@@ -411,7 +417,7 @@ void OBD2Source::setConfiguration(map<string, string> config)
                DebugOut()<<"bluetooth device?"<<endl;
                ObdBluetoothDevice bt;
 
-               std::string tempPort = bt.getDeviceForAddress(port);
+               std::string tempPort = bt.getDeviceForAddress(port, btadapter);
                if(tempPort != "")
                {
                        DebugOut(3)<<"Using bluetooth device \""<<port<<"\" bound to: "<<tempPort<<endl;