]> sigrok.org Git - libsigrok.git/blob - hardware/radioshack-dmm/radioshack-dmm.h
radioshack-dmm: Use message logging helpers.
[libsigrok.git] / hardware / radioshack-dmm / radioshack-dmm.h
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef LIBSIGROK_RADIOSHACK_DMM_H
22 #define LIBSIGROK_RADIOSHACK_DMM_H
23
24 /* Message logging helpers with driver-specific prefix string. */
25 #define DRIVER_LOG_DOMAIN "radioshack-dmm: "
26 #define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
27 #define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
28 #define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
29 #define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
30 #define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
31 #define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
32
33 #define RS_DMM_BUFSIZE  256
34
35 /* Byte 1 of the packet, and the modes it represents */
36 #define RS_22_812_IND1_HZ       (0x80)
37 #define RS_22_812_IND1_OHM      (0x40)
38 #define RS_22_812_IND1_KILO     (0x20)
39 #define RS_22_812_IND1_MEGA     (0x10)
40 #define RS_22_812_IND1_FARAD    (0x08)
41 #define RS_22_812_IND1_AMP      (0x04)
42 #define RS_22_812_IND1_VOLT     (0x02)
43 #define RS_22_812_IND1_MILI     (0x01)
44 /* Byte 2 of the packet, and the modes it represents */
45 #define RS_22_812_IND2_MICRO    (0x80)
46 #define RS_22_812_IND2_NANO     (0x40)
47 #define RS_22_812_IND2_DBM      (0x20)
48 #define RS_22_812_IND2_SEC      (0x10)
49 #define RS_22_812_IND2_DUTY     (0x08)
50 #define RS_22_812_IND2_HFE      (0x04)
51 #define RS_22_812_IND2_REL      (0x02)
52 #define RS_22_812_IND2_MIN      (0x01)
53 /* Byte 7 of the packet, and the modes it represents */
54 #define RS_22_812_INFO_BEEP     (0x80)
55 #define RS_22_812_INFO_DIODE    (0x30)
56 #define RS_22_812_INFO_BAT      (0x20)
57 #define RS_22_812_INFO_HOLD     (0x10)
58 #define RS_22_812_INFO_NEG      (0x08)
59 #define RS_22_812_INFO_AC       (0x04)
60 #define RS_22_812_INFO_RS232    (0x02)
61 #define RS_22_812_INFO_AUTO     (0x01)
62 /* Instead of a decimal point, digit 4 carries the MAX flag */
63 #define RS_22_812_DIG4_MAX      (0x08)
64 /* mask to remove the decimal point fr0m a digit */
65 #define RS_22_812_DP_MASK       (0x08)
66
67 /* What the LCD values represent */
68 #define RS_22_812_LCD_0 0xd7
69 #define RS_22_812_LCD_1 0x50
70 #define RS_22_812_LCD_2 0xb5
71 #define RS_22_812_LCD_3 0xf1
72 #define RS_22_812_LCD_4 0x72
73 #define RS_22_812_LCD_5 0xe3
74 #define RS_22_812_LCD_6 0xe7
75 #define RS_22_812_LCD_7 0x51
76 #define RS_22_812_LCD_8 0xf7
77 #define RS_22_812_LCD_9 0xf3
78
79 #define RS_22_812_LCD_C 0x87
80 #define RS_22_812_LCD_E
81 #define RS_22_812_LCD_F
82 #define RS_22_812_LCD_h 0x66
83 #define RS_22_812_LCD_H 0x76
84 #define RS_22_812_LCD_I
85 #define RS_22_812_LCD_n
86 #define RS_22_812_LCD_P 0x37
87 #define RS_22_812_LCD_r
88
89 typedef struct {
90         uint8_t mode;
91         uint8_t indicatrix1;
92         uint8_t indicatrix2;
93         uint8_t digit4;
94         uint8_t digit3;
95         uint8_t digit2;
96         uint8_t digit1;
97         uint8_t info;
98         uint8_t checksum;
99 } rs_22_812_packet;
100
101 #define RS_22_812_PACKET_SIZE (sizeof(rs_22_812_packet))
102
103 typedef enum {
104         RS_22_812_MODE_DC_V     = 0,
105         RS_22_812_MODE_AC_V     = 1,
106         RS_22_812_MODE_DC_UA    = 2,
107         RS_22_812_MODE_DC_MA    = 3,
108         RS_22_812_MODE_DC_A     = 4,
109         RS_22_812_MODE_AC_UA    = 5,
110         RS_22_812_MODE_AC_MA    = 6,
111         RS_22_812_MODE_AC_A     = 7,
112         RS_22_812_MODE_OHM      = 8,
113         RS_22_812_MODE_FARAD    = 9,
114         RS_22_812_MODE_HZ       = 10,
115         RS_22_812_MODE_VOLT_HZ  = 11,
116         RS_22_812_MODE_AMP_HZ   = 12,
117         RS_22_812_MODE_DUTY     = 13,
118         RS_22_812_MODE_VOLT_DUTY= 14,
119         RS_22_812_MODE_AMP_DUTY = 15,
120         RS_22_812_MODE_WIDTH    = 16,
121         RS_22_812_MODE_VOLT_WIDTH = 17,
122         RS_22_812_MODE_AMP_WIDTH  = 18,
123         RS_22_812_MODE_DIODE    = 19,
124         RS_22_812_MODE_CONT     = 20,
125         RS_22_812_MODE_HFE      = 21,
126         RS_22_812_MODE_LOGIC    = 22,
127         RS_22_812_MODE_DBM      = 23,
128         //RS_22_812_MODE_   EF = 24,
129         RS_22_812_MODE_TEMP     = 25,
130         RS_22_812_MODE_INVALID  = 26,
131 } rs_22_812_mode;
132
133 SR_PRIV gboolean rs_22_812_is_packet_valid(const rs_22_812_packet *data );
134
135 /* Supported models */
136 typedef enum {
137         RADIOSHACK_22_812 = 1,
138 } radioshack_model;
139
140 /* Supported device profiles */
141 struct radioshackdmm_profile {
142         radioshack_model model;
143         const char *modelname;
144         /* How often to poll, in ms. */
145         int poll_period;
146 };
147
148 /* Private, per-device-instance driver context. */
149 typedef struct dev_context {
150         /* const struct radioshackdmm_profile *profile; */
151         uint64_t limit_samples;
152         struct sr_serial_dev_inst *serial;
153         char *serialcomm;
154
155         /* Opaque pointer passed in by the frontend. */
156         void *cb_data;
157
158         /* Runtime. */
159         uint64_t num_samples;
160         uint8_t buf[RS_DMM_BUFSIZE];
161         size_t bufoffset;
162         size_t buflen;
163 } rs_dev_ctx;
164
165
166 SR_PRIV int radioshack_receive_data(int fd, int revents, void *cb_data);
167
168 #endif /* LIBSIGROK_RADIOSHACK_DMM_H */