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

Add temporary ducer implementation #1

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
6 changes: 5 additions & 1 deletion fill/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cc_library(
name = "telemetry_reader",
srcs = ["telemetry_reader.cc"],
hdrs = ["telemetry_reader.h"],
deps = ["//protos:telemetry_cc_proto"],
deps = [
"//protos:telemetry_cc_proto",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, we should probably distinguish (in name) between fill station telemetry and rocket telemetry

"//sensors:sensor"],
)

cc_test(
Expand All @@ -11,6 +13,7 @@ cc_test(
srcs = ["telemetry_reader_test.cc"],
deps = [
":telemetry_reader",
"//sensors:mock_sensor",
"@googletest//:gtest_main",
],
)
Expand All @@ -22,6 +25,7 @@ cc_binary(
":telemetry_reader",
"//protos:command_cc_grpc",
"//protos:telemetry_cc_grpc",
"//sensors:ducer",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
"@abseil-cpp//absl/strings:str_format",
Expand Down
6 changes: 4 additions & 2 deletions fill/fill_station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <thread>

#include "telemetry_reader.h"
#include "sensors/ducer.h"

#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
Expand Down Expand Up @@ -83,12 +84,12 @@ class FillStationClient
{
public:
FillStationClient(std::shared_ptr<Channel> channel)
: stub_(Telemeter::NewStub(channel)) {}
: stub_(Telemeter::NewStub(channel)), ducer_(std::make_shared<Ducer>()) {}

// TODO(Zach) add telemetry parameters
bool SendTelemetry(const std::string &temp)
{
TelemetryReader reader;
TelemetryReader reader(*ducer_);
Telemetry telem = reader.read();

// Container for the Ack
Expand Down Expand Up @@ -117,6 +118,7 @@ class FillStationClient

private:
std::unique_ptr<Telemeter::Stub> stub_;
std::shared_ptr<Sensor> ducer_;
};

/*
Expand Down
2 changes: 1 addition & 1 deletion fill/telemetry_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using telemetry::Telemetry;
Telemetry TelemetryReader::read() {
Telemetry telem;
// TODO(Zach) add telemetry parameters
telem.set_temp("It works!");
telem.set_temp(sensor_.Read());
return telem;
}
12 changes: 10 additions & 2 deletions fill/telemetry_reader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#ifndef FILL_TELEMETRY_READER_H_
#define FILL_TELEMETRY_READER_H_

#include "protos/telemetry.pb.h"
#include "sensors/sensor.h"

using telemetry::Telemetry;

class TelemetryReader {
public:
public:
TelemetryReader(Sensor& sensor) : sensor_(sensor) {}
Telemetry read();
};
private:
Sensor& sensor_;
};
#endif
13 changes: 10 additions & 3 deletions fill/telemetry_reader_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#include "telemetry_reader.h"
#include "sensors/mock_sensor.h"

#include "gtest/gtest.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace {

using ::testing::Return;

TEST(TelemetryReaderTest, BasicTest) {
TelemetryReader reader;
float test_val = 3.14;
MockSensor sensor;
EXPECT_CALL(sensor, Read()).Times(1).WillOnce(Return(test_val));
TelemetryReader reader(sensor);
Telemetry telem = reader.read();
EXPECT_EQ(telem.temp(), "It works!");
EXPECT_EQ(telem.temp(), test_val);
}

} //namespace
2 changes: 1 addition & 1 deletion protos/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ service Telemeter {
// The telemetry message
// TODO(Zach) add telemetry values
message Telemetry {
string temp = 1;
float temp = 1;
}

// The response message containing an ack
Expand Down
33 changes: 33 additions & 0 deletions sensors/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cc_library(
name = "sensor",
hdrs = ["sensor.h"],
deps = [],
visibility = [
"//fill:__subpackages__",
"//ground:__subpackages__",
],
)

cc_library(
name = "ducer",
srcs = ["ducer.cc"],
hdrs = ["ducer.h"],
deps = [":sensor"],
visibility = [
"//fill:__subpackages__",
"//ground:__subpackages__",
],
)

cc_library(
name = "mock_sensor",
hdrs = ["mock_sensor.h"],
deps = [
":sensor",
"@googletest//:gtest_main",
],
visibility = [
"//fill:__subpackages__",
"//ground:__subpackages__",
],
)
7 changes: 7 additions & 0 deletions sensors/ducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "ducer.h"

float Ducer::Read() {
float reading = 3.14;
cache_.push_back(reading);
return reading;
}
6 changes: 6 additions & 0 deletions sensors/ducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "sensor.h"

class Ducer : public Sensor {
public:
float Read();
};
12 changes: 12 additions & 0 deletions sensors/mock_sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SENSORS_MOCK_SENSOR_H_
#define SENSORS_MOCK_SENSOR_H_

#include "sensor.h"

#include <gmock/gmock.h> // Brings in gMock.

class MockSensor : public Sensor {
public:
MOCK_METHOD(float, Read, (), (override));
};
#endif
14 changes: 14 additions & 0 deletions sensors/sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef SENSORS_SENSOR_H_
#define SENSORS_SENSOR_H_

#include <vector>

class Sensor {
public:
virtual ~Sensor() {}
virtual float Read() = 0;
protected:
// cache for rolling averages
std::vector<float> cache_;
};
#endif
Loading