fixed bug in core where sources were getting an unsubscribe request even though there...
authorKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 17 Jan 2013 23:19:41 +0000 (15:19 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 17 Jan 2013 23:19:41 +0000 (15:19 -0800)
ambd/core.cpp
plugins/obd2plugin/obd2source.cpp

index 82a69ce..8efc624 100644 (file)
@@ -267,15 +267,19 @@ void Core::unsubscribeToProperty(VehicleProperty::Property property, AbstractSin
        }
                
        ListPlusPlus<AbstractSink*>(&propertySinkMap[property]).removeOne(self);
-       
-       for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+
+       /// Now we check to see if this is the last subscriber
+       if(propertySinkMap.find(property) == propertySinkMap.end())
        {
-               AbstractSource* src = (*itr);
-               PropertyList properties = src->supported();
-               
-               if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+               for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
                {
-                       src->unsubscribeToPropertyChanges(property);
+                       AbstractSource* src = (*itr);
+                       PropertyList properties = src->supported();
+
+                       if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+                       {
+                               src->unsubscribeToPropertyChanges(property);
+                       }
                }
        }
 }
index f959f79..be33d41 100644 (file)
@@ -211,7 +211,7 @@ void threadLoop(gpointer data)
                        }
                        else if (req->req == "disconnect")
                        {
-                               DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Using queued disconnect" << (ulong)req << "\n";
+                               DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Using queued disconnect" << (ulong)req << endl;
                                obd->closePort();
                                ObdBluetoothDevice bt;
                                bt.disconnect(source->m_btDeviceAddress, source->m_btAdapterAddress);
@@ -225,7 +225,7 @@ void threadLoop(gpointer data)
                query = g_async_queue_try_pop(privSubscriptionRemoveQueue);
                if (query != nullptr)
                {
-                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got unsubscription request\n";
+                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got unsubscription request"<<endl;
                        ObdPid *req = (ObdPid*)query;
                        for (std::list<ObdPid*>::iterator i=reqList.begin();i!= reqList.end();i++)
                        {
@@ -291,10 +291,10 @@ void threadLoop(gpointer data)
                        if (!obd->sendObdRequestString((*i)->pid.c_str(),(*i)->pid.length(),&replyVector))
                        {
                                //This only happens during a error with the com port. Close it and re-open it later.
-                               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unable to send request:" << (*i)->pid << "!\n";
+                               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unable to send request:" << (*i)->pid << endl;
                                if (obd->lastError() == obdLib::NODATA)
                                {
-                                       DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::NODATA for pid" << (*i)->pid << "\n";
+                                       DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::NODATA for pid" << (*i)->pid <<endl;
                                        if (source->m_blacklistPidCountMap.find((*i)->pid) != source->m_blacklistPidCountMap.end())
                                        {
                                                //pid value i not yet in the list.
@@ -320,7 +320,7 @@ void threadLoop(gpointer data)
                                        timeoutCount++;
                                        if (timeoutCount < 2)
                                        {
-                                               DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::TIMEOUT for pid" << (*i)->pid << "\n";
+                                               DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBDLib::TIMEOUT for pid" << (*i)->pid << endl;
                                                StatusMessage *statusreq = new StatusMessage();
                                                statusreq->statusStr = "error:timeout";
                                                g_async_queue_push(privStatusQueue,statusreq);
@@ -354,66 +354,6 @@ void threadLoop(gpointer data)
                                continue;
                        }
                        g_async_queue_push(privResponseQueue,pid);
-                       //printf("Req: %s\n",(*i).c_str());
-                       /*if ((*i) == "ATRV\r")
-                       {
-                               //printf("Requesting voltage...\n");
-                               if (!obd->sendObdRequestString((*i).c_str(),(*i).length(),&replyVector))
-                               {
-                                       //printf("Unable to request voltage!!!\n");
-                                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unable to request voltage!\n";
-                                       continue;
-                               }
-                               std::string replystring = "";
-                               for (int j=0;j<replyVector.size();j++)
-                               {
-                                       replystring += replyVector[j];
-                               }
-                               //printf("Voltage reply: %s\n",replystring.c_str());
-                               replystring.substr(0,replystring.find("V"));*/
-                               /*ObdReply *rep = new ObdReply();
-                               rep->req = "ATRV\r";
-                               rep->reply = replystring;
-                               g_async_queue_push(privResponseQueue,rep);*/
-                       /*}
-                       if (!obd->sendObdRequest((*i).c_str(),(*i).length(),&replyVector))
-                       {
-                               //printf("Error sending obd2 request\n");
-                               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error sending OBD2 request\n";
-                               continue;
-                       }*/
-                       //printf("Reply: %i %i\n",replyVector[0],replyVector[1]);
-                               /*
-                       /*
-                       else if (replyVector[0] == 0x49)
-                       {
-                         /*
-                               49 02 01 00 00 00 31 
-                               49 02 02 47 31 4A 43 
-                               49 02 03 35 34 34 34 
-                               49 02 04 52 37 32 35 
-                               49 02 05 32 33 36 37 
-                               //VIN number reply
-                               string vinstring;
-                               for (int j=0;j<replyVector.size();j++)
-                               {
-                                       if(replyVector[j] == 0x49 && replyVector[j+1] == 0x02)
-                                       {
-                                               //We're at a reply header
-                                               j+=3;
-                                       }
-                                       if (replyVector[j] != 0x00)
-                                       {
-                                               vinstring += (char)replyVector[j];
-                                               //printf("VIN: %i %c\n",replyVector[j],replyVector[j]);
-                                       }
-                               }
-                               /*ObdReply *rep = new ObdReply();
-                               rep->req = "0902";
-                               rep->reply = vinstring;
-                               g_async_queue_push(privResponseQueue,rep);*/
-                               
-                       //DebugOut()<<"Reply: "<<replyVector[2]<<" "<<replyVector[3]<<endl;
                }
                if (badloop == 0)
                {
@@ -428,7 +368,7 @@ void threadLoop(gpointer data)
                obd->closePort();
        }
 }
-static int updateProperties(/*gpointer retval,*/ gpointer data)
+static int updateProperties( gpointer data)
 {
 
        OBD2Source* src = (OBD2Source*)data;
@@ -456,53 +396,6 @@ static int updateProperties(/*gpointer retval,*/ gpointer data)
                AbstractPropertyType* value = VehicleProperty::getPropertyTypeForPropertyNameValue(reply->property, reply->value);
                src->updateProperty(reply->property, value);
 
-               /*if (reply->req == "05")
-               {
-                       VehicleProperty::EngineCoolantTemperatureType speed(reply->reply);
-                       src->updateProperty(VehicleProperty::EngineCoolantTemperature,&speed);
-               }
-               else if (reply->req == "0C")
-               {
-                       VehicleProperty::EngineSpeedType speed(reply->reply);
-                       src->updateProperty(VehicleProperty::EngineSpeed,&speed); 
-               }
-               else if (reply->req == "0D")
-               {
-                       VehicleProperty::VehicleSpeedType speed(reply->reply);
-                       src->updateProperty(VehicleProperty::VehicleSpeed,&speed);
-               }
-               else if (reply->req == "10")
-               {
-                       VehicleProperty::MassAirFlowType mass(reply->reply);
-                       src->updateProperty(VehicleProperty::MassAirFlow,&mass);
-               }
-               else if (reply->req == "ATRV\r")
-               {
-                       VehicleProperty::BatteryVoltageType volts(reply->reply);
-                       src->updateProperty(VehicleProperty::BatteryVoltage,&volts);
-                       
-               }
-               else if (reply->req == "0902")
-               {
-                       //VIN number and WMI
-                       VehicleProperty::VINType vin(reply->reply);
-                       src->updateProperty(VehicleProperty::VIN,&vin);
-                       VehicleProperty::WMIType wmi(reply->reply.substr(0,3));
-                       src->updateProperty(VehicleProperty::WMI,&wmi);
-               }
-               else if (reply->req == "5C")
-               {
-                       VehicleProperty::EngineCoolantTemperatureType ect(reply->reply);
-                       src->updateProperty(VehicleProperty::EngineCoolantTemperature,&ect);
-               }
-               else if (reply->req == "46")
-               {
-                       VehicleProperty::InteriorTemperatureType temp(reply->reply);
-                       src->updateProperty(VehicleProperty::InteriorTemperature,&temp);
-               }
-               //5C -- engine oil temp
-               //46 interior temp*/
-
                delete reply;
        }
 
@@ -666,68 +559,6 @@ string OBD2Source::uuid()
 }
 void OBD2Source::subscribeToPropertyChanges(VehicleProperty::Property property)
 {
-       /*//printf("Subscribed to property: %s\n",property.c_str());
-       if (property == VehicleProperty::EngineSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010C1\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::MassAirFlow)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01101\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::VehicleSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010D1\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::EngineCoolantTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01051\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::VIN)
-       {
-               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "VIN subscription requested... but there's no point!\n";
-       }
-       else if (property == VehicleProperty::WMI)
-       {
-               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "WMI subscription requested... but there's no point!\n";
-       }
-       else if (property == VehicleProperty::EngineOilTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "015C1\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::InteriorTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01461\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       else if (property == VehicleProperty::BatteryVoltage)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "ATRV\r";
-               g_async_queue_push(subscriptionAddQueue,requ);
-       }
-       /*m_supportedProperties.push_back(VehicleProperty::VIN);
-       m_supportedProperties.push_back(VehicleProperty::WMI);
-       m_supportedProperties.push_back(VehicleProperty::EngineOilTemperature);
-       m_supportedProperties.push_back(VehicleProperty::InteriorTemperature);
-       m_supportedProperties.push_back(VehicleProperty::BatteryVoltage);*/
-       /*else
-       {
-               //printf("Unsupported property: %s\n",property.c_str());
-               DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unsupported property requested:" << property << "\n";
-       }*/
-
        if (property == VehicleProperty::VIN)
        {
                DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "VIN subscription requested... but there's no point!"<<endl;
@@ -770,63 +601,6 @@ void OBD2Source::subscribeToPropertyChanges(VehicleProperty::Property property)
 
 void OBD2Source::unsubscribeToPropertyChanges(VehicleProperty::Property property)
 {
-       //
-       /*if (property == VehicleProperty::EngineSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010C1\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::MassAirFlow)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01101\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::VehicleSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010D1\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::EngineCoolantTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01051\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::VIN)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0902\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::WMI)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0902\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::EngineOilTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "015C1\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::InteriorTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "01461\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       else if (property == VehicleProperty::BatteryVoltage)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "ATRV\r";
-               g_async_queue_push(subscriptionRemoveQueue,requ);
-       }
-       */
-
        if(!ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(property))
        {
                DebugOut(0)<<"obd plugin does not support: "<<property<<endl;
@@ -843,64 +617,6 @@ void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply)
        propertyReplyMap[reply->property] = reply;
        VehicleProperty::Property property = reply->property;
 
-       //TODO: There is a much better way to do this, but for now it's hardcoded.
-       /*if (property == VehicleProperty::EngineSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010C\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::MassAirFlow)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0110\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::VehicleSpeed)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "010D\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::EngineCoolantTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0105\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::VIN)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0902\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::WMI)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0902\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::EngineOilTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "015C\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::InteriorTemperature)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "0146\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       else if (property == VehicleProperty::BatteryVoltage)
-       {
-               ObdRequest *requ = new ObdRequest();
-               requ->req = "ATRV\r";
-               g_async_queue_push(singleShotQueue,requ);
-       }
-       */
-
-       ///Here's a better way:
 
        if(!ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(property))
        {