Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing include for <cstdint> #2

Merged
merged 1 commit into from
Apr 23, 2024
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
5 changes: 3 additions & 2 deletions include/schunk_svh_library/SVHFirmwareInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

#include <schunk_svh_library/serial/ByteOrderConversion.h>

Expand Down Expand Up @@ -86,8 +87,8 @@ inline driver_svh::ArrayBuilder& operator>>(driver_svh::ArrayBuilder& ab, SVHFir
{
// Stream operator can not handle arrays (due to missing size information) to make things easy we
// just copy the data around. Feel free to do something else
std::vector<uint8_t> text(48);
std::vector<uint8_t> svh(4);
std::vector<std::uint8_t> text(48);
std::vector<std::uint8_t> svh(4);

ab >> svh >> data.version_major >> data.version_minor >> text;

Expand Down
17 changes: 9 additions & 8 deletions include/schunk_svh_library/serial/ByteOrderConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
#include <iomanip>
#include <iostream>
#include <vector>
#include <cstdint>


namespace driver_svh {

//! template function for adding data to an array while converting everything into correct endianess
template <typename T>
size_t toLittleEndian(const T& data, std::vector<uint8_t>& array, size_t& write_pos)
size_t toLittleEndian(const T& data, std::vector<std::uint8_t>& array, size_t& write_pos)
{
// Resize the target array in case it it to small to avoid out of bounds acces
if (write_pos + sizeof(T) > array.size())
Expand All @@ -61,7 +62,7 @@ size_t toLittleEndian(const T& data, std::vector<uint8_t>& array, size_t& write_
{
// Copy each byte into the bytearray, always convert byte order to little endian regardles of
// source architecture
array[write_pos + i] = static_cast<uint8_t>((data >> (i * 8)) & 0xFF);
array[write_pos + i] = static_cast<std::uint8_t>((data >> (i * 8)) & 0xFF);
}

return write_pos + sizeof(T);
Expand All @@ -70,20 +71,20 @@ size_t toLittleEndian(const T& data, std::vector<uint8_t>& array, size_t& write_
//! Template specialization for float as these have to be handled seperately
template <>
DRIVER_SVH_IMPORT_EXPORT size_t toLittleEndian<float>(const float& data,
std::vector<uint8_t>& array,
std::vector<std::uint8_t>& array,
size_t& write_pos);

//! Template specialization for float as these have to be handled seperately
template <>
DRIVER_SVH_IMPORT_EXPORT size_t toLittleEndian<double>(const double& data,
std::vector<uint8_t>& array,
std::vector<std::uint8_t>& array,
size_t& write_pos);


//! template function for reating data out of an array while converting everything into correct
//! endianess
template <typename T>
size_t fromLittleEndian(T& data, std::vector<uint8_t>& array, size_t& read_pos)
size_t fromLittleEndian(T& data, std::vector<std::uint8_t>& array, size_t& read_pos)
{
// TODO: Remove once everything is tested :)
// std::cout << "From Little Endian Called with: "<<" Size_T: "<< sizeof(T) << " Pos: " <<
Expand Down Expand Up @@ -119,13 +120,13 @@ size_t fromLittleEndian(T& data, std::vector<uint8_t>& array, size_t& read_pos)
//! Template specialization for float as these have to be handled seperately
template <>
DRIVER_SVH_IMPORT_EXPORT size_t fromLittleEndian<float>(float& data,
std::vector<uint8_t>& array,
std::vector<std::uint8_t>& array,
size_t& read_pos);

//! Template specialization for float as these have to be handled seperately
template <>
DRIVER_SVH_IMPORT_EXPORT size_t fromLittleEndian<double>(double& data,
std::vector<uint8_t>& array,
std::vector<std::uint8_t>& array,
size_t& read_pos);

//! template class holding an array and the current index for write commands. Can be used to easily
Expand Down Expand Up @@ -160,7 +161,7 @@ class ArrayBuilder
size_t read_pos;

//! array of template type TArray
std::vector<uint8_t> array;
std::vector<std::uint8_t> array;


//!
Expand Down
7 changes: 4 additions & 3 deletions include/schunk_svh_library/serial/SVHReceiveThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <chrono>
#include <functional>
#include <memory>
#include <cstdint>

using driver_svh::serial::Serial;

Expand Down Expand Up @@ -126,11 +127,11 @@ class SVHReceiveThread
uint16_t m_length;

//! Checksum of packet
uint8_t m_checksum1;
uint8_t m_checksum2;
std::uint8_t m_checksum1;
std::uint8_t m_checksum2;

//! length of received serial data
std::vector<uint8_t> m_data;
std::vector<std::uint8_t> m_data;

//! pointer to array builder object for packet receive
driver_svh::ArrayBuilder m_ab;
Expand Down
4 changes: 2 additions & 2 deletions include/schunk_svh_library/serial/SVHSerialInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ class DRIVER_SVH_IMPORT_EXPORT SVHSerialInterface
//! serial device connected state
bool m_connected;

uint8_t m_last_index;
std::uint8_t m_last_index;

//! pointer to serial interface object
std::shared_ptr<Serial> m_serial_device;

//! cecksum calculation
void calcCheckSum(uint8_t& check_sum1, uint8_t& check_sum2, const SVHSerialPacket& packet);
void calcCheckSum(std::uint8_t& check_sum1, std::uint8_t& check_sum2, const SVHSerialPacket& packet);

//! thread for receiving serial packets
std::thread m_receive_thread;
Expand Down
39 changes: 20 additions & 19 deletions include/schunk_svh_library/serial/SVHSerialPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define SVHSERIALPACKET_H

#include <schunk_svh_library/serial/ByteOrderConversion.h>
#include <cstdint>

namespace driver_svh {

Expand All @@ -49,29 +50,29 @@ const size_t C_PACKET_APPENDIX_SIZE = 8; //!< The packet overhead size in bytes
const size_t C_DEFAULT_PACKET_SIZE = 48; //!< Default packet payload size in bytes

// packet headers
const uint8_t PACKET_HEADER1 = 0x4C; //!< Header sync byte 1
const uint8_t PACKET_HEADER2 = 0xAA; //!< Header sync byte 2
const std::uint8_t PACKET_HEADER1 = 0x4C; //!< Header sync byte 1
const std::uint8_t PACKET_HEADER2 = 0xAA; //!< Header sync byte 2

// adress constants for commands
const uint8_t SVH_GET_CONTROL_FEEDBACK =
const std::uint8_t SVH_GET_CONTROL_FEEDBACK =
0x00; //!< Request the position and current of a channel to be sent
const uint8_t SVH_SET_CONTROL_COMMAND = 0x01; //!< Sets the target position of a channel
const uint8_t SVH_GET_CONTROL_FEEDBACK_ALL =
const std::uint8_t SVH_SET_CONTROL_COMMAND = 0x01; //!< Sets the target position of a channel
const std::uint8_t SVH_GET_CONTROL_FEEDBACK_ALL =
0x02; //!< Requests the positions and currents of ALL channels
const uint8_t SVH_SET_CONTROL_COMMAND_ALL = 0x03; //!< Sends the target position to ALL the channels
const uint8_t SVH_GET_POSITION_SETTINGS =
const std::uint8_t SVH_SET_CONTROL_COMMAND_ALL = 0x03; //!< Sends the target position to ALL the channels
const std::uint8_t SVH_GET_POSITION_SETTINGS =
0x04; //!< Requests the active settings of the position controller
const uint8_t SVH_SET_POSITION_SETTINGS = 0x05; //!< Sets new settings for the position controller
const uint8_t SVH_GET_CURRENT_SETTINGS =
const std::uint8_t SVH_SET_POSITION_SETTINGS = 0x05; //!< Sets new settings for the position controller
const std::uint8_t SVH_GET_CURRENT_SETTINGS =
0x06; //!< Requests the active settings of the current controller
const uint8_t SVH_SET_CURRENT_SETTINGS = 0x07; //!< Sets new settings for the current controller
const uint8_t SVH_GET_CONTROLLER_STATE =
const std::uint8_t SVH_SET_CURRENT_SETTINGS = 0x07; //!< Sets new settings for the current controller
const std::uint8_t SVH_GET_CONTROLLER_STATE =
0x08; //!< Requests the state of the controller (active,faults,enabled channels)
const uint8_t SVH_SET_CONTROLLER_STATE =
const std::uint8_t SVH_SET_CONTROLLER_STATE =
0x09; //!< Sets new controller states (enable channels, clear faults)
const uint8_t SVH_GET_ENCODER_VALUES = 0x0A; //!< Request the current encoder scalings
const uint8_t SVH_SET_ENCODER_VALUES = 0x0B; //!< Set new encoder scalings
const uint8_t SVH_GET_FIRMWARE_INFO = 0x0C; //!< Request the firmware info to be transmitted
const std::uint8_t SVH_GET_ENCODER_VALUES = 0x0A; //!< Request the current encoder scalings
const std::uint8_t SVH_SET_ENCODER_VALUES = 0x0B; //!< Set new encoder scalings
const std::uint8_t SVH_GET_FIRMWARE_INFO = 0x0C; //!< Request the firmware info to be transmitted

/*!
* \brief The SerialPacket holds the (non generated) header and data of one message to the
Expand All @@ -82,18 +83,18 @@ struct SVHSerialPacket
//! \brief Continuosly incremented counter per package
//! \note Continuous counter is currently not used by this software, the hw will just copy the
//! send counter back to the response
uint8_t index;
std::uint8_t index;
//! Adress denotes the actual function of the package
uint8_t address;
std::uint8_t address;
//! Payload of the package
std::vector<uint8_t> data;
std::vector<std::uint8_t> data;

/*!
* \brief SVHSerialPacket contains the send and received data in raw format (bytewise)
* \param data_length initial size to set the data length to. NOTE: To deserialize a packet this
* value HAS TO BE SET!
*/
SVHSerialPacket(size_t data_length = 0, uint8_t address = SVH_GET_CONTROL_FEEDBACK)
SVHSerialPacket(size_t data_length = 0, std::uint8_t address = SVH_GET_CONTROL_FEEDBACK)
: address(address)
, data(data_length, 0)
{
Expand Down