PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
exceptions.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <cstdint>
10#include <span>
11#include <stdexcept>
12#include <string>
13
14namespace profinet
15{
16
21enum class ErrorDecode : std::uint8_t
22{
24 PnioCm = 0x40,
25
27 PnioRw = 0x80,
28
30 Pnio = 0x81
31};
32
39std::string GetErrorDecodeName(ErrorDecode errorDecodeName);
40
45enum class PnioRwErrorCode1 : std::uint8_t
46{
48 InvalidIndex = 0xB0,
49
51 WriteLength = 0xB1,
52
54 Resource = 0xB2,
55
57 Access = 0xB3,
58
60 Application = 0xB4
61};
62
69std::string GetPnioRwErrorCode1Name(PnioRwErrorCode1 errorCodeRw1);
70
75enum class PnioCmErrorCode1 : std::uint8_t
76{
78 Ar = 0x01,
79
81 Iocr = 0x02,
82
84 AlarmCr = 0x03,
85
87 ExpectedSubmodule = 0x04,
88
90 ModuleDiff = 0x05,
91
93 ArRpc = 0x06,
94
96 IrInfo = 0x07,
97
99 SrInfo = 0x08,
100
102 ArFsu = 0x09,
103
105 IodControlRequest = 0x10,
106
108 IodControlResponse = 0x11,
109
111 ArResponse = 0x81,
112
114 IocrResponse = 0x82,
115
117 AlarmCrResponse = 0x83,
118
120 ModuleDiffResponse = 0x84,
121
123 ArServerResponse = 0x85,
124
126 PrmServer = 0x3D,
127
129 CmCtl = 0x3E,
130
132 CmDev = 0x3F,
133
135 CmRpc = 0x40,
136
138 FaultyRecord = 0xFD,
139
141 FaultyAr = 0xFE,
142
144 FaultyBlock = 0xFF
145};
146
153std::string GetPnioCmErrorCode1Name(PnioCmErrorCode1 errorCodeCm1);
154
156enum class PnioRwInvalidIndexErrorCode2 : std::uint8_t
157{
159 IndexNotSupported = 0x00,
160
162 IndexNotWritten = 0x05
163};
164
171
173enum class PnioRwWriteLengthErrorCode2 : std::uint8_t
174{
176 WriteLengthError = 0x00,
177
179 DataTooShort = 0x01,
180
182 DataTooLong = 0x02,
183
185 WriteProtected = 0x03
186};
187
194
196enum class PnioRwResourceErrorCode2 : std::uint8_t
197{
200
202 InvalidSlot = 0x07,
203
205 InvalidSubslot = 0x08,
206
208 ModuleHasNoData = 0x09
209};
210
216std::string GetPnioRwErrorMessage(PnioRwResourceErrorCode2 errorCode2);
217
219enum class PnioRwAccessErrorCode2 : std::uint8_t
220{
222 InvalidArea = 0x00,
223
225 AccessDenied = 0x03,
226
228 InvalidRange = 0x04,
229
231 InvalidState = 0x05,
232
234 LocalControl = 0x06
235};
236
242std::string GetPnioRwErrorMessage(PnioRwAccessErrorCode2 errorCode2);
243
245enum class PnioRwApplicationErrorCode2 : std::uint8_t
246{
248 ReadError = 0x00,
249
251 WriteError = 0x01,
252
254 ModuleFailure = 0x02,
255
257 ResourceBusy = 0x04,
258
260 VersionConflict = 0x05,
261
263 InvalidApi = 0x06,
264
266 BackupNotAllowed = 0x07,
267
269 AlarmPending = 0x08
270};
271
278
280enum class PnioCmArErrorCode2 : std::uint8_t
281{
283 InvalidArType = 0x00,
284
286 ArAlreadyActive = 0x01,
287
289 NoArResources = 0x02,
290
292 NoProviderResources = 0x03,
293
295 NoConsumerResources = 0x04,
296
298 NoAlarmResources = 0x05,
299
301 NoMemory = 0x06,
302
304 InvalidSessionKey = 0x07,
305
307 ArUuidConflict = 0x08
308};
309
316std::string GetPnioCmErrorMessage(PnioCmArErrorCode2 errorCode2);
317
319enum class PnioCmIocrErrorCode2 : std::uint8_t
320{
322 InvalidIocrType = 0x00,
323
325 NoIocrResources = 0x01,
326
328 InvalidFrameId = 0x02,
329
331 InvalidRtClass = 0x03,
332
334 InvalidIoDataLength = 0x04,
335
337 CycleTimeConflict = 0x05,
338
341};
342
349std::string GetPnioCmErrorMessage(PnioCmIocrErrorCode2 errorCode2);
350
352enum class PnioCmAlarmCrErrorCode2 : std::uint8_t
353{
355 InvalidAlarmCrType = 0x00,
356
358 NoAlarmCrResources = 0x01
359};
360
367std::string GetPnioCmErrorMessage(PnioCmAlarmCrErrorCode2 errorCode2);
368
373enum class PnioCmExpectedSubmoduleErrorCode2 : std::uint8_t
374{
376 InvalidSlot = 0x00,
377
379 InvalidSubslot = 0x01,
380
383
386
389};
390
398
403enum class PnioCmDeviceErrorCode2 : std::uint8_t
404{
406 DeviceStateConflict = 0x00,
407
410
412 AlreadyOwned = 0x02,
413
415 ArSetAborted = 0x03
416};
417
424std::string GetPnioCmErrorMessage(PnioCmDeviceErrorCode2 errorCode2);
425
429enum class PnioCmFaultyBlockErrorCode2 : std::uint8_t
430{
433};
434
442
447enum class PnioErrorCode1 : std::uint8_t
448{
450 Rmpm = 0x40,
451
453 PrmServer = 0x3D
454};
455
462std::string GetPnioErrorCode1Name(PnioErrorCode1 errorCode1);
463
468enum class PnioRmpmErrorCode2 : std::uint8_t
469{
472
475
478
481
483 OutOfArResources = 0x04
484};
485
492std::string GetPnioErrorMessage(PnioRmpmErrorCode2 errorCode2);
493
498enum class PnioPrmServerErrorCode2 : std::uint8_t
499{
502 StateConflict = 0x00
503};
504
511std::string GetPnioErrorMessage(PnioPrmServerErrorCode2 errorCode2);
512
523std::string GetPnioRwErrorMessage(PnioRwErrorCode1 errorCode1, std::uint8_t errorCode2);
524
526class ProfinetError : public std::runtime_error
527{
528 public:
531 explicit ProfinetError(const std::string& message)
532 : std::runtime_error(message)
533 {
534 }
535};
536
539{
540 public:
543 explicit DCPError(const std::string& message)
544 : ProfinetError(message)
545 {
546 }
547};
548
551{
552 public:
555 explicit DCPTimeoutError(const std::string& message)
556 : DCPError(message)
557 {
558 }
559};
560
563{
564 public:
567 explicit DCPDeviceNotFoundError(const std::string& message)
568 : DCPError(message)
569 {
570 }
571};
572
575{
576 public:
579 explicit RPCError(const std::string& message)
580 : ProfinetError(message)
581 {
582 }
583};
584
587{
588 public:
591 explicit RPCTimeoutError(const std::string& message)
592 : RPCError(message)
593 {
594 }
595};
596
599{
600 public:
604 explicit RPCFaultError(const std::string& message, std::uint32_t faultCode = 0)
605 : RPCError(message), faultCode(faultCode)
606 {
607 }
608
610 std::uint32_t faultCode;
611};
612
615{
616 public:
619 explicit RPCConnectionError(const std::string& message)
620 : RPCError(message)
621 {
622 }
623};
624
627{
628 public:
631 explicit ValidationError(const std::string& message)
632 : ProfinetError(message)
633 {
634 }
635};
636
639{
640 public:
643 explicit InvalidMACError(const std::string& message)
644 : ValidationError(message)
645 {
646 }
647};
648
651{
652 public:
655 explicit InvalidIPError(const std::string& message)
656 : ValidationError(message)
657 {
658 }
659};
660
663{
664 public:
667 explicit SocketError(const std::string& message)
668 : ProfinetError(message)
669 {
670 }
671};
672
675{
676 public:
679 explicit PermissionDeniedError(const std::string& message)
680 : SocketError(message)
681 {
682 }
683};
684
691class PNIOError : public RPCError
692{
693 public:
695 std::uint8_t errorCode = 0;
696
698 std::uint8_t errorDecode = 0;
699
701 std::uint8_t errorCode1 = 0;
702
704 std::uint8_t errorCode2 = 0;
705
712 PNIOError(const std::string& message,
713 std::uint8_t errorCode,
714 std::uint8_t errorDecode,
715 std::uint8_t errorCode1,
716 std::uint8_t errorCode2)
717 : RPCError(message),
722 {
723 }
724
728 static PNIOError FromBytes(std::span<const std::uint8_t, 4> data);
729
734 static PNIOError FromArgsStatus(std::uint32_t argsStatus);
735
738 [[nodiscard]] bool IsCmError() const
739 {
740 return static_cast<ErrorDecode>(errorDecode) == ErrorDecode::PnioCm;
741 }
742
745 [[nodiscard]] std::string BlockName() const;
746
747 private:
755 static void extracted(const std::uint8_t& errorCode1, const std::uint8_t& errorCode2, std::string& message);
756 static PNIOError CreateFromCodes(std::uint8_t errorCode, std::uint8_t errorDecode,
757 std::uint8_t errorCode1, std::uint8_t errorCode2);
758};
759
760} // namespace profinet
Device not found via DCP.
Definition exceptions.h:563
DCPDeviceNotFoundError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:567
DCP protocol errors.
Definition exceptions.h:539
DCPError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:543
DCP operation timed out.
Definition exceptions.h:551
DCPTimeoutError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:555
Invalid IP address format.
Definition exceptions.h:651
InvalidIPError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:655
Invalid MAC address format.
Definition exceptions.h:639
InvalidMACError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:643
PNIO application error with error codes.
Definition exceptions.h:692
static void extracted(const std::uint8_t &errorCode1, const std::uint8_t &errorCode2, std::string &message)
Shared implementation for FromBytes()/FromArgsStatus(): look up the error message and construct the P...
std::uint8_t errorCode1
Raw ErrorCode1 byte (category / block type).
Definition exceptions.h:701
static PNIOError CreateFromCodes(std::uint8_t errorCode, std::uint8_t errorDecode, std::uint8_t errorCode1, std::uint8_t errorCode2)
std::uint8_t errorCode
Raw ErrorCode byte (see class-level.
Definition exceptions.h:695
std::uint8_t errorDecode
Raw ErrorDecode byte; selects which ErrorCode1/ErrorCode2 table applies.
Definition exceptions.h:698
std::string BlockName() const
Human-readable name of the PNIO-CM block referenced by ErrorCode1.
bool IsCmError() const
Whether this error came from the PNIO-CM (connection management) table.
Definition exceptions.h:738
static PNIOError FromBytes(std::span< const std::uint8_t, 4 > data)
Create a PNIOError from a raw 4-byte error status.
std::uint8_t errorCode2
Raw ErrorCode2 byte (specific error within the category).
Definition exceptions.h:704
static PNIOError FromArgsStatus(std::uint32_t argsStatus)
Create a PNIOError from the little-endian ArgsStatus field carried in a DCE/RPC PDU.
PNIOError(const std::string &message, std::uint8_t errorCode, std::uint8_t errorDecode, std::uint8_t errorCode1, std::uint8_t errorCode2)
Construct directly from the four raw error-status bytes.
Definition exceptions.h:712
Insufficient permissions for raw socket.
Definition exceptions.h:675
PermissionDeniedError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:679
Base exception for all PROFINET errors.
Definition exceptions.h:527
ProfinetError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:531
Failed to establish RPC connection.
Definition exceptions.h:615
RPCConnectionError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:619
DCE/RPC protocol errors.
Definition exceptions.h:575
RPCError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:579
RPC returned a fault response.
Definition exceptions.h:599
std::uint32_t faultCode
DCE/RPC fault code reported by the peer.
Definition exceptions.h:610
RPCFaultError(const std::string &message, std::uint32_t faultCode=0)
Construct with a message and the fault code reported by the peer.
Definition exceptions.h:604
RPC operation timed out.
Definition exceptions.h:587
RPCTimeoutError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:591
Socket operation error.
Definition exceptions.h:663
SocketError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:667
Input validation error.
Definition exceptions.h:627
ValidationError(const std::string &message)
Construct with a human-readable message.
Definition exceptions.h:631
std::string GetPnioRwErrorCode1Name(PnioRwErrorCode1 errorCodeRw1)
Get the human-readable name for a PNIORW ErrorCode1.
PnioCmErrorCode1
PNIO-CM ErrorCode1 values.
Definition exceptions.h:76
@ ArServerResponse
ARServerBlock response.
@ Iocr
IOCRBlock request.
@ CmCtl
Connection management control.
@ IodControlResponse
IODControl response.
@ PrmServer
Parameter server.
@ FaultyRecord
Faulty record data.
@ AlarmCr
AlarmCRBlock request.
@ CmRpc
Connection management RPC.
@ IodControlRequest
IODControl request.
@ ModuleDiff
ModuleDiffBlock.
@ Ar
ARBlock request.
@ ArResponse
ARBlock response.
@ CmDev
Connection management device.
@ ExpectedSubmodule
ExpectedSubmoduleBlock request.
@ IocrResponse
IOCRBlock response.
@ AlarmCrResponse
AlarmCRBlock response.
@ FaultyBlock
Faulty block structure.
@ FaultyAr
Faulty application relation.
@ ModuleDiffResponse
ModuleDiffBlock response.
PnioRwWriteLengthErrorCode2
PNIORW WriteLength ErrorCode2 values.
Definition exceptions.h:174
@ WriteProtected
Write access is denied because the data is write protected.
@ DataTooLong
Write data is too long.
@ WriteLengthError
General write length error.
@ DataTooShort
Write data is too short.
ErrorDecode
PROFINET error decode values.
Definition exceptions.h:22
@ Pnio
General PNIO error.
@ PnioRw
PNIO read/write error.
@ PnioCm
PNIO connection management error.
std::string GetPnioErrorMessage(PnioRmpmErrorCode2 errorCode2)
Get the human-readable message for an RMPM ErrorCode2.
std::string GetPnioCmErrorCode1Name(PnioCmErrorCode1 errorCodeCm1)
Get the human-readable name for a PNIO-CM ErrorCode1.
PnioPrmServerErrorCode2
PNIO Parameter Server ErrorCode2 values.
Definition exceptions.h:499
@ StateConflict
The parameter server is in an invalid state for the requested operation.
PnioRwAccessErrorCode2
PNIORW Access ErrorCode2 values.
Definition exceptions.h:220
@ InvalidArea
Access denied because the area is invalid.
@ LocalControl
Access denied because of local control.
@ InvalidState
Access denied because the device is in an invalid state.
@ InvalidRange
Access denied because the range is invalid.
std::string GetPnioRwErrorMessage(PnioRwInvalidIndexErrorCode2 errorCode2)
Get the human-readable message for an InvalidIndex error.
std::string GetPnioErrorCode1Name(PnioErrorCode1 errorCode1)
Get the human-readable name of a PNIO ErrorCode1.
PnioErrorCode1
PNIO ErrorCode1 values.
Definition exceptions.h:448
@ Rmpm
Runtime parameter and module management (RMPM) error.
PnioCmIocrErrorCode2
PNIO-CM IOCR ErrorCode2 values.
Definition exceptions.h:320
@ NoIocrResources
No IOCR resources are available.
@ InvalidIocrType
Invalid IOCR type.
@ InvalidIoDataLength
The IO data length is invalid.
@ CycleTimeConflict
A cycle time conflict occurred.
@ InvalidFrameId
The frame ID is invalid.
@ WatchdogConfigurationError
The watchdog configuration is invalid.
@ InvalidRtClass
The RT class is invalid.
PnioRmpmErrorCode2
PNIO RMPM ErrorCode2 values.
Definition exceptions.h:469
@ WrongAlarmCrBlockCount
The number of AlarmCR blocks is incorrect.
@ RequiredIocrBlockMissing
A required IOCR block is missing.
@ OutOfArResources
No application relation resources are available.
@ InvalidArgumentsLength
Invalid arguments length.
@ UnknownBlocksInRequest
Unknown blocks were found in the request.
PnioRwInvalidIndexErrorCode2
PNIORW InvalidIndex ErrorCode2 values.
Definition exceptions.h:157
@ IndexNotWritten
Index exists but has not been written.
@ IndexNotSupported
Index is not supported.
PnioRwResourceErrorCode2
PNIORW Resource ErrorCode2 values.
Definition exceptions.h:197
@ ModuleHasNoData
Module has no data.
@ InvalidSlot
Slot number is invalid.
@ ResourceNotAvailable
Resource is not available.
@ InvalidSubslot
Subslot number is invalid.
PnioCmExpectedSubmoduleErrorCode2
PNIO-CM Expected Submodule ErrorCode2 values.
Definition exceptions.h:374
@ IoDataLengthMismatch
IO data length does not match the expected length.
@ WrongModuleIdentNumber
Module identification number does not match.
@ WrongSubmoduleIdentNumber
Submodule identification number does not match.
PnioCmAlarmCrErrorCode2
PNIO-CM Alarm CR ErrorCode2 values.
Definition exceptions.h:353
@ NoAlarmCrResources
No Alarm CR resources are available.
@ InvalidAlarmCrType
Invalid Alarm CR type.
std::string GetPnioCmErrorMessage(PnioCmArErrorCode2 errorCode2)
Get the human-readable message for a PNIO-CM AR error.
PnioRwErrorCode1
PNIO read/write ErrorCode1 values.
Definition exceptions.h:46
@ WriteLength
Write length error.
@ Resource
Resource error.
@ Application
Application error.
@ InvalidIndex
Invalid or unsupported index.
PnioCmDeviceErrorCode2
PNIO-CM Device ErrorCode2 values.
Definition exceptions.h:404
@ ConnectionResourceUnavailable
No connection management resources are available.
@ DeviceStateConflict
Device state conflict.
@ ArSetAborted
The application relation set was aborted.
@ AlreadyOwned
The device is already owned.
std::string GetErrorDecodeName(ErrorDecode errorDecodeName)
Get the human-readable name for an ErrorDecode value.
PnioCmArErrorCode2
PNIO-CM AR ErrorCode2 values.
Definition exceptions.h:281
@ InvalidSessionKey
The session key is invalid.
@ NoAlarmResources
No alarm resources are available.
@ NoConsumerResources
No consumer resources are available.
@ InvalidArType
Invalid AR type.
@ ArAlreadyActive
AR is already active.
@ NoMemory
No memory is available.
@ NoArResources
No AR resources are available.
@ NoProviderResources
No provider resources are available.
@ ArUuidConflict
The AR UUID conflicts with an existing AR.
PnioRwApplicationErrorCode2
PNIORW Application ErrorCode2 values.
Definition exceptions.h:246
@ AlarmPending
An alarm is pending.
@ BackupNotAllowed
Backup is not allowed.
@ InvalidApi
API number is invalid.
PnioCmFaultyBlockErrorCode2
PNIO-CM Faulty Block ErrorCode2 values.
Definition exceptions.h:430
@ FaultyBlockStructure
Faulty block structure.