Exemple #1
0
int carmen_logfile_read_next_line(carmen_logfile_index_p index, carmen_FILE *infile,
				  int max_line_length, char *line)
{
  return carmen_logfile_read_line(index, infile, 
				  index->current_position, 
				  max_line_length, line);
}
bool LogFile::load(const char* filename, bool verbose) {
  char line[100000];

  carmen_FILE *logfile = NULL;
  carmen_logfile_index_p logfile_index = NULL;

  logfile = carmen_fopen(filename, "r");
  if(logfile == NULL) {
    if (verbose)
      carmen_warn("Error: could not open file %s for reading.\n", filename);
    return false;
  }

  /* index the logfile */
  logfile_index = carmen_logfile_index_messages(logfile);

  for(int i = 0; i < logfile_index->num_messages; i++) {
    
    /* read i-th line */
    carmen_logfile_read_line(logfile_index, logfile, i, 100000, line);

    /* create messages */
    if(strncmp(line, "ODOM ", 5) == 0) {
      push_back(new OdometryMessage(line));
    }
    else if(strncmp(line, "RAWLASER", 8) == 0) {
      push_back(new LaserMessage(line));
    }
    else if(strncmp(line, "ROBOTLASER", 10) == 0) {
      push_back(new RobotLaserMessage(line));
    }
    else if(strncmp(line, "FLASER ", 7) == 0) {
      push_back(new RobotLaserMessage(line));
    }
    else if(strncmp(line, "RLASER ", 7) == 0) {
      push_back(new RobotLaserMessage(line));
    }
    else if(strncmp(line, "TRUEPOS ", 8) == 0) {
      push_back(new TrueposMessage(line));
    }
    else if(strncmp(line, "IMU ", 4) == 0) {
      push_back(new IMUMessage(line));
    }
    else if(strncmp(line, "SCANMARK ", 9) == 0) {
      push_back(new ScanmarkMessage(line));
    }
    else if(strncmp(line, "POSITIONLASER ", 14) == 0) {
      push_back(new LaserposMessage(line));
    }
    else if(strlen(line) > 1) {
      push_back(new UnknownMessage(line));
    }
  }
  carmen_fclose(logfile);  
  return true;
}
Exemple #3
0
int read_message(int message_num, int publish, int no_wait)
{
	//  char *line[MAX_LINE_LENGTH];
	char *line;
	char *current_pos;
	int i, j;
	char command[100];
	static double last_update = 0;
	double current_time;

	line = (char *) malloc(MAX_LINE_LENGTH * sizeof(char));
	if (line == NULL)
		carmen_die("Could not alloc memory in playback.c:read_message()\n");

	carmen_logfile_read_line(logfile_index, logfile, message_num,
			MAX_LINE_LENGTH, line);
	current_pos = carmen_next_word(line);

	for(i = 0; i < (int)(sizeof(logger_callbacks) /
			sizeof(logger_callback_t)); i++) {
		/* copy the command over */
		j = 0;
		while(line[j] != ' ') {
			command[j] = line[j];
			j++;
		}
		command[j] = '\0';
		if(strncmp(command, logger_callbacks[i].logger_message_name, j) == 0) {
			if(!basic_messages || !logger_callbacks[i].interpreted) {
				current_pos =
					logger_callbacks[i].conv_func(current_pos,
							logger_callbacks[i].message_data);
				playback_timestamp = atof(current_pos);
				//printf("command = %s, playback_timestamp = %lf\n", command, playback_timestamp);
				if(publish) {
					current_time = carmen_get_time();
					if(current_time - last_update > 0.2) {
						print_playback_status();
						last_update = current_time;
					}
					if (!no_wait)
						wait_for_timestamp(playback_timestamp);
					IPC_publishData(logger_callbacks[i].ipc_message_name,
							logger_callbacks[i].message_data);
				}
				/* return 1 if it is a front laser message */
				free(line);
				return (strcmp(command, "FLASER") == 0);
			}
		}
	}

	free(line);
	return 0;
}