AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
socketcand_windows_network_client.hpp
Go to the documentation of this file.
1//================================================================================================
11//================================================================================================
12#ifndef SOCKETCAND_WINDOWS_NETWORK_CLIENT_HPP
13#define SOCKETCAND_WINDOWS_NETWORK_CLIENT_HPP
14
15#include <string>
16
18#include "isobus/isobus/can_frame.hpp"
20
21#include <WS2tcpip.h>
22#include <WinSock2.h>
23
24struct sockaddr_in;
25
26namespace isobus
27{
30 {
31 public:
36 explicit SocketCANdNetworkInterface(std::string deviceName);
37
43 SocketCANdNetworkInterface(std::string deviceName, const std::string ipAddress, std::uint16_t port = 29536);
44
47
50 bool get_is_valid() const override;
51
54 std::string get_device_name() const;
55
58 const std::string get_connected_ip_address() const;
59
61 void close() override;
62
64 void open() override;
65
69 bool read_frame(isobus::HardwareInterfaceCANFrame &canFrame) override;
70
74 bool write_frame(const isobus::HardwareInterfaceCANFrame &canFrame) override;
75
76 private:
78 void initialize();
79
80 static constexpr std::uint32_t MAX_RECV_LENGTH = 1024;
81
82 std::unique_ptr <
83 sockaddr_in serverDefinition = {};
84 const std::string name;
85 const std::string targetIP;
86 std::uint16_t targetPort = 29536;
87 WSADATA wsa_data;
88 SOCKET mainSocket;
89 SOCKET beaconSocket;
90 bool openCalled = false;
91 bool valid = false;
92 };
93}
94#endif // SOCKETCAND_WINDOWS_NETWORK_CLIENT_HPP
An abstraction between this CAN stack and any hardware layer.
A base class for a CAN driver. Can be derived into your platform's required interface.
An abstract base class for a CAN driver.
A CAN Driver for using socket CAN remotely over TCP socket.
void close() override
Closes the connection.
bool write_frame(const isobus::HardwareInterfaceCANFrame &canFrame) override
Writes a frame to the bus (synchronous)
void open() override
Connects to the server.
const std::string get_connected_ip_address() const
Returns the IP that the plugin is connected to.
SocketCANdNetworkInterface(std::string deviceName)
Constructor for the socket CAN driver.
bool read_frame(isobus::HardwareInterfaceCANFrame &canFrame) override
Returns a frame from the hardware (synchronous), or false if no frame can be read.
bool get_is_valid() const override
Returns if the connection is valid.
virtual ~SocketCANdNetworkInterface()
The destructor for SocketCANdNetworkInterface.
void initialize()
Initializes some class variables.
std::string get_device_name() const
Returns the device name the driver is using.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...