19#include <gtest/gtest.h>
37 const std::uint16_t raw =
47 EXPECT_EQ(props.channelTypeValue, ChannelType::Specific);
48 EXPECT_EQ(props.accumulative, ChannelAccumulative::MainFault);
49 EXPECT_TRUE(props.maintenanceRequired);
50 EXPECT_TRUE(props.naintenanceDemanded);
51 EXPECT_EQ(props.specifier, ChannelSpecifier::Appears);
52 EXPECT_EQ(props.direction, ChannelDirection::Input);
60 EXPECT_EQ(props.channelTypeValue, ChannelType::Reserved);
61 EXPECT_FALSE(props.maintenanceRequired);
62 EXPECT_FALSE(props.naintenanceDemanded);
74 "Data transmission impossible");
78 "IO-Link device event");
86 "Manufacturer-specific (0x0200)");
90 "Profile-specific (0x9100)");
100 "Link state mismatch - Loss of link");
110 "Accumulative info");
114 "Manufacturer-specific (0x1234)");
123Bytes MakeChannelDiagEntry(
124 std::uint16_t channel,
126 std::uint16_t errorType)
138Bytes MakeExtChannelDiagEntry(
139 std::uint16_t channel,
141 std::uint16_t errorType,
142 std::uint16_t extErrorType,
143 std::uint32_t extAddValue)
172 MakeChannelDiagEntry(0x0001, 0x0000, 0x0006);
174 data.insert(data.end(), entry.begin(), entry.end());
182 ASSERT_EQ(result.entries.size(), 1U);
184 EXPECT_TRUE(result.HasErrors());
185 EXPECT_EQ(result.entries[0].base.channelNumber, 0x0001);
186 EXPECT_EQ(result.entries[0].base.errorType, 0x0006);
187 EXPECT_EQ(result.entries[0].base.errorTypeName,
"Line break");
188 EXPECT_TRUE(result.entries[0].IsChannelDiagnosis());
202 MakeExtChannelDiagEntry(
209 data.insert(data.end(), entry.begin(), entry.end());
213 ASSERT_EQ(result.entries.size(), 1U);
215 EXPECT_TRUE(result.entries[0].IsExtChannelDiagnosis());
216 ASSERT_TRUE(result.entries[0].ext.has_value());
219 result.entries[0].ext->extErrorTypeName,
240 MakeChannelDiagEntry(0x0001, 0x0000, 0x0001);
242 data.insert(data.end(), entry.begin(), entry.end());
246 ASSERT_EQ(result.entries.size(), 1U);
248 EXPECT_EQ(result.entries[0].base.slot, 3);
249 EXPECT_EQ(result.entries[0].base.subslot, 1);
255 const Bytes data = {0x01, 0x02, 0x03};
259 EXPECT_FALSE(result.HasErrors());
260 EXPECT_TRUE(result.entries.empty());
287 ASSERT_EQ(result.entries.size(), 1U);
289 EXPECT_EQ(result.entries[0].base.errorTypeName,
"Error");
290 EXPECT_EQ(result.entries[0].base.slot, 2);
305 MakeChannelDiagEntry(
310 data.insert(data.end(), entry.begin(), entry.end());
314 EXPECT_TRUE(result.HasMaintenanceRequired());
315 EXPECT_FALSE(result.HasMaintenanceDemanded());
328 Bytes e1 = MakeChannelDiagEntry(0x0001, 0, 0x0001);
330 Bytes e2 = MakeChannelDiagEntry(0x0002, 0, 0x0002);
332 data.insert(data.end(), e1.begin(), e1.end());
333 data.insert(data.end(), e2.begin(), e2.end());
337 ASSERT_EQ(result.entries.size(), 2U);
339 auto matches = result.GetByChannel(0x0002);
341 ASSERT_EQ(matches.size(), 1U);
342 EXPECT_EQ(matches[0]->base.channelNumber, 0x0002);
PROFINET diagnosis data structures, error decoding, and parsers.
std::string DecodeChannelErrorType(std::uint16_t errorType)
Decode a ChannelErrorType to a human-readable string.
DiagnosisData ParseDiagnosisSimple(const Bytes &data, std::uint32_t api=0, std::uint16_t slot=0, std::uint16_t subslot=0)
Parse a simple, fixed-format diagnosis block.
DiagnosisData ParseDiagnosisBlock(const Bytes &data, std::uint32_t api=0, std::uint16_t slot=0, std::uint16_t subslot=0)
Parse a full DiagnosisData block from raw bytes.
std::string DecodeExtChannelErrorType(std::uint16_t channelErrorType, std::uint16_t extErrorType)
Decode an ExtChannelErrorType given its ChannelErrorType context.
void PutU8(std::vector< std::uint8_t > &out, std::uint8_t value)
Append a single byte to a buffer.
void PutU16(std::vector< std::uint8_t > &out, std::uint16_t value)
Append a 16-bit value to a buffer in big-endian order.
void PutU32(std::vector< std::uint8_t > &out, std::uint32_t value)
Append a 32-bit value to a buffer in big-endian order.
TEST_F(AlarmListenerTests, InitializesWithEndpoint)
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
static ChannelProperties FromUint16(std::uint16_t value)
Decode a raw 16-bit ChannelProperties value.
Generic helpers for reading and writing integer and byte data in big- and little-endian wire formats.