]> sigrok.org Git - libsigrok.git/blame - hardware/common/dmm/m2110.c
Centralise duplicated logging helper defines.
[libsigrok.git] / hardware / common / dmm / m2110.c
CommitLineData
825da8b2
MH
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2013 Matthias Heidbrink <m-sigrok@heidbrink.biz>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
95ecc765
UH
20/**
21 * @file
825da8b2 22 *
95ecc765
UH
23 * BBC Goerz Metrawatt M2110 ASCII protocol parser.
24 *
25 * Most probably the simplest multimeter protocol ever ;-) .
825da8b2
MH
26 */
27
825da8b2
MH
28#include <string.h>
29#include <math.h>
30#include <glib.h>
31#include "libsigrok.h"
32#include "libsigrok-internal.h"
33
825da8b2
MH
34SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf)
35{
36 float val;
37
38 if ((buf[7] != '\r') || (buf[8] != '\n'))
39 return FALSE;
40
95ecc765 41 if (!strncmp((const char *)buf, "OVERRNG", 7))
825da8b2
MH
42 return TRUE;
43
95ecc765 44 if (sscanf((const char *)buf, "%f", &val) == 1)
825da8b2
MH
45 return TRUE;
46 else
47 return FALSE;
48}
49
50SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
51 struct sr_datafeed_analog *analog, void *info)
52{
53 float val;
54
55 (void)info;
56
95ecc765
UH
57 /* We don't know the unit, so that's the best we can do. */
58 analog->mq = SR_MQ_GAIN;
825da8b2
MH
59 analog->unit = SR_UNIT_UNITLESS;
60 analog->mqflags = 0;
61
95ecc765 62 if (!strncmp((const char *)buf, "OVERRNG", 7))
825da8b2 63 *floatval = INFINITY;
95ecc765 64 else if (sscanf((const char *)buf, "%f", &val) == 1)
825da8b2
MH
65 *floatval = val;
66
67 return SR_OK;
68}