-
-
Notifications
You must be signed in to change notification settings - Fork 93
[HW]: Add Peak Ethernet Gateway DR support #455
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
Open
ad3154
wants to merge
1
commit into
main
Choose a base branch
from
adrian/ethernet-gateway
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
87 changes: 87 additions & 0 deletions
87
hardware_integration/include/isobus/hardware_integration/peak_ethernet_gateway_plugin.hpp
This file contains hidden or 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,87 @@ | ||
| //================================================================================================ | ||
| /// @file peak_ethernet_gateway_plugin.hpp | ||
| /// | ||
| /// @brief An interface for using a PEAK Ethernet Gateway DR. | ||
| /// @author Adrian Del Grosso | ||
| /// | ||
| /// @copyright 2024 The Open-Agriculture Developers | ||
| //================================================================================================ | ||
| #ifndef PEAK_ETHERNET_GATEWAY_PLUGIN_HPP | ||
| #define PEAK_ETHERNET_GATEWAY_PLUGIN_HPP | ||
|
|
||
| #include <deque> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #ifdef WIN32 | ||
| #include <winsock.h> | ||
| #else | ||
| #include <sys/socket.h> | ||
| #endif | ||
|
|
||
| #include "isobus/hardware_integration/can_hardware_plugin.hpp" | ||
| #include "isobus/isobus/can_hardware_abstraction.hpp" | ||
| #include "isobus/isobus/can_message_frame.hpp" | ||
|
|
||
| namespace isobus | ||
| { | ||
| /// @brief Peak Ethernet Gateway CAN hardware plugin | ||
| class PeakEthernetGatewayPlugin : public CANHardwarePlugin | ||
| { | ||
| public: | ||
| /// @brief Constructor for a PeakEthernetGatewayPlugin | ||
| /// @param[in] targetIPAddress The IP address of the gateway | ||
| /// @param[in] txPort The port to send data to | ||
| /// @param[in] rxPort The port to receive data from (this is the port the gateway sends data from) | ||
| /// @param[in] useUDP If `true`, use UDP, otherwise use TCP | ||
| PeakEthernetGatewayPlugin(std::string targetIPAddress, | ||
| std::uint16_t txPort, | ||
| std::uint16_t rxPort, | ||
| bool useUDP = true); | ||
|
|
||
| /// @brief The destructor for PCANBasicWindowsPlugin | ||
| virtual ~PeakEthernetGatewayPlugin(); | ||
|
|
||
| /// @brief Returns if the connection with the hardware is valid | ||
| /// @returns `true` if connected, `false` if not connected | ||
| bool get_is_valid() const override; | ||
|
|
||
| /// @brief Closes the connection to the hardware | ||
| void close() override; | ||
|
|
||
| /// @brief Connects to the hardware you specified in the constructor's channel argument | ||
| void open() override; | ||
|
|
||
| /// @brief Returns a frame from the hardware (synchronous), or `false` if no frame can be read. | ||
| /// @param[in, out] canFrame The CAN frame that was read | ||
| /// @returns `true` if a CAN frame was read, otherwise `false` | ||
| bool read_frame(isobus::CANMessageFrame &canFrame) override; | ||
|
|
||
| /// @brief Writes a frame to the bus (synchronous) | ||
| /// @param[in] canFrame The frame to write to the bus | ||
| /// @returns `true` if the frame was written, otherwise `false` | ||
| bool write_frame(const isobus::CANMessageFrame &canFrame) override; | ||
|
|
||
| private: | ||
| /// @brief Opens the receive socket | ||
| /// @returns `true` if the socket was opened, otherwise `false` | ||
| bool open_rx_socket(); | ||
|
|
||
| /// @brief Opens the transmit socket | ||
| /// @returns `true` if the socket was opened, otherwise `false` | ||
| bool open_tx_socket(); | ||
|
|
||
| static constexpr std::uint32_t RX_BUFFER_SIZE_BYTES = 2048; ///< Default size of the receive buffer | ||
|
|
||
| std::unique_ptr<std::uint8_t> rxBuffer; ///< The receive buffer (multiple frames can be in the buffer, per ethernet frame) | ||
| std::deque<isobus::CANMessageFrame> rxQueue; ///< The queue of received frames, which get passed to the CAN Hardware Abstraction when needed | ||
| std::string ipAddress; ///< The IP address of the gateway | ||
| int rxSocket = 0; ///< The receive socket identifier | ||
| int txSocket = 0; ///< The transmit socket identifier | ||
| std::uint16_t sendPort; ///< The port to send data to | ||
| std::uint16_t receivePort; ///< The port to receive data from | ||
| bool isOpen = false; ///< If the connection is open | ||
| bool udp; ///< If the connection is using UDP | ||
| }; | ||
| } | ||
| #endif // PEAK_ETHERNET_GATEWAY_PLUGIN_HPP |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.