Changeset 1845
- Timestamp:
- 04/29/12 23:08:36 (13 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
firmware/openos/bsp/boards/pc/board.c (modified) (2 diffs)
-
firmware/openos/bsp/boards/pc/bsp_timer.c (modified) (4 diffs)
-
firmware/openos/bsp/boards/pc/leds.c (modified) (2 diffs)
-
firmware/openos/bsp/boards/pc/opensim_client.c (modified) (6 diffs)
-
firmware/openos/projects/common/01bsp_leds/SConscript (modified) (1 diff)
-
software/opensim/SimEngine/MoteHandler.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/firmware/openos/bsp/boards/pc/board.c
r1839 r1845 14 14 #include "radiotimer.h" 15 15 #include "eui64.h" 16 // OpenSim environment 17 #include "opensim_client.h" 16 18 17 19 //=========================== variables ======================================= … … 22 24 23 25 void board_init() { 24 // poipoipoi stub 25 printf("TODO board_init\r\n"); 26 //poipoiopensim_client_send(0); 26 27 } 27 28 28 29 void board_sleep() { 29 // poipoipoi stub 30 printf("TODO board_sleep\r\n"); 30 //poipoiopensim_client_send(1); 31 31 } 32 32 -
trunk/firmware/openos/bsp/boards/pc/bsp_timer.c
r1839 r1845 22 22 //=========================== public ========================================== 23 23 24 /**25 \brief Initialize this module.26 27 This functions starts the timer, i.e. the counter increments, but doesn't set28 any compare registers, so no interrupt will fire.29 */30 24 void bsp_timer_init() { 31 25 … … 37 31 } 38 32 39 /**40 \brief Register a callback.41 42 \param cb The function to be called when a compare event happens.43 */44 33 void bsp_timer_set_callback(bsp_timer_cbt cb) { 45 34 bsp_timer_vars.cb = cb; 46 35 } 47 36 48 /**49 \brief Reset the timer.50 51 This function does not stop the timer, it rather resets the value of the52 counter, and cancels a possible pending compare event.53 */54 37 void bsp_timer_reset() { 55 38 // poipoipoi stub … … 57 40 } 58 41 59 /**60 \brief Schedule the callback to be called in some specified time.61 62 The delay is expressed relative to the last compare event. It doesn't matter63 how long it took to call this function after the last compare, the timer will64 expire precisely delayTicks after the last one.65 66 The only possible problem is that it took so long to call this function that67 the delay specified is shorter than the time already elapsed since the last68 compare. In that case, this function triggers the interrupt to fire right away.69 70 This means that the interrupt may fire a bit off, but this inaccuracy does not71 propagate to subsequent timers.72 73 \param delayTicks Number of ticks before the timer expired, relative to the74 last compare event.75 */76 42 void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks) { 77 43 // poipoipoi stub … … 79 45 } 80 46 81 /**82 \brief Cancel a running compare.83 */84 47 void bsp_timer_cancel_schedule() { 85 48 // poipoipoi stub -
trunk/firmware/openos/bsp/boards/pc/leds.c
r1839 r1845 6 6 7 7 #include "leds.h" 8 #include "opensim_proto.h" 8 9 9 10 //=========================== defines ========================================= … … 16 17 17 18 void leds_init() { 18 // poipoipoi stub 19 printf("TODO leds_init\r\n"); 19 opensim_requ_leds_init_t requ; 20 opensim_repl_leds_init_t repl; 21 22 // prepare request 23 requ.cmdId = OPENSIM_CMD_leds_init; 24 25 // send request to server and get reply 26 opensim_client_send((void*)&requ, 27 sizeof(opensim_requ_leds_init_t), 28 (void*)&repl, 29 sizeof(opensim_repl_leds_init_t)); 30 31 // make sure server did not return any errors 32 if (repl.rc!=OPENSIM_ERR_NONE) { 33 printf("ERROR rc=%d for leds_init\n",repl.rc); 34 } 20 35 } 21 36 22 37 void leds_error_on() { 23 // poipoipoi stub 24 printf("TODO leds_error_on\r\n"); 38 opensim_requ_leds_error_on_t requ; 39 opensim_repl_leds_error_on_t repl; 40 41 // prepare request 42 requ.cmdId = OPENSIM_CMD_leds_error_on; 43 44 // send request to server and get reply 45 opensim_client_send((void*)&requ, 46 sizeof(opensim_requ_leds_error_on_t), 47 (void*)&repl, 48 sizeof(opensim_repl_leds_error_on_t)); 49 50 // make sure server did not return any errors 51 if (repl.rc!=OPENSIM_ERR_NONE) { 52 printf("ERROR rc=%d for leds_error_on\n",repl.rc); 53 } 25 54 } 26 55 void leds_error_off() { 27 // poipoipoi stub 28 printf("TODO leds_error_off\r\n"); 56 opensim_requ_leds_error_off_t requ; 57 opensim_repl_leds_error_off_t repl; 58 59 // prepare request 60 requ.cmdId = OPENSIM_CMD_leds_error_off; 61 62 // send request to server and get reply 63 opensim_client_send((void*)&requ, 64 sizeof(opensim_requ_leds_error_off_t), 65 (void*)&repl, 66 sizeof(opensim_repl_leds_error_off_t)); 67 68 // make sure server did not return any errors 69 if (repl.rc!=OPENSIM_ERR_NONE) { 70 printf("ERROR rc=%d for leds_error_off\n",repl.rc); 71 } 29 72 } 30 73 void leds_error_toggle() { 31 // poipoipoi stub 32 printf("TODO leds_error_toggle\r\n"); 74 opensim_requ_leds_error_toggle_t requ; 75 opensim_repl_leds_error_toggle_t repl; 76 77 // prepare request 78 requ.cmdId = OPENSIM_CMD_leds_error_toggle; 79 80 // send request to server and get reply 81 opensim_client_send((void*)&requ, 82 sizeof(opensim_requ_leds_error_toggle_t), 83 (void*)&repl, 84 sizeof(opensim_repl_leds_error_toggle_t)); 85 86 // make sure server did not return any errors 87 if (repl.rc!=OPENSIM_ERR_NONE) { 88 printf("ERROR rc=%d for leds_error_toggle\n",repl.rc); 89 } 33 90 } 34 91 uint8_t leds_error_isOn() { 35 // poipoipoi stub 36 printf("TODO leds_error_isOn\r\n"); 92 opensim_requ_leds_error_isOn_t requ; 93 opensim_repl_leds_error_isOn_t repl; 94 95 // prepare request 96 requ.cmdId = OPENSIM_CMD_leds_error_isOn; 97 98 // send request to server and get reply 99 opensim_client_send((void*)&requ, 100 sizeof(opensim_requ_leds_error_isOn_t), 101 (void*)&repl, 102 sizeof(opensim_repl_leds_error_isOn_t)); 103 104 // make sure server did not return any errors 105 if (repl.rc!=OPENSIM_ERR_NONE) { 106 printf("ERROR rc=%d for leds_error_isOn\n",repl.rc); 107 } 37 108 } 38 109 39 110 void leds_radio_on() { 40 // poipoipoi stub 41 printf("TODO leds_radio_on\r\n"); 111 opensim_requ_leds_radio_on_t requ; 112 opensim_repl_leds_radio_on_t repl; 113 114 // prepare request 115 requ.cmdId = OPENSIM_CMD_leds_radio_on; 116 117 // send request to server and get reply 118 opensim_client_send((void*)&requ, 119 sizeof(opensim_requ_leds_radio_on_t), 120 (void*)&repl, 121 sizeof(opensim_repl_leds_radio_on_t)); 122 123 // make sure server did not return any errors 124 if (repl.rc!=OPENSIM_ERR_NONE) { 125 printf("ERROR rc=%d for leds_radio_on\n",repl.rc); 126 } 42 127 } 43 128 void leds_radio_off() { 44 // poipoipoi stub 45 printf("TODO leds_radio_off\r\n"); 129 opensim_requ_leds_radio_off_t requ; 130 opensim_repl_leds_radio_off_t repl; 131 132 // prepare request 133 requ.cmdId = OPENSIM_CMD_leds_radio_off; 134 135 // send request to server and get reply 136 opensim_client_send((void*)&requ, 137 sizeof(opensim_requ_leds_radio_off_t), 138 (void*)&repl, 139 sizeof(opensim_repl_leds_radio_off_t)); 140 141 // make sure server did not return any errors 142 if (repl.rc!=OPENSIM_ERR_NONE) { 143 printf("ERROR rc=%d for leds_radio_off\n",repl.rc); 144 } 46 145 } 47 146 void leds_radio_toggle() { 48 // poipoipoi stub 49 printf("TODO leds_radio_toggle\r\n"); 147 opensim_requ_leds_radio_toggle_t requ; 148 opensim_repl_leds_radio_toggle_t repl; 149 150 // prepare request 151 requ.cmdId = OPENSIM_CMD_leds_radio_toggle; 152 153 // send request to server and get reply 154 opensim_client_send((void*)&requ, 155 sizeof(opensim_requ_leds_radio_toggle_t), 156 (void*)&repl, 157 sizeof(opensim_repl_leds_radio_toggle_t)); 158 159 // make sure server did not return any errors 160 if (repl.rc!=OPENSIM_ERR_NONE) { 161 printf("ERROR rc=%d for leds_radio_toggle\n",repl.rc); 162 } 50 163 } 51 164 uint8_t leds_radio_isOn() { 52 // poipoipoi stub 53 printf("TODO leds_radio_isOn\r\n"); 165 opensim_requ_leds_radio_isOn_t requ; 166 opensim_repl_leds_radio_isOn_t repl; 167 168 // prepare request 169 requ.cmdId = OPENSIM_CMD_leds_radio_isOn; 170 171 // send request to server and get reply 172 opensim_client_send((void*)&requ, 173 sizeof(opensim_requ_leds_radio_isOn_t), 174 (void*)&repl, 175 sizeof(opensim_repl_leds_radio_isOn_t)); 176 177 // make sure server did not return any errors 178 if (repl.rc!=OPENSIM_ERR_NONE) { 179 printf("ERROR rc=%d for leds_radio_isOn\n",repl.rc); 180 } 54 181 } 55 182 56 183 // green 57 184 void leds_sync_on() { 58 // poipoipoi stub 59 printf("TODO leds_sync_on\r\n"); 185 opensim_requ_leds_sync_on_t requ; 186 opensim_repl_leds_sync_on_t repl; 187 188 // prepare request 189 requ.cmdId = OPENSIM_CMD_leds_sync_on; 190 191 // send request to server and get reply 192 opensim_client_send((void*)&requ, 193 sizeof(opensim_requ_leds_sync_on_t), 194 (void*)&repl, 195 sizeof(opensim_repl_leds_sync_on_t)); 196 197 // make sure server did not return any errors 198 if (repl.rc!=OPENSIM_ERR_NONE) { 199 printf("ERROR rc=%d for leds_sync_on\n",repl.rc); 200 } 60 201 } 61 202 void leds_sync_off() { 62 // poipoipoi stub 63 printf("TODO leds_sync_off\r\n"); 203 opensim_requ_leds_sync_off_t requ; 204 opensim_repl_leds_sync_off_t repl; 205 206 // prepare request 207 requ.cmdId = OPENSIM_CMD_leds_sync_off; 208 209 // send request to server and get reply 210 opensim_client_send((void*)&requ, 211 sizeof(opensim_requ_leds_sync_off_t), 212 (void*)&repl, 213 sizeof(opensim_repl_leds_sync_off_t)); 214 215 // make sure server did not return any errors 216 if (repl.rc!=OPENSIM_ERR_NONE) { 217 printf("ERROR rc=%d for leds_sync_off\n",repl.rc); 218 } 64 219 } 65 220 void leds_sync_toggle() { 66 // poipoipoi stub 67 printf("TODO leds_sync_toggle\r\n"); 221 opensim_requ_leds_sync_toggle_t requ; 222 opensim_repl_leds_sync_toggle_t repl; 223 224 // prepare request 225 requ.cmdId = OPENSIM_CMD_leds_sync_toggle; 226 227 // send request to server and get reply 228 opensim_client_send((void*)&requ, 229 sizeof(opensim_requ_leds_sync_toggle_t), 230 (void*)&repl, 231 sizeof(opensim_repl_leds_sync_toggle_t)); 232 233 // make sure server did not return any errors 234 if (repl.rc!=OPENSIM_ERR_NONE) { 235 printf("ERROR rc=%d for leds_sync_toggle\n",repl.rc); 236 } 68 237 } 69 238 uint8_t leds_sync_isOn() { 70 // poipoipoi stub 71 printf("TODO leds_sync_isOn\r\n"); 239 opensim_requ_leds_sync_isOn_t requ; 240 opensim_repl_leds_sync_isOn_t repl; 241 242 // prepare request 243 requ.cmdId = OPENSIM_CMD_leds_sync_isOn; 244 245 // send request to server and get reply 246 opensim_client_send((void*)&requ, 247 sizeof(opensim_requ_leds_sync_isOn_t), 248 (void*)&repl, 249 sizeof(opensim_repl_leds_sync_isOn_t)); 250 251 // make sure server did not return any errors 252 if (repl.rc!=OPENSIM_ERR_NONE) { 253 printf("ERROR rc=%d for leds_sync_isOn\n",repl.rc); 254 } 72 255 } 73 256 74 257 // yellow 75 258 void leds_debug_on() { 76 // poipoipoi stub 77 printf("TODO leds_debug_on\r\n"); 259 opensim_requ_leds_debug_on_t requ; 260 opensim_repl_leds_debug_on_t repl; 261 262 // prepare request 263 requ.cmdId = OPENSIM_CMD_leds_debug_on; 264 265 // send request to server and get reply 266 opensim_client_send((void*)&requ, 267 sizeof(opensim_requ_leds_debug_on_t), 268 (void*)&repl, 269 sizeof(opensim_repl_leds_debug_on_t)); 270 271 // make sure server did not return any errors 272 if (repl.rc!=OPENSIM_ERR_NONE) { 273 printf("ERROR rc=%d for leds_debug_on\n",repl.rc); 274 } 78 275 } 79 276 void leds_debug_off() { 80 // poipoipoi stub 81 printf("TODO leds_debug_off\r\n"); 277 opensim_requ_leds_debug_off_t requ; 278 opensim_repl_leds_debug_off_t repl; 279 280 // prepare request 281 requ.cmdId = OPENSIM_CMD_leds_debug_off; 282 283 // send request to server and get reply 284 opensim_client_send((void*)&requ, 285 sizeof(opensim_requ_leds_debug_off_t), 286 (void*)&repl, 287 sizeof(opensim_repl_leds_debug_off_t)); 288 289 // make sure server did not return any errors 290 if (repl.rc!=OPENSIM_ERR_NONE) { 291 printf("ERROR rc=%d for leds_debug_off\n",repl.rc); 292 } 82 293 } 83 294 void leds_debug_toggle() { 84 // poipoipoi stub 85 printf("TODO leds_debug_toggle\r\n"); 295 opensim_requ_leds_debug_toggle_t requ; 296 opensim_repl_leds_debug_toggle_t repl; 297 298 // prepare request 299 requ.cmdId = OPENSIM_CMD_leds_debug_toggle; 300 301 // send request to server and get reply 302 opensim_client_send((void*)&requ, 303 sizeof(opensim_requ_leds_debug_toggle_t), 304 (void*)&repl, 305 sizeof(opensim_repl_leds_debug_toggle_t)); 306 307 // make sure server did not return any errors 308 if (repl.rc!=OPENSIM_ERR_NONE) { 309 printf("ERROR rc=%d for leds_debug_toggle\n",repl.rc); 310 } 86 311 } 87 312 uint8_t leds_debug_isOn() { 88 // poipoipoi stub 89 printf("TODO leds_debug_isOn\r\n"); 313 opensim_requ_leds_debug_isOn_t requ; 314 opensim_repl_leds_debug_isOn_t repl; 315 316 // prepare request 317 requ.cmdId = OPENSIM_CMD_leds_debug_isOn; 318 319 // send request to server and get reply 320 opensim_client_send((void*)&requ, 321 sizeof(opensim_requ_leds_debug_isOn_t), 322 (void*)&repl, 323 sizeof(opensim_repl_leds_debug_isOn_t)); 324 325 // make sure server did not return any errors 326 if (repl.rc!=OPENSIM_ERR_NONE) { 327 printf("ERROR rc=%d for leds_debug_isOn\n",repl.rc); 328 } 90 329 } 91 330 92 331 void leds_all_on() { 93 // poipoipoi stub 94 printf("TODO leds_all_on\r\n"); 332 opensim_requ_leds_all_on_t requ; 333 opensim_repl_leds_all_on_t repl; 334 335 // prepare request 336 requ.cmdId = OPENSIM_CMD_leds_all_on; 337 338 // send request to server and get reply 339 opensim_client_send((void*)&requ, 340 sizeof(opensim_requ_leds_all_on_t), 341 (void*)&repl, 342 sizeof(opensim_repl_leds_all_on_t)); 343 344 // make sure server did not return any errors 345 if (repl.rc!=OPENSIM_ERR_NONE) { 346 printf("ERROR rc=%d for leds_all_on\n",repl.rc); 347 } 95 348 } 96 349 void leds_all_off() { 97 // poipoipoi stub 98 printf("TODO leds_all_off\r\n"); 350 opensim_requ_leds_all_off_t requ; 351 opensim_repl_leds_all_off_t repl; 352 353 // prepare request 354 requ.cmdId = OPENSIM_CMD_leds_all_off; 355 356 // send request to server and get reply 357 opensim_client_send((void*)&requ, 358 sizeof(opensim_requ_leds_all_off_t), 359 (void*)&repl, 360 sizeof(opensim_repl_leds_all_off_t)); 361 362 // make sure server did not return any errors 363 if (repl.rc!=OPENSIM_ERR_NONE) { 364 printf("ERROR rc=%d for leds_all_off\n",repl.rc); 365 } 99 366 } 100 367 void leds_all_toggle() { 101 // poipoipoi stub 102 printf("TODO leds_all_toggle\r\n"); 368 opensim_requ_leds_all_toggle_t requ; 369 opensim_repl_leds_all_toggle_t repl; 370 371 // prepare request 372 requ.cmdId = OPENSIM_CMD_leds_all_toggle; 373 374 // send request to server and get reply 375 opensim_client_send((void*)&requ, 376 sizeof(opensim_requ_leds_all_toggle_t), 377 (void*)&repl, 378 sizeof(opensim_repl_leds_all_toggle_t)); 379 380 // make sure server did not return any errors 381 if (repl.rc!=OPENSIM_ERR_NONE) { 382 printf("ERROR rc=%d for leds_all_toggle\n",repl.rc); 383 } 103 384 } 104 385 105 386 void leds_circular_shift() { 106 // poipoipoi stub 107 printf("TODO leds_circular_shift\r\n"); 387 opensim_requ_leds_circular_shift_t requ; 388 opensim_repl_leds_circular_shift_t repl; 389 390 // prepare request 391 requ.cmdId = OPENSIM_CMD_leds_circular_shift; 392 393 // send request to server and get reply 394 opensim_client_send((void*)&requ, 395 sizeof(opensim_requ_leds_circular_shift_t), 396 (void*)&repl, 397 sizeof(opensim_repl_leds_circular_shift_t)); 398 399 // make sure server did not return any errors 400 if (repl.rc!=OPENSIM_ERR_NONE) { 401 printf("ERROR rc=%d for leds_circular_shift\n",repl.rc); 402 } 108 403 } 109 404 110 405 void leds_increment() { 111 // poipoipoi stub 112 printf("TODO leds_increment\r\n"); 406 opensim_requ_leds_increment_t requ; 407 opensim_repl_leds_increment_t repl; 408 409 // prepare request 410 requ.cmdId = OPENSIM_CMD_leds_increment; 411 412 // send request to server and get reply 413 opensim_client_send((void*)&requ, 414 sizeof(opensim_requ_leds_increment_t), 415 (void*)&repl, 416 sizeof(opensim_repl_leds_increment_t)); 417 418 // make sure server did not return any errors 419 if (repl.rc!=OPENSIM_ERR_NONE) { 420 printf("ERROR rc=%d for leds_increment\n",repl.rc); 421 } 113 422 } 114 423 -
trunk/firmware/openos/bsp/boards/pc/opensim_client.c
r1842 r1845 1 1 /** 2 \brief Client program to the OpenSim engine2 \brief Client program to the OpenSim server. 3 3 4 4 \author Thomas Watteyne <watteyne@eecs.berkeley.edu>, April 2012. … … 10 10 #include <string.h> 11 11 #include "tcp_port.h" 12 #include "opensim_client.h" 12 13 13 #define DEFAULT_SERVER_NAME "localhost" 14 #define DEFAULT_SERVER_PORT 14159 14 //=========================== variables ======================================= 15 15 16 void Usage(char* progname) { 17 fprintf(stderr,"Usage: %s -n [server_address name/IP address] -p [port_num] -l [iterations]\n", progname); 18 fprintf(stderr,"Where:\n\tprotocol is one of TCP or UDP\n"); 19 fprintf(stderr,"\t- server_address is the IP address or name of server_address\n"); 20 fprintf(stderr,"\t- port_num is the port to listen on\n"); 21 WSACleanup(); 22 exit(1); 23 } 16 typedef struct { 17 char txBuffer[OPENCLIENT_BUFSIZE]; 18 char rxBuffer[OPENCLIENT_BUFSIZE]; 19 SOCKET conn_socket; 20 } opensim_client_vars_t; 21 22 opensim_client_vars_t opensim_client_vars; 23 24 //=========================== prototypes ====================================== 25 26 void printUsage(char* progname); 27 28 //=========================== main ============================================ 24 29 25 30 int main(int argc, char **argv) { 26 char Buffer[12];27 31 unsigned short server_port; 28 32 char* server_name; … … 31 35 int loopcount; 32 36 int numloops; 33 SOCKET conn_socket;34 37 int retval; 35 38 … … 53 56 break; 54 57 default: 55 Usage(argv[0]);58 printUsage(argv[0]); 56 59 break; 57 60 } 58 61 } else { 59 Usage(argv[0]);62 printUsage(argv[0]); 60 63 } 61 64 } … … 63 66 64 67 // connect to the server 65 conn_socket = tcp_port_connect(server_name, server_port);68 opensim_client_vars.conn_socket = tcp_port_connect(server_name, server_port); 66 69 67 // send some data68 while( numloops>0) {70 // wait for command from the server 71 while(1) { 69 72 70 // send to server 71 wsprintf(Buffer,"poipoipoipoi"); 72 retval = send(conn_socket, Buffer, sizeof(Buffer), 0); 73 if (retval == SOCKET_ERROR) { 74 fprintf(stderr,"ERROR: send() failed (error=%d)\n", WSAGetLastError()); 75 WSACleanup(); 76 return -1; 77 } 78 printf("poipoi sent"); 79 80 // receive from server 81 retval = recv(conn_socket, Buffer, sizeof(Buffer), 0); 73 // receive command from server 74 retval = recv(opensim_client_vars.conn_socket, 75 opensim_client_vars.rxBuffer, 76 sizeof(opensim_client_vars.rxBuffer), 77 0); 82 78 if (retval==SOCKET_ERROR) { 83 79 fprintf(stderr,"ERROR: recv() failed (error=%d)\n", WSAGetLastError()); 84 closesocket( conn_socket);80 closesocket(opensim_client_vars.conn_socket); 85 81 WSACleanup(); 86 82 return -1; … … 88 84 if (retval == 0) { 89 85 printf("WARNING: server closed connection.\n"); 90 closesocket( conn_socket);86 closesocket(opensim_client_vars.conn_socket); 91 87 WSACleanup(); 92 88 return -1; 93 89 } 94 printf("INFO: Received %d bytes, data \"%s\" from server_address.\n", retval, Buffer); 95 96 // decrement number of loops 97 numloops--; 90 printf("INFO: Received %d bytes, data \"%s\"\n", 91 retval, 92 opensim_client_vars.rxBuffer); 93 94 mote_main(); 98 95 } 99 96 100 closesocket( conn_socket);97 closesocket(opensim_client_vars.conn_socket); 101 98 WSACleanup(); 102 99 return 0; 103 100 } 101 102 //=========================== public ========================================== 103 104 int opensim_client_send(int* pTxData, 105 int txDataLength, 106 int* pRxBuffer, 107 int maxRxBufferLength) { 108 int retval; 109 110 // send command to OpenSim server 111 retval = send(opensim_client_vars.conn_socket, 112 pTxData, 113 txDataLength, 114 0); 115 if (retval == SOCKET_ERROR) { 116 fprintf(stderr,"ERROR: send() failed (error=%d)\n", WSAGetLastError()); 117 WSACleanup(); 118 exit(1); 119 } 120 printf("command sent\r\n"); 121 122 // wait for reply 123 retval = recv(opensim_client_vars.conn_socket, 124 opensim_client_vars.rxBuffer, 125 sizeof(opensim_client_vars.rxBuffer), 126 0); 127 if (retval==SOCKET_ERROR) { 128 fprintf(stderr,"FATAL: recv failed (error=%d)\n", WSAGetLastError()); 129 closesocket(opensim_client_vars.conn_socket); 130 WSACleanup(); 131 exit(1); 132 } 133 if (retval==0) { 134 fprintf(stderr,"FATAL: server closed connection.\n"); 135 closesocket(opensim_client_vars.conn_socket); 136 WSACleanup(); 137 exit(1); 138 } 139 if (retval>maxRxBufferLength) { 140 fprintf(stderr,"FATAL: expected at most %d bytes, got %d.\n",maxRxBufferLength,retval); 141 closesocket(opensim_client_vars.conn_socket); 142 WSACleanup(); 143 exit(1); 144 } 145 146 // copy reply in pRxBuffer 147 memcpy(pRxBuffer,opensim_client_vars.rxBuffer,retval); 148 149 printf("INFO: received %d bytes\n",retval); 150 printf("ack received\r\n"); 151 return 0; 152 } 153 154 //=========================== private ========================================= 155 156 void printUsage(char* progname) { 157 fprintf(stderr,"printUsage: %s -n [server_address name/IP address] -p [port_num] -l [iterations]\n", progname); 158 fprintf(stderr,"Where:\n\tprotocol is one of TCP or UDP\n"); 159 fprintf(stderr,"\t- server_address is the IP address or name of server_address\n"); 160 fprintf(stderr,"\t- port_num is the port to listen on\n"); 161 WSACleanup(); 162 exit(1); 163 } -
trunk/firmware/openos/projects/common/01bsp_leds/SConscript
r1832 r1845 15 15 library_files = [ 16 16 'libbsppc.lib', 17 'ws2_32.lib', 18 'user32.lib', 17 19 ] 18 20 source_files = ['01bsp_leds.c', 21 os.path.join('#','firmware','openos','bsp','boards','pc','opensim_client.c'), 22 os.path.join('#','firmware','openos','bsp','boards','pc','tcp_port.c'), 19 23 ] 20 24 -
trunk/software/opensim/SimEngine/MoteHandler.py
r1843 r1845 5 5 import logging 6 6 import os 7 import time 7 8 8 9 TCPRXBUFSIZE = 4096 # size of the TCP reception buffer … … 47 48 self.log.info('starting') 48 49 50 self.conn.send('poipoi') 51 49 52 while(1): 50 53 try: … … 54 57 else: 55 58 self.log.info('received input='+str(input)) 56 self.conn.send('poipoipoipoi') 59 60 print len(input) 61 62 time.sleep(1) 63 64 self.conn.send(chr(0)) 57 65 58 66 #======================== private =========================================
Note: See TracChangeset
for help on using the changeset viewer.
