summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Carpenter <malcom2073@gmail.com>2012-08-24 23:16:14 -0400
committerMichael Carpenter <malcom2073@gmail.com>2012-08-24 23:16:14 -0400
commit921b10b6c5cfd193f63c145e69beee6fa7908900 (patch)
treeab47eaefaa6df06076f80da6dce07f1e5ff6c925
parent1ba6621888be98399de96e27092eeab8e906eac1 (diff)
downloadautomotive-message-broker-921b10b6c5cfd193f63c145e69beee6fa7908900.tar.gz
Fix for current subscription changes to api.js. Added steering wheel angle and transmission status
-rw-r--r--plugins/websocketsink/websocketsink.cpp21
-rw-r--r--plugins/websocketsink/websocketsinkmanager.cpp113
2 files changed, 117 insertions, 17 deletions
diff --git a/plugins/websocketsink/websocketsink.cpp b/plugins/websocketsink/websocketsink.cpp
index a0513fc1..e66831ec 100644
--- a/plugins/websocketsink/websocketsink.cpp
+++ b/plugins/websocketsink/websocketsink.cpp
@@ -49,7 +49,26 @@ void WebSocketSink::propertyChanged(VehicleProperty::Property property, boost::a
stringstream s;
//TODO: Dirty hack hardcoded stuff, jsut to make it work.
- s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":[{\"name\":\"" << property << "\",\"value\":\"" << velocity << "\"}],\"transactionid\":\"" << m_uuid << "\"}";
+ string tmpstr = "";
+ if (property == VehicleProperty::VehicleSpeed)
+ {
+ tmpstr = "running_status_speedometer";
+ }
+ else if (property == VehicleProperty::EngineSpeed)
+ {
+ tmpstr = "running_status_engine_speed";
+ }
+ else if (property == VehicleProperty::SteeringWheelAngle)
+ {
+ tmpstr = "running_status_steering_wheel_angle";
+ }
+ else if (property == VehicleProperty::TransmissionShiftPosition)
+ {
+ tmpstr = "running_status_transmission_gear_status";
+ }
+
+
+ s << "{\"type\":\"valuechanged\",\"name\":\"" << tmpstr << "\",\"data\":\"" << velocity << "\",\"transactionid\":\"" << m_uuid << "\"}";
string replystr = s.str();
printf("Reply: %s\n",replystr.c_str());
diff --git a/plugins/websocketsink/websocketsinkmanager.cpp b/plugins/websocketsink/websocketsinkmanager.cpp
index 12f44cd5..35a8d96d 100644
--- a/plugins/websocketsink/websocketsinkmanager.cpp
+++ b/plugins/websocketsink/websocketsinkmanager.cpp
@@ -54,13 +54,30 @@ void WebSocketSinkManager::addSingleShotSink(libwebsocket* socket, VehicleProper
{
AsyncPropertyRequest velocityRequest;
velocityRequest.property = property;
- velocityRequest.completed = [socket,id](AsyncPropertyReply* reply) {
+ velocityRequest.completed = [socket,id,property](AsyncPropertyReply* reply) {
printf("Got property:%i\n",boost::any_cast<uint16_t>(reply->value));
uint16_t velocity = boost::any_cast<uint16_t>(reply->value);
stringstream s;
//TODO: Dirty hack hardcoded stuff, jsut to make it work.
- s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":[{\"name\":\"running_status_speedometer\",\"value\":\"" << velocity << "\"}],\"transactionid\":\"" << id << "\"}";
+ string tmpstr = "";
+ if (property == VehicleProperty::VehicleSpeed)
+ {
+ tmpstr = "running_status_speedometer";
+ }
+ else if (property == VehicleProperty::EngineSpeed)
+ {
+ tmpstr = "running_status_engine_speed";
+ }
+ else if (property == VehicleProperty::SteeringWheelAngle)
+ {
+ tmpstr = "running_status_steering_wheel_angle";
+ }
+ else if (property == VehicleProperty::TransmissionShiftPosition)
+ {
+ tmpstr = "running_status_transmission_gear_status";
+ }
+ s << "{\"type\":\"methodReply\",\"name\":\"get\",\"data\":[{\"name\":\"" << tmpstr << "\",\"value\":\"" << velocity << "\"}],\"transactionid\":\"" << id << "\"}";
string replystr = s.str();
printf("Reply: %s\n",replystr.c_str());
@@ -79,6 +96,41 @@ void WebSocketSinkManager::addSingleShotSink(libwebsocket* socket, VehicleProper
}
void WebSocketSinkManager::addSink(libwebsocket* socket, VehicleProperty::Property property,string uuid)
{
+ stringstream s;
+
+ //TODO: Dirty hack hardcoded stuff, jsut to make it work.
+ string tmpstr = "";
+ if (property == VehicleProperty::VehicleSpeed)
+ {
+ tmpstr = "running_status_speedometer";
+ }
+ else if (property == VehicleProperty::EngineSpeed)
+ {
+ tmpstr = "running_status_engine_speed";
+ }
+ else if (property == VehicleProperty::SteeringWheelAngle)
+ {
+ tmpstr = "running_status_steering_wheel_angle";
+ }
+ else if (property == VehicleProperty::TransmissionShiftPosition)
+ {
+ tmpstr = "running_status_transmission_gear_status";
+ }
+
+
+
+
+
+ s << "{\"type\":\"methodReply\",\"name\":\"subscribe\",\"data\":[\"" << tmpstr << "\"],\"transactionid\":\"" << uuid << "\"}";
+
+ string replystr = s.str();
+ printf("Reply: %s\n",replystr.c_str());
+
+ char *new_response = new char[LWS_SEND_BUFFER_PRE_PADDING + strlen(replystr.c_str()) + LWS_SEND_BUFFER_POST_PADDING];
+ new_response+=LWS_SEND_BUFFER_PRE_PADDING;
+ strcpy(new_response,replystr.c_str());
+ libwebsocket_write(socket, (unsigned char*)new_response, strlen(new_response), LWS_WRITE_TEXT);
+
WebSocketSink *sink = new WebSocketSink(m_engine,socket,uuid,property);
}
@@ -155,8 +207,8 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb
gchar** members = json_reader_list_members(reader);
string type;
string name;
- list<string> arguments;
- string data;
+ list<string> data;
+ //string data;
//stringlist arguments
string id;
json_reader_read_member(reader,"type");
@@ -179,9 +231,18 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb
json_reader_end_member(reader);
*/
json_reader_read_member(reader,"data");
- printf("Data Type Name: %s\n",g_type_name(json_node_get_value_type(json_reader_get_value(reader))));
- data = json_reader_get_string_value(reader);
+ g_assert(json_reader_is_array(reader));
+ for(int i=0; i < json_reader_count_elements(reader); i++)
+ {
+ json_reader_read_element(reader,i);
+ string path = json_reader_get_string_value(reader);
+ data.push_back(path);
+ json_reader_end_element(reader);
+ }
json_reader_end_member(reader);
+ //printf("Data Type Name: %s\n",g_type_name(json_node_get_value_type(json_reader_get_value(reader))));
+ //data = json_reader_get_string_value(reader);
+ //json_reader_end_member(reader);
//running_status_engine_speed
@@ -191,7 +252,7 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb
//node->
//printf("Type Name: %s\n",gtype);
- printf("Before\n");
+ //printf("Before\n");
//GType gtype = json_reader_get_type();
//json_reader_error_get_type();
if (strcmp("gchararray",g_type_name(json_node_get_value_type(json_reader_get_value(reader)))) == 0)
@@ -215,30 +276,50 @@ static int websocket_callback(struct libwebsocket_context *context,struct libweb
{
if (name == "get")
{
+ if (data.size() > 0)
+ {
//GetProperty is going to be a singleshot sink.
//string arg = arguments.front();
- if (data== "running_status_speedometer")
+ if (data.front()== "running_status_speedometer")
{
- printf("Found velocity\n");
- //m_engine->subscribeToProperty(VehicleProperty::VehicleSpeed,this);
-
-
sinkManager->addSingleShotSink(wsi,VehicleProperty::VehicleSpeed,id);
- //libwebsocket_write(wsi, (unsigned char*)new_response, strlen(new_response), LWS_WRITE_TEXT);
-
}
- else if (data == "running_status_engine_speed")
+ else if (data.front() == "running_status_engine_speed")
{
sinkManager->addSingleShotSink(wsi,VehicleProperty::EngineSpeed,id);
}
+ else if (data.front() == "running_status_steering_wheel_angle")
+ {
+ sinkManager->addSingleShotSink(wsi,VehicleProperty::SteeringWheelAngle,id);
+ }
+ else if (data.front() == "running_status_transmission_gear_status")
+ {
+ sinkManager->addSingleShotSink(wsi,VehicleProperty::TransmissionShiftPosition,id);
+ }
+ }
//EngineSpeed
//AccelerationX
}
- else if (name == "Subscribe")
+ else if (name == "subscribe")
{
+ if (data.front()== "running_status_speedometer")
+ {
//Subscribe is a permanent sink, until unsubscription.
sinkManager->addSink(wsi,VehicleProperty::VehicleSpeed,id);
+ }
+ else if (data.front()== "running_status_engine_speed")
+ {
+ sinkManager->addSink(wsi,VehicleProperty::EngineSpeed,id);
+ }
+ else if (data.front() == "running_status_steering_wheel_angle")
+ {
+ sinkManager->addSink(wsi,VehicleProperty::SteeringWheelAngle,id);
+ }
+ else if (data.front() == "running_status_transmission_gear_status")
+ {
+ sinkManager->addSink(wsi,VehicleProperty::TransmissionShiftPosition,id);
+ }
}
}