Skip to content

Commit 03ddfdd

Browse files
committed
Add version support via protobuf
1 parent 5df3ec1 commit 03ddfdd

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ To update vcpkg packages set the vcpkg registry submodule to a newer commit and
5858

5959
### Updating protobuf messages
6060

61-
You can modify the protobuf messages for communication between the server and this driver at [src\bridge\ProtobufMessages.proto](src\bridge\ProtobufMessages.proto)
61+
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)
6262

6363
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`

src/bridge/BridgeClient.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void BridgeClient::CreateConnection() {
4040
logger_->Log("[%s] connected", path.c_str());
4141
connected_ = true;
4242
last_error_ = std::nullopt;
43+
SendVersion();
4344
});
4445
connection_handle_->on<uvw::end_event>([this, path](const uvw::end_event&, uvw::pipe_handle&) {
4546
logger_->Log("[%s] disconnected", path.c_str());
@@ -79,3 +80,12 @@ void BridgeClient::CloseConnectionHandles() {
7980
if (reconnect_timeout_) reconnect_timeout_->close();
8081
connected_ = false;
8182
}
83+
84+
void BridgeClient::SendVersion() {
85+
messages::ProtobufMessage* message = google::protobuf::Arena::CreateMessage<messages::ProtobufMessage>(&arena_);
86+
messages::Version* version = google::protobuf::Arena::CreateMessage<messages::Version>(&arena_);
87+
message->set_allocated_version(version);
88+
version->set_protocol_version(PROTOCOL_VERSION);
89+
SendBridgeMessage(*message);
90+
arena_.Reset();
91+
}

src/bridge/BridgeClient.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include "BridgeTransport.hpp"
3030

31+
#define PROTOCOL_VERSION 1
32+
3133
/**
3234
* @brief Client implementation for communication with SlimeVR Server using pipes or unix sockets.
3335
*
@@ -49,8 +51,11 @@ class BridgeClient: public BridgeTransport {
4951
void ResetConnection() override;
5052
void CloseConnectionHandles() override;
5153
void Reconnect();
54+
void SendVersion();
5255

5356
std::optional<std::string> last_error_;
5457
std::optional<std::string> last_path_;
5558
std::shared_ptr<uvw::timer_handle> reconnect_timeout_;
59+
60+
google::protobuf::Arena arena_;
5661
};

src/bridge/ProtobufMessages.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ option optimize_for = LITE_RUNTIME;
5454
message PingPong {
5555
}
5656

57+
message Version {
58+
int32 protocol_version = 1;
59+
}
60+
5761
message Position {
5862
int32 tracker_id = 1;
5963
optional float x = 2;
@@ -117,5 +121,6 @@ message ProtobufMessage {
117121
TrackerAdded tracker_added = 3;
118122
TrackerStatus tracker_status = 4;
119123
Battery battery = 5;
124+
Version version = 6;
120125
}
121126
}

0 commit comments

Comments
 (0)