KaCanOpen
 All Classes Functions Variables Typedefs Enumerations Pages
sdo_error.cpp
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 #include "sdo_error.h"
33 
34 namespace kaco {
35 
36  sdo_error::sdo_error(type error_type, const std::string& additional_information)
37  : sdo_error(static_cast<uint32_t>(error_type),additional_information)
38  { }
39 
40  sdo_error::sdo_error(uint32_t sdo_data, const std::string& additional_information)
41  : canopen_error("") {
42 
43  #define SDO_ERROR_CASE(t,msg) case static_cast<uint32_t>(type:: t ): m_message = msg ; m_type = type:: t ; break;
44 
45  switch (sdo_data) {
46 
47  // Standard Cia 301 SDO error codes
48 
49  SDO_ERROR_CASE(toggle_bit,"Toggle bit not alternated.")
50  SDO_ERROR_CASE(timeout,"SDO protocol timed out.")
51  SDO_ERROR_CASE(command_specifier,"Client/server command specifier not valid or unknown.")
52  SDO_ERROR_CASE(block_size,"Invalid block size (block mode only).")
53  SDO_ERROR_CASE(sequence_number,"Invalid sequence number (block mode only).")
54  SDO_ERROR_CASE(crc,"CRC error (block mode only).")
55  SDO_ERROR_CASE(memory,"Out of memory.")
56  SDO_ERROR_CASE(access,"Unsupported access to an object.")
57  SDO_ERROR_CASE(write_only,"Attempt to read a write only object.")
58  SDO_ERROR_CASE(read_only,"Attempt to write a read only object.")
59  SDO_ERROR_CASE(not_in_dictionary,"Object does not exist in the object dictionary.")
60  SDO_ERROR_CASE(no_mapping,"Object cannot be mapped to the PDO.")
61  SDO_ERROR_CASE(pdo_length_exceeded,"The number and length of the objects to be mapped whould exeed PDO length.")
62  SDO_ERROR_CASE(parameter_incompatibility,"General parameter incompatibility reason.")
63  SDO_ERROR_CASE(internal_incompatibility,"General internal incompatibility in the device.")
64  SDO_ERROR_CASE(hardware_error,"Access failed due to a hardware error.")
65  SDO_ERROR_CASE(service_parameter,"Data type does not match, length of service parameter does not match.")
66  SDO_ERROR_CASE(service_parameter_too_high,"Data type does not match, length of service parameter too high.")
67  SDO_ERROR_CASE(service_parameter_too_low,"Data type does not match, length of service parameter too low.")
68  SDO_ERROR_CASE(subindex,"Sub-index does not exist.")
69  SDO_ERROR_CASE(value,"Invalid value for parameter.")
70  SDO_ERROR_CASE(value_too_high,"Value of parameter written too high.")
71  SDO_ERROR_CASE(value_too_low,"Value of parameter written too low.")
72  SDO_ERROR_CASE(max_less_than_min,"Maximum value is less than minimum value")
73  SDO_ERROR_CASE(sdo_connection,"Resource not available: SDO connection")
74  SDO_ERROR_CASE(general,"General error")
75  SDO_ERROR_CASE(transfer_or_storage,"Data cannot be transferred or stored to the application.")
76  SDO_ERROR_CASE(transfer_or_storage_local_control,"Data cannot be transferred or stored to the application because of local control.")
77  SDO_ERROR_CASE(transfer_or_storage_device_state,"Data cannot be transferred or stored to the application because of the present device state.")
78  SDO_ERROR_CASE(no_dictionary,"Object dictionary dynamic generation fails or no object dictionary is present (e.g. object dictionary is generated from file and generation fails because of a file error).")
79  SDO_ERROR_CASE(no_data,"No data available.")
80 
81  // Custom KaCanOpen error codes
82 
83  SDO_ERROR_CASE(response_timeout,"Timeout while waiting for response.")
84  SDO_ERROR_CASE(segmented_download,"Segmented download not yet supported.")
85  SDO_ERROR_CASE(response_command,"Invalid response command.")
86  SDO_ERROR_CASE(response_toggle_bit,"Toggle bit in response is not equal to toggle bit in request.")
87 
88  // just for completeness
89  SDO_ERROR_CASE(unknown,"Unknown SDO error")
90 
91  // Unknown error
92 
93  default:
94  m_message = "Unknown SDO error.";
95  m_type = type::unknown;
96 
97  }
98 
99  #undef SDO_ERROR_CASE
100 
101  m_message = "SDO Error: " + m_message + (additional_information.empty()?"":" "+additional_information);
102 
103  }
104 
105  const char* sdo_error::what() const noexcept {
106  return m_message.c_str();
107  }
108 
110  return m_type;
111  }
112 
113 }
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
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