-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added helper lib (shared code over many examples)
- Loading branch information
1 parent
367ab6f
commit 040d8f2
Showing
12 changed files
with
1,346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
*.DS_STORE | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "lib-helper" | ||
version = "0.1.0" | ||
authors = ["Lind, Niclas <[email protected]>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
futures = "0.3.19" | ||
prost = "0.9.0" | ||
sha2 = "0.10.1" | ||
tokio = { version = "1.14.0", features = ["rt-multi-thread", "time", "fs", "macros", "net"] } | ||
tonic = "0.6.2" | ||
walkdir = "2.3.2" | ||
|
||
[build-dependencies] | ||
tonic-build = "0.6.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::configure() | ||
.build_server(false) | ||
.out_dir("src/beamy_api") | ||
.compile( | ||
&[ | ||
"protos/common.proto", | ||
"protos/diagnostics_api.proto", | ||
"protos/functional_api.proto", | ||
"protos/network_api.proto", | ||
"protos/system_api.proto", | ||
"protos/traffic_api.proto", | ||
], | ||
&["protos"], | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
syntax = "proto3"; | ||
|
||
package base; | ||
|
||
message Empty { | ||
} | ||
|
||
message ClientId { | ||
string id = 1; | ||
} | ||
|
||
message SignalId { | ||
string name = 1; | ||
NameSpace namespace = 2; | ||
} | ||
|
||
message SignalInfo { | ||
SignalId id = 1; | ||
MetaData metaData = 2; | ||
} | ||
|
||
message MetaData { | ||
string description = 4; | ||
int32 max = 5; | ||
int32 min = 6; | ||
string unit = 7; | ||
int32 size = 8; | ||
bool isRaw = 9; | ||
double factor = 10; | ||
double offset = 11; | ||
} | ||
|
||
message NameSpace { | ||
string name = 1; | ||
} | ||
|
||
message NetworkInfo { | ||
NameSpace namespace = 1; | ||
string type = 2; | ||
string description = 3; | ||
} | ||
|
||
message FrameInfo { | ||
SignalInfo signalInfo = 1; | ||
repeated SignalInfo childInfo = 2; | ||
} | ||
|
||
message Frames { | ||
repeated FrameInfo frame = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
syntax = "proto3"; | ||
|
||
import "common.proto"; | ||
|
||
package base; | ||
|
||
// # 0x22 read data by identinifier (Service id) | ||
// # 0x1f90 did for vin number (Data identifier) | ||
|
||
service DiagnosticsService { | ||
rpc SendDiagnosticsQuery (DiagnosticsRequest) returns (DiagnosticsResponse) {} | ||
} | ||
|
||
message DiagnosticsRequest { | ||
SignalId upLink = 1; | ||
SignalId downLink = 2; | ||
bytes serviceId = 3; | ||
bytes dataIdentifier = 4; | ||
} | ||
|
||
message DiagnosticsResponse { | ||
bytes raw = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
syntax = "proto3"; | ||
|
||
// fix this with compiler flag -I | ||
import "common.proto"; | ||
|
||
package base; | ||
|
||
service FunctionalService { | ||
rpc OpenPassWindow (ClientId) returns (Empty) {} | ||
rpc ClosePassWindow (ClientId) returns (Empty) {} | ||
rpc SetFanSpeed (SenderInfo) returns (Empty) {} | ||
rpc SubscribeToFanSpeed (SubscriberRequest) returns (stream Value) {} | ||
} | ||
|
||
// to stop hammering make same call with frequency 0 | ||
message SenderInfo { | ||
ClientId clientId = 1; | ||
Value value = 2; | ||
int32 frequency = 3; | ||
} | ||
|
||
message SubscriberRequest { | ||
ClientId clientId = 1; | ||
bool onChange = 2; | ||
} | ||
|
||
message Value { | ||
int32 payload = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
syntax = "proto3"; | ||
|
||
import "common.proto"; | ||
|
||
package base; | ||
|
||
service NetworkService { | ||
rpc SubscribeToSignals (SubscriberConfig) returns (stream Signals) {} | ||
rpc PublishSignals (PublisherConfig) returns (Empty) {} | ||
rpc ReadSignals (SignalIds) returns (Signals) {} | ||
} | ||
|
||
message SubscriberConfig { | ||
ClientId clientId = 1; | ||
SignalIds signals = 2; | ||
bool onChange = 3; | ||
} | ||
|
||
message SignalIds { | ||
repeated SignalId signalId = 1; | ||
} | ||
|
||
message Signals { | ||
repeated Signal signal = 1; | ||
} | ||
|
||
message PublisherConfig { | ||
Signals signals = 1; | ||
ClientId clientId = 2; | ||
int32 frequency = 3; | ||
} | ||
|
||
message Signal { | ||
SignalId id = 1; | ||
oneof payload { | ||
int64 integer = 2; | ||
double double = 3; | ||
bool arbitration = 4; | ||
bool empty = 6; | ||
} | ||
bytes raw = 5; | ||
int64 timestamp = 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
syntax = "proto3"; | ||
|
||
import "common.proto"; | ||
|
||
package base; | ||
|
||
service SystemService { | ||
rpc GetConfiguration (Empty) returns (Configuration) {} | ||
rpc ListSignals (NameSpace) returns (Frames) {} | ||
rpc UploadFileChunk (FileUploadChunkRequest) returns (FileUploadResponse) {} | ||
rpc UploadFile (stream FileUploadRequest) returns (FileUploadResponse) {} | ||
rpc DownloadFile (FileDescription) returns (stream FileDownloadResponse) {} | ||
// will not return until new configuration is tested an active, make sure to set timeout to a large value. (fibex on pi > 50s) | ||
rpc ReloadConfiguration (Empty) returns (ReloadMessage) {} | ||
rpc GetLicenseInfo (Empty) returns (LicenseInfo) {} | ||
rpc SetLicense (License) returns (LicenseInfo) {} | ||
} | ||
|
||
message Configuration { | ||
repeated NetworkInfo networkInfo = 1; | ||
bytes interfacesJson = 2; | ||
string publicAddress = 4; | ||
string serverVersion = 5; | ||
} | ||
|
||
message ReloadMessage{ | ||
oneof status { | ||
Configuration configuration = 1; | ||
string errorMessage = 2; | ||
} | ||
} | ||
|
||
message FileDescription{ | ||
// sha256 is base16 encoded and not relevant when downloading | ||
string sha256 = 1; | ||
string path = 2; | ||
} | ||
|
||
message FileUploadRequest{ | ||
oneof data { | ||
FileDescription fileDescription = 1; | ||
bytes chunk = 2; | ||
} | ||
} | ||
|
||
message FileUploadChunkRequest{ | ||
FileDescription fileDescription = 1; | ||
uint32 chunks = 2; | ||
uint32 chunkId = 3; | ||
bytes chunk = 4; | ||
bool cancelUpload = 5; | ||
uint32 uploadTimeout = 6; | ||
} | ||
|
||
message FileUploadResponse{ | ||
oneof data { | ||
bool finished = 1; | ||
bool cancelled = 2; | ||
string errorMessage = 3; | ||
}; | ||
} | ||
|
||
message FileDownloadResponse{ | ||
oneof data { | ||
bytes chunk = 1; | ||
string errorMessage = 2; | ||
}; | ||
} | ||
|
||
enum LicenseStatus { | ||
UNSET = 0; | ||
VALID = 1; | ||
EXPIRED = 2; | ||
BADDATE = 3; | ||
WRONGMACHINE = 4; | ||
INCOMPLETEJSON = 5; | ||
INVALIDJSON = 6; | ||
BADSIGNATURE = 7; | ||
MALFORMED = 8; | ||
SERVERERROR = 9; | ||
NOTERMSAGREEMENT = 10; | ||
} | ||
|
||
message LicenseInfo { | ||
LicenseStatus status = 1; | ||
// verbatim json from the license data (if base64-decodable) | ||
bytes json = 2; | ||
// extracted from json for convenience | ||
string expires = 3; | ||
// info to use when requesting a new license | ||
string requestId = 4; | ||
bytes requestMachineId = 5; | ||
} | ||
|
||
message License { | ||
bytes data = 1; | ||
bool termsAgreement = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
syntax = "proto3"; | ||
|
||
import "common.proto"; | ||
import "system_api.proto"; | ||
|
||
package base; | ||
|
||
service TrafficService { | ||
rpc PlayTraffic (PlaybackInfos) returns (PlaybackInfos) {} | ||
} | ||
|
||
enum Mode { | ||
PLAY = 0; | ||
PAUSE = 1; | ||
STOP = 2; | ||
RECORD = 3; | ||
} | ||
|
||
message PlaybackMode { | ||
oneof status { | ||
string errorMessage = 2; | ||
string EOF = 3; | ||
Mode mode = 4; | ||
} | ||
} | ||
|
||
message PlaybackInfos { | ||
repeated PlaybackInfo playbackInfo = 1; | ||
} | ||
|
||
message PlaybackConfig { | ||
FileDescription fileDescription = 1; | ||
NameSpace namespace = 2; | ||
} | ||
|
||
message PlaybackInfo { | ||
PlaybackConfig playbackConfig = 1; | ||
PlaybackMode playbackMode = 2; | ||
} | ||
|
Oops, something went wrong.