mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-12 11:00:47 +02:00
implemented serialization of general rtde headers and the request
protocol version package
This commit is contained in:
84
include/ur_rtde_driver/comm/package_serializer.h
Normal file
84
include/ur_rtde_driver/comm/package_serializer.h
Normal file
@@ -0,0 +1,84 @@
|
||||
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
|
||||
|
||||
// -- htobeGIN LICENSE BLOCK ----------------------------------------------
|
||||
// Copyright 2019 FZI Forschungszentrum Informatik
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// -- END LICENSE BLOCK ------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/*!\file
|
||||
*
|
||||
* \author Tristan Schnell schnell@fzi.de
|
||||
* \date 2019-04-10
|
||||
*
|
||||
*/
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#ifndef UR_RTDE_DRIVER_PACKAGE_SERIALIZER_H_INCLUDED
|
||||
#define UR_RTDE_DRIVER_PACKAGE_SERIALIZER_H_INCLUDED
|
||||
|
||||
#include <endian.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace ur_driver
|
||||
{
|
||||
namespace comm
|
||||
{
|
||||
class PackageSerializer
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
static size_t serialize(uint8_t* buffer, T val)
|
||||
{
|
||||
size_t size = sizeof(T);
|
||||
T tmp = encode(val);
|
||||
std::memcpy(buffer, &tmp, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static T encode(T val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
static uint16_t encode(uint16_t val)
|
||||
{
|
||||
return htobe16(val);
|
||||
}
|
||||
static uint32_t encode(uint32_t val)
|
||||
{
|
||||
return htobe32(val);
|
||||
}
|
||||
static uint64_t encode(uint64_t val)
|
||||
{
|
||||
return htobe64(val);
|
||||
}
|
||||
static int16_t encode(int16_t val)
|
||||
{
|
||||
return htobe16(val);
|
||||
}
|
||||
static int32_t encode(int32_t val)
|
||||
{
|
||||
return htobe32(val);
|
||||
}
|
||||
static int64_t encode(int64_t val)
|
||||
{
|
||||
return htobe64(val);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace comm
|
||||
} // namespace ur_driver
|
||||
#endif // UR_RTDE_DRIVER_PACKAGE_SERIALIZER_H_INCLUDED
|
||||
Reference in New Issue
Block a user