added a whole bunch of new properties that breaks stuff
authorKevron Rees <tripzero.kev@gmail.com>
Fri, 15 Feb 2013 18:39:09 +0000 (10:39 -0800)
committerKevron Rees <tripzero.kev@gmail.com>
Fri, 15 Feb 2013 18:39:39 +0000 (10:39 -0800)
ambd/main.cpp
docs/drivingsafety.txt
lib/CMakeLists.txt
lib/abstractpropertytype.h
lib/mappropertytype.hpp [new file with mode: 0644]
lib/vehicleproperty.cpp
lib/vehicleproperty.h
plugins/exampleplugin.cpp
plugins/examplesink.cpp

index 2579c0f..a978618 100644 (file)
@@ -148,6 +148,8 @@ int main(int argc, char **argv)
        
        g_type_init();
 
+       VehicleProperty::factory();
+
        /* Register signal handler */
        signal(SIGINT, interrupt);
        signal(SIGTERM, interrupt);
index b272e54..f17fe46 100644 (file)
@@ -2,127 +2,136 @@ Driving Safety hierarchy
 =================
 
 Service         org.automotive
-Interface       org.automotive.drivingsafety
-Object path     /
+Object path     /org/automotive/drivingSafety
 
  
-Properties             byte AntilockBrakingSystem [readonly]
+Interface:     org.automotive.antilockBrakingSystem
+Object path:   /org/automotive/vehicleInfo/vehicleId
+Properties:
+               bool AntilockBrakingSystem [readonly]
 
-                               Idle = 0,
-                               Engaged = 1
+                       Idle = false,
+                       Engaged = true
                                
-                       byte TractionControlSystem [readonly]
+               bool TractionControlSystem [readonly]
                        
-                               Off = 0,
-                               On = 1
+                       Off = false,
+                       On = true
                                
-                       uint16 VehicleTopSpeedLimit [readonly]
+               uint16 VehicleTopSpeedLimit [readonly]
                        
-                               top rated speed in km/h. 0 = no limit
+                       top rated speed in km/h. 0 = no limit
                                
-                       dict{ byte, byte } AirbagStatus [readonly]
+               dict{ byte, byte } AirbagStatus [readonly]
                        
-                               Dictionary of Airbag (byte) and Status (byte)
+                       Dictionary of Airbag (byte) and Status (byte)
                                
-                               Airbag:
+                       Airbag:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftSide = 2,
-                               RightSide = 3
+                       Driver = 0,
+                       Passenger = 1,
+                       LeftSide = 2,
+                       RightSide = 3
                                
-                               Status:
+                       Status:
                                
-                               Active = 0,
-                               Inactive = 1,
-                               Deployed = 2
+                       Inactive = 0,
+                       Active = 1,
+                       Deployed = 2
                                
-                       dict{ byte, byte } DoorStatus [readonly]
+               dict{ byte, byte } DoorStatus [readonly]
                        
-                               Dictionary of Door (byte) and Status (byte)
+                       Dictionary of Door (byte) and Status (byte)
                                
-                               Door:
+                       Door:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftRear = 2,
-                               RightRear = 3,
-                               Trunk = 4,
-                               FuelCap = 5,
-                               Hood = 6
+                       Driver = 0,
+                       Passenger = 1,
+                       LeftRear = 2,
+                       RightRear = 3,
+                       Trunk = 4,
+                       FuelCap = 5,
+                       Hood = 6
                                
-                               Status:
+                       Status:
                                
-                               Closed = 0,
-                               Open = 1,
-                               Ajar = 2
+                       Closed = 0,
+                       Open = 1,
+                       Ajar = 2
                        
-                       dict{ byte, bool } DoorLockStatus [readonly]
+               dict{ byte, bool } DoorLockStatus [readonly]
                        
-                               Dictionary of Door (byte) and Status (bool locked = true)
+                       Dictionary of Door (byte) and Status (bool locked = true, unlocked = false)
                                
-                               Door:
+                       Door:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftRear = 2,
-                               RightRear = 3,
+                       Driver = 0,
+                       Passenger = 1,
+                       LeftRear = 2,
+                       RightRear = 3,
+
+               bool ChildLockStatus  [readwrite]
+
+                       Child lock status of rear doors.  active = true, inactive = false.
+                       Setting this to 'true' will prevent the rear doors from being opened
+                       from the inside.
                        
-                       dict{ byte, bool } SeatBeltStatus [readonly]
+               dict{ byte, bool } SeatBeltStatus [readonly]
                        
