KaCanOpen
 All Classes Functions Variables Typedefs Enumerations Pages
sdo_error.h
1 /*
2  * Copyright (c) 2015, Thomas Keh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 #include <cstdint>
35 #include <string>
36 #include <stdexcept>
37 
38 #include "canopen_error.h"
39 
40 namespace kaco {
41 
48  class sdo_error : public canopen_error {
49 
50  public:
51 
53  enum class type : uint32_t {
54 
55  // Standard Cia 301 SDO error codes
56 
57  toggle_bit = 0x05030000,
58  timeout = 0x05040000,
59  command_specifier = 0x05040001,
60  block_size = 0x05040002,
61  sequence_number = 0x05040003,
62  crc = 0x05040004,
63  memory = 0x05040005,
64  access = 0x06010000,
65  write_only = 0x06010001,
66  read_only = 0x06010002,
67  not_in_dictionary = 0x06020000,
68  no_mapping = 0x06040041,
69  pdo_length_exceeded = 0x06040042,
70  parameter_incompatibility = 0x06040043,
71  internal_incompatibility = 0x06040047,
72  hardware_error = 0x06060000,
73  service_parameter = 0x06070010,
74  service_parameter_too_high = 0x06070012,
75  service_parameter_too_low = 0x06070013,
76  subindex = 0x06090011,
77  value = 0x06090030,
78  value_too_high = 0x06090031,
79  value_too_low = 0x06090032,
80  max_less_than_min = 0x06090036,
81  sdo_connection = 0x060A0023,
82  general = 0x08000000,
83  transfer_or_storage = 0x08000020,
84  transfer_or_storage_local_control = 0x08000021,
85  transfer_or_storage_device_state = 0x08000022,
86  no_dictionary = 0x08000023,
87  no_data = 0x08000024,
88 
89  // Custom KaCanOpen error codes
90 
91  response_timeout = 0x10000000,
92  segmented_download = 0x10000001,
93  response_command = 0x10000002,
94  response_toggle_bit = 0x10000003,
95 
96  // Unknown error
97 
98  unknown = 0x20000000
99 
100  };
101 
105  explicit sdo_error(type error_type, const std::string& additional_information = "");
106 
110  explicit sdo_error(uint32_t sdo_data, const std::string& additional_information = "");
111 
113  virtual ~sdo_error() { }
114 
116  virtual const char* what() const noexcept override;
117 
119  type get_type() const noexcept;
120 
121  private:
122 
123  std::string m_message;
124  type m_type;
125 
126  };
127 
128 } // end namespace kaco
virtual const char * what() const noexceptoverride
Returns error description.
Definition: sdo_error.cpp:105
sdo_error(type error_type, const std::string &additional_information="")
Constructor when type is known.
Definition: sdo_error.cpp:36
type get_type() const noexcept
Returns type of the error.
Definition: sdo_error.cpp:109
virtual ~sdo_error()
Destructor.
Definition: sdo_error.h:113
This type of exception is thrown when there are problems while accessing devices via SDO...
Definition: sdo_error.h:48
This is the base class of all types of exceptions thrown by the KaCanOpen library. It can be used directly like std::runtime_error if there isn't any more specific error class.
Definition: canopen_error.h:43
type
Exact type of the SDO error.
Definition: sdo_error.h:53