Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/ci-typescript.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Compile TypeScript Protobuf Definitions

on: [push]

jobs:
compile:
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
registry-url: "https://registry.npmjs.org/"
scope: "@blueyerobotics"

- name: Create tsconfig
run: |
cd protobuf_definitions
echo '{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"declaration": true,
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": ["./**/*.ts"]
}' > tsconfig.json

- name: Create package
run: |
cd protobuf_definitions
SHORT_SHA=${GITHUB_SHA::8}
echo '{
"name": "@blueyerobotics/protocol-definitions",
"version": "3.2.0-'${SHORT_SHA}'",
"license": "LGPL-3.0-only",
"description": "TypeScript definitions for Blueye Robotics protocols",
"repository": {
"type": "git",
"url": "https://github.com/BluEye-Robotics/ProtocolDefinitions.git"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "tsc"
},
"dependencies": {
"@bufbuild/protobuf": "^2.5.2"
},
"devDependencies": {
"ts-proto": "^2.7.5",
"typescript": "^5.8.3"
}
}' > package.json

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
cd protobuf_definitions
npm install

- name: Generate
run: |
cd protobuf_definitions
mkdir -p ./out/ &&
protoc *.proto --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./out \
--ts_proto_opt=outputIndex=true --ts_proto_opt=globalThisPolyfill=true

- name: Compile
run: |
cd protobuf_definitions
npm run build

- name: Publish to npm
run: |
cp README.npm.md protobuf_definitions/README.md
cd protobuf_definitions
npm publish --access public --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Check npm pack contents
run: |
cd protobuf_definitions
npm pack
tar -tzf *.tgz
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
This repository contains protocol definitions for interacting with the Blueye underwater drones.

## Protocol v2

Drones running a Blunux version \< 3.0 will need to use the legacy protocol. [blueye.legacyprotocol](https://github.com/BluEye-Robotics/blueye.legacyprotocol) contains a Python package that is built on this protocol and simplifies its use.

## Protocol v3

Version 3 of the Blueye communication protocol is based on [Protocol Buffers](https://developers.google.com/protocol-buffers).

The protobuf definitions are compiled to language specific libraries, and are available as a [NuGet package](https://github.com/BluEye-Robotics/ProtocolDefinitions/packages/1239508) and a [Python package](https://pypi.org/project/blueye.protocol/).
The protobuf definitions are compiled to language specific libraries, and are available as a [NuGet package](https://github.com/BluEye-Robotics/ProtocolDefinitions/packages/1239508), [Python package](https://pypi.org/project/blueye.protocol/) and a [npm package](https://www.npmjs.com/package/@blueyerobotics/protocol-definitions).

Automatically generated documentation for the protocol format can be found [here](https://blueyebuildserver.blob.core.windows.net/protocoldefinitions/docs/protocol.html).

### Installation

#### OS X

```
make
make install PREFIX=/usr/local
```

### Uninstall

#### OS X

```
make uninstall PREFIX=/usr/local
```
40 changes: 40 additions & 0 deletions README.npm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @blueyerobotics/protocol-definitions

TypeScript protobuf definitions for Blueye Robotics protocols generated using [ts-proto](https://github.com/stephenh/ts-proto).

## Installation

```bash
npm install @blueyerobotics/protocol-definitions
```

## Usage

```ts
import { blueye } from "@blueyerobotics/protocol-definitions";

// Create a new GetBatteryReq message
const request = blueye.protocol.GetBatteryReq.create();

// Serialize the message to a Uint8Array (binary)
const binary = blueye.protocol.GetBatteryReq.encode(request).finish();

// ...

// For demonstration, we will simulate a response from the device
const response = blueye.protocol.GetBatteryRep.create({
battery: {
level: 85,
voltage: 12.5,
temperature: 25,
},
});

const binaryResponse = blueye.protocol.GetBatteryRep.encode(response).finish();

// Decode a binary response back into a message
const decoded = blueye.protocol.GetBatteryRep.decode(binaryResponse);

// Access fields
console.log(decoded.battery?.level);
```