Author: hummen Date: Thu Oct 8 18:50:08 2009 New Revision: 1066 Log: added msleep as I didn't find a package (debian) for high precision sleep...once again Added: trunk/tools/Makefile.am trunk/tools/msleep.c Modified: trunk/Makefile.am trunk/configure.ac Modified: trunk/Makefile.am ============================================================================== --- trunk/Makefile.am Thu Oct 8 18:39:11 2009 (r1065) +++ trunk/Makefile.am Thu Oct 8 18:50:08 2009 (r1066) @@ -13,7 +13,7 @@ EXTRA_DIST += tools/writeff.pl tools/tunnel/screamer.rb EXTRA_DIST += tools/tunnel/seteth1address -SUBDIRS = libpisa pairing performance pisacd pisand pisasd test pisabeacon +SUBDIRS = libpisa pairing performance pisacd pisand pisasd test pisabeacon tools SUBDIRS += community-operator # has to be enabled for compilation on openwrt pisaincludedir=$(includedir) Modified: trunk/configure.ac ============================================================================== --- trunk/configure.ac Thu Oct 8 18:39:11 2009 (r1065) +++ trunk/configure.ac Thu Oct 8 18:50:08 2009 (r1066) @@ -184,6 +184,8 @@ AC_SUBST(PISA_PISASD_INCLUDES, "$PISA_PISASD") AC_SUBST(PISA_PISABEACON, "$TOPSRC/pisabeacon") AC_SUBST(PISA_PISABEACON_INCLUDES, "$PISA_PISABEACON") +AC_SUBST(PISA_TOOLS, "$TOPSRC/tools") +AC_SUBST(PISA_TOOLS_INCLUDES, "$PISA_TOOLS") @@ -216,6 +218,7 @@ test/Makefile community-operator/Makefile performance/Makefile + tools/Makefile Makefile]) AC_OUTPUT Added: trunk/tools/Makefile.am ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tools/Makefile.am Thu Oct 8 18:50:08 2009 (r1066) @@ -0,0 +1,19 @@ +# Copyright (c) 2008, Distributed Systems Group, RWTH Aachen +# All rights reserved. +# +# Author: Rene Hummen <hummen@xxxxxxxxxxxxxxxxx> + +AUTOMAKE_OPTIONS = foreign + +CFLAGS = -Wall -g +INCLUDES = -I$(PISA_COMMON_INCLUDES) + +sbin_PROGRAMS = msleep + +pisalsddir = . + +LDADD = +LDFLAGS = @LDFLAGS@ + +LDADD += -lm +msleep_SOURCES = msleep.c Added: trunk/tools/msleep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tools/msleep.c Thu Oct 8 18:50:08 2009 (r1066) @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2009, Distributed Systems Group, RWTH Aachen + * All rights reserved. + */ + +/** + * @file usleep.c + * @brief Provides similar functionality to sleep with higher precision. + * @author Ren� Hummen <hummen@xxxxxxxxxxxxxxxxx> + * @date 08.10.2009 + */ + +#include <ctype.h> /* isprint() */ +#include <stdio.h> /* printf(), ... */ +#include <stdlib.h> /* atoi() */ +#include <getopt.h> /* command line parsing */ +#include <unistd.h> /* usleep */ + +#define DEFAULT_MSECS 100000 +#define USEC_TO_MSEC 1000 + +useconds_t get_msecs_from_args(const int argc, char *argv[]); + + +int main(int argc, char *argv[]) +{ + useconds_t msecs = 0; + + msecs = get_msecs_from_args(argc, argv); + + if (usleep(msecs)) + printf("failed to msleep\n"); + + exit(0); +} + +useconds_t get_msecs_from_args(const int argc, char *argv[]) +{ + int c = 0; + useconds_t msecs = DEFAULT_MSECS; + + while ((c = getopt(argc, argv, "hi:")) != -1) + { + switch (c) + { + case 'h': + printf("usage: \tusleep [-i <uint> ms]\n"); + exit(0); + case 'i': + msecs = atoi(optarg) * USEC_TO_MSEC; + break; + case '?': + if (optopt == 'i') + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); + exit(1); + default: + break; + } + } + + return msecs; +}