Skip to content

Commit

Permalink
Incorporate requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishKittur committed Oct 15, 2024
1 parent 068f554 commit c01c64b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ target_link_libraries(alpha_build PUBLIC
drivebrain_control
drivebrain_comms
drivebrain_mcap_logger
protobuf::libprotobuf
Boost::program_options
)

Expand Down
1 change: 0 additions & 1 deletion drivebrain_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <versions.h>

#include "hytech_msgs.pb.h"
#include "base_msgs.pb.h"

// TODO first application will have

Expand Down
1 change: 0 additions & 1 deletion drivebrain_core_impl/drivebrain_comms/include/CANComms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ namespace comms
core::Logger& _logger;
std::shared_ptr<loggertype> _message_logger;
deqtype &_input_deque_ref;
// deqtype &_output_deque_ref;

std::condition_variable _cv;
std::thread _output_thread;
Expand Down
14 changes: 7 additions & 7 deletions drivebrain_core_impl/drivebrain_comms/src/CANComms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ std::shared_ptr<google::protobuf::Message> comms::CANDriver::_get_pb_msg_by_name
std::shared_ptr<google::protobuf::Message> prototype_message;

const google::protobuf::Descriptor *desc = google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName("hytech." + name);
if (!desc) {
std::cerr << "Prototype message does not exist in descriptor pool" << std::endl;
return nullptr;
}
prototype_message.reset(google::protobuf::MessageFactory::generated_factory()->GetPrototype(desc)->New());
if (!prototype_message)
{
Expand Down Expand Up @@ -213,6 +217,9 @@ std::shared_ptr<google::protobuf::Message> comms::CANDriver::pb_msg_recv(const c
{
auto msg = iter->second->Clone();
auto msg_to_populate = _get_pb_msg_by_name(_to_lowercase(msg->Name()));
if (!msg_to_populate) {
return nullptr;
}

std::unordered_map<std::string, comms::CANDriver::FieldVariant> msg_field_map;
for (const dbcppp::ISignal &sig : msg->Signals())
Expand All @@ -233,7 +240,6 @@ std::shared_ptr<google::protobuf::Message> comms::CANDriver::pb_msg_recv(const c
else{
// TODO get correct type from raw signal and store it in the map. right now they are all doubles
msg_field_map[sig.Name()] = sig.RawToPhys(raw_value);
// std::cout << "\t" << sig.Name() << "=" << sig.RawToPhys(sig.Decode(frame.data)) << sig.Unit() << "\n";
}

}
Expand Down Expand Up @@ -299,7 +305,6 @@ std::optional<can_frame> comms::CANDriver::_get_CAN_msg(std::shared_ptr<google::
can_frame frame{};
std::string type_url = pb_msg->GetTypeName();
std::string messageTypeName = type_url.substr(type_url.find_last_of('.') + 1);
std::cout << "got message type name of " << messageTypeName << std::endl;

if (_messages_names_and_ids.find(messageTypeName) != _messages_names_and_ids.end())
{
Expand All @@ -317,23 +322,18 @@ std::optional<can_frame> comms::CANDriver::_get_CAN_msg(std::shared_ptr<google::
if (std::holds_alternative<std::monostate>(arg)) {
std::cout << "No value found or unsupported field" << std::endl;
} else if (std::holds_alternative<float>(arg)){
// std::cout << "float Field value: " << std::get<float>(arg) << std::endl;
auto val = std::get<float>(arg);
sig.Encode(sig.PhysToRaw(val), frame.data);
} else if(std::holds_alternative<int32_t>(arg)){
// std::cout << "Field value: " << std::get<int32_t>(arg) << std::endl;
auto val = std::get<int32_t>(arg);
sig.Encode(sig.PhysToRaw(val), frame.data);
} else if(std::holds_alternative<int64_t>(arg)){
// std::cout << "Field value: " << std::get<int64_t>(arg) << std::endl;
auto val = std::get<int64_t>(arg);
sig.Encode(sig.PhysToRaw(val), frame.data);
} else if(std::holds_alternative<uint64_t>(arg)){
// std::cout << "Field value: " << std::get<uint64_t>(arg) << std::endl;
auto val = std::get<uint64_t>(arg);
sig.Encode(sig.PhysToRaw(val), frame.data);
} else if(std::holds_alternative<bool>(arg)){
// std::cout << "Field value: " << std::get<bool>(arg) << std::endl;
auto val = std::get<bool>(arg);
sig.Encode(val, frame.data);

Expand Down

0 comments on commit c01c64b

Please sign in to comment.