aboutsummaryrefslogtreecommitdiff
path: root/src/survive.c
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2016-12-03 18:02:20 -0500
committercnlohr <lohr85@gmail.com>2016-12-03 18:02:20 -0500
commit684b109e8cd3246c93fdec3e63157bbd11bb359a (patch)
tree22bb039638bda9a6329615db9e2bd01162ab9b8e /src/survive.c
parent00f9c8d9a66ffad686bd09041894ba6c25264665 (diff)
downloadlibsurvive-684b109e8cd3246c93fdec3e63157bbd11bb359a.tar.gz
libsurvive-684b109e8cd3246c93fdec3e63157bbd11bb359a.tar.bz2
first stab at trying to pull off config data, didn't work.
Diffstat (limited to 'src/survive.c')
-rw-r--r--src/survive.c63
1 files changed, 47 insertions, 16 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <zlib.h>
+
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;
+}
+