22 int ret = sscanf(line+*cur,
" %lf %n", d, &inc);
24 sm_error(
"Could not read double at %p + %d '%s'. ret: %d.\n", line, *cur, line+*cur, ret);
34 if(1 != sscanf(line+*cur,
" %d %n", d, &inc)) {
44 int from = *cur;
while(isspace(line[from])) from++;
45 size_t len = 0;
while(!isspace(line[from+len])) len++;
46 if(len > buf_len ) len = buf_len;
47 strncpy(buf, line+from, len);
55 sm_error(
"This is not a Carmen line: \n-> %s\n", line);
64 sm_error(
"Could not get number of rays.\n");
72 double min_reading = 0;
73 double max_reading = 80;
81 if(!print) { print = 1;
82 sm_info(
"Assuming that 769 rays is an Hokuyo " 83 "with fov = %f deg, min_reading = %f m, max_reading = %fm\n",
84 rad2deg(fov), min_reading, max_reading);
93 for(i=0;i<nrays;i++) {
96 sm_error(
"Could not read ray #%d / %d, \n", i, nrays);
101 ld->
valid[i] = (reading > min_reading) && (reading < max_reading);
116 if(on_error)
goto error;
132 static int warn_format = 1;
134 int inc;
int sec=-1, usec=-1;
135 int res = sscanf(line + cur,
"%d %s %d%n", &sec, ld->
hostname, &usec, &inc);
138 ld->
tv.tv_usec = usec;
140 sm_info(
"Reading timestamp as 'sec hostname usec'.\n");
143 res = sscanf(line + cur,
"%lf %s %lf%n", &v1, ld->
hostname, &v2, &inc);
145 ld->
tv.tv_sec = (int) floor(v1);
146 ld->
tv.tv_usec = floor( (v1 - floor(v1)) * 1e6 );
149 sm_info(
"Reading timestamp as doubles (discarding second one).\n");
155 sm_info(
"I could not read timestamp+hostname; ignoring (I will warn only once for this).\n");
161 fprintf(stderr,
"l");
165 printf(
"Malformed line: '%s'\nat cur = %d\n\t-> '%s'\n", line,(
int)cur,line+cur);
172 #define MAX_LINE_LENGTH 10000 177 sm_debug(
"Skipping line: \n-> %s\n", line);
183 printf(
"Malformed line? \n-> '%s'", line);
197 sm_error(
"Writing bad data to the stream.\n");
199 fprintf(stream,
"FLASER %d ", ld->
nrays);
200 for(i=0; i<ld->
nrays; i++){
201 fprintf(stream,
"%g ", ld->
readings[i]);
206 timestamp = ld->
tv.tv_sec + ((double)ld->
tv.tv_sec)/1e6;
208 fprintf(stream,
"%g %s %g", timestamp, ld->
hostname, timestamp);
214 if(!strncmp(out_format,
"carmen", 6))
void ld_write_as_json(LDP ld, FILE *stream)
void ld_write_format(LDP ld, FILE *f, const char *out_format)
int read_next_string(const char *line, size_t *cur, char *buf, size_t buf_len)
LDP ld_from_carmen_string(const char *line)
int ld_valid_fields(LDP ld)
int read_next_integer(const char *line, size_t *cur, int *d)
double *restrict readings
int read_next_double(const char *line, size_t *cur, double *d)
void ld_write_as_carmen(LDP ld, FILE *stream)
void sm_debug(const char *msg,...)
void sm_info(const char *msg,...)
LDP ld_alloc_new(int nrays)
const char * carmen_prefix
void sm_error(const char *msg,...)
int ld_read_next_laser_carmen(FILE *file, LDP *ld)
double rad2deg(double rad)