forked from SEAME-pt/SEAME-Course-24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
129838a
commit 9e12a64
Showing
17 changed files
with
271 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
cc_binary( | ||
name = "bin", | ||
srcs = ["main.cpp"], | ||
srcs = ["src/main.cpp"], | ||
features = ["warnings_critical_code_gcc"], | ||
linkopts = [ | ||
"-lzmq", | ||
], | ||
deps = [ | ||
"//com-middleware/can", | ||
"//com-middleware/exceptions", | ||
"//com-middleware/src/can", | ||
"//com-middleware/src/exceptions", | ||
"//com-middleware/src/mq", | ||
"@cppzmq", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
cc_library( | ||
name = "can", | ||
srcs = ["CanDriver.cpp"], | ||
hdrs = ["CanDriver.hpp"], | ||
srcs = glob(["*.cpp"]), | ||
hdrs = glob(["*.hpp"]), | ||
features = ["warnings_critical_code_gcc"], | ||
visibility = ["//visibility:public"], | ||
deps = ["//com-middleware/exceptions"], | ||
deps = ["//com-middleware/src/exceptions"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <linux/can.h> | ||
|
||
#include <cstdint> | ||
|
||
/** | ||
* @brief Asbtracts the Linux CAN Socket logic | ||
* | ||
*/ | ||
class ICanDriver { | ||
public: | ||
ICanDriver() = default; | ||
ICanDriver(const ICanDriver&) = default; | ||
auto operator=(const ICanDriver&) -> ICanDriver& = default; | ||
ICanDriver(ICanDriver&&) = default; | ||
auto operator=(ICanDriver&&) -> ICanDriver& = default; | ||
virtual ~ICanDriver() = default; | ||
|
||
/** | ||
* @brief Receives CAN message | ||
* | ||
* @param frame CAN frame | ||
* @return int32_t number of bytes received | ||
*/ | ||
virtual auto receive(can_frame* frame) const -> int32_t = 0; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cc_library( | ||
name = "mq", | ||
srcs = glob(["*.cpp"]), | ||
hdrs = glob(["*.hpp"]), | ||
features = ["warnings_critical_code_gcc"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@cppzmq", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef MQ_PUBLISHER_HPP | ||
#define MQ_PUBLISHER_HPP | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace mq { | ||
|
||
class IMQPublisher { | ||
protected: | ||
// Constructors | ||
IMQPublisher() = default; | ||
IMQPublisher(const IMQPublisher&) = default; | ||
IMQPublisher(IMQPublisher&&) = default; | ||
|
||
// Asignment operators | ||
auto operator=(const IMQPublisher&) -> IMQPublisher& = default; | ||
auto operator=(IMQPublisher&&) -> IMQPublisher& = default; | ||
|
||
public: | ||
virtual ~IMQPublisher() = default; | ||
virtual void subscribe(const std::string& topic) = 0; | ||
virtual auto publish(const std::vector<uint8_t>& data) -> bool = 0; | ||
}; | ||
} // namespace mq | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MQ_SUBSCRIBER_HPP | ||
#define MQ_SUBSCRIBER_HPP | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace mq { | ||
|
||
class IMQSubscriber { | ||
protected: | ||
// Constructors | ||
IMQSubscriber() = default; | ||
IMQSubscriber(const IMQSubscriber&) = default; | ||
IMQSubscriber(IMQSubscriber&&) = default; | ||
|
||
// Asignment operators | ||
auto operator=(const IMQSubscriber&) -> IMQSubscriber& = default; | ||
auto operator=(IMQSubscriber&&) -> IMQSubscriber& = default; | ||
|
||
public: | ||
virtual ~IMQSubscriber() = 0; | ||
virtual void subscribe(const std::string& topic) = 0; | ||
virtual auto receive() -> std::vector<uint8_t> = 0; | ||
}; | ||
} // namespace mq | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "ZeroMQPublisher.hpp" | ||
|
||
#include <iostream> | ||
|
||
namespace mq { | ||
ZeroMQPublisher::ZeroMQPublisher(std::unique_ptr<zmq::socket_t> socket) | ||
: m_socket(std::move(socket)) {}; | ||
|
||
ZeroMQPublisher::~ZeroMQPublisher() { | ||
if (m_socket) { | ||
std::cout << "Closing publisher\n"; | ||
m_socket->close(); | ||
} | ||
} | ||
|
||
void ZeroMQPublisher::subscribe(const std::string& topic) { m_socket->bind(topic); } | ||
|
||
auto ZeroMQPublisher::publish(const std::vector<uint8_t>& data) -> bool { | ||
zmq::message_t msg(data.size()); | ||
memcpy(msg.data(), data.data(), data.size()); | ||
std::cout << m_socket.get() << "\n"; | ||
zmq::send_result_t res = m_socket->send(msg, zmq::send_flags::none); | ||
if (res.has_value()) { | ||
std::cout << "!sent\n"; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} // namespace mq |
Oops, something went wrong.