Skip to content

Commit dc5787f

Browse files
authored
Merge pull request #205 from BluEye-Robotics/jp-pino/typescript
2 parents 0484a68 + 0f5b72b commit dc5787f

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Compile TypeScript Protobuf Definitions
2+
3+
on: [push]
4+
5+
jobs:
6+
compile:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout source
11+
uses: actions/checkout@v4
12+
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: "latest"
17+
registry-url: "https://registry.npmjs.org/"
18+
scope: "@blueyerobotics"
19+
20+
- name: Create tsconfig
21+
run: |
22+
cd protobuf_definitions
23+
echo '{
24+
"compilerOptions": {
25+
"target": "ES2020",
26+
"module": "CommonJS",
27+
"declaration": true,
28+
"outDir": "dist",
29+
"strict": true,
30+
"esModuleInterop": true
31+
},
32+
"include": ["./**/*.ts"]
33+
}' > tsconfig.json
34+
35+
- name: Create package
36+
run: |
37+
cd protobuf_definitions
38+
SHORT_SHA=${GITHUB_SHA::8}
39+
echo '{
40+
"name": "@blueyerobotics/protocol-definitions",
41+
"version": "3.2.0-'${SHORT_SHA}'",
42+
"license": "LGPL-3.0-only",
43+
"description": "TypeScript definitions for Blueye Robotics protocols",
44+
"repository": {
45+
"type": "git",
46+
"url": "https://github.com/BluEye-Robotics/ProtocolDefinitions.git"
47+
},
48+
"main": "dist/index.js",
49+
"types": "dist/index.d.ts",
50+
"files": ["dist"],
51+
"scripts": {
52+
"build": "tsc"
53+
},
54+
"dependencies": {
55+
"@bufbuild/protobuf": "^2.5.2"
56+
},
57+
"devDependencies": {
58+
"ts-proto": "^2.7.5",
59+
"typescript": "^5.8.3"
60+
}
61+
}' > package.json
62+
63+
- name: Install dependencies
64+
run: |
65+
sudo apt-get update
66+
sudo apt-get install -y protobuf-compiler
67+
cd protobuf_definitions
68+
npm install
69+
70+
- name: Generate
71+
run: |
72+
cd protobuf_definitions
73+
mkdir -p ./out/ &&
74+
protoc *.proto --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./out \
75+
--ts_proto_opt=outputIndex=true --ts_proto_opt=globalThisPolyfill=true
76+
77+
- name: Compile
78+
run: |
79+
cd protobuf_definitions
80+
npm run build
81+
82+
- name: Publish to npm
83+
run: |
84+
cp README.npm.md protobuf_definitions/README.md
85+
cd protobuf_definitions
86+
npm publish --access public --tag latest
87+
env:
88+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
89+
90+
- name: Check npm pack contents
91+
run: |
92+
cd protobuf_definitions
93+
npm pack
94+
tar -tzf *.tgz

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@
55
This repository contains protocol definitions for interacting with the Blueye underwater drones.
66

77
## Protocol v2
8+
89
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.
910

1011
## Protocol v3
12+
1113
Version 3 of the Blueye communication protocol is based on [Protocol Buffers](https://developers.google.com/protocol-buffers).
1214

13-
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/).
15+
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).
1416

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

1719
### Installation
20+
1821
#### OS X
22+
1923
```
2024
make
2125
make install PREFIX=/usr/local
2226
```
2327

2428
### Uninstall
29+
2530
#### OS X
31+
2632
```
2733
make uninstall PREFIX=/usr/local
2834
```

README.npm.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @blueyerobotics/protocol-definitions
2+
3+
TypeScript protobuf definitions for Blueye Robotics protocols generated using [ts-proto](https://github.com/stephenh/ts-proto).
4+
5+
## Installation
6+
7+
```bash
8+
npm install @blueyerobotics/protocol-definitions
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { blueye } from "@blueyerobotics/protocol-definitions";
15+
16+
// Create a new GetBatteryReq message
17+
const request = blueye.protocol.GetBatteryReq.create();
18+
19+
// Serialize the message to a Uint8Array (binary)
20+
const binary = blueye.protocol.GetBatteryReq.encode(request).finish();
21+
22+
// ...
23+
24+
// For demonstration, we will simulate a response from the device
25+
const response = blueye.protocol.GetBatteryRep.create({
26+
battery: {
27+
level: 85,
28+
voltage: 12.5,
29+
temperature: 25,
30+
},
31+
});
32+
33+
const binaryResponse = blueye.protocol.GetBatteryRep.encode(response).finish();
34+
35+
// Decode a binary response back into a message
36+
const decoded = blueye.protocol.GetBatteryRep.decode(binaryResponse);
37+
38+
// Access fields
39+
console.log(decoded.battery?.level);
40+
```

0 commit comments

Comments
 (0)