Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
added SimCommand backdoor to the gen plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tripzero committed Mar 28, 2014
1 parent f5ed75c commit ccc3a5c
Show file tree
Hide file tree
Showing 12 changed files with 825 additions and 8 deletions.

Large diffs are not rendered by default.

Binary file not shown.
Binary file modified build/plugins/cansimplugin/cansimplugin.so
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/abstractpropertytype.h
Expand Up @@ -459,7 +459,7 @@ class StringPropertyType: public AbstractPropertyType
StringPropertyType(std::string propertyName)
:AbstractPropertyType(propertyName)
{

setValue(std::string());
}

StringPropertyType(std::string propertyName, std::string val)
Expand Down
8 changes: 6 additions & 2 deletions lib/vehicleproperty.cpp
Expand Up @@ -350,10 +350,14 @@ AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(Vehic

bool VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
{
if(!contains(mCustomProperties,name))
{
mCustomProperties.push_back(name);

mCustomProperties.push_back(name);
return registerPropertyPriv(name, factory);
}

return registerPropertyPriv(name, factory);
return false;
}

bool VehicleProperty::registerPropertyPriv(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
Expand Down
24 changes: 23 additions & 1 deletion plugins/cangenplugin/cangenplugin.cpp
Expand Up @@ -54,6 +54,10 @@ CANGenPlugin::CANGenPlugin(AbstractRoutingEngine* re, const map<string, string>&
AmbPluginImpl(re, config, parent),
ws(new WebSockets(*this))
{
addPropertySupport(Zone::None,[]()
{
return new SimCommand();
});
}

CANGenPlugin::~CANGenPlugin()
Expand All @@ -74,7 +78,19 @@ void CANGenPlugin::propertyChanged(AbstractPropertyType* value)
return;
if(!value->name.compare("MappingTable")) {
parseMappingTable(value->toString());
}
}
}

AsyncPropertyReply *CANGenPlugin::setProperty(const AsyncSetPropertyRequest &request)
{
if(request.property == "SimCommand")
{
std::string v = request.value->toString();

dataReceived(nullptr,v.c_str(),v.length());
}

return AmbPluginImpl::setProperty(request);
}

void CANGenPlugin::parseMappingTable(const std::string& table)
Expand Down Expand Up @@ -303,6 +319,12 @@ void CANGenPlugin::dataReceived(libwebsocket* socket, const char* data, size_t l
json_object *nameobject = json_object_object_get(rootobject.get(),"name");
json_object *transidobject = json_object_object_get(rootobject.get(),"transactionid");

if(!typeobject || !nameobject || !transidobject)
{
DebugOut(DebugOut::Warning)<<"Malformed json. aborting"<<endl;
return;
}

string type = string(json_object_get_string(typeobject));
string name = string(json_object_get_string(nameobject));
string id;
Expand Down
9 changes: 9 additions & 0 deletions plugins/cangenplugin/cangenplugin.h
Expand Up @@ -102,6 +102,8 @@ class CANGenPlugin: public AmbPluginImpl, public CANObserver, public WebSocketsO
*/
void propertyChanged(AbstractPropertyType* value);

AsyncPropertyReply* setProperty(const AsyncSetPropertyRequest &request);

// from CANObserver
public:
/*!
Expand Down Expand Up @@ -299,6 +301,13 @@ class CANGenPlugin: public AmbPluginImpl, public CANObserver, public WebSocketsO
interprocess_recursive_mutex mutex;
};

class SimCommand: public StringPropertyType
{
public:
SimCommand(): StringPropertyType("SimCommand") { }
SimCommand(std::string val) : StringPropertyType("SimCommand",val) { }
};

#endif // _CANGENPLUGINIMPL_H_

/** @} */
2 changes: 1 addition & 1 deletion plugins/cansimplugin/cansimplugin.h
Expand Up @@ -53,7 +53,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* \brief CAN frames listener plug-in for the AMB CAN Simulator.
*
* Listens on AMB notification for changes in supported properties using supportedChanged() callback. \n
* On startup it registers property called 'MappingTable' and all properties needed for simulation in intelPoc12.Dashboard and intelPoc16.HVAC applications. \n
* On startup it registers property called 'MappingTable' and all properties needed for simulation in html5UI.Dashboard and html5UI.HVAC applications. \n
* Immediately after it registers own properties it will get first notification supportedChanged().\n
* On every notification from supportedChanged() CANSimPlugin goes through all supported properties in AMB, exclude those properties for which there are known sources in the AMB,\n
* assigns to each single property and zone some unique CAN Id(builds 'mapping table') and this 'mapping table' stores as JSON string and updates it as a 'MappingTable' property in AMB.\n
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/ambpluginimpl.cpp
Expand Up @@ -118,7 +118,7 @@ PropertyList AmbPluginImpl::supported() const

int AmbPluginImpl::supportedOperations() const
{
return AbstractSource::Get /*| AbstractSource::Set*/;
return AbstractSource::Get | AbstractSource::Set;
}

void AmbPluginImpl::unsubscribeToPropertyChanges(const VehicleProperty::Property& property)
Expand Down
1 change: 0 additions & 1 deletion plugins/dbus/dbussignaller.h
Expand Up @@ -103,7 +103,6 @@ class DBusSignaller
g_dbus_connection_emit_signal(signal.connection, NULL, signal.objectPath.c_str(), "org.freedesktop.DBus.Properties", signal.signalName.c_str(), g_variant_new("(sa{sv}as)",
signal.interface.c_str(),
&builder, NULL), &error);

if(error)
{
DebugOut(DebugOut::Error)<<error->message<<std::endl;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
@@ -1,3 +1,3 @@
set(amb_tests amb-get amb-set amb-get-history amb-listen)
set(amb_tests amb-get amb-set amb-get-history amb-listen gen-set)
install (PROGRAMS ${amb_tests} DESTINATION bin)

27 changes: 27 additions & 0 deletions tests/gen-set
@@ -0,0 +1,27 @@
#!/usr/bin/python

import dbus
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("property", help="{propertyToSet}")
parser.add_argument("value", help="{value}")
parser.add_argument("zone", help="{zone}")

args = parser.parse_args()

# "{'type' : 'method', 'name' : 'set', 'transactionid' : 'meh',
# 'data' : [{'interface' : 'vcan0', 'property' : 'VehicleSpeed', 'value' : '33', 'zone' : '0' }]}"

realValue = "{'type' : 'method', 'name' : 'set', 'transactionid' : 'meh', 'data' : [{'interface' : 'vcan0', 'property' : '" + args.property + "', 'value' : '" + args.value + "', 'zone' : " + args.zone + " }]}"

bus = dbus.SystemBus()
managerObject = bus.get_object("org.automotive.message.broker", "/");
managerInterface = dbus.Interface(managerObject, "org.automotive.Manager")

object = managerInterface.FindObjectForZone("SimCommand", 0)

propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.freedesktop.DBus.Properties")
propertiesInterface.Set("org.automotive.SimCommand", "SimCommand", realValue)
print "Success!"

0 comments on commit ccc3a5c

Please sign in to comment.