]>
Commit | Line | Data |
---|---|---|
7b4edcb6 MH |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
c90beca7 | 4 | * Copyright (C) 2013, 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz> |
7b4edcb6 MH |
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 | ||
6392d599 MH |
20 | /** @file |
21 | * Gossen Metrawatt Metrahit 1x/2x drivers | |
c90beca7 | 22 | * @internal |
6392d599 MH |
23 | */ |
24 | ||
7b4edcb6 MH |
25 | #ifndef LIBSIGROK_HARDWARE_GMC_MH_1X_2X_PROTOCOL_H |
26 | #define LIBSIGROK_HARDWARE_GMC_MH_1X_2X_PROTOCOL_H | |
27 | ||
28 | #include <stdint.h> | |
29 | #include <glib.h> | |
30 | #include "libsigrok.h" | |
31 | #include "libsigrok-internal.h" | |
32 | ||
3544f848 | 33 | #define LOG_PREFIX "gmc-mh-1x-2x" |
7b4edcb6 | 34 | |
f5792417 MH |
35 | #define GMC_BUFSIZE 266 |
36 | ||
37 | /** Message ID bits 4, 5 */ | |
fc348b77 UH |
38 | #define MSGID_MASK 0x30 /**< Mask to get message ID bits */ |
39 | #define MSGID_INF 0x00 /**< Start of message with device info */ | |
40 | #define MSGID_D10 0x10 /**< Start of data message, non-displayed intermediate */ | |
41 | #define MSGID_DTA 0x20 /**< Start of data message, displayed, averaged */ | |
42 | #define MSGID_DATA 0x30 /**< Data byte in message */ | |
f5792417 | 43 | |
6392d599 | 44 | #define MSGC_MASK 0x0f /**< Mask to get message byte contents in send mode */ |
f5792417 MH |
45 | |
46 | #define MSGSRC_MASK 0xc0 /**< Mask to get bits related to message source */ | |
47 | ||
48 | #define bc(x) (x & MSGC_MASK) /**< Get contents from a byte */ | |
49 | ||
fc348b77 | 50 | #define MASK_6BITS 0x3f /**< Mask lower six bits. */ |
f5792417 | 51 | |
fc348b77 UH |
52 | /** |
53 | * Internal multimeter model codes. In opposite to the multimeter models from | |
54 | * protocol (see decode_model()), these codes allow working with ranges. | |
f5792417 MH |
55 | */ |
56 | enum model { | |
873e0c12 UH |
57 | METRAHIT_NONE = 0, /**< Value for uninitialized variable */ |
58 | METRAHIT_12S = 12, | |
59 | METRAHIT_13S14A = 13, | |
60 | METRAHIT_14S = 14, | |
61 | METRAHIT_15S = 15, | |
62 | METRAHIT_16S = 16, | |
63 | METRAHIT_16I = 17, | |
64 | METRAHIT_16X = METRAHIT_16I, /**< All Metrahit 16 */ | |
f5792417 | 65 | /* A Metrahit 17 exists, but seems not to have an IR interface. */ |
873e0c12 UH |
66 | METRAHIT_18S = 18, |
67 | METRAHIT_2X = 20, /**< For model type comparisons */ | |
c90beca7 MH |
68 | METRAHIT_22SM = METRAHIT_2X + 1, /**< Send mode */ |
69 | METRAHIT_22S = METRAHIT_22SM + 1, /**< Bidi mode */ | |
70 | METRAHIT_22M = METRAHIT_22S + 1, /**< Bidi mode */ | |
71 | METRAHIT_23S = METRAHIT_22M + 1, | |
72 | METRAHIT_24S = METRAHIT_23S + 1, | |
73 | METRAHIT_25S = METRAHIT_24S + 1, | |
74 | METRAHIT_26SM = METRAHIT_25S + 1, /**< Send mode */ | |
75 | METRAHIT_26S = METRAHIT_26SM + 1, /**< Bidi mode */ | |
76 | METRAHIT_26M = METRAHIT_26S + 1, /**< Bidi mode */ | |
77 | METRAHIT_28S = METRAHIT_26M + 1, | |
78 | METRAHIT_29S = METRAHIT_28S + 1, | |
f5792417 MH |
79 | }; |
80 | ||
7b4edcb6 MH |
81 | /** Private, per-device-instance driver context. */ |
82 | struct dev_context { | |
83 | /* Model-specific information */ | |
f5792417 | 84 | enum model model; /**< Model code. */ |
7b4edcb6 MH |
85 | |
86 | /* Acquisition settings */ | |
f5792417 MH |
87 | uint64_t limit_samples; /**< Target number of samples */ |
88 | uint64_t limit_msec; /**< Target sampling time */ | |
89 | ||
90 | /* Opaque pointer passed in by frontend. */ | |
91 | void *cb_data; | |
7b4edcb6 MH |
92 | |
93 | /* Operational state */ | |
f5792417 | 94 | gboolean settings_ok; /**< Settings msg received yet. */ |
c90beca7 MH |
95 | int msg_type; /**< Message type (MSGID_INF, ...). */ |
96 | int msg_len; /**< Message lengh (valid when msg, curr. type known).*/ | |
97 | int mq; /**< Measured quantity */ | |
98 | int unit; /**< Measured unit */ | |
f5792417 MH |
99 | uint64_t mqflags; /**< Measured quantity flags */ |
100 | float value; /**< Measured value */ | |
101 | float scale; /**< Scale for value. */ | |
c90beca7 | 102 | int8_t scale1000; /**< Additional scale factor 1000x. */ |
f5792417 | 103 | gboolean vmains_29S; /**< Measured ctmv is V mains (29S only). */ |
c90beca7 MH |
104 | int addr; /**< Device address (1..15). */ |
105 | int cmd_idx; /**< Parameter "Idx" (Index) of current command, if required. */ | |
106 | int cmd_seq; /**< Command sequence. Used to query status every n messages. */ | |
107 | gboolean autorng; /**< Auto range enabled. */ | |
108 | float ubatt; /**< Battery voltage. */ | |
109 | uint8_t fw_ver_maj; /**< Firmware version major. */ | |
110 | uint8_t fw_ver_min; /**< Firmware version minor. */ | |
111 | int64_t req_sent_at; /**< Request sent. */ | |
112 | gboolean response_pending; /**< Request sent, response is pending. */ | |
7b4edcb6 MH |
113 | |
114 | /* Temporary state across callbacks */ | |
f5792417 | 115 | uint64_t num_samples; /**< Current #samples for limit_samples */ |
fc348b77 UH |
116 | GTimer *elapsed_msec; /**< Used for sampling with limit_msec */ |
117 | uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */ | |
f5792417 | 118 | int buflen; /**< Data len in buf */ |
7b4edcb6 MH |
119 | }; |
120 | ||
c90beca7 MH |
121 | /* Forward declarations */ |
122 | SR_PRIV int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, | |
53b4680f | 123 | const struct sr_channel_group *cg); |
c90beca7 MH |
124 | SR_PRIV void create_cmd_14(guchar addr, guchar func, guchar* params, guchar* buf); |
125 | SR_PRIV void dump_msg14(guchar* buf, gboolean raw); | |
126 | SR_PRIV int gmc_decode_model_bd(uint8_t mcode); | |
6392d599 | 127 | SR_PRIV int gmc_decode_model_sm(uint8_t mcode); |
c90beca7 MH |
128 | SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data); |
129 | SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data); | |
130 | SR_PRIV const char *gmc_model_str(enum model mcode); | |
131 | SR_PRIV int process_msg14(struct sr_dev_inst *sdi); | |
132 | SR_PRIV int req_meas14(const struct sr_dev_inst *sdi); | |
133 | SR_PRIV int req_stat14(const struct sr_dev_inst *sdi, gboolean power_on); | |
7b4edcb6 MH |
134 | |
135 | #endif |