Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lcm-logger: Fix -l option #465

Merged
merged 3 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lcm-logger/glib_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ int signal_pipe_attach_glib(signal_pipe_glib_handler_t func, gpointer user_data)
return -1;

g_sp.ioc = g_io_channel_unix_new(g_sp.fds[0]);
g_io_channel_set_flags(
g_sp.ioc, (GIOFlags) (g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL);
g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition) (G_IO_IN | G_IO_PRI),
g_io_channel_set_flags(g_sp.ioc,
(GIOFlags)(g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL);
g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition)(G_IO_IN | G_IO_PRI),
(GIOFunc) signal_handler_glib, NULL);

g_sp.userfunc = func;
Expand Down
45 changes: 26 additions & 19 deletions lcm-logger/lcm_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,83 +424,90 @@ int main(int argc, char *argv[])
logger.append = 0;

char *lcmurl = NULL;
char *optstring = "fic:shm:vu:qa";
int c;

// Arg Parsing:
// https://www.gnu.org/software/libc/manual/html_node/Getopt.html
char *optstring = "ac:fhil:m:qsu:v";

// Keep sorted based on the 4th (`val`) arg which needs to be a unique character (int) per
// option.
// If a short option is desired, it must be placed above in the optstring.
struct option long_opts[] = {
{"append", no_argument, 0, 'a'},
{"split-mb", required_argument, 0, 'b'},
{"channel", required_argument, 0, 'c'},
{"force", no_argument, 0, 'f'},
{"increment", required_argument, 0, 'i'},
{"lcm-url", required_argument, 0, 'l'},
{"max-unwritten-mb", required_argument, 0, 'm'},
{"quiet", no_argument, 0, 'q'},
{"rotate", required_argument, 0, 'r'},
{"strftime", required_argument, 0, 's'},
{"quiet", no_argument, 0, 'q'},
{"append", no_argument, 0, 'a'},
{"invert-channels", no_argument, 0, 'v'},
{"flush-interval", required_argument, 0, 'u'},
{"invert-channels", no_argument, 0, 'v'},
{0, 0, 0, 0},
};

