Project

General

Profile

Revision 412

only using sleep when not on robot

View differences:

trunk/code/projects/libwireless/lib/xbee.c
203 203
	#ifdef ROBOT
204 204

  
205 205
	//enable the receiving interrupt
206
	#ifdef FIREFLY
206
#ifdef FIREFLY
207 207
	UCSR0B |= _BV(RXCIE) | _BV(RXEN);
208
	#else
208
#else
209 209
	UCSR1B |= _BV(RXCIE);
210
	#endif
210
#endif
211 211
	sei();
212
	#else
212
#else
213 213
	printf("Connecting to port %s.\n", xbee_com_port);
214 214
	xbee_stream = open(xbee_com_port, O_RDWR);
215 215
	if (xbee_stream == -1/* || lockf(xbee_stream, F_TEST, 0) != 0*/)
......
256 256
		fprintf(stderr, "Failed to create listener thread.\r\n");
257 257
		return -1;
258 258
	}
259
#endif
259 260

  
260
	#endif
261 261
	xbee_enter_command_mode();
262 262
	xbee_enter_api_mode();
263 263
	xbee_exit_command_mode();
......
266 266
	//wait to return until the address is set
267 267
	while (xbee_address == 0) xbee_get_packet(NULL);
268 268

  
269

  
270 269
	return 0;
271 270
}
272 271

  
......
390 389
 **/
391 390
static void xbee_wait_for_string(char* s, int len)
392 391
{
393
  char* curr = s;
394
  while (curr - s < len) {
395
    // check if buffer is empty
396
    if (buffer_last != buffer_first) {
397
      char c = arrival_buf[buffer_first++];
398
      if (buffer_first == XBEE_BUFFER_SIZE) {
399
	buffer_first = 0;
400
      }
392
	char* curr = s;
393
	while (curr - s < len) {
394
		// check if buffer is empty
395
		if (buffer_last != buffer_first) {
396
			char c = arrival_buf[buffer_first++];
397
			if (buffer_first == XBEE_BUFFER_SIZE) {
398
				buffer_first = 0;
399
			}
401 400

  
402
      if (c == *curr) {
403
	curr++;
404
      } else {
405
	curr = s;
406
      }
407
    }
401
			if (c == *curr) {
402
				curr++;
403
			} else {
404
				curr = s;
405
			}
406
		}
408 407

  
409
    usleep(1000);
410
  }
408
#ifndef ROBOT
409
		usleep(1000);
410
#endif
411
	}
411 412
}
412 413

  
413 414
/**

Also available in: Unified diff