Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dynamixel/errors/bad_packet.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DYNAMIXEL_BAD_PACKET_ERROR_HPP_
#define DYNAMIXEL_BAD_PACKET_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -39,7 +39,7 @@ namespace dynamixel {
private:
const std::vector<uint8_t> _packet;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
11 changes: 6 additions & 5 deletions src/dynamixel/errors/crc_error.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#ifndef DYNAMIXEL_ERRORS_CRC_ERROR_HPP_
#define DYNAMIXEL_ERRORS_CRC_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

namespace dynamixel {
namespace errors {
class CrcError : public Error {
public:
CrcError(uint8_t id, uint8_t protocol, uint32_t expected, uint32_t received) : _id(id), _protocol(protocol), _expected(expected), _received(received)
CrcError(uint8_t id, uint8_t protocol, uint32_t expected, uint32_t received)
: _id(id), _protocol(protocol), _expected(expected), _received(received)
{
std::stringstream err_message;
err_message << "Status: checksum error while decoding packet with ID " << (int)id;
Expand Down Expand Up @@ -44,7 +45,7 @@ namespace dynamixel {
uint8_t _id, _protocol;
uint32_t _expected, _received;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
4 changes: 2 additions & 2 deletions src/dynamixel/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace dynamixel {
{
return err.print(os);
}
}
}
} // namespace errors
} // namespace dynamixel

#define CHECK(val, msg) check(__FILE__, __LINE__, (val), msg)
#endif
8 changes: 4 additions & 4 deletions src/dynamixel/errors/servo_limit_error.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef DYNAMIXEL_ERRORS_SERVO_LIMIT_ERROR_HPP_
#define DYNAMIXEL_ERRORS_SERVO_LIMIT_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -46,7 +46,7 @@ namespace dynamixel {
int _id;
double _max, _min, _value;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
6 changes: 3 additions & 3 deletions src/dynamixel/errors/status_error.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DYNAMIXEL_STATUS_ERROR_HPP_
#define DYNAMIXEL_STATUS_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -38,7 +38,7 @@ namespace dynamixel {
private:
uint8_t _id, _protocol, _error_byte;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
4 changes: 2 additions & 2 deletions src/dynamixel/errors/unpack_error.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef DYNAMIXEL_ERRORS_UNPACK_ERROR_HPP_
#define DYNAMIXEL_ERRORS_UNPACK_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down
55 changes: 55 additions & 0 deletions src/dynamixel/errors/vector_size_errors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef DYNAMIXEL_VECTOR_SIZE_ERROR_HPP_
#define DYNAMIXEL_VECTOR_SIZE_ERROR_HPP_

#include <string>

#include "error.hpp"

namespace dynamixel {
namespace errors {
class VectorEmptyError : public Error {
public:
VectorEmptyError(const std::string& method_name,
const std::string& vector_name)
: _method_name(method_name), _vector_name(vector_name)
{
this->_msg = "The vector " + vector_name + ", passed to "
+ method_name + " cannot be empty (size 0)";
}

std::string vector_name() const
{
return _vector_name;
}

std::string method_name() const
{
return _method_name;
}

protected:
const std::string _method_name, _vector_name;
};

class VectorSizesDifferError : public Error {
public:
VectorSizesDifferError(const std::string& method_name,
const std::string& name1, const std::string& name2)
: _method_name(method_name)
{
this->_msg = "The vectors " + name1 + " and " + name2
+ ", passed to " + method_name + " should have the same size.";
}

std::string method_name() const
{
return _method_name;
}

protected:
const std::string _method_name;
};
} // namespace errors
} // namespace dynamixel

#endif
12 changes: 6 additions & 6 deletions src/dynamixel/instructions/bulk_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cassert>
#include <stdint.h>

#include "../errors/error.hpp"
#include "../errors/vector_size_errors.hpp"
#include "../instruction_packet.hpp"

namespace dynamixel {
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace dynamixel {
const uint8_t& data_length)
{
if (ids.size() == 0)
throw errors::Error("BulkRead: ids vector of size zero");
throw errors::VectorEmptyError("BulkRead", "ids");

std::vector<uint8_t> parameters(3 * ids.size() + 3);

Expand Down Expand Up @@ -95,7 +95,7 @@ namespace dynamixel {
const uint16_t& data_length)
{
if (ids.size() == 0)
throw errors::Error("BulkRead: ids vector of size zero");
throw errors::VectorEmptyError("BulkRead", "ids");

std::vector<uint8_t> parameters(5 * ids.size() + 5);
size_t curr = 0;
Expand All @@ -116,11 +116,11 @@ namespace dynamixel {
std::vector<C> lengths)
{
if (ids.size() == 0)
throw errors::Error("BulkRead: ids vector of size zero");
throw errors::VectorEmptyError("BulkRead", "ids");
if (ids.size() != addresses.size())
throw errors::Error("BulkRead: mismatching size for ids and addresses");
throw errors::VectorSizesDifferError("BulkRead", "ids", "addresses");
if (ids.size() != lengths.size())
throw errors::Error("BulkRead: mismatching size for ids and lengths/sizes");
throw errors::VectorSizesDifferError("BulkRead", "ids", "lengths");
}
};
} // namespace instructions
Expand Down
4 changes: 2 additions & 2 deletions src/dynamixel/instructions/bulk_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cassert>
#include <stdint.h>

#include "../errors/error.hpp"
#include "../errors/vector_size_errors.hpp"
#include "../instruction_packet.hpp"

namespace dynamixel {
Expand All @@ -22,7 +22,7 @@ namespace dynamixel {
const uint16_t& data_length, const std::vector<std::vector<uint8_t>>& data)
{
if (ids.size() == 0)
throw errors::Error("BulkWrite: ids vector of size zero");
throw errors::VectorEmptyError("BulkWrite", "ids");

std::vector<uint8_t> parameters((5 + data_length) * ids.size() + 5);
size_t curr = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/dynamixel/instructions/sync_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cassert>
#include <stdint.h>

#include "../errors/error.hpp"
#include "../errors/vector_size_errors.hpp"
#include "../instruction_packet.hpp"

namespace dynamixel {
Expand All @@ -20,7 +20,7 @@ namespace dynamixel {
uint16_t data_length)
{
if (ids.size() == 0)
throw errors::Error("SyncRead: ids vector of size zero");
throw errors::VectorEmptyError("SyncRead", "ids");

std::vector<uint8_t> parameters(ids.size() + 9);

Expand Down
10 changes: 5 additions & 5 deletions src/dynamixel/instructions/sync_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cassert>
#include <stdint.h>

#include "../errors/error.hpp"
#include "../errors/vector_size_errors.hpp"
#include "../instruction_packet.hpp"

namespace dynamixel {
Expand All @@ -21,9 +21,9 @@ namespace dynamixel {
const std::vector<std::vector<uint8_t>>& data)
{
if (ids.size() == 0)
throw errors::Error("SyncWrite: ids vector of size zero");
throw errors::VectorEmptyError("SyncWrite", "ids");
if (ids.size() != data.size())
throw errors::Error("SyncWrite: mismatching vectors size for ids and data");
throw errors::VectorSizesDifferError("SyncWrite", "ids", "data");

typename T::length_t data_length = data[0].size();
std::vector<uint8_t> parameters((data_length + 1) * ids.size() + 2);
Expand All @@ -50,9 +50,9 @@ namespace dynamixel {
const std::vector<std::vector<uint8_t>>& data)
{
if (ids.size() == 0)
throw errors::Error("SyncWrite: ids vector of size zero");
throw errors::VectorEmptyError("SyncWrite", "ids");
if (ids.size() != data.size())
throw errors::Error("SyncWrite: mismatching vectors size for ids and data");
throw errors::VectorSizesDifferError("SyncWrite", "ids", "data");

typename T::length_t data_length = data[0].size();
std::vector<uint8_t> parameters((data_length + 1) * ids.size() + 4);
Expand Down
Loading