]> sigrok.org Git - libsigrok.git/blobdiff - src/transform/invert.c
scpi-pps: Support for the EEZ PSU series
[libsigrok.git] / src / transform / invert.c
index 5a64afac5d06324aa42af396cea0352a0c4095c7..a3e14cb82ae701015d734d78bc270bb78023e76b 100644 (file)
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <string.h>
 #include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
@@ -30,12 +30,9 @@ static int receive(const struct sr_transform *t,
 {
        const struct sr_datafeed_logic *logic;
        const struct sr_datafeed_analog *analog;
-       struct sr_channel *ch;
-       GSList *l;
-       float *fdata, *f;
-       int si, num_channels, c;
        uint8_t *b;
-       uint64_t i, j;
+       int64_t p;
+       uint64_t i, j, q;
 
        if (!t || !t->sdi || !packet_in || !packet_out)
                return SR_ERR_ARG;
@@ -53,17 +50,12 @@ static int receive(const struct sr_transform *t,
                break;
        case SR_DF_ANALOG:
                analog = packet_in->payload;
-               fdata = (float *)analog->data;
-               num_channels = g_slist_length(analog->channels);
-               for (si = 0; si < analog->num_samples; si++) {
-                       /* For now invert all values in all channels. */
-                       for (l = analog->channels, c = 0; l; l = l->next, c++) {
-                               ch = l->data;
-                               (void)ch;
-                               f = &fdata[si * num_channels + c];
-                               *f = 1.0 / *f;
-                       }
-               }
+               p = analog->encoding->scale.p;
+               q = analog->encoding->scale.q;
+               if (q > INT64_MAX)
+                       return SR_ERR;
+               analog->encoding->scale.p = (p < 0) ? -q : q;
+               analog->encoding->scale.q = (p < 0) ? -p : p;
                break;
        default:
                sr_spew("Unsupported packet type %d, ignoring.", packet_in->type);