Skip to content

YAMCS protocol buffer definitions provided as a static module

License

Notifications You must be signed in to change notification settings

ozyx/yamcs-protobufjs-static

Repository files navigation

yamcs-protobufjs-static

This package provides protobufjs definitions and typings for YAMCS.

To use:

// 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());
}

About

YAMCS protocol buffer definitions provided as a static module

Resources

License

Stars

Watchers

Forks

Packages

No packages published