]>
Commit | Line | Data |
---|---|---|
8fa9368e BV |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> | |
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_CEM_DT_885X_PROTOCOL_H | |
21 | #define LIBSIGROK_HARDWARE_CEM_DT_885X_PROTOCOL_H | |
22 | ||
23 | #include <stdint.h> | |
24 | #include <glib.h> | |
25 | #include "libsigrok.h" | |
26 | #include "libsigrok-internal.h" | |
27 | ||
28 | /* Message logging helpers with subsystem-specific prefix string. */ | |
29 | #define LOG_PREFIX "cem-dt-885x: " | |
30 | #define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args) | |
31 | #define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args) | |
32 | #define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args) | |
33 | #define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args) | |
34 | #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) | |
35 | #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) | |
36 | ||
e37c4b39 | 37 | #define BUF_SIZE 32 |
14cf708f BV |
38 | /* When in hold mode, force the last measurement out at this interval. |
39 | * We're using 50ms, which duplicates the non-hold 20Hz update rate. */ | |
40 | #define HOLD_REPEAT_INTERVAL 50 * 1000 | |
e37c4b39 BV |
41 | |
42 | enum { | |
43 | TOKEN_WEIGHT_TIME_FAST = 0x02, | |
44 | TOKEN_WEIGHT_TIME_SLOW = 0x03, | |
45 | TOKEN_HOLD_MAX = 0x04, | |
46 | TOKEN_HOLD_MIN = 0x05, | |
47 | TOKEN_TIME = 0x06, | |
48 | TOKEN_MEAS_RANGE_OVER = 0x07, | |
49 | TOKEN_MEAS_RANGE_UNDER = 0x08, | |
50 | TOKEN_STORE_FULL = 0x09, | |
51 | TOKEN_RECORDING_ON = 0x0a, | |
52 | TOKEN_MEAS_WAS_READOUT = 0x0b, | |
53 | TOKEN_MEAS_WAS_BARGRAPH = 0x0c, | |
54 | TOKEN_MEASUREMENT = 0xd, | |
55 | TOKEN_HOLD_NONE = 0x0e, | |
56 | TOKEN_BATTERY_LOW = 0x0f, | |
57 | TOKEN_MEAS_RANGE_OK = 0x11, | |
58 | TOKEN_STORE_OK = 0x19, | |
59 | TOKEN_RECORDING_OFF = 0x1a, | |
60 | TOKEN_WEIGHT_FREQ_A = 0x1b, | |
61 | TOKEN_WEIGHT_FREQ_C = 0x1c, | |
62 | TOKEN_BATTERY_OK = 0x1f, | |
63 | TOKEN_MEAS_RANGE_30_80 = 0x30, | |
64 | TOKEN_MEAS_RANGE_30_130 = 0x40, | |
65 | TOKEN_MEAS_RANGE_50_100 = 0x4b, | |
66 | TOKEN_MEAS_RANGE_80_130 = 0x4c, | |
67 | }; | |
68 | ||
e1af0e85 BV |
69 | enum { |
70 | CMD_TOGGLE_RECORDING = 0x55, | |
be733919 | 71 | CMD_TOGGLE_WEIGHT_FREQ = 0x99, |
1487ce4f | 72 | CMD_TOGGLE_WEIGHT_TIME = 0x77, |
a90e480c | 73 | CMD_TOGGLE_HOLD_MAX_MIN = 0x11, |
f157b2ee | 74 | CMD_TOGGLE_MEAS_RANGE = 0x88, |
e1af0e85 BV |
75 | }; |
76 | ||
8fa9368e BV |
77 | /** Private, per-device-instance driver context. */ |
78 | struct dev_context { | |
e1af0e85 BV |
79 | /* Device state */ |
80 | uint64_t cur_mqflags; | |
81 | int recording; | |
f157b2ee | 82 | int cur_meas_range; |
e1af0e85 | 83 | |
8fa9368e | 84 | /* Acquisition settings */ |
7fb8279c | 85 | uint64_t limit_samples; |
8fa9368e BV |
86 | |
87 | /* Operational state */ | |
e37c4b39 BV |
88 | int state; |
89 | uint64_t num_samples; | |
8fa9368e BV |
90 | |
91 | /* Temporary state across callbacks */ | |
e37c4b39 BV |
92 | void *cb_data; |
93 | unsigned char cmd; | |
94 | unsigned char token; | |
95 | int buf_len; | |
96 | unsigned char buf[BUF_SIZE]; | |
bc114328 | 97 | float last_spl; |
14cf708f | 98 | gint64 hold_last_sent; |
e37c4b39 | 99 | }; |
8fa9368e | 100 | |
e37c4b39 BV |
101 | /* Parser state machine. */ |
102 | enum { | |
103 | ST_INIT, | |
104 | ST_GET_TOKEN, | |
105 | ST_GET_DATA, | |
106 | ST_GET_LOG, | |
8fa9368e BV |
107 | }; |
108 | ||
109 | SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data); | |
e1af0e85 | 110 | SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start); |
0cd9107d BV |
111 | SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi, |
112 | int *state); | |
be733919 BV |
113 | SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi); |
114 | SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw); | |
1487ce4f BV |
115 | SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi); |
116 | SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew); | |
a90e480c BV |
117 | SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi, |
118 | gboolean *holdmode); | |
119 | SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode); | |
f157b2ee BV |
120 | SR_PRIV int cem_dt_885x_meas_range_get(const struct sr_dev_inst *sdi, |
121 | uint64_t *low, uint64_t *high); | |
122 | SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi, | |
123 | uint64_t low, uint64_t high); | |
8fa9368e BV |
124 | |
125 | #endif |