Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
219229c
update CMakeLists.txt for newer version of .protos in api repo
penguinland Apr 30, 2024
a3fa6d6
buf.lock was changed automatically. Is this needed?
penguinland Apr 30, 2024
4501e94
Add vim's .swp files to the gitignore
penguinland Apr 30, 2024
1451547
remove conversion functions for removed AnalogStatus and InterruptStatus
penguinland Apr 30, 2024
e3386f5
switch to new Status message for converting board status to/from protos
penguinland Apr 30, 2024
30a789b
remove status from board server
penguinland Apr 30, 2024
6f4d1e8
remove get_status from board_client
penguinland Apr 30, 2024
5380780
remove status from mock board
penguinland May 1, 2024
7ad7824
remove status from board.hpp
penguinland May 1, 2024
f0522f5
remove get_analog_reader_names() and get_digital_interrupt_names()
penguinland May 1, 2024
294bd77
remove get_analog_readers() and get_digital_interrupts()
penguinland May 1, 2024
605e1e1
remove tests of removed functions
penguinland May 1, 2024
dec394d
get things to build again
penguinland May 2, 2024
dccc004
undo linker debugging in cmake
penguinland May 6, 2024
52ce94d
undo changes to .gitignore
penguinland May 6, 2024
d07125f
prune google/expr/ from CMakeLists.txt
penguinland May 6, 2024
b7af358
prune google/api/ from CMakeLists.txt, back to the old version plus a…
penguinland May 6, 2024
0b4616d
remove unnecessary mentions of google/rpc/ from cmakelists.txt
penguinland May 6, 2024
4674c86
add rpc/status.pb.h to cmakelists.txt again
penguinland May 6, 2024
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
9 changes: 9 additions & 0 deletions src/viam/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
endif()

