11#include <gtest/gtest.h>
31 for (
const auto& [blockType, expectedName] : values)
33 EXPECT_EQ(
GetBlockTypeName(blockType), expectedName) <<
"BlockType value: " <<
static_cast<std::uint16_t
>(blockType);
40 for (
const auto& [alarmType, expectedName] : values)
42 EXPECT_EQ(
GetAlarmTypeName(alarmType), expectedName) <<
"AlarmType value: " <<
static_cast<std::uint16_t
>(alarmType);
49 for (
const auto& [iocrType, expectedName] : values)
51 EXPECT_EQ(
GetIocrTypeName(iocrType), expectedName) <<
"IocrType value: " <<
static_cast<std::uint16_t
>(iocrType);
58 for (
const auto& [rtClass, expectedName] : values)
60 EXPECT_EQ(
GetIocrRtClassName(rtClass), expectedName) <<
"IocrRtClass value: " <<
static_cast<std::uint8_t
>(rtClass);
67 for (
const auto& [usi, expectedName] : values)
69 EXPECT_EQ(
GetUsiName(usi), expectedName) <<
"Usi value: " <<
static_cast<std::uint16_t
>(usi);
74 void ExpectIndexNames(
const std::vector<std::pair<std::uint16_t, std::string>>& values)
76 for (
const auto& [index, expectedName] : values)
78 EXPECT_EQ(
GetIndexName(index), expectedName) <<
"Index value: " << index;
83 void ExpectScopes(
const std::vector<std::pair<std::uint16_t, std::string>>& values)
85 for (
const auto& [index, expectedScope] : values)
87 EXPECT_EQ(
GetScope(index), expectedScope) <<
"Index value: " << index;
94 for (
const auto& [state, expectedName] : values)
103 for (
const auto& [state, expectedName] : values)
110 void ExpectPeModes(
const std::vector<std::pair<std::uint8_t, std::string>>& values)
112 for (
const auto& [mode, expectedName] : values)
114 EXPECT_EQ(
GetPeModeName(mode), expectedName) <<
"Mode value: " <<
static_cast<unsigned int>(mode);
121 ASSERT_EQ(actual.size(), expected.size());
123 for (std::size_t i = 0; i < expected.size(); ++i)
125 EXPECT_EQ(actual[i].first, expected[i].first) <<
"Unexpected index at table position " << i;
126 EXPECT_EQ(actual[i].second, expected[i].second) <<
"Unexpected name at table position " << i;
134 ExpectBlockTypeNames({
216 ExpectAlarmTypeNames({
250 ExpectIocrTypeNames({
299 {
static_cast<Usi>(0x0000),
"Manufacturer Specific (0x0000)"},
300 {
static_cast<Usi>(0x0001),
"Manufacturer Specific (0x0001)"},
301 {
static_cast<Usi>(0x7FFF),
"Manufacturer Specific (0x7FFF)"},
309 {
static_cast<Usi>(0x8400),
"Profile Specific (0x8400)"},
310 {
static_cast<Usi>(0x8500),
"Profile Specific (0x8500)"},
311 {
static_cast<Usi>(0x8FFF),
"Profile Specific (0x8FFF)"},
319 {
static_cast<Usi>(0x8004),
"Reserved (0x8004)"},
320 {
static_cast<Usi>(0x83FF),
"Reserved (0x83FF)"},
321 {
static_cast<Usi>(0x9000),
"Reserved (0x9000)"},
322 {
static_cast<Usi>(0xFFFF),
"Reserved (0xFFFF)"},
346 ExpectSubmoduleStates({
377 EXPECT_EQ(
GetPeModeName(mode),
"PE_EnergySavingMode_" + std::to_string(mode) +
"(" +
Hex2(mode) +
")");
399 for (uint16_t mode = 0x20; mode <= 0xEF; ++mode)
401 const auto byteMode =
static_cast<uint8_t
>(mode);
476 {
IM0,
"I&M0 (mandatory)"},
493 ASSERT_EQ(indices.size(), 16U);
495 for (std::size_t i = 0; i < indices.size(); ++i)
497 EXPECT_EQ(indices[i].first,
static_cast<std::uint16_t
>(
IM0 + i));
498 EXPECT_EQ(indices[i].second,
"I&M" + std::to_string(i));
549 EXPECT_FALSE(indices.empty());
551 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
552 { return entry.first == IM0; }),
554 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
555 { return entry.first == DIAG_CHANNEL_SUBSLOT; }),
557 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
558 { return entry.first == DIAG_DEVICE; }),
560 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
561 { return entry.first == PD_PORT_DATA_REAL; }),
563 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
564 { return entry.first == PD_INTERFACE_DATA_REAL; }),
566 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
567 { return entry.first == AR_DATA; }),
569 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
570 { return entry.first == EXPECTED_ID_SUBSLOT; }),
572 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
573 { return entry.first == REAL_ID_SUBSLOT; }),
575 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
576 { return entry.first == MODULE_DIFF_BLOCK; }),
578 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
579 { return entry.first == SUBSTITUTE_VALUES; }),
581 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
582 { return entry.first == RECORD_INPUT_DATA; }),
584 EXPECT_NE(std::ranges::find_if(indices.begin(), indices.end(), [](
const auto& entry)
585 { return entry.first == RECORD_OUTPUT_DATA; }),
627 {0x0000,
"User-specific (0x0000)"},
628 {0x0001,
"User-specific (0x0001)"},
629 {0x7FFF,
"User-specific (0x7FFF)"},
647 {0x8004,
"Subslot data (0x8004)"},
648 {0x80FF,
"Subslot data (0x80FF)"},
649 {0x8FFF,
"Subslot data (0x8FFF)"},
657 {0xC100,
"Slot data (0xC100)"},
658 {0xCFFF,
"Slot data (0xCFFF)"},
666 {0xE100,
"AR data (0xE100)"},
667 {0xEFFF,
"AR data (0xEFFF)"},
675 {0xF100,
"API data (0xF100)"},
676 {0xF7FF,
"API data (0xF7FF)"},
684 {0xF900,
"Device data (0xF900)"},
685 {0xFBFF,
"Device data (0xFBFF)"},
693 {0x9000,
"Unknown (0x9000)"},
694 {0x9FFF,
"Unknown (0x9FFF)"},
695 {0xB000,
"Unknown (0xB000)"},
696 {0xFFFF,
"Unknown (0xFFFF)"},
void ExpectIndexNames(const std::vector< std::pair< std::uint16_t, std::string > > &values)
Verifies that every supplied index resolves to its expected name.
void ExpectIocrTypeNames(const std::vector< std::pair< IocrType, std::string > > &values)
Verifies that every supplied IocrType resolves to its expected name.
void ExpectScopes(const std::vector< std::pair< std::uint16_t, std::string > > &values)
Verifies that every supplied index resolves to its expected scope.
void ExpectModuleStates(const std::vector< std::pair< std::uint16_t, std::string > > &values)
Verifies that every supplied state value resolves to its expected name.
void ExpectIndexTable(const IndexNamePairs &actual, const IndexNamePairs &expected)
Verifies that an index table contains exactly the supplied entries.
void ExpectSubmoduleStates(const std::vector< std::pair< std::uint16_t, std::string > > &values)
Verifies that every supplied submodule state value resolves to its expected name.
void ExpectIocrRtClassNames(const std::vector< std::pair< IocrRtClass, std::string > > &values)
Verifies that every supplied IocrRtClass resolves to its expected name.
void ExpectUsiNames(const std::vector< std::pair< Usi, std::string > > &values)
Verifies that every supplied USI resolves to its expected name.
void ExpectBlockTypeNames(const std::vector< std::pair< BlockType, std::string > > &values)
Verifies that every supplied BlockType resolves to its expected name.
void ExpectAlarmTypeNames(const std::vector< std::pair< AlarmType, std::string > > &values)
Verifies that every supplied AlarmType resolves to its expected name.
void ExpectPeModes(const std::vector< std::pair< std::uint8_t, std::string > > &values)
Verifies that every supplied PROFIenergy mode resolves to its expected name.
PROFINET record-data indices, block types, and protocol enumerations.
std::string Hex2(std::uint8_t value)
Format an 8-bit unsigned integer as a 2-digit hexadecimal string.
constexpr std::uint16_t PD_PORT_DATA_REAL
PD Port Data Real.
constexpr std::uint16_t AR_DATA
AR Data.
constexpr std::uint16_t DIAG_DEVICE
DIAG Device.
BlockType
PROFINET block types.
@ PortDataRealExtended
PD Port Data Real Extended block.
@ MrpRingStateData
MRP Ring State Data block.
@ IoCrRequest
IOCR block request.
@ SubmoduleList
Submodule list block.
@ PortDataCheck
PD Port Data Check block.
@ IdentificationMaintenance2
I&M2 block.
@ ExpectedProcessData
PD Expected Data block.
@ IdentificationMaintenance4
I&M4 block.
@ ControlPrmEndRequest
IOD Control Prm End request.
@ RealIdentificationDataApi
Real Identification Data API block.
@ InterfaceMrpDataAdjust
PD Interface MRP Data Adjust block.
@ AlarmAcknowledgementLow
Alarm acknowledgement low block.
@ IoDataReadResponse
IOD read response block.
@ PortFoDataReal
PD Port FO Data Real block.
@ ApplicationRelationRequest
AR block request.
@ IdentificationMaintenance14
I&M14 block.
@ AlarmAcknowledgementHigh
Alarm acknowledgement high block.
@ IdentificationMaintenance13
I&M13 block.
@ ControlPrmEndResponse
IOD Control Prm End response.
@ IdentificationMaintenance10
I&M10 block.
@ PortMrpDataReal
PD Port MRP Data Real block.
@ PortStatistics
PD Port Statistic block.
@ AlarmNotificationHigh
Alarm notification high block.
@ ModuleDifference
Module difference block.
@ ReleaseResponse
IOD Release response.
@ IdentificationMaintenance11
I&M11 block.
@ ControlRtClass3Request
IOD Control RT Class 3 request.
@ IdentificationMaintenance7
I&M7 block.
@ ExpectedIdentificationData
Expected identification data block.
@ PortFoDataCheck
PD Port FO Data Check block.
@ IdentificationMaintenance6
I&M6 block.
@ PortDataReal
PD Port Data Real block.
@ ExpectedSubmoduleRequest
Expected submodule block request.
@ AlarmCrRequest
AlarmCR block request.
@ ReleaseRequest
IOD Release request.
@ IdentificationMaintenance3
I&M3 block.
@ ContainerContent
CO Container Content block.
@ AlarmCrResponse
AlarmCR block response.
@ DiagnosisData
Diagnosis data block.
@ IdentificationMaintenance8
I&M8 block.
@ ControlApplicationReadyRequest
IOD Control Application Ready request.
@ ApplicationRelationServer
AR Server Block.
@ IdentificationMaintenance1
I&M1 block.
@ IdentificationMaintenance12
I&M12 block.
@ ApplicationRelationResponse
AR block response.
@ RealProcessData
PD Real Data block.
@ IoCrResponse
IOCR block response.
@ ParameterizationBeginRequest
Parameterization Begin request.
@ IoDataWriteResponse
IOD write response block.
@ ParameterizationBeginResponse
Parameterization Begin response.
@ ApplicationRelationData
ARData block.
@ InterfaceMrpDataReal
PD Interface MRP Data Real block.
@ IoDataWriteRequest
IOD write request block.
@ ControlApplicationReadyResponse
IOD Control Application Ready response.
@ RealIdentificationData
Real identification data block.
@ IoDataReadRequest
IOD read request block.
@ PortDataAdjust
PD Port Data Adjust block.
@ PortDataInterfaceDataReal
PD Interface Data Real block.
@ IdentificationMaintenance15
I&M15 block.
@ PortFoDataAdjust
PD Port FO Data Adjust block.
@ MultipleHeader
Multiple Header block.
@ IdentificationMaintenance0
I&M0 block.
@ ControlRtClass3Response
IOD Control RT Class 3 response.
@ AlarmNotificationLow
Alarm notification low block.
@ IdentificationMaintenance9
I&M9 block.
@ IdentificationMaintenance5
I&M5 block.
constexpr std::uint16_t DIAG_ALL_API
DIAG All API.
const IndexNamePairs & DiagnosisIndices(const std::string &scope)
Diagnosis indices for a given addressing scope.
TEST_F(AlarmListenerTests, InitializesWithEndpoint)
constexpr std::uint8_t PE_MODE_ENERGY_SAVING_MAX
PE Mode Energy Saving Max.
const IndexNamePairs & CriticalIndices()
Critical indices that should always be tested.
constexpr std::uint16_t SUBSTITUTE_VALUES
Substitute Values.
std::string GetIocrRtClassName(IocrRtClass rtClass)
Get the human-readable name for an IOCR real-time class.
std::string GetScope(std::uint16_t index)
Get the addressing scope for an index.
std::string GetSubmoduleStateName(std::uint16_t state)
Get the human-readable name for a submodule state.
constexpr std::uint8_t PE_MODE_POWER_OFF
PE Mode Power Off.
std::string GetModuleStateName(std::uint16_t state)
Get the human-readable name for a module state.
constexpr std::uint16_t PD_REAL_DATA
PD Real Data.
constexpr std::uint16_t SUBMODULE_STATE_APPLICATION_READY_PENDING
Submodule State Application Ready Pending.
constexpr std::uint16_t DIAG_ALL_AR
DIAG All AR.
constexpr std::uint16_t MODULE_DIFF_BLOCK
Module Diff Block.
std::string GetBlockTypeName(BlockType blockType)
Get the human-readable name for a block type.
AlarmType
PROFINET Alarm Types used in AlarmNotification blocks.
@ IsochronousModeProblem
Isochronous mode problem alarm.
@ MulticastMismatch
Multicast mismatch alarm.
@ PlugWrongSubmodule
Plug wrong submodule alarm.
@ DfpProblem
DFP problem alarm.
@ ReturnOfSubmodule
Return of submodule alarm.
@ Diagnosis
Diagnosis alarm.
@ PortDataChange
Port data change alarm.
@ SyncDataChanged
Sync data changed alarm.
@ ControlledBySupervisor
Controlled by supervisor alarm.
@ NetworkComponentProblem
Network component problem alarm.
@ Released
Released alarm.
@ TimeDataChanged
Time data changed alarm.
@ Redundancy
Redundancy alarm.
@ PullModule
Pull module alarm.
@ UploadRetrieval
Upload retrieval alarm.
@ DiagnosisDisappears
Diagnosis disappears alarm.
constexpr std::uint16_t DIAG_MAINTENANCE_SUBSLOT
DIAG Maintenance Subslot.
constexpr std::uint16_t SUBMODULE_STATE_NO_SUBMODULE
Submodule State No Submodule.
const IndexNamePairs & AllStandardIndices()
Union of every standard index category.
std::string GetUsiName(Usi usi)
Get the human-readable name for a User Structure Identifier.
IocrType
PROFINET IOCR types.
@ MulticastConsumer
Multicast consumer IOCR.
@ MulticastProvider
Multicast provider IOCR.
std::string GetPeModeName(std::uint8_t mode)
Get the human-readable name for a PROFIenergy operational mode.
constexpr std::uint16_t IM0
I&M0.
constexpr std::uint16_t PD_PORT_MRP_DATA_REAL
PD Port MRP Data Real.
std::vector< std::pair< std::uint16_t, std::string > > IndexNamePairs
(index, name) pairs, e.g. for building a "try each of these" scan.
constexpr std::uint16_t SUBMODULE_STATE_WRONG_SUBMODULE
Submodule State Wrong Submodule.
constexpr std::uint16_t DIAG_CHANNEL_API
DIAG Channel API.
constexpr std::uint16_t EXPECTED_ID_SUBSLOT
Expected ID Subslot.
constexpr std::uint16_t DIAG_CHANNEL_SLOT
DIAG Channel Slot.
constexpr std::uint16_t DIAG_ALL_SLOT
DIAG All Slot.
constexpr std::uint8_t PE_MODE_SLEEP_MODE_WOL
PE Mode Sleep Mode WOL.
constexpr std::uint16_t IM15
I&M15.
std::string GetIocrTypeName(IocrType iocrType)
Get the human-readable name for an IOCR type.
constexpr std::uint16_t DIAG_MAINTENANCE_AR
DIAG Maintenance AR.
constexpr std::uint16_t MODULE_STATE_SUBSTITUTE_MODULE
Module State Substitute Module.
constexpr std::uint16_t MODULE_STATE_PROPER_MODULE
Module State Proper Module.
constexpr std::uint16_t DIAG_CHANNEL_AR
DIAG Channel AR.
const IndexNamePairs & DeviceIndices()
Device-level indices.
constexpr std::uint16_t RECORD_INPUT_DATA
Record Input Data.
constexpr std::uint16_t LOG_DATA
Log Data.
const IndexNamePairs & ImIndices()
I&M0-I&M15 indices.
constexpr std::uint16_t AUTO_CONFIG
Auto Config.
constexpr std::uint16_t DIAG_MAINTENANCE_API
DIAG Maintenance API.
constexpr std::uint16_t SUBMODULE_STATE_OK
Submodule State Ok.
constexpr std::uint16_t IM0_FILTER_DATA
I&M0 Filter Data.
Usi
PROFINET User Structure Identifiers (USI).
@ Maintenance
Maintenance item.
@ MultipleDiagnosis
Multiple diagnosis.
@ IParameter
iParameter item.
@ PralAlarm
PRAL alarm item.
@ ExtendedChannelDiagnosis
Extended channel diagnosis.
@ ChannelDiagnosis
Channel diagnosis.
@ RsAlarmHigh
RS alarm item for high alarm.
@ RsAlarmSubmodule
RS alarm item for submodule.
@ RsAlarmLow
RS alarm item for low alarm.
@ QualifiedChannelDiagnosis
Qualified channel diagnosis.
constexpr std::uint16_t DIAG_MAINTENANCE_SLOT
DIAG Maintenance Slot.
constexpr std::uint16_t PDEV_DATA
Pdev Data.
constexpr std::uint16_t PD_INTERFACE_DATA_REAL
PD Interface Data Real.
constexpr std::uint16_t PD_EXPECTED_DATA
PD Expected Data.
constexpr std::uint16_t DIAG_ALL_SUBSLOT
DIAG All Subslot.
constexpr std::uint16_t PD_PORT_DATA_CHECK
PD Port Data Check.
constexpr std::uint16_t MODULE_STATE_NO_MODULE
Module State No Module.
constexpr std::uint16_t PD_NC_DATA_CHECK
PD NC Data Check.
constexpr std::uint8_t PE_MODE_ENERGY_SAVING_MIN
PE Mode Energy Saving Min.
constexpr std::uint16_t REAL_ID_SUBSLOT
Real ID Subslot.
constexpr std::uint16_t API_DATA
API Data.
constexpr std::uint8_t PE_MODE_READY_TO_OPERATE
PE Mode Ready To Operate.
const IndexNamePairs & InterfaceIndices()
Interface-level indices.
std::string GetIndexName(std::uint16_t index)
Get the human-readable name for a record data index.
std::string GetAlarmTypeName(AlarmType alarmType)
Get the human-readable name for an alarm type.
const IndexNamePairs & PortIndices()
Port-level indices.
constexpr std::uint8_t PE_MODE_OPERATE
PE Mode Operate.
constexpr std::uint16_t RECORD_OUTPUT_DATA
Record Output Data.
constexpr std::uint16_t MODULE_STATE_WRONG_MODULE
Module State Wrong Module.
constexpr std::uint16_t PD_PORT_DATA_ADJUST
PD Port Data Adjust.
constexpr std::uint16_t DIAG_CHANNEL_SUBSLOT
DIAG Channel Subslot.
constexpr std::uint16_t PD_PORT_STATISTIC
PD Port Statistic.
IocrRtClass
PROFINET IOCR real-time classes.
@ Udp
UDP real-time class.
constexpr std::uint16_t PD_INTERFACE_MRP_DATA_REAL
PD Interface MRP Data Real.
constexpr std::uint16_t SUBMODULE_STATE_LOCKED_BY_SUPERVISOR
Submodule State Locked By Supervisor.
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.