-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,64 @@ | ||
# yamcs-protobufjs-static | ||
|
||
WIP | ||
This package provides protobufjs definitions and typings for YAMCS. | ||
|
||
To use: | ||
|
||
```js | ||
// Import the package | ||
import { google, yamcs } from 'yamcs-protobufjs-static'; | ||
|
||
// Extract the needed types | ||
const { SubscribeParametersRequest } = yamcs.protobuf.processing; | ||
const { ClientMessage, CancelOptions } = yamcs.api; | ||
const { Any } = google.protobuf; | ||
|
||
const socket = new WebSocket('ws://localhost:8090/', 'protobuf'); | ||
socket.binaryType = 'arraybuffer'; | ||
|
||
let connected = false; | ||
|
||
socket.onopen = () => { | ||
connected = true; | ||
} | ||
|
||
// Example of subscribing to a parameter | ||
const id = [yamcs.protobuf.NamedObjectId.create({ name: 'myNamedObject'})]; | ||
const message = { | ||
type: 'parameters', | ||
instance: 'myInstance', | ||
processor: 'myProcessor', | ||
id, | ||
sendFromCache: true, | ||
updateOnExpiration: true | ||
}; | ||
|
||
// Verify that it fits the schema of a `SubscribeParametersRequest` | ||
let err = SubscribeParametersRequest.verify(message); | ||
if (err) { | ||
throw Error(err); | ||
} | ||
|
||
let payload = SubscribeParametersRequest.create(message); | ||
const arrayBuffer = SubscribeParametersRequest.encode(payload).finish(); | ||
const clientMessagePayload = { | ||
type: dataType, | ||
id: subscriptionId, | ||
options: Any.create({ | ||
type_url: SubscribeParametersRequest.getTypeUrl(), | ||
value: arrayBuffer | ||
}) | ||
}; | ||
|
||
// Verify that it fits the schema of a `ClientMessage` | ||
err = ClientMessage.verify(clientMessagePayload); | ||
if (err) { | ||
throw Error(err); | ||
} | ||
|
||
const clientMessage = ClientMessage.create(clientMessagePayload); | ||
|
||
if(connected) { | ||
socket.send(ClientMessage.encode(clientMessage).finish()); | ||
} | ||
``` |