Skip to content

Commit

Permalink
Creating Rocket Telemetry Go Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
bwz5 committed Dec 6, 2024
1 parent 84259a4 commit 083456d
Show file tree
Hide file tree
Showing 11 changed files with 758 additions and 366 deletions.
118 changes: 118 additions & 0 deletions .github/workflows/rocket_telem_proxy_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Create and publish the Telemetry Proxy Docker image

# Configures this workflow to run every time a change is pushed to the branch called `main` or a pull request to `main` is created
on:
push:
branches: ['main']
pull_request:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/rocket-telem-proxy

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=ref,event=pr
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
file: go-proxies/rocket-telem-proxy/Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=ref,event=pr
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
2 changes: 1 addition & 1 deletion fill/umbilical/proto_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using command::RocketUmbTelemetry;

class RocketTelemetryProtoBuilder {
private:
const char* usb_port = "PUT NAME HERE";
const char* usb_port = "/dev/ttyACM0";

std::ifstream serial_data;
public:
Expand Down
4 changes: 2 additions & 2 deletions go-proxies/fill-telem-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
go func(ctx context.Context, grpcClient pb.FillStationTelemeterClient) {
for {

stream, err := grpcClient.StreamTelemetry(ctx, &pb.TelemetryRequest{})
stream, err := grpcClient.StreamTelemetry(ctx, &pb.FillStationTelemetryRequest{})
if err != nil {
log.Printf("could not receive stream: %v, retrying in 5 seconds...", err)
time.Sleep(5 * time.Second)
Expand All @@ -52,7 +52,7 @@ func main() {
}

// Store packet
datastore.Store(packet)
datastore.FillStationTelemetryStore(packet)
}
}
}(ctx, grpcClient)
Expand Down
80 changes: 79 additions & 1 deletion go-proxies/pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (d *Datastore) Init(ctx context.Context) {
}

// Store parses a packet and writes it to InfluxDB
func (d *Datastore) Store(packet *pb.FillStationTelemetry) {
func (d *Datastore) FillStationTelemetryStore(packet *pb.FillStationTelemetry) {
// Create tags map
tags := map[string]string{}

Expand All @@ -100,6 +100,84 @@ func (d *Datastore) Store(packet *pb.FillStationTelemetry) {
}
}

// Stores RocketTelemetry to InfluxDB
func (d *Datastore) RocketTelemetryStore(packet *pb.RocketTelemetry) {
timestamp := time.Now()
// Create tags map
tags := map[string]string{}

// Create fields map
fields := map[string]interface{}{}

// Access Umb telemetry data if available
if packet.UmbTelem != nil {
umbTelem := packet.UmbTelem
fields["ms_since_boot"] = umbTelem.MsSinceBoot
fields["radio_state"] = umbTelem.RadioState
fields["transmit_state"] = umbTelem.TransmitState
fields["voltage"] = umbTelem.Voltage
fields["pt3"] = umbTelem.Pt3
fields["pt4"] = umbTelem.Pt4
fields["rtd_temp"] = umbTelem.RtdTemp

if umbTelem.Metadata != nil {
metaData := umbTelem.Metadata

// Tags have to be of type [string][string]
tags["alt_armed"] = fmt.Sprintf("%v", metaData.AltArmed)
tags["alt_valid"] = fmt.Sprintf("%v", metaData.AltValid)
tags["gps_valid"] = fmt.Sprintf("%v", metaData.GpsValid)
tags["imu_valid"] = fmt.Sprintf("%v", metaData.ImuValid)
tags["acc_valid"] = fmt.Sprintf("%v", metaData.AccValid)
tags["therm_valid"] = fmt.Sprintf("%v", metaData.ThermValid)
tags["voltage_valid"] = fmt.Sprintf("%v", metaData.VoltageValid)
tags["adc_valid"] = fmt.Sprintf("%v", metaData.AdcValid)
tags["fram_valid"] = fmt.Sprintf("%v", metaData.FramValid)
tags["sd_valid"] = fmt.Sprintf("%v", metaData.SdValid)
tags["gps_msg_valid"] = fmt.Sprintf("%v", metaData.GpsMsgValid)
tags["mav_state"] = fmt.Sprintf("%v", metaData.MavState)
tags["sv_state"] = fmt.Sprintf("%v", metaData.SvState)
tags["flight_mode"] = metaData.FlightMode.String()
}

if umbTelem.Events != nil {
events := umbTelem.Events
fields["altitude_armed"] = events.AltitudeArmed
fields["altimeter_init_failed"] = events.AltimeterInitFailed
fields["altimeter_reading_failed"] = events.AltimeterReadingFailed
fields["gps_init_failed"] = events.GpsInitFailed
fields["gps_reading_failed"] = events.GpsReadingFailed
fields["imu_init_failed"] = events.ImuInitFailed
fields["imu_reading_failed"] = events.ImuReadingFailed
fields["accelerometer_init_failed"] = events.AccelerometerInitFailed
fields["accelerometer_reading_failed"] = events.AccelerometerReadingFailed
fields["thermometer_init_failed"] = events.ThermometerInitFailed
fields["thermometer_reading_failed"] = events.ThermometerReadingFailed
fields["voltage_init_failed"] = events.VoltageInitFailed
fields["voltage_reading_failed"] = events.VoltageReadingFailed
fields["adc_init_failed"] = events.AdcInitFailed
fields["adc_reading_failed"] = events.AdcReadingFailed
fields["fram_init_failed"] = events.FramInitFailed
fields["fram_write_failed"] = events.FramWriteFailed
fields["sd_init_failed"] = events.SdInitFailed
fields["sd_write_failed"] = events.SdWriteFailed
fields["mav_was_actuated"] = events.MavWasActuated
fields["sv_was_actuated"] = events.SvWasActuated
fields["main_deploy_wait_end"] = events.MainDeployWaitEnd
fields["main_log_shutoff"] = events.MainLogShutoff
fields["cycle_overflow"] = events.CycleOverflow
fields["invalid_command"] = events.InvalidCommand
}
}

point := write.NewPoint("telemetry", tags, fields, timestamp)
writeCtx, writeCancel := context.WithTimeout(d.ctx, time.Second)
defer writeCancel()
if err := d.writeAPI.WritePoint(writeCtx, point); err != nil {
log.Println(err)
}
}

// Query parses and executes a json request for historical data
func (d *Datastore) Query(req HistoricalDataRequest) HistoricalDataResponse {
// Validate input (important to prevent injection attacks!)
Expand Down
Loading

0 comments on commit 083456d

Please sign in to comment.