From 04fb190243442e83349f129b523ab747e58100bf Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Sat, 05 Apr 2008 11:17:33 +0000 Subject: Initial commit into public repository Signed-off-by: Michael Krelin --- (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..579d0cc --- a/dev/null +++ b/test/.gitignore @@ -0,0 +1,4 @@ +/sleeptracker-decode +/sleeptracker-decode.o +/.libs +/.deps diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..09c3ed7 --- a/dev/null +++ b/test/Makefile.am @@ -0,0 +1,7 @@ +noinst_PROGRAMS = sleeptracker-decode + +INCLUDES = -I${top_srcdir}/include/ ${MODULES_CFLAGS} +LIBS = ${top_builddir}/lib/libnapkin.la + +sleeptracker_decode_SOURCES = sleeptracker-decode.cc +sleeptracker_decode_DEPENDENCIES = ${LIBS} diff --git a/test/sleeptracker-decode.cc b/test/sleeptracker-decode.cc new file mode 100644 index 0000000..77d4fbd --- a/dev/null +++ b/test/sleeptracker-decode.cc @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#include + +string str_f_time(const char *fmt,time_t t) { + struct tm tt; + localtime_r(&t,&tt); + char rv[1024]; + strftime(rv,sizeof(rv),fmt,&tt); + return rv; +} + +ostream& operator<<(ostream& o,const napkin::hypnodata_t& hd) { + o + << "Window is " << hd.window << endl + << "'To bed' time is " << str_f_time("%Y-%m-%d %H:%M",hd.to_bed) << endl + << "Alarm time is " << str_f_time("%Y-%m-%d %H:%M",hd.alarm) << endl + << "Data A is " << hd.data_a/60 << ":" << hd.data_a%60 << endl; + for(vector::const_iterator i=hd.almost_awakes.begin();i!=hd.almost_awakes.end();++i) + o << " almost awake at " << str_f_time("%Y-%m-%d %H:%M:%S",*i) << endl; + return o; +} + +int main(int/*argc*/,char **argv) { + try { + int fd = open(argv[1],O_RDONLY); + if(fd<0) + throw runtime_error("failed to open() data"); + unsigned char buffer[1024]; + int rb = read(fd,buffer,sizeof(buffer)); + if(!(rb>0)) + throw runtime_error("failed to read() data"); + close(fd); + + napkin::hypnodata_t hd; + cout << napkin::sleeptracker::decode(hd,buffer,rb); + }catch(exception& e) { + cerr << "oops: " << e.what() << endl; + } +} + -- cgit v0.9.0.2