]> sigrok.org Git - libsigrok.git/blobdiff - hardware/cem-dt-885x/protocol.h
build: Portability fixes.
[libsigrok.git] / hardware / cem-dt-885x / protocol.h
index 7f296e83dc3cf4422c004ba4d24eb25d5569ca93..233ef8603876d103e0c403cd23daca8ed3e06303 100644 (file)
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
-/* Message logging helpers with subsystem-specific prefix string. */
-#define LOG_PREFIX "cem-dt-885x: "
-#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
-#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
-#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
-#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
-#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
-#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
+#define LOG_PREFIX "cem-dt-885x"
 
-#define BUF_SIZE 32
+/* When retrieving samples from device memory, group this many
+ * together into a sigrok packet. */
+#define SAMPLES_PER_PACKET 50
+
+/* Various temporary storage, at least 8 bytes. */
+#define BUF_SIZE SAMPLES_PER_PACKET * 2
+
+/* When in hold mode, force the last measurement out at this interval.
+ * We're using 50ms, which duplicates the non-hold 20Hz update rate. */
+#define HOLD_REPEAT_INTERVAL 50 * 1000
 
 enum {
        TOKEN_WEIGHT_TIME_FAST = 0x02,
@@ -63,15 +65,43 @@ enum {
        TOKEN_MEAS_RANGE_80_130 = 0x4c,
 };
 
+enum {
+       CMD_TOGGLE_RECORDING = 0x55,
+       CMD_TOGGLE_WEIGHT_FREQ = 0x99,
+       CMD_TOGGLE_WEIGHT_TIME = 0x77,
+       CMD_TOGGLE_HOLD_MAX_MIN = 0x11,
+       CMD_TOGGLE_MEAS_RANGE = 0x88,
+       CMD_TOGGLE_POWER_OFF = 0x33,
+       CMD_TRANSFER_MEMORY = 0xac,
+};
+
+enum {
+       RECORD_DBA = 0xaa,
+       RECORD_DBC = 0xcc,
+       RECORD_DATA = 0xac,
+       RECORD_END = 0xdd,
+};
+
+enum {
+       DATA_SOURCE_LIVE,
+       DATA_SOURCE_MEMORY,
+};
+
 /** Private, per-device-instance driver context. */
 struct dev_context {
+       /* Device state */
+       uint64_t cur_mqflags;
+       int recording;
+       int cur_meas_range;
+       int cur_data_source;
+
        /* Acquisition settings */
        uint64_t limit_samples;
 
        /* Operational state */
        int state;
        uint64_t num_samples;
-       uint64_t cur_mqflags;
+       gboolean enable_data_source_memory;
 
        /* Temporary state across callbacks */
        void *cb_data;
@@ -79,7 +109,8 @@ struct dev_context {
        unsigned char token;
        int buf_len;
        unsigned char buf[BUF_SIZE];
-
+       float last_spl;
+       gint64 hold_last_sent;
 };
 
 /* Parser state machine. */
@@ -87,9 +118,26 @@ enum {
        ST_INIT,
        ST_GET_TOKEN,
        ST_GET_DATA,
-       ST_GET_LOG,
+       ST_GET_LOG_HEADER,
+       ST_GET_LOG_RECORD_META,
+       ST_GET_LOG_RECORD_DATA,
 };
 
 SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data);
+SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start);
+SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi,
+               int *state);
+SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi);
+SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw);
+SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi);
+SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew);
+SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi,
+               gboolean *holdmode);
+SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode);
+SR_PRIV int cem_dt_885x_meas_range_get(const struct sr_dev_inst *sdi,
+               uint64_t *low, uint64_t *high);
+SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi,
+               uint64_t low, uint64_t high);
+SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi);
 
 #endif