-                               Dictionary of Seat Belt (byte) and Status (bool: Fasten = true)
+                       Dictionary of Seat Belt (byte) and Status (bool: Fasten = true, Unfastened = false)
                                
-                               Seat Belt:
+                       Seat Belt:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftRear = 2,
-                               RightRear = 3
+                       Driver = 0,
+                       MiddleFront = 1,
+                       Passenger = 2,
+                       LeftRear = 3,
+                       MiddleRear = 4,
+                       RightRear = 5
                                
-                       dict{ byte, bool } WindowLockStatus [readonly]
+               dict{ byte, bool } WindowLockStatus [readonly]
                        
-                               Dictionary of Windows (byte) and Status (bool: Locked = true)
+                       Dictionary of Windows (byte) and Status (bool: Locked = true)
                                
-                               Window:
+                       Window:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftRear = 2,
-                               RightRear = 3
+                       Driver = 0,
+                       Passenger = 1,
+                       LeftRear = 2,
+                       RightRear = 3,
+                       Sunroof = 4
                        
-                       dict{ byte, byte } OccupantStatus [readonly]
+               dict{ byte, byte } OccupantStatus [readonly]
                        
-                               Dictionary of Occupant (byte) and Status
-                               
-                               Occupant:
+                       Dictionary of Occupant (byte) and Status
+                       
+                       Occupant:
                                
-                               Driver = 0,
-                               Passenger = 1,
-                               LeftRear = 2,
-                               RightRear = 3
+                       Driver = 0,
+                       Passenger = 1,
+                       LeftRear = 2,
+                       RightRear = 3
                                
-                               Status:
+                       Status:
                                
-                               Vacant = 0,
-                               Child = 1, 
-                               Adult = 2
+                       Vacant = 0,
+                       Child = 1, 
+                       Adult = 2
+
+                       /// TODO: document the weight threshold standard for child vs adult
                                
-                       dict{ byte, double } ObstacleDistance [readonly]
+               dict{ byte, double } ObstacleDistance [readonly]
                        
-                               Dictionary of Distance Sensor and distance (double) in m
+                       Dictionary of Distance Sensor and distance (double) in m
                        
-                               Distance Sensors:
+                       Distance Sensors:
                                
-                               LeftFront = 0,
-                               RightFront = 1,
-                               LeftRear = 2,
-                               RightRear = 3,
-                               LeftBlindSpot = 4,
-                               RightBlindSPot = 5
+                       LeftFront = 0,
+                       RightFront = 1,
+                       LeftRear = 2,
+                       RightRear = 3,
+                       LeftBlindSpot = 4,
+                       RightBlindSPot = 5
                                
-                       string CameraFrame [readonly]
-                       
-                               string representing a shared memory key where the camera frame is stored.  
-                               The frame is stored as a PNG encoded byte array.
 
-                               
\ No newline at end of file
+                               
index 079dec2..7359ba0 100644 (file)
@@ -1,5 +1,5 @@
-set(amb_sources abstractpropertytype.cpp abstractroutingengine.cpp listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp timestamp.cpp uuidhelper.cpp)
-set(amb_headers_install abstractpropertytype.h nullptr.h abstractroutingengine.h listplusplus.h abstractsink.h vehicleproperty.h debugout.h abstractsource.h timestamp.h uuidhelper.h)
+set(amb_sources abstractpropertytype.cpp abstractroutingengine.cpp listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp timestamp.cpp uuidhelper.cpp mappropertytype.hpp)
+set(amb_headers_install abstractpropertytype.h nullptr.h abstractroutingengine.h listplusplus.h abstractsink.h vehicleproperty.h debugout.h abstractsource.h timestamp.h uuidhelper.h )
 include_directories( ${include_dirs} )
 add_library(amb SHARED ${amb_sources})
 
