-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Add Peak Ethernet Gateway DR support
- Loading branch information
Showing
4 changed files
with
474 additions
and
1 deletion.
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
78 changes: 78 additions & 0 deletions
78
hardware_integration/include/isobus/hardware_integration/peak_ethernet_gateway_plugin.hpp
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,78 @@ | ||
//================================================================================================ | ||
/// @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 | ||
explicit PeakEthernetGatewayPlugin(std::string targetIPAddress, | ||
std::uint16_t txPort, | ||
std::uint16_t rxPort, | ||
std::uint8_t CANChannelOnGateway, | ||
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: | ||
bool openRxSocket(); | ||
bool openTxSocket(); | ||
|
||
std::unique_ptr<std::uint8_t> rxBuffer; | ||
std::deque<isobus::CANMessageFrame> rxQueue; | ||
std::string ipAddress; | ||
int rxSocket = 0; | ||
int txSocket = 0; | ||
std::uint16_t sendPort; | ||
std::uint16_t receivePort; | ||
std::uint8_t gatewayChannel; | ||
bool isOpen = false; | ||
bool udp; | ||
}; | ||
} | ||
#endif // PEAK_ETHERNET_GATEWAY_PLUGIN_HPP |
Oops, something went wrong.