PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
stubRpcTransport.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <gmock/gmock.h>
8
9#include "profinet/rpc.h"
10
11namespace profinet
12{
13constexpr std::uint16_t kInputFrameId = 0x9000;
14constexpr std::uint16_t kOutputFrameId = 0x8001;
15
18{
19 public:
21 Bytes SendReceive(const Bytes& request, std::chrono::milliseconds) override
22 {
23 requests.push_back(request);
24
25 const auto parsed = PNRPCHeader::Parse(request);
26 PNRPCHeader response = parsed;
28
29 Bytes blocks;
30 for (const auto [type, frameId] :
31 std::array<std::pair<std::uint16_t, std::uint16_t>, 2>{
32 {{1, kInputFrameId}, {2, kOutputFrameId}}})
33 {
38 wire::PutU16(blocks, type);
39 wire::PutU16(blocks, type);
40 wire::PutU16(blocks, frameId);
41 }
42
43 PNNRDData nrd;
44 nrd.argsMaximumStatus = 0;
45 nrd.argsLength = static_cast<std::uint32_t>(blocks.size());
46 nrd.maximumCount = 1500;
47 nrd.offset = 0;
48 nrd.actualCount = static_cast<std::uint32_t>(blocks.size());
49 nrd.payload = blocks;
50 response.payload = nrd.ToBytes();
51 response.lengthOfBody = static_cast<std::uint16_t>(response.payload.size());
52 return response.ToBytes();
53 }
54
56 void Send(const Bytes& data) override
57 {
58 sends.push_back(data);
59 }
60
62 void Open(const std::string&, std::uint16_t, bool = false) override
63 {
64 }
65
67 Bytes Receive(std::chrono::milliseconds, asio::ip::udp::endpoint&) override
68 {
69 return {};
70 }
71
73 void SendTo(const Bytes& data, const asio::ip::udp::endpoint&) override
74 {
75 sends.push_back(data);
76 }
77
79 void Close() noexcept override
80 {
81 }
82
83 std::vector<Bytes> requests;
84 std::vector<Bytes> sends;
85};
86} // namespace profinet
void Open(const std::string &, std::uint16_t, bool=false) override
Open the transport and configure the remote endpoint.
Bytes Receive(std::chrono::milliseconds, asio::ip::udp::endpoint &) override
Wait for an incoming byte array and capture the sender's endpoint.
std::vector< Bytes > sends
std::vector< Bytes > requests
void Close() noexcept override
Close the transport.
Bytes SendReceive(const Bytes &request, std::chrono::milliseconds) override
void Send(const Bytes &data) override
void SendTo(const Bytes &data, const asio::ip::udp::endpoint &) override
Send a byte array of data to a specific remote asio endpoint.
constexpr std::uint8_t VERSION_HIGH
Version high.
Definition rpc.h:42
constexpr std::uint8_t VERSION_LOW
Version low.
Definition rpc.h:44
void PutU8(std::vector< std::uint8_t > &out, std::uint8_t value)
Append a single byte to a buffer.
Definition wire.h:89
void PutU16(std::vector< std::uint8_t > &out, std::uint16_t value)
Append a 16-bit value to a buffer in big-endian order.
Definition wire.h:97
constexpr std::uint16_t kInputFrameId
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:55
constexpr std::uint16_t kOutputFrameId
PROFINET DCE/RPC protocol structures and IO-Device connection API.
static constexpr std::uint16_t BLOCK_TYPE
Block type identifier for IOCRBlockRes.
Definition protocol.h:1943
static constexpr std::size_t kSize
Size in bytes of this block.
Definition protocol.h:1959
NRD (Network Representation Data) wrapper carrying the actual IOD payload.
Definition protocol.h:1128
Bytes payload
The wrapped IOD data.
Definition protocol.h:1145
Bytes ToBytes() const
Serialize this wrapper and payload back to raw bytes.
Definition protocol.h:1175
std::uint32_t argsLength
Length in bytes of the arguments (usually equals ActualCount).
Definition protocol.h:1133
std::uint32_t offset
Byte offset into the logical result (0 unless fragmented).
Definition protocol.h:1139
std::uint32_t argsMaximumStatus
Maximum status/argument buffer size accepted by the caller.
Definition protocol.h:1130
std::uint32_t maximumCount
Maximum number of bytes the caller can accept.
Definition protocol.h:1136
std::uint32_t actualCount
Actual length in bytes of Payload.
Definition protocol.h:1142
DCE/RPC PDU header used to carry PROFINET connect/read/write/control requests.
Definition protocol.h:860
Bytes ToBytes() const
Serialize this header and body back to raw bytes.
Definition protocol.h:1045
static PNRPCHeader Parse(const Bytes &data)
Parse an RPC header and body from raw bytes.
Definition protocol.h:1012
std::uint8_t packetType
Packet type (REQUEST/RESPONSE/FAULT/...).
Definition protocol.h:922
static constexpr std::uint8_t RESPONSE
Packet type: RESPONSE.
Definition protocol.h:869
Bytes payload
PDU body (NRD data for read/write/control, etc.).
Definition protocol.h:976
std::uint16_t lengthOfBody
Length in bytes of Payload.
Definition protocol.h:964
std::uint16_t frameId
Ethernet FrameID.