Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sending proto definitions from the websocket server #21

Merged
merged 21 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Ignition Launch 1.X.X

1. Added ability to get protobuf definitions from the websocket server
* [Pull Request 21](https://github.com/ignitionrobotics/ign-launch/pull/21)

1. Added ability to set the publication rate of the websocket server.
* [Pull Request 17](https://github.com/ignitionrobotics/ign-launch/pull/17)

Expand Down
11 changes: 11 additions & 0 deletions plugins/websocket_server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ if (websockets_FOUND)
set (sources WebsocketServer.cc)

add_library(${plugin} SHARED ${sources})

file (READ combined.proto MESSAGE_DEFINITIONS)
configure_file("MessageDefinitions.hh.in"
"${CMAKE_CURRENT_BINARY_DIR}/MessageDefinitions.hh" @ONLY)
# Add a dependency on binary source dir so that you can change the
# combinded.proto file and `make` will rebuild the plugin.
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS combined.proto)
target_include_directories(${plugin} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/>
)

target_link_libraries(${plugin}
PRIVATE
${websockets_LIBRARIES}
Expand Down
32 changes: 32 additions & 0 deletions plugins/websocket_server/MessageDefinitions.hh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2019 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_LAUNCH_WEBSOCKETSERVER_MESSAGE_DEFINITIONS_HH_
#define IGNITION_LAUNCH_WEBSOCKETSERVER_MESSAGE_DEFINITIONS_HH_

namespace ignition
{
namespace launch
{
/// \brief All of the protobuf messages provided by the websocket
/// server.
/// \todo Get this information from a running simulation. The problem
/// right now is that Ignition Transport does not show subscribers.
static const std::string kMessageDefinitions =
R"protos(@MESSAGE_DEFINITIONS@)protos";
}
}
#endif
14 changes: 13 additions & 1 deletion plugins/websocket_server/WebsocketServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <ignition/common/Util.hh>
#include <ignition/msgs.hh>

#include "MessageDefinitions.hh"
#include "WebsocketServer.hh"

using namespace ignition::launch;
Expand Down Expand Up @@ -268,10 +269,19 @@ void WebsocketServer::OnDisconnect(int _socketId)
//////////////////////////////////////////////////
void WebsocketServer::OnMessage(int _socketId, const std::string &_msg)
{
// Handle the case where the client requests the message definitions.
if (_msg == "message_definitions")
{
igndbg << "Message definitions request recieved\n";
this->QueueMessage(this->connections[_socketId].get(),
kMessageDefinitions.c_str(), kMessageDefinitions.length());
return;
}

ignition::msgs::WebRequest requestMsg;
requestMsg.ParseFromString(_msg);

if (requestMsg.operation() == "list")
if (requestMsg.operation() == "topic_list")
{
igndbg << "Topic list request recieved\n";
ignition::msgs::Packet msg;
Expand All @@ -285,6 +295,8 @@ void WebsocketServer::OnMessage(int _socketId, const std::string &_msg)
for (const std::string &topic : topics)
msg.mutable_string_msg_v()->add_data(topic);

msg.set_topic("/topic_list");
msg.set_type("ignition.msgs.StringMsg_V");
std::string data = msg.SerializeAsString();

// Queue the message for delivery.
Expand Down
16 changes: 16 additions & 0 deletions plugins/websocket_server/WebsocketServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,31 @@ namespace ignition
/// \brief Reads from a USB joystick device and outputs
/// ignition::msgs::WebsocketServer messages.
///
/// # Websocket Server Interface
///
/// \todo: Describe the websocket API.
///
/// # Example usage
///
/// ## Websocket Server
///
/// 1. Define a launch file by copying the following contents to a file
/// called `websocket.ign`.
///
/// <!-- Inform ignition::Launch about the JoyToTwist plugin -->
/// <plugin name="ignition::launch::WebsocketServer"
/// filename="libignition-launch-joystick0.so">
///
/// <!-- Publication Hz -->
/// <publication_hz>30</publication_hz>
/// </plugin>
///
/// 2. Run the launch file
///
/// `ign launch -v 4 websocket.ign`
///
/// 3. Open the [index.html](https://github.com/ignitionrobotics/ign-launch/blob/master/plugins/websocket_server/index.html) webpage.
///
class WebsocketServer : public ignition::launch::Plugin
{
/// \brief Constructor
Expand Down
125 changes: 125 additions & 0 deletions plugins/websocket_server/combined.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
syntax = "proto3";

package ignition.msgs;

message Time {
int64 sec = 1;
int32 nsec = 2;
}

message Clock
{
Header header = 1;
Time system = 2;
Time real = 3;
Time sim = 4;
}
message Header {
message Map {
string key = 1;
repeated string value = 2;
}
Time stamp = 1;
repeated Map data = 2;
}
message WebRequest
{
Header header = 1;
string operation = 2;
string topic = 3;
string msg_type = 4;
string compression = 5;
double hz = 6;
}
message StringMsg_V
{
repeated string data = 2;
}
message CmdVel2D
{
Header header = 1;
double velocity = 2;
double theta = 3;
}
enum PixelFormatType
{
UNKNOWN_PIXEL_FORMAT = 0;
L_INT8 = 1;
L_INT16 = 2;
RGB_INT8 = 3;
RGBA_INT8 = 4;
BGRA_INT8 = 5;
RGB_INT16 = 6;
RGB_INT32 = 7;
BGR_INT8 = 8;
BGR_INT16 = 9;
BGR_INT32 = 10;
R_FLOAT16 = 11;
RGB_FLOAT16 = 12;
R_FLOAT32 = 13;
RGB_FLOAT32 = 14;
BAYER_RGGB8 = 15;
BAYER_RGGR8 = 16;
BAYER_GBRG8 = 17;
BAYER_GRBG8 = 18;
}

message Image
{
Header header = 1;
uint32 width = 2;
uint32 height = 3;
uint32 pixel_format = 4;
uint32 step = 5;
bytes data = 6;
}
message Vector3d
{
Header header = 1;
double x = 2;
double y = 3;
double z = 4;
}
message Pose
{
Header header = 1;
string name = 2;
uint32 id = 3;
Vector3d position = 4;
Quaternion orientation = 5;
}
message Quaternion
{
Header header = 1;
double x = 2;
double y = 3;
double z = 4;
double w = 5;
}
message Double_V
{
repeated double data = 1;
}
message Pose_V
{
Header header = 1;
repeated Pose pose = 2;
}
message Packet
{
string topic = 1;
string type = 2;

oneof content
{
CmdVel2D cmd_vel2d = 3;
Image image = 4;
StringMsg_V string_msg_v = 5;
WebRequest web_request = 6;
Pose pose = 7;
Double_V doublev = 8;
Pose_V pose_v = 9;
Time time = 10;
Clock clock = 11;
}
}
1 change: 1 addition & 0 deletions plugins/websocket_server/eventemitter2.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading