I use zlib 1.3.1 on MicroChip/XC32. It’s imported through included Harmony and it translates perfect. My goal is to receive data via a serial connection through various ways. This already works with uncompressed data. To save time i want to compress the data and i made tests with an amount of 4k, 8k and now 16k blocks of uncompressed binary data. I transfer the data within a loop and inflate() it on the microcontroller.
For transfering the datablocks i use Python3.6 importing zlib( 1.2.10 ) there.
The code is:
# create compressor with user defined options
compressor = zlib.compressobj( level=zlib.Z_BEST_COMPRESSION, wbits=zlib.MAX_WBITS )
data = compressor.compress(datablock) + compressor.flush() # datablock size is 16k
send the data ...
The microcontroller code after receiving the data in in rcvbuf[] is:
/* allocate inflate state */
out_stream.zalloc = Z_NULL;
out_stream.zfree = Z_NULL;
out_stream.opaque = Z_NULL;
out_stream.avail_in = 0;
out_stream.next_in = Z_NULL;
ret = inflateInit( &out_stream );
if( ret != Z_OK ) {
// return ret;
// neg_response();
return; // DEBUG
}
out_stream.avail_in = dat_len; // the length of the compressed datablock
out_stream.next_in = &rcvbuf; // the receive buffer with datablock inside
out_stream.avail_out = sizeof( decompress_buf ); // size of decrompress buffer
out_stream.next_out = &decompress_buf[0]; // the decrompress buffer
do {
// out_stream.avail_out = sizeof( decompress_buf );
// out_stream.next_out = &decompress_buf[0];
// run DE-compression
ret = inflate( &out_stream, Z_PARTIAL_FLUSH ); //Z_NO_FLUSH );// Z_FINISH );
// setting break point here!
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
// DEBUG
switch( ret ) {
case Z_NEED_DICT :
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR :
case Z_MEM_ERROR :
inflateEnd( &out_stream );
// return ret;
// negativ_response();
// DEBUG
return;
// case Z_OK :
// break;
// default:
// return;
}
have = sizeof( decompress_buf ) - out_stream.avail_out;
write_to_sram_buffer( my_adr, &diag_decompress_buf[0], have );
my_adr += have;
// } while (out_stream.avail_out == 0);
} while ( ret !=Z_STREAM_END );
inflateEnd( &out_stream );
I’m transfering binary data(images and code).
The things is, depending on the content of the compressed datablocks it works or not.
I tried different options and window sizes but i run always into the same problem after different calls to inflate().
Setting up a breakpoint after the inflate() function indicates to me it hangs inside there.
Using Python3 is only for testing at the moment and will be replaced later on with C++ Code.
Is it because of using two different versions of zlib for compress(deflate) and inflate?
Craggan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.