Hi everyone, I've pushed a first, very simple and work-in-progress version of the generic "transforms" framework we wanted to have in libsigrok for quite a while now (and the respective sigrok-cli support for it).
A "transform" is basically something that takes one packet (analog or digital or other) and outputs a packet (or NULL, i.e. no packet). A few simple ones are implemented for now: - nop: Do nothing; take the packet, output it again unmodified. - scale: For every analog packet it gets it will scale (multiply) the analog (float) value by a specified factor. Any packets other than analog ones are ignored and passed on unmodified. - invert: - For analog packets: outputs the same packet, but analog values x are changed to 1/x. - For logic packets: Every 0 probe becomes 1 (and vice versa). There are *many* further transform modules that can be written and should prove highly useful, e.g. "add", "subtract", "multiply", "divide", "average", "adc", "dac", "downsample", "upsample", and lots more. I'm currently in the process of writing a few more, e.g. "adc" which will convert an analog channel to a digital one (using a "threshold" option that specifies which analog values are to be considered "high" and "low"). Implementations for other modules and ideas for useful ones we should consider adding are welcome! Here's a few examples of what is currently possible with this initial draft version: $ sigrok-cli -d demo:analog_channels=1:logic_channels=0 --samples 2 -T nop A0: -25.000000 V A0: -25.000000 V A0: 0.000000 V $ sigrok-cli -d demo:analog_channels=1:logic_channels=0 --samples 2 -T scale:factor=3.5 A0: -87.500000 V A0: -87.500000 V A0: 0.000000 V $ sigrok-cli -d demo:analog_channels=1:logic_channels=0 --samples 2 -T invert A0: -0.040000 V A0: -0.040000 V A0: inf V $ sigrok-cli -d demo:analog_channels=0:logic_channels=1 --samples 192 -T nop D0:10001111 00001111 10001111 00001111 10001111 01110111 11111111 00111111 D0:10001111 00001111 10001111 00001111 10001111 01110111 11111111 00111111 D0:10001111 00001111 10001111 00001111 10001111 01110111 11111111 00111111 $ sigrok-cli -d demo:analog_channels=0:logic_channels=1 --samples 192 -T invert D0:01110000 11110000 01110000 11110000 01110000 10001000 00000000 11000000 D0:01110000 11110000 01110000 11110000 01110000 10001000 00000000 11000000 D0:01110000 11110000 01110000 11110000 01110000 10001000 00000000 11000000 There are *many* missing features, as well as various design and implementation problems and bugs. Please don't consider this as a finished feature yet, it's more of a preview of where we're aiming at with this; lots more work is required to make it all useful. Any reviews, comments, suggestions are highly welcome of course. Here's a short and incomplete list of TODOs and issues: - Most modules will need a "channels" option to specify on which channel(s) they should operate. Currently they're all hardcoded to affect all channels. - (C++) bindings need to gain support for this (e.g. to make this feature available to frontends like PulseView and sigrok-meter). - Various design/technical issues need to be sorted out, e.g. who frees what and when; how to let frontends know that a transform is generating a "new channel" that has nothing to do with any physical channel that may have been present on original device, etc. etc. - Currently multiple transforms can be chained linearly; later on we'll likely want some "pipes-and-filters"-style, "flowgraph" based system with more flexible facilities. - Options may need some more metadata, e.g. frontends may need to know which options are required or optional, which ranges of values are allowed etc. etc. - lots more... Uwe. -- http://hermann-uwe.de | http://randomprojects.org | http://sigrok.org ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel