REC RPC library
rec_rpc_utils.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011, REC Robotics Equipment Corporation GmbH, Planegg, Germany
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 - Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 - Neither the name of the REC Robotics Equipment Corporation GmbH nor the names of
14  its contributors may be used to endorse or promote products derived from this software
15  without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
18 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 #ifndef _REC_RPC_UTILS_H_
28 #define _REC_RPC_UTILS_H_
29 
30 #include "rec/rpc/defines.h"
31 #include <qglobal.h>
32 
33 namespace rec
34 {
35  namespace rpc
36  {
37  static const float PI = 3.14159265358979323846f;
38 
39  static REC_RPC_FUNCTION_IS_NOT_USED float deg2rad( float deg )
40  {
41  return PI * deg / 180.0f;
42  }
43 
44  static REC_RPC_FUNCTION_IS_NOT_USED float rad2deg( float rad )
45  {
46  return 180.0f * rad / PI;
47  }
48 
49  static char* encodeInt32( char* data, const qint32 value )
50  {
51  *data++ = 0xFF & value;
52  *data++ = 0xFF & ( value >> 8 );
53  *data++ = 0xFF & ( value >> 16 );
54  *data++ = 0xFF & ( value >> 24 );
55  return data;
56  }
57 
58  static char* encodeUInt32( char* data, const quint32 value )
59  {
60  *data++ = 0xFF & value;
61  *data++ = 0xFF & ( value >> 8 );
62  *data++ = 0xFF & ( value >> 16 );
63  *data++ = 0xFF & ( value >> 24 );
64  return data;
65  }
66 
67  static const char* decodeInt32( const char* data, qint32* value )
68  {
69  *value = qint32( quint8( *data++ ) );
70  *value |= ( qint32( quint8( *data++ ) ) << 8);
71  *value |= ( qint32( quint8( *data++ ) ) << 16);
72  *value |= ( qint32( quint8( *data++ ) ) << 24);
73  return data;
74  }
75 
76  static const char* decodeUInt32( const char* data, quint32* value )
77  {
78  *value = quint32( quint8( *data++ ) );
79  *value |= ( quint32( quint8( *data++ ) ) << 8);
80  *value |= ( quint32( quint8( *data++ ) ) << 16);
81  *value |= ( quint32( quint8( *data++ ) ) << 24);
82  return data;
83  }
84 
85  static qint32 decodeInt32( const char* data )
86  {
87  qint32 value = quint8( *data++ );
88  value |= ( qint32( quint8( *data++ ) ) << 8);
89  value |= ( qint32( quint8( *data++ ) ) << 16);
90  value |= ( qint32( quint8( *data++ ) ) << 24);
91  return value;
92  }
93 
94  static quint32 decodeUInt32( const char* data )
95  {
96  quint32 value = quint8( *data++ );
97  value |= ( quint32( quint8( *data++ ) ) << 8);
98  value |= ( quint32( quint8( *data++ ) ) << 16);
99  value |= ( quint32( quint8( *data++ ) ) << 24);
100  return value;
101  }
102  }
103 }
104 
105 #endif //_REC_RPC_UTILS_H_
#define REC_RPC_FUNCTION_IS_NOT_USED
Definition: defines.h:57
static char * encodeUInt32(char *data, const quint32 value)
Definition: rec_rpc_utils.h:58
static const char * decodeInt32(const char *data, qint32 *value)
Definition: rec_rpc_utils.h:67
static const float PI
Definition: rec_rpc_utils.h:37
static REC_RPC_FUNCTION_IS_NOT_USED float rad2deg(float rad)
Definition: rec_rpc_utils.h:44
static REC_RPC_FUNCTION_IS_NOT_USED float deg2rad(float deg)
Definition: rec_rpc_utils.h:39
static char * encodeInt32(char *data, const qint32 value)
Definition: rec_rpc_utils.h:49
static const char * decodeUInt32(const char *data, quint32 *value)
Definition: rec_rpc_utils.h:76