From 684b109e8cd3246c93fdec3e63157bbd11bb359a Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sat, 3 Dec 2016 18:02:20 -0500 Subject: first stab at trying to pull off config data, didn't work. --- src/survive.c | 63 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 16 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index 223cd57..3712537 100644 --- a/src/survive.c +++ b/src/survive.c @@ -6,36 +6,44 @@ #include #include #include +#include + struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, const char * fault ), void(*notefunction)( struct SurviveContext * ctx, const char * note ) ) { int r = 0; - struct SurviveContext * ret = calloc( 1, sizeof( struct SurviveContext ) ); - - ret->headset.sensors = 32; - ret->headset.ctx = ret; - memcpy( ret->headset.codename, "HED", 4 ); + struct SurviveContext * ctx = calloc( 1, sizeof( struct SurviveContext ) ); - ret->watchman[0].sensors = 16; - ret->watchman[0].ctx = ret; - memcpy( ret->watchman[0].codename, "CT0", 4 ); + ctx->faultfunction = ff; + ctx->notefunction = notefunction; - ret->watchman[1].sensors = 16; - ret->watchman[1].ctx = ret; - memcpy( ret->watchman[1].codename, "CT1", 4 ); + ctx->headset.sensors = 32; + ctx->headset.ctx = ctx; + memcpy( ctx->headset.codename, "HED", 4 ); + ctx->watchman[0].sensors = 16; + ctx->watchman[0].ctx = ctx; + memcpy( ctx->watchman[0].codename, "CT0", 4 ); - ret->faultfunction = ff; - ret->notefunction = notefunction; + ctx->watchman[1].sensors = 16; + ctx->watchman[1].ctx = ctx; + memcpy( ctx->watchman[1].codename, "CT1", 4 ); //USB must happen last. - if( r = survive_usb_init( ret ) ) + if( r = survive_usb_init( ctx ) ) { return 0; } - //ret->headset->photos = malloc( ret->headset->sensors * sizeof(struct SurvivePhoto) ); - return ret; + //Next, pull out the config stuff. +/* char * ct0conf; + int len = survive_get_config( &ct0conf, ctx, 1, 0 ); + printf( "%d\n", len ); + puts( ct0conf ); +*/ + + //ctx->headset->photos = malloc( ctx->headset->sensors * sizeof(struct SurvivePhoto) ); + return ctx; } @@ -49,3 +57,26 @@ int survive_poll( struct SurviveContext * ctx ) survive_usb_poll( ctx ); } +int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ) +{ + z_stream zs; //Zlib stream. May only be used by configuration at beginning and by USB thread periodically. + memset( &zs, 0, sizeof( zs ) ); + inflateInit( &zs ); ///Consider checking error + + //XXX: Todo: If we find that this is not useful past the beginning (nix this here and move into the configuration getter) + zs.avail_in = inlen; + zs.next_in = (z_const Bytef *)input; + zs.avail_out = outlen; + zs.next_out = output; + + if( inflate( &zs, Z_FINISH) != Z_STREAM_END ) + { + printf( "Zissue\n" ); + SV_INFO("survive_simple_inflate could not inflate." ); + return -1; + } + int len = zs.total_out; + inflateEnd( &zs ); + return len; +} + -- cgit v1.2.3