Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ vcpkg_installed/
# Project-specific
build/*
out/
/.vscode
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ Run the bootstrap script to build vcpkg binary `.\vcpkg\bootstrap-vcpkg.bat` or

After installing vcpkg if you're on Windows, you need to run `vcpkg integrate install` command from the vcpkg folder to integrate it for VSCode.

For other systems and IDEs instructions are not available as of now, contributions are welcome.
Then you will need to run `cmake -B build` once to setup CMake.

Finally, everytime you want to build binaries, just run `cmake --build build --config Release`. The newly built binary will be in the build/release directory.

For other systems and IDEs, instructions are not available as of now, but contributions are welcome.

### Updating vcpkg packages

To update vcpkg packages set the vcpkg registry submodule to a newer commit and rerun the bootstrap script.
To update vcpkg packages set the vcpkg registry submodule to a newer commit and rerun the bootstrap script.

### Updating protobuf messages

You can modify the protobuf messages for communication between the server and this driver in [src\bridge\ProtobufMessages.proto](src\bridge\ProtobufMessages.proto). Please update PROTOCOL_VERSION in [src\bridge\BridgeClient.hpp](src\bridge\BridgeClient.hpp)

To update the protobuf messages on the server, you will need to install [protoc](https://protobuf.dev/installation/) (we use version 4.31.1), then make sure that your SlimeVR-Server and SlimeVR-OpenVR-Driver repositories are in the same parent directory and run `protobuf_update.bat` located at `SlimeVR-Server\server\desktop`
10 changes: 10 additions & 0 deletions src/bridge/BridgeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void BridgeClient::CreateConnection() {
logger_->Log("[{}] connected", path);
connected_ = true;
last_error_ = std::nullopt;
SendVersion();
});
connection_handle_->on<uvw::end_event>([this, path](const uvw::end_event&, uvw::pipe_handle&) {
logger_->Log("[{}] disconnected", path);
Expand Down Expand Up @@ -79,3 +80,12 @@ void BridgeClient::CloseConnectionHandles() {
if (reconnect_timeout_) reconnect_timeout_->close();
connected_ = false;
}

void BridgeClient::SendVersion() {
messages::ProtobufMessage* message = google::protobuf::Arena::CreateMessage<messages::ProtobufMessage>(&arena_);
messages::Version* version = google::protobuf::Arena::CreateMessage<messages::Version>(&arena_);
message->set_allocated_version(version);
version->set_protocol_version(PROTOCOL_VERSION);
SendBridgeMessage(*message);
arena_.Reset();
}
5 changes: 5 additions & 0 deletions src/bridge/BridgeClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "BridgeTransport.hpp"

#define PROTOCOL_VERSION 1

/**
* @brief Client implementation for communication with SlimeVR Server using pipes or unix sockets.
*
Expand All @@ -49,8 +51,11 @@ class BridgeClient: public BridgeTransport {
void ResetConnection() override;
void CloseConnectionHandles() override;
void Reconnect();
void SendVersion();

std::optional<std::string> last_error_;
std::optional<std::string> last_path_;
std::shared_ptr<uvw::timer_handle> reconnect_timeout_;

google::protobuf::Arena arena_;
};
8 changes: 4 additions & 4 deletions src/bridge/BridgeTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void BridgeTransport::OnRecv(const uvw::data_event& event) {
char len_buf[4];
recv_buf_.Peek(len_buf, 4);
uint32_t size = 0;
size |= static_cast<uint32_t>(static_cast<uint8_t>(len_buf[0])) << 0;
size |= static_cast<uint32_t>(static_cast<uint8_t>(len_buf[1])) << 8;
size |= static_cast<uint32_t>(static_cast<uint8_t>(len_buf[2])) << 16;
size |= static_cast<uint32_t>(static_cast<uint8_t>(len_buf[3])) << 24;
size = static_cast<uint32_t>(static_cast<uint8_t>(len_buf[0])) |
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[1])) << 8) |
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[2])) << 16) |
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[3])) << 24);

if (size > VRBRIDGE_MAX_MESSAGE_SIZE) {
logger_->Log(
Expand Down
7 changes: 6 additions & 1 deletion src/bridge/ProtobufMessages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ package messages;
* recieve messages this frame.
*/

option java_package = "dev.slimevr.bridge";
option java_package = "dev.slimevr.desktop.platform";
option java_outer_classname = "ProtobufMessages";
option optimize_for = LITE_RUNTIME;

message PingPong {
}

message Version {
int32 protocol_version = 1;
}

message Position {
int32 tracker_id = 1;
optional float x = 2;
Expand Down Expand Up @@ -117,5 +121,6 @@ message ProtobufMessage {
TrackerAdded tracker_added = 3;
TrackerStatus tracker_status = 4;
Battery battery = 5;
Version version = 6;
}
}
5 changes: 4 additions & 1 deletion test/TestBridgeClientMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ TEST_CASE("IO with a mock server", "[Bridge]") {
tracker_position->set_qw(0);
server_mock->SendBridgeMessage(*server_message);
}
} else {
} else if(message.has_version()) {
TestLogVersion(logger, message);
}
else {
invalid_messages++;
}

Expand Down
6 changes: 6 additions & 0 deletions test/common/TestBridgeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ void TestLogTrackerStatus(std::shared_ptr<Logger> logger, const messages::Protob
}
}

void TestLogVersion(std::shared_ptr<Logger> logger, const messages::ProtobufMessage& message) {
if (!message.has_version()) return;
messages::Version version = message.version();
logger->Log("protocol version {}", version.protocol_version());
}

void TestBridgeClient() {
using namespace std::chrono;

Expand Down
1 change: 1 addition & 0 deletions test/common/TestBridgeClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

void TestLogTrackerAdded(std::shared_ptr<Logger> logger, const messages::ProtobufMessage& message);
void TestLogTrackerStatus(std::shared_ptr<Logger> logger, const messages::ProtobufMessage& message);
void TestLogVersion(std::shared_ptr<Logger> logger, const messages::ProtobufMessage& message);
void TestBridgeClient();