]>
Commit | Line | Data |
---|---|---|
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 | ||
6ec6c43b | 28 | #include <config.h> |
825da8b2 MH |
29 | #include <string.h> |
30 | #include <math.h> | |
31 | #include <glib.h> | |
c1aae900 | 32 | #include <libsigrok/libsigrok.h> |
825da8b2 MH |
33 | #include "libsigrok-internal.h" |
34 | ||
b95dd761 UH |
35 | #define LOG_PREFIX "m2110" |
36 | ||
825da8b2 MH |
37 | SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf) |
38 | { | |
39 | float val; | |
40 | ||
41 | if ((buf[7] != '\r') || (buf[8] != '\n')) | |
42 | return FALSE; | |
43 | ||
95ecc765 | 44 | if (!strncmp((const char *)buf, "OVERRNG", 7)) |
825da8b2 MH |
45 | return TRUE; |
46 | ||
95ecc765 | 47 | if (sscanf((const char *)buf, "%f", &val) == 1) |
825da8b2 MH |
48 | return TRUE; |
49 | else | |
50 | return FALSE; | |
51 | } | |
52 | ||
53 | SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval, | |
b02bb45f | 54 | struct sr_datafeed_analog *analog, void *info) |
825da8b2 | 55 | { |
8882e7e6 | 56 | int dot_pos, digits = 0; |
825da8b2 MH |
57 | float val; |
58 | ||
59 | (void)info; | |
60 | ||
95ecc765 | 61 | /* We don't know the unit, so that's the best we can do. */ |
b02bb45f UH |
62 | analog->meaning->mq = SR_MQ_GAIN; |
63 | analog->meaning->unit = SR_UNIT_UNITLESS; | |
64 | analog->meaning->mqflags = 0; | |
825da8b2 | 65 | |
95ecc765 | 66 | if (!strncmp((const char *)buf, "OVERRNG", 7)) |
825da8b2 | 67 | *floatval = INFINITY; |
8882e7e6 | 68 | else if (sscanf((const char *)buf, "%f", &val) == 1) { |
825da8b2 | 69 | *floatval = val; |
8882e7e6 AJ |
70 | dot_pos = strcspn((const char *)buf, "."); |
71 | if (dot_pos < 7) | |
72 | digits = 6 - dot_pos; | |
73 | } | |
74 | ||
75 | analog->encoding->digits = digits; | |
76 | analog->spec->spec_digits = digits; | |
825da8b2 MH |
77 | |
78 | return SR_OK; | |
79 | } |