[go: up one dir, main page]

Menu

[r1]: / trunk / include / common_kerl.h  Maximize  Restore  History

Download this file

199 lines (184 with data), 4.2 kB

  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
/**
* \file common_kerl.h
* \brief Common definitions
* \author Thomas Lorentsen, Sten Gruener
*
* This file contains common definitions and functions needed for kerl.
*
* Error numbers start from severl ranges depending on where
* they were caused, this makes debugging easier as we can
* tell if it is a player problem, ei problem or a kerl problem.
*
* Errors caused in kerl code start from -64
* Errors returned from the player server start from -128
* Errors returned from ei start from -192
*/
/**
* \def DBUG(x, args...)
* Issue a debug message if debugging is enabled.
*/
#ifdef DEBUG
#define DBUG(x, args...) fprintf(stderr, x, ##args)
#else
#define DBUG(x, args...)
#endif
/**
* \def BENCH(x, args...)
* Issue a benchmark message is benchmarking is enabled.
*/
#ifdef BENCHMARKING
#define BENCH(x, args...) fprintf(stderr, x, ##args)
#else
#define BENCH(x, args...)
#endif
/**
* \struct ClientQuery
* Player client query
*/
typedef struct {
/*! Robot identifier */
char *robotID;
/*! Internal stage identifier */
int index;
/*! Connection address */
char* address;
/*! Connection port */
int port;
/*! Devices to query */
int devices;
} ClientQuery;
/**
* \def ECASE
* Error case definition - on error return message.
*/
#define ECASE(error, message) case error : return message
// Configuration
/**
* \def FNLENGTH
* Maximum length of a funciton name in driver_kerl
*/
#define FNLENGTH 20
/**
* \def IDLENGTH
* Maximum length of the robot id
*/
#define IDLENGTH 50
/**
* \def DOMAINLENGTH
* Maximum length of the domainname of player
*/
#define DOMAINLENGTH 50
// Append error messages
// general return values
/**
* \def SUCCESS
* Success return value
*/
#define SUCCESS 0
/**
* \def GENERICFAIL
* Generic failure return value
*/
#define GENERICFAIL -1
/**
* \def BROKENCODE
* Broken code - see code for details
*/
#define BROKENCODE -2
// general player kerl errors start from -64
/**
* \def NAMEINUSE
* Error: Name in use
*/
#define NAMEINUSE -64
/**
* \def NOSUCHCLIENT
* Error: No such client
*/
#define NOSUCHCLIENT -65
/**
* \def NOTSTORED
* Error: Not stored
*/
#define NOTSTORED -66
/**
* \def DEVICENOTINITIALISED
* Error: Device not initialised
*/
#define DEVICENOTINITIALISED -67
/**
* \def NOSUCHDEVICE
* Error: No such device
*/
#define NOSUCHDEVICE -68
/**
* \def ERRORQUERYINGDEVICES
* Error: Error querying devices
*/
#define ERRORQUERYINGDEVICES -69
/**
* \def INVALIDINDEX
* Error: Invalid index specified
*/
#define INVALIDINDEX -70
// errors from player start from -128
/**
* \def ERRORCONNECTING
* Player error: Error connecting
*/
#define ERRORCONNECTING -128
/**
* \def PLAYERFAIL
* Player error: Player failure
*/
#define PLAYERFAIL -127
/**
* \def NOSOCKET
* Player error: No socket
*/
#define NOSOCKET -126
// errors from erlang interface start from -192
/**
* \def UNDEFINEDFUNCTION
* Erlang interface error: Undefined function
*/
#define UNDEFINEDFUNCTION -192
/**
* \def UNDEFINEDOPTION
* Erlang interface error: Undefined option
*/
#define UNDEFINEDOPTION -193
// This is a list of devices we can support
/**
* \def SUPPOSITION
* Supported device: Position sensor
*/
#define SUPPOSITION 0x1
/**
* \def SUPLASERS
* Supported device: Laser range finder
*/
#define SUPLASERS 0x2
/**
* \def SUPSONAR
* Supported device: Sonar range finder
*/
#define SUPSONAR 0x4
//add to this list must be in power of twos
//for example, gps might be 0x8 and then camera might be 0x16
//This allows device to be represented as a binary on or off
/**
* \fn errorToString(int)
* \param errorno the error value passed
* \return the string representation of the error
* Converts a error defined in common_kerl.h
* into a human readable form
* All spaces must be replaced with underscores to be
* passed as erlang atoms
* If the error is not found it should return the number
* as a string.
* You can also pass SUCCESS to get a string representation
* that will work in Erlang, just dont pass it back as
* an error {error, ok} otherwise it will seem rather silly
*/
char* errorToString(int errorno);