Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test Cstyle writing/reading #166

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 }}
3 changes: 2 additions & 1 deletion fill/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cc_binary(
"//protos:command_cc_grpc",
"//fill/actuators:qd",
"//fill/actuators:ball_valve",
"//fill/umbilical:rocket_proto_builder",
"//fill/actuators:sol_valve",
"//fill/sensors:pt",
"@abseil-cpp//absl/flags:flag",
Expand All @@ -13,4 +14,4 @@ cc_binary(
"@com_github_grpc_grpc//:grpc++",
"@com_github_grpc_grpc//:grpc++_reflection",
],
)
)
6 changes: 1 addition & 5 deletions fill/actuators/sol_valve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ SolValve::SolValve(){

SolValve::~SolValve(){}



void SolValve::open(){
pinMode(SV_SIGNAL, OUTPUT);
digitalWrite(SV_SIGNAL, HIGH);
Expand All @@ -37,6 +35,4 @@ void SolValve::close(){
pinMode(SV_SIGNAL, OUTPUT);
digitalWrite(SV_SIGNAL, LOW);
isOpen=false;
}


}
40 changes: 29 additions & 11 deletions fill/fill_station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "actuators/sol_valve.h"

#include "sensors/pt.h"
#include "umbilical/proto_build.h"

#include "wiringPi.h"

Expand All @@ -31,7 +32,10 @@ using command::Commander;
using command::FillStationTelemeter;
using command::CommandReply;
using command::FillStationTelemetry;
using command::TelemetryRequest;
using command::FillStationTelemetryRequest;
using command::RocketTelemetryRequest;
using command::RocketTelemetry;
using command::RocketTelemeter;
using grpc::Channel;
using grpc::ClientContext;
using grpc::Server;
Expand All @@ -48,6 +52,8 @@ SolValve sv1;
/* Sensors */
PT pt1 = PT(0x48, 3);
PT pt2 = PT(0x48, 2);
/* Umblical Tools */
RocketTelemetryProtoBuilder protoBuild;

ABSL_FLAG(uint16_t, server_port, 50051, "Server port for the service");

Expand Down Expand Up @@ -115,23 +121,17 @@ class CommanderServiceImpl final : public Commander::Service
sv1.close();
}
}
if (request->sv2_close()){
// send TCP command to rocket_controller
}
if (request->mav_open()){
// send TCP command to rocket_controller
}
if (request->fire()){
// send TCP command to rocket_controller
}

protoBuild.sendCommand(request);

return Status::OK;
}
};

// Fill Station service to stream telemetry.
class TelemeterServiceImpl final : public FillStationTelemeter::Service
{
Status StreamTelemetry(ServerContext *context, const TelemetryRequest *request,
Status StreamTelemetry(ServerContext *context, const FillStationTelemetryRequest *request,
ServerWriter<FillStationTelemetry> *writer) override
{
while (true) {
Expand All @@ -147,12 +147,29 @@ class TelemeterServiceImpl final : public FillStationTelemeter::Service
}
};

class RocketTelemeterServiceImpl final : public RocketTelemeter::Service
{
Status StreamTelemetry(ServerContext *context, const RocketTelemetryRequest *request,
ServerWriter<RocketTelemetry> *writer) override
{
while (true) {
auto now = std::chrono::high_resolution_clock::now();
RocketTelemetry t = protoBuild.buildProto();
if (!writer->Write(t)) {
// Broken stream
return Status::CANCELLED;
}
}
}
};

// Server startup function
void RunServer(uint16_t port, std::shared_ptr<Server> server)
{
std::string server_address = absl::StrFormat("0.0.0.0:%d", port);
CommanderServiceImpl commander_service;
TelemeterServiceImpl telemeter_service;
RocketTelemeterServiceImpl rocket_telemeter_service;

grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
Expand All @@ -162,6 +179,7 @@ void RunServer(uint16_t port, std::shared_ptr<Server> server)
// Register services.
builder.RegisterService(&commander_service);
builder.RegisterService(&telemeter_service);
builder.RegisterService(&rocket_telemeter_service);
// Finally assemble the server.
server = builder.BuildAndStart();
// std::unique_ptr<Server> server(builder.BuildAndStart());
Expand Down
13 changes: 13 additions & 0 deletions fill/umbilical/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cc_library(
name = "rocket_proto_builder",
srcs = ["proto_build.cc"],
hdrs = ["proto_build.h"],
deps = [
"//protos:command_cc_grpc",
"@com_github_grpc_grpc//:grpc++",
"@com_github_grpc_grpc//:grpc++_reflection",
],
visibility = [
"//fill:__subpackages__",
],
)
Loading
Loading