diff --git a/.gitignore b/.gitignore index d37e53d..98e9c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ vcpkg_installed/ # Project-specific build/* out/ +/.vscode diff --git a/README.md b/README.md index b0a3690..0a31f8c 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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` \ No newline at end of file diff --git a/src/bridge/BridgeClient.cpp b/src/bridge/BridgeClient.cpp index 2f451a3..716bcda 100644 --- a/src/bridge/BridgeClient.cpp +++ b/src/bridge/BridgeClient.cpp @@ -40,6 +40,7 @@ void BridgeClient::CreateConnection() { logger_->Log("[{}] connected", path); connected_ = true; last_error_ = std::nullopt; + SendVersion(); }); connection_handle_->on([this, path](const uvw::end_event&, uvw::pipe_handle&) { logger_->Log("[{}] disconnected", path); @@ -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(&arena_); + messages::Version* version = google::protobuf::Arena::CreateMessage(&arena_); + message->set_allocated_version(version); + version->set_protocol_version(PROTOCOL_VERSION); + SendBridgeMessage(*message); + arena_.Reset(); +} diff --git a/src/bridge/BridgeClient.hpp b/src/bridge/BridgeClient.hpp index d8daadc..0c9ea5e 100644 --- a/src/bridge/BridgeClient.hpp +++ b/src/bridge/BridgeClient.hpp @@ -28,6 +28,8 @@ #include "BridgeTransport.hpp" +#define PROTOCOL_VERSION 1 + /** * @brief Client implementation for communication with SlimeVR Server using pipes or unix sockets. * @@ -49,8 +51,11 @@ class BridgeClient: public BridgeTransport { void ResetConnection() override; void CloseConnectionHandles() override; void Reconnect(); + void SendVersion(); std::optional last_error_; std::optional last_path_; std::shared_ptr reconnect_timeout_; + + google::protobuf::Arena arena_; }; \ No newline at end of file diff --git a/src/bridge/BridgeTransport.cpp b/src/bridge/BridgeTransport.cpp index aa3b664..1031aea 100644 --- a/src/bridge/BridgeTransport.cpp +++ b/src/bridge/BridgeTransport.cpp @@ -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(static_cast(len_buf[0])) << 0; - size |= static_cast(static_cast(len_buf[1])) << 8; - size |= static_cast(static_cast(len_buf[2])) << 16; - size |= static_cast(static_cast(len_buf[3])) << 24; + size = static_cast(static_cast(len_buf[0])) | + (static_cast(static_cast(len_buf[1])) << 8) | + (static_cast(static_cast(len_buf[2])) << 16) | + (static_cast(static_cast(len_buf[3])) << 24); if (size > VRBRIDGE_MAX_MESSAGE_SIZE) { logger_->Log( diff --git a/src/bridge/ProtobufMessages.proto b/src/bridge/ProtobufMessages.proto index 26b4a5c..b174e0a 100644 --- a/src/bridge/ProtobufMessages.proto +++ b/src/bridge/ProtobufMessages.proto @@ -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; @@ -117,5 +121,6 @@ message ProtobufMessage { TrackerAdded tracker_added = 3; TrackerStatus tracker_status = 4; Battery battery = 5; + Version version = 6; } } \ No newline at end of file diff --git a/test/TestBridgeClientMock.cpp b/test/TestBridgeClientMock.cpp index b3f1f8e..3b4612f 100644 --- a/test/TestBridgeClientMock.cpp +++ b/test/TestBridgeClientMock.cpp @@ -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++; } diff --git a/test/common/TestBridgeClient.cpp b/test/common/TestBridgeClient.cpp index 1fabb03..efc485a 100644 --- a/test/common/TestBridgeClient.cpp +++ b/test/common/TestBridgeClient.cpp @@ -25,6 +25,12 @@ void TestLogTrackerStatus(std::shared_ptr logger, const messages::Protob } } +void TestLogVersion(std::shared_ptr 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; diff --git a/test/common/TestBridgeClient.hpp b/test/common/TestBridgeClient.hpp index 65a5c28..1ce08df 100644 --- a/test/common/TestBridgeClient.hpp +++ b/test/common/TestBridgeClient.hpp @@ -8,4 +8,5 @@ void TestLogTrackerAdded(std::shared_ptr logger, const messages::ProtobufMessage& message); void TestLogTrackerStatus(std::shared_ptr logger, const messages::ProtobufMessage& message); +void TestLogVersion(std::shared_ptr logger, const messages::ProtobufMessage& message); void TestBridgeClient();