int c;
while ((c = getopt_long(argc, argv, optstring, long_opts, 0)) >= 0) {
switch (c) {
case 'b':
case 'b': /* --split-mb */
logger.auto_split_mb = strtod(optarg, NULL);
if (logger.auto_split_mb <= 0) {
usage();
return 1;
}
break;
case 'f':
case 'f': /* force */
logger.force_overwrite = 1;
break;
case 'c':
case 'c': /* --channel */
free(chan_regex);
chan_regex = strdup(optarg);
break;
case 'i':
case 'i': /* --increment */
logger.auto_increment = 1;
break;
case 's':
case 's': /* strftime */
logger.use_strftime = 1;
break;
case 'l':
case 'l': /* --lcm-url */
free(lcmurl);
lcmurl = strdup(optarg);
break;
case 'q':
case 'q': /* quiet */
logger.quiet = 1;
break;
case 'v':
case 'v': /* --invert-channels */
logger.invert_channels = 1;
break;
case 'm':
case 'm': /* --invert-channels */
max_write_queue_size_mb = strtod(optarg, NULL);
if (max_write_queue_size_mb <= 0) {
usage();
return 1;
}
break;
case 'r': {
case 'r': { /* --rotate */
char *eptr = NULL;
logger.rotate = strtol(optarg, &eptr, 10);
if (*eptr) {
usage();
return 1;
}
} break;
case 'u':
case 'u': /* --flush-interval */
logger.fflush_interval_ms = atol(optarg);
if (logger.fflush_interval_ms <= 0) {
usage();
return 1;
}
break;
case 'a':
case 'a': /* --append */
logger.append = 1;
break;
case 'h':
default:
default: /* implicit --help */
usage();
return 1;
};
Expand Down Expand Up @@ -530,7 +537,7 @@ int main(int argc, char *argv[])
}

logger.time0 = g_get_real_time();
logger.max_write_queue_size = (int64_t) (max_write_queue_size_mb * (1 << 20));
logger.max_write_queue_size = (int64_t)(max_write_queue_size_mb * (1 << 20));

if (0 != open_logfile(&logger))
return 1;
Expand Down
2 changes: 1 addition & 1 deletion lcm/eventlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int lcm_eventlog_seek_to_timestamp(lcm_eventlog_t *l, int64_t timestamp)

while (1) {
frac = 0.5 * (frac1 + frac2);
off_t offset = (off_t) (frac * file_len);
off_t offset = (off_t)(frac * file_len);
fseeko(l->f, offset, SEEK_SET);
cur_time = get_event_time(l);
if (cur_time < 0)
Expand Down
2 changes: 1 addition & 1 deletion lcm/ioutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static inline int fread64(FILE *f, int64_t *v64)
// See Section 5.8 paragraph 3 of the standard
// http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf
// use uint for shifting instead if int
*v64 = (int64_t) (((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff);
*v64 = (int64_t)(((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions liblcm-test/lcm-logfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ int main(int argc, char **argv)
double start_time = strtod(optarg, &eptr);
if (*eptr != 0)
usage();
start_utime = (int64_t) (start_time * 1000000);
start_utime = (int64_t)(start_time * 1000000);
} break;
case 'e': {
char *eptr = NULL;
double end_time = strtod(optarg, &eptr);
if (*eptr != 0)
usage();
end_utime = (int64_t) (end_time * 1000000);
end_utime = (int64_t)(end_time * 1000000);
have_end_utime = 1;
} break;
case 'i':
Expand Down
4 changes: 2 additions & 2 deletions test/c/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int check_lcmtest_primitives_list_t(const lcmtest_primitives_list_t *msg, int ex
const lcmtest_primitives_t *ex = &msg->items[n];
CHECK_FIELD(ex->i8, -(n % 100), "%d");
CHECK_FIELD(ex->i16, -n * 10, "%d");
CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64);
CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64);
CHECK_FIELD(ex->position[0], (double) -n, "%f");
CHECK_FIELD(ex->position[1], (double) -n, "%f");
CHECK_FIELD(ex->position[2], (double) -n, "%f");
Expand Down Expand Up @@ -269,7 +269,7 @@ int check_lcmtest_primitives_t(const lcmtest_primitives_t *msg, int expected)
int n = expected;
CHECK_FIELD(msg->i8, n % 100, "%d");
CHECK_FIELD(msg->i16, n * 10, "%d");
CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64);
CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64);
CHECK_FIELD(msg->position[0], (double) n, "%f");
CHECK_FIELD(msg->position[1], (double) n, "%f");
CHECK_FIELD(msg->position[2], (double) n, "%f");
Expand Down
4 changes: 2 additions & 2 deletions test/cpp/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int CheckLcmType(const lcmtest::primitives_list_t *msg, int expected)
const lcmtest::primitives_t *ex = &msg->items[n];
CHECK_FIELD(ex->i8, -(n % 100), "%d");
CHECK_FIELD(ex->i16, -n * 10, "%d");
CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64);
CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64);
CHECK_FIELD(ex->position[0], (double) -n, "%f");
CHECK_FIELD(ex->position[1], (double) -n, "%f");
CHECK_FIELD(ex->position[2], (double) -n, "%f");
Expand Down Expand Up @@ -246,7 +246,7 @@ int CheckLcmType(const lcmtest::primitives_t *msg, int expected)
int n = expected;
CHECK_FIELD(msg->i8, n % 100, "%d");
CHECK_FIELD(msg->i16, n * 10, "%d");
CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64);
CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64);
CHECK_FIELD(msg->position[0], (double) n, "%f");
CHECK_FIELD(msg->position[1], (double) n, "%f");
CHECK_FIELD(msg->position[2], (double) n, "%f");
Expand Down
Loading