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