set(BUF_PROTO_COMPONENTS
app/mltraining
app/packages
app/v1
common
Expand Down Expand Up @@ -124,6 +125,8 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
# it sanely? We would need to filter out (or add in) the headers.

# This list is needed for the core library.
${PROTO_GEN_DIR}/app/mltraining/v1/ml_training.pb.cc
${PROTO_GEN_DIR}/app/mltraining/v1/ml_training.pb.h
${PROTO_GEN_DIR}/app/packages/v1/packages.pb.cc
${PROTO_GEN_DIR}/app/packages/v1/packages.pb.h
${PROTO_GEN_DIR}/app/v1/app.grpc.pb.cc
Expand Down Expand Up @@ -184,6 +187,8 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
${PROTO_GEN_DIR}/google/api/httpbody.pb.h
${PROTO_GEN_DIR}/google/api/http.pb.cc
${PROTO_GEN_DIR}/google/api/http.pb.h
${PROTO_GEN_DIR}/google/rpc/status.pb.cc
${PROTO_GEN_DIR}/google/rpc/status.pb.h
${PROTO_GEN_DIR}/module/v1/module.grpc.pb.cc
${PROTO_GEN_DIR}/module/v1/module.grpc.pb.h
${PROTO_GEN_DIR}/module/v1/module.pb.cc
Expand Down Expand Up @@ -257,6 +262,7 @@ add_library(viam-cpp-sdk::viamapi ALIAS viamapi)

target_sources(viamapi
PRIVATE
${PROTO_GEN_DIR}/app/mltraining/v1/ml_training.pb.cc
${PROTO_GEN_DIR}/app/packages/v1/packages.pb.cc
${PROTO_GEN_DIR}/app/v1/app.grpc.pb.cc
${PROTO_GEN_DIR}/app/v1/app.pb.cc
Expand Down Expand Up @@ -287,6 +293,7 @@ target_sources(viamapi
${PROTO_GEN_DIR}/google/api/annotations.pb.cc
${PROTO_GEN_DIR}/google/api/http.pb.cc
${PROTO_GEN_DIR}/google/api/httpbody.pb.cc
${PROTO_GEN_DIR}/google/rpc/status.pb.cc
${PROTO_GEN_DIR}/module/v1/module.grpc.pb.cc
${PROTO_GEN_DIR}/module/v1/module.pb.cc
${PROTO_GEN_DIR}/robot/v1/robot.grpc.pb.cc
Expand All @@ -303,6 +310,7 @@ target_sources(viamapi
BASE_DIRS
${PROTO_GEN_DIR}/../..
FILES
${PROTO_GEN_DIR}/../../viam/api/app/mltraining/v1/ml_training.pb.h
${PROTO_GEN_DIR}/../../viam/api/app/packages/v1/packages.pb.h
${PROTO_GEN_DIR}/../../viam/api/app/v1/app.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/app/v1/app.pb.h
Expand Down Expand Up @@ -333,6 +341,7 @@ target_sources(viamapi
${PROTO_GEN_DIR}/../../viam/api/google/api/annotations.pb.h
${PROTO_GEN_DIR}/../../viam/api/google/api/http.pb.h
${PROTO_GEN_DIR}/../../viam/api/google/api/httpbody.pb.h
${PROTO_GEN_DIR}/../../viam/api/google/rpc/status.pb.h
${PROTO_GEN_DIR}/../../viam/api/module/v1/module.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/module/v1/module.pb.h
${PROTO_GEN_DIR}/../../viam/api/robot/v1/robot.grpc.pb.h
Expand Down
3 changes: 1 addition & 2 deletions src/viam/examples/modules/complex/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: ee48893a270147348e3edc6c1a03de0e
digest: shake256:a35b0576a2b55dad72747e786af05c03539c2b96be236c9de39fe10d551931ac252eb68445c0cef6bbd27fa20e8c26eee5b8a9fe9c2fde6f63a03e18f8cf980d
commit: 74015a8aeb8445aa9e3e1454cb54bc35
61 changes: 7 additions & 54 deletions src/viam/sdk/components/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ API API::traits<Board>::api() {
return {kRDK, kComponent, "board"};
}

Board::status Board::from_proto(const viam::common::v1::BoardStatus& proto) {
Board::status Board::from_proto(const viam::component::board::v1::Status& proto) {
Board::status status;
for (const auto& analog : proto.analogs()) {
status.analog_reader_values.emplace(analog.first, analog.second.value());
status.analog_reader_values.emplace(analog.first, analog.second);
}
for (const auto& digital : proto.digital_interrupts()) {
status.digital_interrupt_values.emplace(digital.first, digital.second.value());
status.digital_interrupt_values.emplace(digital.first, digital.second);
}
return status;
}

Board::analog_value Board::from_proto(const viam::common::v1::AnalogStatus& proto) {
return proto.value();
}

Board::digital_value Board::from_proto(const viam::common::v1::DigitalInterruptStatus& proto) {
return proto.value();
}

Board::power_mode Board::from_proto(viam::component::board::v1::PowerMode proto) {
switch (proto) {
case viam::component::board::v1::POWER_MODE_NORMAL: {
Expand All @@ -55,30 +47,18 @@ Board::power_mode Board::from_proto(viam::component::board::v1::PowerMode proto)
}
}

viam::common::v1::BoardStatus Board::to_proto(const status& status) {
viam::common::v1::BoardStatus proto;
viam::component::board::v1::Status Board::to_proto(const status& status) {
viam::component::board::v1::Status proto;
for (const auto& analog : status.analog_reader_values) {
proto.mutable_analogs()->insert({analog.first, to_proto(analog.second)});
proto.mutable_analogs()->insert({analog.first, analog.second});
}

for (const auto& digital : status.digital_interrupt_values) {
proto.mutable_digital_interrupts()->insert({digital.first, to_proto(digital.second)});
proto.mutable_digital_interrupts()->insert({digital.first, digital.second});
}
return proto;
}

viam::common::v1::AnalogStatus Board::to_proto(analog_value analog_value) {
viam::common::v1::AnalogStatus proto;
proto.set_value(analog_value);
return proto;
}

viam::common::v1::DigitalInterruptStatus Board::to_proto(digital_value digital_value) {
viam::common::v1::DigitalInterruptStatus proto;
proto.set_value(digital_value);
return proto;
}

viam::component::board::v1::PowerMode Board::to_proto(Board::power_mode power_mode) {
switch (power_mode) {
case Board::power_mode::normal: {
Expand All @@ -93,33 +73,6 @@ viam::component::board::v1::PowerMode Board::to_proto(Board::power_mode power_mo
}
}

std::vector<std::string> Board::get_analog_reader_names() {
std::vector<std::string> names;
auto status = this->get_status();
names.reserve(status.analog_reader_values.size());
for (const auto& kv : status.analog_reader_values) {
names.push_back(kv.first);
}
return names;
}

std::vector<std::string> Board::get_digital_interrupt_names() {
std::vector<std::string> names;
auto status = this->get_status();
names.reserve(status.digital_interrupt_values.size());
for (const auto& kv : status.digital_interrupt_values) {
names.push_back(kv.first);
}
return names;
}

std::unordered_map<std::string, Board::analog_value> Board::get_analog_readers() {
return this->get_status().analog_reader_values;
}

std::unordered_map<std::string, Board::digital_value> Board::get_digital_interrupts() {
return this->get_status().digital_interrupt_values;
}
Board::Board(std::string name) : Component(std::move(name)){};

bool operator==(const Board::status& lhs, const Board::status& rhs) {
Expand Down
41 changes: 2 additions & 39 deletions src/viam/sdk/components/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,54 +66,17 @@ class Board : public Component {
API api() const override;

/// @brief Creates a `status` struct from its proto representation.
static status from_proto(const viam::common::v1::BoardStatus& proto);

/// @brief Creates a `analog_value` struct from its proto representation.
static analog_value from_proto(const viam::common::v1::AnalogStatus& proto);

/// @brief Creates a `digital_value` struct from its proto representation.
static digital_value from_proto(const viam::common::v1::DigitalInterruptStatus& proto);
static status from_proto(const viam::component::board::v1::Status& proto);

/// @brief Creates a `power_mode` enum from its proto representation.
static power_mode from_proto(viam::component::board::v1::PowerMode proto);

/// @brief Converts a `status` struct to its proto representation.
static viam::common::v1::BoardStatus to_proto(const status& status);

/// @brief Converts a `analog_value` struct to its proto representation.
static viam::common::v1::AnalogStatus to_proto(analog_value analog_value);

/// @brief Converts a `digital_value` struct to its proto representation.
static viam::common::v1::DigitalInterruptStatus to_proto(digital_value digital_value);
static viam::component::board::v1::Status to_proto(const status& status);

/// @brief Converts a `power_mode` enum to its proto representation.
static viam::component::board::v1::PowerMode to_proto(power_mode power_mode);

/// @brief Get the status of all of the registered analog readers and digital interrupt readers
inline status get_status() {
return get_status({});
}

/// @brief Get the status of all of the registered analog readers and digital interrupt readers
/// @param extra Any additional arguments to the method
virtual status get_status(const AttributeMap& extra) = 0;

/// @brief Get the names of the defined analog readers defined for this board
/// This information comes from calling `get_status()`
std::vector<std::string> get_analog_reader_names();

/// @brief Get the names of the defined digital interrupts for this board
/// This information comes from calling `get_status()`
std::vector<std::string> get_digital_interrupt_names();

/// @brief Get all defined analog readers defined for this board
/// This information comes from calling `get_status()`
std::unordered_map<std::string, analog_value> get_analog_readers();

/// @brief Get all defined digital interrupts for this board
/// This information comes from calling `get_status()`
std::unordered_map<std::string, digital_value> get_digital_interrupts();

/// @brief Gets the high/low state of the given pin on a board.
/// @param pin board pin name
/// @return high/low state of the given pin. High = on, low = off
Expand Down
6 changes: 0 additions & 6 deletions src/viam/sdk/components/private/board_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ BoardClient::BoardClient(std::string name, std::shared_ptr<grpc::Channel> channe
stub_(viam::component::board::v1::BoardService::NewStub(channel)),
channel_(std::move(channel)){};

Board::status BoardClient::get_status(const AttributeMap& extra) {
return make_client_helper(this, *stub_, &StubType::Status)
.with(extra)
.invoke([](auto& response) { return from_proto(response.status()); });
}

void BoardClient::set_gpio(const std::string& pin, bool high, const AttributeMap& extra) {
return make_client_helper(this, *stub_, &StubType::SetGPIO)
.with(extra,
Expand Down
2 changes: 0 additions & 2 deletions src/viam/sdk/components/private/board_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BoardClient : public Board {
using interface_type = Board;
BoardClient(std::string name, std::shared_ptr<grpc::Channel> channel);
AttributeMap do_command(const AttributeMap& command) override;
status get_status(const AttributeMap& extra) override;
void set_gpio(const std::string& pin, bool high, const AttributeMap& extra) override;
bool get_gpio(const std::string& pin, const AttributeMap& extra) override;
double get_pwm_duty_cycle(const std::string& pin, const AttributeMap& extra) override;
Expand Down Expand Up @@ -62,7 +61,6 @@ class BoardClient : public Board {
using Board::get_gpio;
using Board::get_pwm_duty_cycle;
using Board::get_pwm_frequency;
using Board::get_status;
using Board::read_analog;
using Board::read_digital_interrupt;
using Board::set_gpio;
Expand Down
12 changes: 0 additions & 12 deletions src/viam/sdk/components/private/board_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ namespace impl {
BoardServer::BoardServer(std::shared_ptr<ResourceManager> manager)
: ResourceServer(std::move(manager)){};

::grpc::Status BoardServer::Status(
::grpc::ServerContext*,
const ::viam::component::board::v1::StatusRequest* request,
::viam::component::board::v1::StatusResponse* response) noexcept {
return make_service_helper<Board>(
"BoardServer::Status", this, request)([&](auto& helper, auto& board) {
const viam::common::v1::BoardStatus status =
Board::to_proto(board->get_status(helper.getExtra()));
*response->mutable_status() = status;
});
}

::grpc::Status BoardServer::SetGPIO(::grpc::ServerContext*,
const ::viam::component::board::v1::SetGPIORequest* request,
::viam::component::board::v1::SetGPIOResponse*) noexcept {
Expand Down
4 changes: 0 additions & 4 deletions src/viam/sdk/components/private/board_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class BoardServer : public ResourceServer,
using interface_type = Board;
explicit BoardServer(std::shared_ptr<ResourceManager> manager);

::grpc::Status Status(::grpc::ServerContext* context,
const ::viam::component::board::v1::StatusRequest* request,
::viam::component::board::v1::StatusResponse* response) noexcept override;

::grpc::Status SetGPIO(
::grpc::ServerContext* context,
const ::viam::component::board::v1::SetGPIORequest* request,
Expand Down
4 changes: 0 additions & 4 deletions src/viam/sdk/tests/mocks/mock_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ using namespace viam::sdk;

MockBoard::MockBoard(std::string name) : Board(std::move(name)){};

Board::status MockBoard::get_status(const AttributeMap&) {
return this->peek_get_status_ret;
}

void MockBoard::set_gpio(const std::string& pin, bool high, const AttributeMap&) {
this->peek_pin = pin;
this->peek_set_gpio_high = high;
Expand Down
2 changes: 0 additions & 2 deletions src/viam/sdk/tests/mocks/mock_board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace board {
class MockBoard : public viam::sdk::Board {
public:
MockBoard(std::string name);
Board::status get_status(const sdk::AttributeMap& extra) override;
void set_gpio(const std::string& pin, bool high, const sdk::AttributeMap& extra) override;
bool get_gpio(const std::string& pin, const sdk::AttributeMap& extra) override;
double get_pwm_duty_cycle(const std::string& pin, const sdk::AttributeMap& extra) override;
Expand Down Expand Up @@ -39,7 +38,6 @@ class MockBoard : public viam::sdk::Board {
std::string peek_pin, peek_analog_reader_name, peek_digital_interrupt_name;
int peek_pin_value;
std::map<std::string, std::function<bool(Board::Tick tick)>> peek_callbacks;
Board::status peek_get_status_ret;
bool peek_set_gpio_high;
bool peek_get_gpio_ret;
double peek_get_pwm_duty_cycle_ret;
Expand Down
41 changes: 0 additions & 41 deletions src/viam/sdk/tests/test_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ BOOST_AUTO_TEST_CASE(mock_get_api) {
BOOST_CHECK_EQUAL(static_api.resource_subtype(), "board");
}

BOOST_AUTO_TEST_CASE(test_status) {
const auto mock = std::make_shared<MockBoard>("mock_board");
client_to_mock_pipeline<Board>(mock, [&](Board& client) {
std::unordered_map<std::string, Board::analog_value> analogs;
analogs.emplace("analog", 1);
std::unordered_map<std::string, Board::digital_value> digitals;
digitals.emplace("digital", 2);
mock->peek_get_status_ret = Board::status{analogs, digitals};

BOOST_CHECK(client.get_status() == mock->peek_get_status_ret);
});
}

BOOST_AUTO_TEST_CASE(test_set_gpio) {
const auto mock = std::make_shared<MockBoard>("mock_board");
client_to_mock_pipeline<Board>(mock, [&](Board& client) {
Expand Down Expand Up @@ -162,34 +149,6 @@ BOOST_AUTO_TEST_CASE(test_stream_ticks) {
});
}

BOOST_AUTO_TEST_CASE(test_get_analog_reader_names) {
const auto mock = std::make_shared<MockBoard>("mock_board");
client_to_mock_pipeline<Board>(mock, [&](Board& client) {
std::unordered_map<std::string, Board::analog_value> analogs;
analogs.emplace("analog1", 2);
analogs.emplace("analog2", 2);
mock->peek_get_status_ret = Board::status{analogs, {}};
auto ret = client.get_analog_reader_names();
std::sort(ret.begin(), ret.end());
BOOST_CHECK_EQUAL(ret[0], "analog1");
BOOST_CHECK_EQUAL(ret[1], "analog2");
});
}

BOOST_AUTO_TEST_CASE(test_get_digital_interrupt_names) {
const auto mock = std::make_shared<MockBoard>("mock_board");
client_to_mock_pipeline<Board>(mock, [&](Board& client) {
std::unordered_map<std::string, Board::digital_value> digitals;
digitals.emplace("digital1", 2);
digitals.emplace("digital2", 2);
mock->peek_get_status_ret = Board::status{{}, digitals};
auto ret = client.get_digital_interrupt_names();
std::sort(ret.begin(), ret.end());
BOOST_CHECK_EQUAL(ret[0], "digital1");
BOOST_CHECK_EQUAL(ret[1], "digital2");
});
}

BOOST_AUTO_TEST_CASE(test_get_geometries) {
const auto mock = std::make_shared<MockBoard>("mock_board");
client_to_mock_pipeline<Board>(mock, [](Board& client) {
Expand Down