index d17cb37..612ce8c 100644 (file)
@@ -197,18 +197,36 @@ template <typename T>
 class BasicPropertyType: public AbstractPropertyType
 {
 public:
+       BasicPropertyType(): AbstractPropertyType()
+       {
+               mValue = T();
+       }
        BasicPropertyType(BasicPropertyType const &other)
                :AbstractPropertyType()
        {
                setValue(other.value<T>());
+               timestamp = other.timestamp;
+               sequence = other.sequence;
        }
 
        BasicPropertyType & operator = (BasicPropertyType const & other)
        {
                setValue(other.value<T>());
+               timestamp = other.timestamp;
+               sequence = other.sequence;
                return *this;
        }
 
+       bool operator < (const BasicPropertyType<T>& other) const
+       {
+               return value<T>() < other.value<T>();
+       }
+
+       bool operator > (const BasicPropertyType<T>& other) const
+       {
+               return value<T>() > other.value<T>();
+       }
+
        BasicPropertyType(T val)
                :AbstractPropertyType()
        {
@@ -401,7 +419,7 @@ public:
        }
 
        /** append - appends a property to the list
-        * @arg property - property to be appended.  Will be copied and owned by ListPropertyType.
+        * @arg property - property to be appended.  Property will be copied and owned by ListPropertyType.
         * You are responsible for freeing property after append is called.
         **/
        void append(AbstractPropertyType* property)
diff --git a/lib/mappropertytype.hpp b/lib/mappropertytype.hpp
new file mode 100644 (file)
index 0000000..3240bf3
--- /dev/null
@@ -0,0 +1,133 @@
+#ifndef _MAPPROPERTYTYPE_H_
+#define _MAPPROPERTYTYPE_H_
+
+
+#include "abstractpropertytype.h"
+#include <map>
+#include <debugout.h>
+#include <json-glib/json-glib.h>
+
+template <class T, class N>
+class MapPropertyType: public AbstractPropertyType
+{
+public:
+       MapPropertyType(){}
+
+       void append(T  key, N  value)
+       {
+               appendPriv(key,value);
+       }
+
+       AbstractPropertyType* copy()
+       {
+               MapPropertyType<T,N> *t = new MapPropertyType<T,N>();
+
+               t->setMap(mMap);
+
+               return t;
+       }
+
+       std::string toString() const
+       {
+               std::stringstream str;
+
+               str<<"{";
+
+               for(auto itr = mMap.begin(); itr != mMap.end(); itr++)
+               {
+                       if(str.str() != "{")
+                               str << ", ";
+
+                        auto t = *itr;
+
+                        str <<"'"<< t.first.toString() <<"':'"<<t.second.toString()<<"'";
+               }
+
+               str << "}";
+
+               return str.str();
+       }
+
+       void fromString(std::string str)
+       {
+               JsonParser* parser = json_parser_new();
+               GError* error = nullptr;
+               if(!json_parser_load_from_data(parser, str.c_str(), str.length(), &error))
+               {
+                       DebugOut()<<"Failed to load config: "<<error->message;
+                       throw std::runtime_error("Failed to load config");
+               }
+
+               JsonNode* node = json_parser_get_root(parser);
+
+               if(node == nullptr)
+                       throw std::runtime_error("Unable to get JSON root object");
+
+               JsonReader* reader = json_reader_new(node);
+
+               if(reader == nullptr)
+                       throw std::runtime_error("Unable to create JSON reader");
+
+               DebugOut()<<"Config members: "<<json_reader_count_members(reader)<<endl;
+
+               gchar** srcMembers = json_reader_list_members(reader);
+
+               for(int i=0; i< json_reader_count_members(reader); i++)
+               {
+                       json_reader_read_member(reader,srcMembers[i]);
+                       T one(srcMembers[i]);
+                       N two(json_reader_get_string_value(reader));
+
+                       append(one,two);
+                       json_reader_end_member(reader);
+               }
+
+               g_free(srcMembers);
+               g_object_unref(reader);
+               g_object_unref(parser);
+       }
+
+       GVariant* toVariant()
+       {
+               GVariantBuilder params;
+               g_variant_builder_init(&params, G_VARIANT_TYPE_DICTIONARY);
+
+               for(auto itr = mMap.begin(); itr != mMap.end(); itr++)
+               {
+                       GVariant **v = g_new(GVariant*,2);
+//                     v[0] = (*itr).first.toVariant();
+                       v[1] = (*itr).second.toVariant();
+                       GVariant* tuple = g_variant_new_tuple(v,2);
+
+                       g_variant_builder_add_value(&params,tuple);
+
+                       g_free(v);
+               }
+
+               GVariant* var =  g_variant_builder_end(&params);
+               g_assert(var);
+               return var;
+       }
+
+       void fromVariant(GVariant*)
+       {
+
+       }
+
+       void setMap(std::map<T, N> m)
+       {
+               mMap = m;
+       }
+
+private:
+
+       void appendPriv(T  key, N  value)
+       {
+               mMap[key] = value;
+       }
+
+       std::map<T, N> mMap;
+};
+
+
+#endif
index f91af1d..7e4f045 100644 (file)
@@ -34,6 +34,8 @@ using namespace std;
 
 std::map<VehicleProperty::Property, VehicleProperty::PropertyTypeFactoryCallback> VehicleProperty::registeredPropertyFactoryMap;
 
+VehicleProperty* VehicleProperty::thereCanOnlyBeOne = nullptr;
+
 const VehicleProperty::Property VehicleProperty::NoValue = "NoValue";
 const VehicleProperty::Property VehicleProperty::VehicleSpeed = "VehicleSpeed";
 const VehicleProperty::Property VehicleProperty::EngineSpeed = "EngineSpeed";
@@ -118,6 +120,15 @@ const VehicleProperty::Property VehicleProperty::SecurityAlertStatus = "Security
 const VehicleProperty::Property VehicleProperty::ParkingBrakeStatus = "ParkingBrakeStatus";
 const VehicleProperty::Property VehicleProperty::ParkingLightStatus = "ParkingLightStatus";
 const VehicleProperty::Property VehicleProperty::HazardLightStatus = "HazardLightStatus";
+const VehicleProperty::Property VehicleProperty::AirbagStatus = "AirbagStatus";
+const VehicleProperty::Property VehicleProperty::AntilockBrakingSystem = "AntilockBrakingSystem";
+const VehicleProperty::Property VehicleProperty::TractionControlSystem = "TractionControlSystem";
+const VehicleProperty::Property VehicleProperty::VehicleTopSpeedLimit = "VehicleTopSpeedLimit";
+const VehicleProperty::Property VehicleProperty::DoorStatus = "DoorStatus";
+const VehicleProperty::Property VehicleProperty::DoorLockStatus = "DoorLockStatus";
+const VehicleProperty::Property VehicleProperty::SeatBeltStatus = "SeatBeltStatus";
+const VehicleProperty::Property VehicleProperty::WindowLockStatus = "WindowLockStatus";
+const VehicleProperty::Property VehicleProperty::ObstacleDistance = "ObstacleDistance";
 
 
 std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
@@ -208,10 +219,36 @@ VehicleProperty::VehicleProperty()
        REGISTERPROPERTY(ParkingBrakeStatus,false);
        REGISTERPROPERTY(ParkingLightStatus,false);
        REGISTERPROPERTY(HazardLightStatus,false);
+       registerPropertyPriv(AirbagStatus,[]()
+       {
+               BasicPropertyType<Airbag::Location> a(Airbag::Driver);
+               BasicPropertyType<Airbag::Status> b(Airbag::Inactive);
+               AirbagStatusType* t = new AirbagStatusType();
+               t->append(a,b);
+
+               return t;
+       });
+
+       REGISTERPROPERTY(AntilockBrakingSystem,false);
+       REGISTERPROPERTY(TractionControlSystem,false);
+       REGISTERPROPERTY(VehicleTopSpeedLimit,0);
+
+       registerPropertyPriv(DoorStatus,[]()
+       {
+               DoorStatusType* t = new DoorStatusType();
+               t->append(Door::Driver,Door::Closed);
 
+               return t;
+       });
 
 }
 
