-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyRideCommon.h
334 lines (287 loc) · 7.62 KB
/
PyRideCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
* PyRideCommon.h
* PyRIDE
*
* Created by Xun Wang on 20/04/2010.
* Copyright 2009 Galaxy Network. All rights reserved.
*
*/
#ifndef PyRideCommon_h_DEFINED
#define PyRideCommon_h_DEFINED
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#ifndef WIN32
#include <sys/time.h>
#endif
#include "PyRideCustom.h"
#define PYRIDE_PROTOCOL_VERSION 6
#define PYRIDE_MSG_INIT 0xAC
#define PYRIDE_MSG_END '#'
#define PYRIDE_MSG_MIN_LENGTH 5
#define PYRIDE_MSG_HEADER_SIZE 4
#define PYRIDE_BROADCAST_IP "255.255.255.255"
#define PYRIDE_CONTROL_PORT 29430
#define PYRIDE_VIDEO_STREAM_BASE_PORT 35210 //34529
#define PYRIDE_DEFAULT_BUFFER_SIZE 4096
#define PYRIDE_MSG_BUFFER_SIZE 10240
#define PYRIDE_AUDIO_SAMPLE_RATE 16000
#define PYRIDE_AUDIO_FRAME_PERIOD 0.02 // time period for an audio frame 20ms
#define PYRIDE_AUDIO_BYTES_PER_PACKET 46
#define PYRIDE_AUDIO_BITS_PER_SAMPLE 16
#define PYRIDE_AUDIO_BYTES_PER_SAMPLE (PYRIDE_AUDIO_BITS_PER_SAMPLE/8)
#define PYRIDE_AUDIO_PLAY_BUFFERS 2
#define PYRIDE_AUDIO_CAPTURE_BUFFERS 3
#if defined( IOS_BUILD )
#define PYRIDE_LOGGING_INIT
#define DEBUG_MSG( MSG... ) \
printf( "DEBUG: " ); \
printf( MSG );
#define ERROR_MSG( MSG... ) \
printf( "ERROR: " ); \
printf( MSG );
#define WARNING_MSG( MSG... ) \
printf( "WARNING: " ); \
printf( MSG );
#define INFO_MSG( MSG... ) \
printf( "INFO: " ); \
printf( MSG );
#else // !IOS_BUILD
#ifdef WIN32
#define WM_FGNOTIFY WM_USER+1
#define PYRIDE_LOGGING_DECLARE( LOGNAME )
#define PYRIDE_LOGGING_INIT
#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( ... )
#else
#define DEBUG_MSG(...) \
{ char outputStr[200]; \
sprintf_s( outputStr, 200, __VA_ARGS__ ); \
OutputDebugStringA( outputStr ); \
}
#endif
#define INFO_MSG(...) \
{ char outputStr[200]; \
sprintf_s( outputStr, 200, __VA_ARGS__ ); \
OutputDebugStringA( outputStr ); \
}
#define WARNING_MSG(...)
#define ERROR_MSG(...) \
{ char outputStr[200]; \
sprintf_s( outputStr, 200, __VA_ARGS__ ); \
OutputDebugStringA( outputStr ); \
}
#else
#define PYRIDE_NO_LOGGING \
FILE * s_pyridelog = NULL;
#define PYRIDE_LOGGING_DECLARE( LOGNAME ) \
FILE * s_pyridelog = NULL; \
const char * logFileName = LOGNAME
extern FILE * s_pyridelog;
#define PYRIDE_LOGGING_INIT \
{ \
char * sep = NULL; \
if ((sep = strrchr( (char*)logFileName, '/' )) != NULL ) { \
struct stat sb; \
int dirlen = sep - logFileName; \
char * dirname = (char *) malloc( dirlen + 1 ); \
memcpy( dirname, logFileName, dirlen ); \
dirname[dirlen] = '\0'; \
if (stat( dirname, &sb ) == -1) \
mkdir( dirname, 0755 ); \
free( dirname ); \
} \
} \
s_pyridelog = fopen( logFileName, "a" )
//#define s_pyridelog stdout
#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( MSG... )
#else
#define DEBUG_MSG( MSG... ) \
if (s_pyridelog) { \
struct timeval now; \
gettimeofday( &now, NULL ); \
fprintf( s_pyridelog, "[%ld%c%ld] DEBUG: ", (long)now.tv_sec, 46, (long)now.tv_usec ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog ); \
}
#endif
#define INFO_MSG( MSG... ) \
if (s_pyridelog) { \
struct timeval now; \
gettimeofday( &now, NULL ); \
fprintf( s_pyridelog, "[%ld%c%ld] INFO: ", (long)now.tv_sec, 46, (long)now.tv_usec ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog ); \
}
#define WARNING_MSG( MSG... ) \
if (s_pyridelog) { \
struct timeval now; \
gettimeofday( &now, NULL ); \
fprintf( s_pyridelog, "[%ld%c%ld] WARNING: ", (long)now.tv_sec, 46, (long)now.tv_usec ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog ); \
}
#define ERROR_MSG( MSG... ) \
if (s_pyridelog) { \
struct timeval now; \
gettimeofday( &now, NULL ); \
fprintf( s_pyridelog, "[%ld%c%ld] ERROR: ", (long)now.tv_sec, 46, (long)now.tv_usec ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog ); \
}
#define PYRIDE_LOGGING_FINI \
if (s_pyridelog) { \
fclose( s_pyridelog ); \
}
#endif // !WIN32
#endif // IOS_BUILD
#ifdef WIN32
#include <winsock2.h>
#define SOCKET_T SOCKET
#else
#define SOCKET_T int
#define INVALID_SOCKET -1
#endif
#ifndef DEFINED_ENCRYPTION_KEY
#pragma message ( "Make sure you change the encryption key for PyRIDE client server communication. \
To disable this warning, set DEFINED_ENCRYPTION_KEY macro to true." )
#endif
enum CommandStatus {
NONE = 0,
OK,
FAIL,
DUPLICATE
};
enum TeamColour {
BlueTeam = 1,
PinkTeam = 2
};
typedef enum {
RAW = 0,
RGB,
PROCESSED,
RGBA,
BGRA
}ImageFormat;
typedef enum {
ROBOT_TEAM_MSG = 0x0,
ROBOT_DISCOVERY = 0x1,
ROBOT_DECLARE = 0x2,
ROBOT_TELEMETRY = 0x3,
ROBOT_STATUS = 0x4,
CLIENT_COMMAND = 0x5,
CLIENT_RESPONSE = 0x6,
CLIENT_SHUTDOWN = 0x7
} PyRideControl;
typedef enum {
VIDEO_SWITCH = 0x0,
VIDEO_START = 0x1,
VIDEO_STOP = 0x2,
VIDEO_FORMAT = 0x3,
TELEMETRY_START = 0x4,
TELEMETRY_STOP = 0x5,
CUSTOM_COMMAND = 0x6,
CANCEL_CUR_OP = 0x7
} PyRideCommand;
typedef enum {
HEART_BEAT = 0x0, // used by CLIENT_RESPONSE
USER_AUTH = 0x1 // used by ROBOT_DISCOVERY only
} PyRideClientMode;
typedef enum {
YELLOW_GOAL = 0x1,
BLUE_GOAL = 0x2,
BALL = 0x3,
ROBOT = 0x4
} ObjectType;
typedef enum {
UNKNOWN = 0x0,
NAO = 0x1,
PR2 = 0x2,
TURTLE_BOT = 0x3,
KIOSK = 0x4,
PEPPER = 0x5,
REEM = 0x6,
CRUZR = 0x7
} RobotType;
typedef enum {
MOBILITY = 0x1,
MANIPULATION = 0x2,
AUDIO_FEEBACK = 0x4,
VIDEO_FEEBACK = 0x8
} RobotCapability;
typedef struct {
float x;
float y;
float theta;
} RobotPose;
typedef struct {
RobotType type;
RobotPose pose;
RobotCapability capabilities;
RobotOperationalState status;
int nofcams;
int nofaudios;
} RobotInfo;
typedef struct {
ObjectType objType;
float x;
float y;
} FieldObject;
typedef struct {
bool isBlueTeam;
bool isLogging;
bool isAutoSampling;
int samplingRate;
} PyRideSettings;
typedef struct {
int width;
int height;
} CameraQuality;
typedef struct {
char fps;
char format;
char resolution;
char reserved;
short dataport;
short ctrlport;
} VideoSettings;
typedef struct {
char channels;
char samplebytes;
unsigned short sampling;
short dataport;
short ctrlport;
int reserved;
} AudioSettings;
static const int kHeartBeatWindow = 3; // in seconds
static const int kSupportFrameRate[] = { 1, 2, 5, 10, 15, 20, 25, 30 };
static const int kErrorFrameRate = 255;
static const int kMaxSamplingRate = 20;
static const int kMinSamplingRate = 1;
static const CameraQuality kSupportedCameraQuality[] = {{160, 120},{320,240},{640,480}};
static const int kCompressionRate[] = { 95, 80, 70 };
static const int kMotionCommandFreq = 5;
static const int kPublishFreq = 20;
static const int kUDPHeartBeatWindow = 60;
static const double kDegreeToRAD = 0.01745329252;
#ifdef USE_ENCRYPTION
#ifdef __cplusplus
extern "C" {
#endif
unsigned char * decodeBase64( const char * input, size_t * outLen );
char * encodeBase64( const unsigned char * input, size_t length );
void endecryptInit(void);
void endecryptFini(void);
int decryptMessage( const unsigned char * origMesg, int origMesgLength, unsigned char ** decryptedMesg, int * decryptedMesgLength );
int encryptMessage( const unsigned char * origMesg, int origMesgLength, unsigned char ** encryptedMesg, int * encryptedMesgLength );
int secureSHA256Hash( const unsigned char * password, const int pwlen, unsigned char * code );
#ifdef __cplusplus
}
#endif
#endif // USE_ENCRYPTION
#ifdef WIN32
int win_gettimeofday( struct timeval * tp,void * tz );
#endif
#endif // PyRideCommon_h_DEFINED