]>
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> | |
c1aae900 | 25 | #include <libsigrok/libsigrok.h> |
8fa9368e BV |
26 | #include "libsigrok-internal.h" |
27 | ||
3544f848 | 28 | #define LOG_PREFIX "cem-dt-885x" |
8fa9368e | 29 | |
cea26f6e BV |
30 | /* When retrieving samples from device memory, group this many |
31 | * together into a sigrok packet. */ | |
32 | #define SAMPLES_PER_PACKET 50 | |
33 | ||
34 | /* Various temporary storage, at least 8 bytes. */ | |
1a46cc62 | 35 | #define BUF_SIZE (SAMPLES_PER_PACKET * 2) |
cea26f6e | 36 | |
14cf708f BV |
37 | /* When in hold mode, force the last measurement out at this interval. |
38 | * We're using 50ms, which duplicates the non-hold 20Hz update rate. */ | |
1a46cc62 | 39 | #define HOLD_REPEAT_INTERVAL (50 * 1000) |
e37c4b39 BV |
40 | |
41 | enum { | |
42 | TOKEN_WEIGHT_TIME_FAST = 0x02, | |
43 | TOKEN_WEIGHT_TIME_SLOW = 0x03, | |
44 | TOKEN_HOLD_MAX = 0x04, | |
45 | TOKEN_HOLD_MIN = 0x05, | |
46 | TOKEN_TIME = 0x06, | |
47 | TOKEN_MEAS_RANGE_OVER = 0x07, | |
48 | TOKEN_MEAS_RANGE_UNDER = 0x08, | |
49 | TOKEN_STORE_FULL = 0x09, | |
50 | TOKEN_RECORDING_ON = 0x0a, | |
51 | TOKEN_MEAS_WAS_READOUT = 0x0b, | |
52 | TOKEN_MEAS_WAS_BARGRAPH = 0x0c, | |
53 | TOKEN_MEASUREMENT = 0xd, | |
54 | TOKEN_HOLD_NONE = 0x0e, | |
55 | TOKEN_BATTERY_LOW = 0x0f, | |
56 | TOKEN_MEAS_RANGE_OK = 0x11, | |
57 | TOKEN_STORE_OK = 0x19, | |
58 | TOKEN_RECORDING_OFF = 0x1a, | |
59 | TOKEN_WEIGHT_FREQ_A = 0x1b, | |
60 | TOKEN_WEIGHT_FREQ_C = 0x1c, | |
61 | TOKEN_BATTERY_OK = 0x1f, | |
62 | TOKEN_MEAS_RANGE_30_80 = 0x30, | |
63 | TOKEN_MEAS_RANGE_30_130 = 0x40, | |
64 | TOKEN_MEAS_RANGE_50_100 = 0x4b, | |
65 | TOKEN_MEAS_RANGE_80_130 = 0x4c, | |
66 | }; | |
67 | ||
e1af0e85 BV |
68 | enum { |
69 | CMD_TOGGLE_RECORDING = 0x55, | |
be733919 | 70 | CMD_TOGGLE_WEIGHT_FREQ = 0x99, |
1487ce4f | 71 | CMD_TOGGLE_WEIGHT_TIME = 0x77, |
a90e480c | 72 | CMD_TOGGLE_HOLD_MAX_MIN = 0x11, |
f157b2ee | 73 | CMD_TOGGLE_MEAS_RANGE = 0x88, |
4c22355f | 74 | CMD_TOGGLE_POWER_OFF = 0x33, |
cea26f6e BV |
75 | CMD_TRANSFER_MEMORY = 0xac, |
76 | }; | |
77 | ||
78 | enum { | |
79 | RECORD_DBA = 0xaa, | |
80 | RECORD_DBC = 0xcc, | |
81 | RECORD_DATA = 0xac, | |
82 | RECORD_END = 0xdd, | |
e1af0e85 BV |
83 | }; |
84 | ||
662172d4 BV |
85 | enum { |
86 | DATA_SOURCE_LIVE, | |
87 | DATA_SOURCE_MEMORY, | |
88 | }; | |
89 | ||
8fa9368e BV |
90 | /** Private, per-device-instance driver context. */ |
91 | struct dev_context { | |
e1af0e85 | 92 | /* Device state */ |
7f9932e8 | 93 | enum sr_mqflag cur_mqflags; |
e1af0e85 | 94 | int recording; |
f157b2ee | 95 | int cur_meas_range; |
662172d4 | 96 | int cur_data_source; |
e1af0e85 | 97 | |
8fa9368e | 98 | /* Acquisition settings */ |
7fb8279c | 99 | uint64_t limit_samples; |
8fa9368e BV |
100 | |
101 | /* Operational state */ | |
e37c4b39 BV |
102 | int state; |
103 | uint64_t num_samples; | |
cea26f6e | 104 | gboolean enable_data_source_memory; |
8fa9368e BV |
105 | |
106 | /* Temporary state across callbacks */ | |
e37c4b39 BV |
107 | unsigned char cmd; |
108 | unsigned char token; | |
109 | int buf_len; | |
110 | unsigned char buf[BUF_SIZE]; | |
bc114328 | 111 | float last_spl; |
14cf708f | 112 | gint64 hold_last_sent; |
e37c4b39 | 113 | }; |
8fa9368e | 114 | |
e37c4b39 BV |
115 | /* Parser state machine. */ |
116 | enum { | |
117 | ST_INIT, | |
118 | ST_GET_TOKEN, | |
119 | ST_GET_DATA, | |
cea26f6e BV |
120 | ST_GET_LOG_HEADER, |
121 | ST_GET_LOG_RECORD_META, | |
122 | ST_GET_LOG_RECORD_DATA, | |
8fa9368e BV |
123 | }; |
124 | ||
125 | SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data); | |
e1af0e85 | 126 | SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start); |
0cd9107d BV |
127 | SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi, |
128 | int *state); | |
be733919 BV |
129 | SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi); |
130 | SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw); | |
1487ce4f BV |
131 | SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi); |
132 | SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew); | |
a90e480c BV |
133 | SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi, |
134 | gboolean *holdmode); | |
135 | SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode); | |
f157b2ee BV |
136 | SR_PRIV int cem_dt_885x_meas_range_get(const struct sr_dev_inst *sdi, |
137 | uint64_t *low, uint64_t *high); | |
138 | SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi, | |
139 | uint64_t low, uint64_t high); | |
4c22355f | 140 | SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi); |
8fa9368e BV |
141 | |
142 | #endif |