+void VehicleProperty::factory()
+{
+       if(!thereCanOnlyBeOne)
+               thereCanOnlyBeOne = new VehicleProperty();
+}
+
 std::list<VehicleProperty::Property> VehicleProperty::capabilities()
 {
        return mCapabilities;
@@ -266,4 +303,4 @@ bool VehicleProperty::registerPropertyPriv(VehicleProperty::Property name, Vehic
 
 }
 
-VehicleProperty vehiclePropertyConstruct;
+
index ad70529..7ad369d 100644 (file)
@@ -27,8 +27,8 @@
 #include <sstream>
 #include <map>
 #include <functional>
-
 #include <abstractpropertytype.h>
+#include "mappropertytype.hpp"
 
 namespace ButtonEvents {
 enum ButtonEventType {
@@ -154,6 +154,90 @@ enum Status
 };
 }
 
+namespace Airbag {
+enum Location
+{
+       Driver = 0,
+       Passenger,
+       LeftSide,
+       RightSide
+};
+
+enum Status
+{
+       Inactive = 0,
+       Active,
+       Deployed
+};
+
+}
+
+namespace Door {
+enum Location
+{
+       Driver=0,
+       Passenger,
+       LeftRear,
+       RightRear,
+       Trunk,
+       FuelCap,
+       Hood
+};
+
+enum Status
+{
+       Closed = 0,
+       Open,
+       Ajar
+};
+
+}
+
+namespace Seat
+{
+enum Location
+{
+       Driver = 0,
+       FrontMiddle = 1,
+       Passenger,
+       LeftRear,
+       MiddleRear,
+       RightRear
+};
+
+enum Status
+{
+       Vacant = 0,
+       Child,
+       Adult
+};
+}
+
+namespace Window
+{
+enum Location
+{
+       Driver = 0,
+       Passenger,
+       LeftRear,
+       RightRear,
+       Sunroof
+};
+}
+
+namespace DistanceSensor
+{
+enum Location
+{
+       LeftFront = 0,
+       RightFront = 1,
+       LeftRear = 2,
+       RightRear = 3,
+       LeftBlindSpot = 4,
+       RightBlindSPot = 5
+
+};
+}
 
 class VehicleProperty
 {
@@ -161,7 +245,7 @@ class VehicleProperty
 public:
        
 
-       VehicleProperty();
+       static void factory();
 
        typedef std::string Property;
        typedef std::function<AbstractPropertyType* (void)> PropertyTypeFactoryCallback;
@@ -438,6 +522,33 @@ public:
        static const Property HazardLightStatus;
        typedef BasicPropertyType<bool> HazardLightStatusType;
 
+       static const Property AntilockBrakingSystem;
+       typedef BasicPropertyType<bool> AntilockBrakingSystemType;
+
+       static const Property TractionControlSystem;
+       typedef BasicPropertyType<bool> TractionControlSystemType;
+
+       static const Property VehicleTopSpeedLimit;
+       typedef BasicPropertyType<uint16_t> VehicleTopSpeedType;
+
+       static const Property AirbagStatus;
+       typedef MapPropertyType<BasicPropertyType<Airbag::Location>, BasicPropertyType<Airbag::Status> > AirbagStatusType;
+
+       static const Property DoorStatus;
+       typedef MapPropertyType<BasicPropertyType<Door::Location>, BasicPropertyType<Door::Status> > DoorStatusType;
+
+       static const Property DoorLockStatus;
+       typedef MapPropertyType<BasicPropertyType<Door::Location>, BasicPropertyType<bool> > DoorLockStatusType;
+
+       static const Property SeatBeltStatus;
+       typedef MapPropertyType<BasicPropertyType<Seat::Location>, BasicPropertyType<bool> > SeatBeltStatusType;
+
+       static const Property WindowLockStatus;
+       typedef MapPropertyType<BasicPropertyType<Window::Location>, BasicPropertyType<bool> > WindowLockStatusType;
+
+       static const Property ObstacleDistance;
+       typedef MapPropertyType<BasicPropertyType<DistanceSensor::Location>, BasicPropertyType<double> > ObstacleDistanceType;
+
 
        /** END PROPERTIES **/
 
@@ -474,6 +585,11 @@ public:
 
 
 private:
+
+       VehicleProperty();
+
+       static VehicleProperty* thereCanOnlyBeOne;
+
        static bool registerPropertyPriv(Property name, PropertyTypeFactoryCallback factory);
 
        static std::map<Property, PropertyTypeFactoryCallback> registeredPropertyFactoryMap;
index 1742eb3..8420a97 100644 (file)
@@ -151,6 +151,19 @@ void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
                reply->success = true;
                reply->completed(reply);
        }
+       else if(reply->property == VehicleProperty::AirbagStatus)
+       {
+               VehicleProperty::AirbagStatusType temp;
+
+               temp.append(Airbag::Driver, Airbag::Active);
+               temp.append(Airbag::Passenger, Airbag::Active);
+               temp.append(Airbag::LeftSide, Airbag::Active);
+               temp.append(Airbag::RightSide, Airbag::Active);
+
+               reply->value = &temp;
+               reply->success = true;
+               reply->completed(reply);
+       }
 }
 
 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
@@ -184,6 +197,7 @@ PropertyList ExampleSourcePlugin::supported()
        props.push_back(VehicleProperty::MachineGunTurretStatus);
        props.push_back(VehicleProperty::ExteriorBrightness);
        props.push_back(VehicleProperty::DoorsPerRow);
+       props.push_back(VehicleProperty::AirbagStatus);
        
        return props;
 }
index d980941..20fe36b 100644 (file)
@@ -86,6 +86,15 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties)
 
        routingEngine->getPropertyAsync(doorsPerRowRequest);
 
+       AsyncPropertyRequest airbagStatus;
+       airbagStatus.property = VehicleProperty::AirbagStatus;
+       airbagStatus.completed = [](AsyncPropertyReply* reply)
+       {
+               DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl; delete reply;
+       };
+
+       routingEngine->getPropertyAsync(airbagStatus);
+
        auto getRangedCb = [](gpointer data)
        {
                AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;