NorbertNiderla / sprintz-revised

Compression algorithms C implementations for IoT devices.
GNU Lesser General Public License v2.1
3 stars 0 forks source link

Example of usage? #1

Open rob-g235 opened 2 years ago

rob-g235 commented 2 years ago

Hi,

Thanks firstly for making the attempt to port Sprintz to plain C.

Is this repo in it's current state usable? I cloned, and used the functions sprintz_encode and sprintz_decode but it segfaults somewhere, probably because some other modules need to be intited but not sure exactly which ones. Also just guessed the usage of those functions. The main.c in /lib just makes references to fns likesprintzEncode which don't exist.

Do you have examples of usage of these modules? Does it finally perform the run-length and huffman coding steps outlined in the paper?

Would love to get this working on an embedded target,

thanks.

NorbertNiderla commented 2 years ago

Hi, I'm pretty exited that someone is interested in this repo. Main problem here is that I've written that code when I had almost zero knowledge about tests, architecture, documentation, clean coding and so on.., neverthless algorithms should be working fine. lib directory is probably thrown there from another branch or something like that. You should take a look at frame_compression.h in src directory. There are functions that are using algorithms to compress data into packets of specific size, of course there is no documentation there :/, at least names of function and variables are somewhat helpful.

In frame_compression.h you can find function that is using Sprintz+Hufmann encoding. There is no variant with run-length encoding because, acording to my research, it was useless when you want to compress single time series (other difference of my implementation from original is that it is compressing only one data source).

If you have a specific case that you have to work on, maybe you can share it with me, I can add some documentation and description for functions that you need, also maybe I can add some tests to show possible usage and correctness of encoding. I don't have time and necessity to upgrade whole repo.

rob-g235 commented 2 years ago

Hi, glad to hear that!

Well it's fine, I'm starting to piece together what you wrote and add some improvements to the structure + adding some comments. Like I said I'm really interested on getting this working on an embedded target as part of a larger application that stores raw sensor data and has to send it via bluetooth. I think that use case is perfectly fine for what you have written.

Cheers, I'm going take a look at frame_compression.h since you've said that's the 'top level' module that makes it clearer how to use it.

I think I should be able to get that all working for my use case, I'm going to have a try and let you know how I get on. I'll add some unit tests too, as that's my first goal at the moment (to benchmark the compression ratio with some existing data). Once I do that I can share with you and potentially we can update the repo or something.

Also I saw some of the code is repeated also in your other repo iot-data-compression. Is that more recent and is there anything there I should take a look at?

NorbertNiderla commented 2 years ago

Ok then, I hope that you won't get frustrated fighting with this code. I believe that sprintz code in the other repo was updated at the same time. It was part of another research so I just copied it.

rob-g235 commented 2 years ago

I've made some good progress cleaning up get_sprintz_huffman_frame inside frame_compression.c. So this function will take in a buffer of samples, compress them, and output a compressed byte array, just like it already does, but with a few things moved around. It seems to run and output the output byte array of compressed data.

Did you ever write a similar function, but for decoding the data? Would like to try that now and see if everything works.