]>
Commit | Line | Data |
---|---|---|
7b4edcb6 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 | ||
20 | #ifndef LIBSIGROK_HARDWARE_GMC_MH_1X_2X_PROTOCOL_H | |
21 | #define LIBSIGROK_HARDWARE_GMC_MH_1X_2X_PROTOCOL_H | |
22 | ||
23 | #include <stdint.h> | |
24 | #include <glib.h> | |
25 | #include "libsigrok.h" | |
26 | #include "libsigrok-internal.h" | |
27 | ||
3544f848 | 28 | #define LOG_PREFIX "gmc-mh-1x-2x" |
7b4edcb6 | 29 | |
f5792417 MH |
30 | #define GMC_BUFSIZE 266 |
31 | ||
32 | /** Message ID bits 4, 5 */ | |
fc348b77 UH |
33 | #define MSGID_MASK 0x30 /**< Mask to get message ID bits */ |
34 | #define MSGID_INF 0x00 /**< Start of message with device info */ | |
35 | #define MSGID_D10 0x10 /**< Start of data message, non-displayed intermediate */ | |
36 | #define MSGID_DTA 0x20 /**< Start of data message, displayed, averaged */ | |
37 | #define MSGID_DATA 0x30 /**< Data byte in message */ | |
f5792417 | 38 | |
fc348b77 | 39 | #define MSGC_MASK 0x0f /**< Mask to get message byte contents */ |
f5792417 MH |
40 | |
41 | #define MSGSRC_MASK 0xc0 /**< Mask to get bits related to message source */ | |
42 | ||
43 | #define bc(x) (x & MSGC_MASK) /**< Get contents from a byte */ | |
44 | ||
fc348b77 | 45 | #define MASK_6BITS 0x3f /**< Mask lower six bits. */ |
f5792417 | 46 | |
fc348b77 UH |
47 | /** |
48 | * Internal multimeter model codes. In opposite to the multimeter models from | |
49 | * protocol (see decode_model()), these codes allow working with ranges. | |
f5792417 MH |
50 | */ |
51 | enum model { | |
873e0c12 UH |
52 | METRAHIT_NONE = 0, /**< Value for uninitialized variable */ |
53 | METRAHIT_12S = 12, | |
54 | METRAHIT_13S14A = 13, | |
55 | METRAHIT_14S = 14, | |
56 | METRAHIT_15S = 15, | |
57 | METRAHIT_16S = 16, | |
58 | METRAHIT_16I = 17, | |
59 | METRAHIT_16X = METRAHIT_16I, /**< All Metrahit 16 */ | |
f5792417 | 60 | /* A Metrahit 17 exists, but seems not to have an IR interface. */ |
873e0c12 UH |
61 | METRAHIT_18S = 18, |
62 | METRAHIT_2X = 20, /**< For model type comparisons */ | |
63 | METRAHIT_22SM = 22, | |
64 | METRAHIT_23S = 23, | |
65 | METRAHIT_24S = 24, | |
66 | METRAHIT_25SM = 25, | |
67 | METRAHIT_26S = 26, | |
68 | METRAHIT_28S = 28, | |
69 | METRAHIT_29S = 29, | |
f5792417 MH |
70 | }; |
71 | ||
72 | /** Convert GMC model code in send mode to sigrok-internal one. */ | |
873e0c12 | 73 | SR_PRIV int gmc_decode_model_sm(uint8_t mcode); |
f5792417 | 74 | |
fc348b77 UH |
75 | /** |
76 | * Convert GMC model code in bidirectional mode to sigrok-internal one. | |
f5792417 | 77 | * |
fc348b77 UH |
78 | * @param[in] mcode Model code. |
79 | * | |
80 | * @return Model code. | |
f5792417 | 81 | */ |
873e0c12 | 82 | SR_PRIV int gmc_decode_model_bidi(uint8_t mcode); |
f5792417 | 83 | |
fc348b77 | 84 | /** Get model string from sigrok-internal model code. */ |
873e0c12 | 85 | SR_PRIV const char *gmc_model_str(enum model mcode); |
f5792417 | 86 | |
7b4edcb6 MH |
87 | /** Private, per-device-instance driver context. */ |
88 | struct dev_context { | |
89 | /* Model-specific information */ | |
f5792417 | 90 | enum model model; /**< Model code. */ |
7b4edcb6 MH |
91 | |
92 | /* Acquisition settings */ | |
f5792417 MH |
93 | uint64_t limit_samples; /**< Target number of samples */ |
94 | uint64_t limit_msec; /**< Target sampling time */ | |
95 | ||
96 | /* Opaque pointer passed in by frontend. */ | |
97 | void *cb_data; | |
7b4edcb6 MH |
98 | |
99 | /* Operational state */ | |
f5792417 MH |
100 | gboolean settings_ok; /**< Settings msg received yet. */ |
101 | int msg_type; /**< Message type (MSGID_INF, ...). */ | |
102 | int msg_len; /**< Message lengh (valid when msg, curr. type known).*/ | |
103 | int mq; /**< Measured quantity */ | |
104 | int unit; /**< Measured unit */ | |
105 | uint64_t mqflags; /**< Measured quantity flags */ | |
106 | float value; /**< Measured value */ | |
107 | float scale; /**< Scale for value. */ | |
108 | int8_t scale1000; /**< Additional scale factor 1000^x. */ | |
109 | gboolean vmains_29S; /**< Measured ctmv is V mains (29S only). */ | |
7b4edcb6 MH |
110 | |
111 | /* Temporary state across callbacks */ | |
f5792417 | 112 | uint64_t num_samples; /**< Current #samples for limit_samples */ |
fc348b77 UH |
113 | GTimer *elapsed_msec; /**< Used for sampling with limit_msec */ |
114 | uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */ | |
f5792417 | 115 | int buflen; /**< Data len in buf */ |
7b4edcb6 MH |
116 | }; |
117 | ||
118 | SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data); | |
119 | ||
120 | #endif |