libsigrok-internal.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. /** @file
  20. * @internal
  21. */
  22. #ifndef LIBSIGROK_LIBSIGROK_INTERNAL_H
  23. #define LIBSIGROK_LIBSIGROK_INTERNAL_H
  24. #include <stdarg.h>
  25. #include <glib.h>
  26. #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
  27. #ifdef HAVE_LIBUSB_1_0
  28. #include <libusb.h>
  29. #endif
  30. #ifdef HAVE_LIBSERIALPORT
  31. #include <libserialport.h>
  32. #endif
  33. /**
  34. * @file
  35. *
  36. * libsigrok private header file, only to be used internally.
  37. */
  38. /*--- Macros ----------------------------------------------------------------*/
  39. #ifndef ARRAY_SIZE
  40. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  41. #endif
  42. #ifndef ARRAY_AND_SIZE
  43. #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
  44. #endif
  45. /**
  46. * Read a 8 bits integer out of memory.
  47. * @param x a pointer to the input memory
  48. * @return the corresponding integer
  49. */
  50. #define R8(x) ((unsigned)((const uint8_t*)(x))[0])
  51. /**
  52. * Read a 16 bits big endian integer out of memory.
  53. * @param x a pointer to the input memory
  54. * @return the corresponding integer
  55. */
  56. #define RB16(x) (((unsigned)((const uint8_t*)(x))[0] << 8) | \
  57. (unsigned)((const uint8_t*)(x))[1])
  58. /**
  59. * Read a 16 bits little endian integer out of memory.
  60. * @param x a pointer to the input memory
  61. * @return the corresponding integer
  62. */
  63. #define RL16(x) (((unsigned)((const uint8_t*)(x))[1] << 8) | \
  64. (unsigned)((const uint8_t*)(x))[0])
  65. /**
  66. * Read a 32 bits big endian integer out of memory.
  67. * @param x a pointer to the input memory
  68. * @return the corresponding integer
  69. */
  70. #define RB32(x) (((unsigned)((const uint8_t*)(x))[0] << 24) | \
  71. ((unsigned)((const uint8_t*)(x))[1] << 16) | \
  72. ((unsigned)((const uint8_t*)(x))[2] << 8) | \
  73. (unsigned)((const uint8_t*)(x))[3])
  74. /**
  75. * Read a 32 bits little endian integer out of memory.
  76. * @param x a pointer to the input memory
  77. * @return the corresponding integer
  78. */
  79. #define RL32(x) (((unsigned)((const uint8_t*)(x))[3] << 24) | \
  80. ((unsigned)((const uint8_t*)(x))[2] << 16) | \
  81. ((unsigned)((const uint8_t*)(x))[1] << 8) | \
  82. (unsigned)((const uint8_t*)(x))[0])
  83. /**
  84. * Write a 8 bits integer to memory.
  85. * @param p a pointer to the output memory
  86. * @param x the input integer
  87. */
  88. #define W8(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); } while(0)
  89. /**
  90. * Write a 16 bits integer to memory stored as big endian.
  91. * @param p a pointer to the output memory
  92. * @param x the input integer
  93. */
  94. #define WB16(p, x) do { ((uint8_t*)(p))[1] = (uint8_t) (x); \
  95. ((uint8_t*)(p))[0] = (uint8_t)((x)>>8); } while(0)
  96. /**
  97. * Write a 16 bits integer to memory stored as little endian.
  98. * @param p a pointer to the output memory
  99. * @param x the input integer
  100. */
  101. #define WL16(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); \
  102. ((uint8_t*)(p))[1] = (uint8_t)((x)>>8); } while(0)
  103. /**
  104. * Write a 32 bits integer to memory stored as big endian.
  105. * @param p a pointer to the output memory
  106. * @param x the input integer
  107. */
  108. #define WB32(p, x) do { ((uint8_t*)(p))[3] = (uint8_t) (x); \
  109. ((uint8_t*)(p))[2] = (uint8_t)((x)>>8); \
  110. ((uint8_t*)(p))[1] = (uint8_t)((x)>>16); \
  111. ((uint8_t*)(p))[0] = (uint8_t)((x)>>24); } while(0)
  112. /**
  113. * Write a 32 bits integer to memory stored as little endian.
  114. * @param p a pointer to the output memory
  115. * @param x the input integer
  116. */
  117. #define WL32(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); \
  118. ((uint8_t*)(p))[1] = (uint8_t)((x)>>8); \
  119. ((uint8_t*)(p))[2] = (uint8_t)((x)>>16); \
  120. ((uint8_t*)(p))[3] = (uint8_t)((x)>>24); } while(0)
  121. /* Portability fixes for FreeBSD. */
  122. #ifdef __FreeBSD__
  123. #define LIBUSB_CLASS_APPLICATION 0xfe
  124. #define libusb_handle_events_timeout_completed(ctx, tv, c) \
  125. libusb_handle_events_timeout(ctx, tv)
  126. #endif
  127. struct sr_context {
  128. #ifdef HAVE_LIBUSB_1_0
  129. libusb_context *libusb_ctx;
  130. gboolean usb_source_present;
  131. #ifdef _WIN32
  132. GThread *usb_thread;
  133. gboolean usb_thread_running;
  134. GMutex usb_mutex;
  135. HANDLE usb_event;
  136. GPollFD usb_pollfd;
  137. sr_receive_data_callback usb_cb;
  138. void *usb_cb_data;
  139. #endif
  140. #endif
  141. };
  142. #ifdef HAVE_LIBUSB_1_0
  143. /** USB device instance */
  144. struct sr_usb_dev_inst {
  145. /** USB bus */
  146. uint8_t bus;
  147. /** Device address on USB bus */
  148. uint8_t address;
  149. /** libusb device handle */
  150. struct libusb_device_handle *devhdl;
  151. };
  152. #endif
  153. #ifdef HAVE_LIBSERIALPORT
  154. #define SERIAL_PARITY_NONE SP_PARITY_NONE
  155. #define SERIAL_PARITY_EVEN SP_PARITY_EVEN
  156. #define SERIAL_PARITY_ODD SP_PARITY_ODD
  157. struct sr_serial_dev_inst {
  158. /** Port name, e.g. '/dev/tty42'. */
  159. char *port;
  160. /** Comm params for serial_set_paramstr(). */
  161. char *serialcomm;
  162. /** Port is non-blocking. */
  163. int nonblocking;
  164. /** libserialport port handle */
  165. struct sp_port *data;
  166. /** libserialport event set */
  167. struct sp_event_set *event_set;
  168. /** GPollFDs for event polling */
  169. GPollFD *pollfds;
  170. };
  171. #endif
  172. struct sr_usbtmc_dev_inst {
  173. char *device;
  174. int fd;
  175. };
  176. /* Private driver context. */
  177. struct drv_context {
  178. /** sigrok context */
  179. struct sr_context *sr_ctx;
  180. GSList *instances;
  181. };
  182. /*--- log.c -----------------------------------------------------------------*/
  183. SR_PRIV int sr_log(int loglevel, const char *format, ...);
  184. SR_PRIV int sr_spew(const char *format, ...);
  185. SR_PRIV int sr_dbg(const char *format, ...);
  186. SR_PRIV int sr_info(const char *format, ...);
  187. SR_PRIV int sr_warn(const char *format, ...);
  188. SR_PRIV int sr_err(const char *format, ...);
  189. /* Message logging helpers with subsystem-specific prefix string. */
  190. #ifndef NO_LOG_WRAPPERS
  191. #define sr_log(l, s, args...) sr_log(l, "%s: " s, LOG_PREFIX, ## args)
  192. #define sr_spew(s, args...) sr_spew("%s: " s, LOG_PREFIX, ## args)
  193. #define sr_dbg(s, args...) sr_dbg("%s: " s, LOG_PREFIX, ## args)
  194. #define sr_info(s, args...) sr_info("%s: " s, LOG_PREFIX, ## args)
  195. #define sr_warn(s, args...) sr_warn("%s: " s, LOG_PREFIX, ## args)
  196. #define sr_err(s, args...) sr_err("%s: " s, LOG_PREFIX, ## args)
  197. #endif
  198. /*--- device.c --------------------------------------------------------------*/
  199. /** Values for the changes argument of sr_dev_driver.config_channel_set. */
  200. enum {
  201. /** The enabled state of the channel has been changed. */
  202. SR_CHANNEL_SET_ENABLED = 1 << 0,
  203. /** The trigger setup of the channel has been changed. */
  204. SR_CHANNEL_SET_TRIGGER = 1 << 1,
  205. };
  206. SR_PRIV struct sr_channel *sr_channel_new(int index, int type,
  207. gboolean enabled, const char *name);
  208. /* Generic device instances */
  209. SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int index, int status,
  210. const char *vendor, const char *model, const char *version);
  211. SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
  212. #ifdef HAVE_LIBUSB_1_0
  213. /* USB-specific instances */
  214. SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
  215. uint8_t address, struct libusb_device_handle *hdl);
  216. SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
  217. #endif
  218. #ifdef HAVE_LIBSERIALPORT
  219. /* Serial-specific instances */
  220. SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
  221. const char *serialcomm);
  222. SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
  223. #endif
  224. /* USBTMC-specific instances */
  225. SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device);
  226. SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
  227. /*--- hwdriver.c ------------------------------------------------------------*/
  228. SR_PRIV void sr_hw_cleanup_all(void);
  229. SR_PRIV struct sr_config *sr_config_new(int key, GVariant *data);
  230. SR_PRIV void sr_config_free(struct sr_config *src);
  231. SR_PRIV int sr_source_remove(int fd);
  232. SR_PRIV int sr_source_add(int fd, int events, int timeout,
  233. sr_receive_data_callback cb, void *cb_data);
  234. /*--- session.c -------------------------------------------------------------*/
  235. struct sr_session {
  236. /** List of struct sr_dev pointers. */
  237. GSList *devs;
  238. /** List of struct datafeed_callback pointers. */
  239. GSList *datafeed_callbacks;
  240. GTimeVal starttime;
  241. gboolean running;
  242. unsigned int num_sources;
  243. /*
  244. * Both "sources" and "pollfds" are of the same size and contain pairs
  245. * of descriptor and callback function. We can not embed the GPollFD
  246. * into the source struct since we want to be able to pass the array
  247. * of all poll descriptors to g_poll().
  248. */
  249. struct source *sources;
  250. GPollFD *pollfds;
  251. int source_timeout;
  252. /*
  253. * These are our synchronization primitives for stopping the session in
  254. * an async fashion. We need to make sure the session is stopped from
  255. * within the session thread itself.
  256. */
  257. /** Mutex protecting access to abort_session. */
  258. GMutex stop_mutex;
  259. /** Abort current session. See sr_session_stop(). */
  260. gboolean abort_session;
  261. };
  262. SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
  263. const struct sr_datafeed_packet *packet);
  264. SR_PRIV int sr_session_stop_sync(void);
  265. SR_PRIV int sr_sessionfile_check(const char *filename);
  266. /*--- std.c -----------------------------------------------------------------*/
  267. typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
  268. typedef void (*std_dev_clear_callback)(void *priv);
  269. SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
  270. const char *prefix);
  271. #ifdef HAVE_LIBSERIALPORT
  272. SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
  273. SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
  274. void *cb_data, dev_close_callback dev_close_fn,
  275. struct sr_serial_dev_inst *serial, const char *prefix);
  276. #endif
  277. SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
  278. const char *prefix);
  279. SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
  280. std_dev_clear_callback clear_private);
  281. SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
  282. /*--- strutil.c -------------------------------------------------------------*/
  283. SR_PRIV int sr_atol(const char *str, long *ret);
  284. SR_PRIV int sr_atoi(const char *str, int *ret);
  285. SR_PRIV int sr_atod(const char *str, double *ret);
  286. SR_PRIV int sr_atof(const char *str, float *ret);
  287. SR_PRIV int sr_atof_ascii(const char *str, float *ret);
  288. /*--- hardware/common/serial.c ----------------------------------------------*/
  289. #ifdef HAVE_LIBSERIALPORT
  290. enum {
  291. SERIAL_RDWR = 1,
  292. SERIAL_RDONLY = 2,
  293. SERIAL_NONBLOCK = 4,
  294. };
  295. typedef gboolean (*packet_valid_callback)(const uint8_t *buf);
  296. SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
  297. SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
  298. SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
  299. SR_PRIV int serial_write(struct sr_serial_dev_inst *serial,
  300. const void *buf, size_t count);
  301. SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
  302. const void *buf, size_t count);
  303. SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
  304. const void *buf, size_t count);
  305. SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf,
  306. size_t count);
  307. SR_PRIV int serial_read_blocking(struct sr_serial_dev_inst *serial, void *buf,
  308. size_t count);
  309. SR_PRIV int serial_read_nonblocking(struct sr_serial_dev_inst *serial, void *buf,
  310. size_t count);
  311. SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
  312. int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
  313. SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
  314. const char *paramstr);
  315. SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
  316. int *buflen, gint64 timeout_ms);
  317. SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
  318. uint8_t *buf, size_t *buflen,
  319. size_t packet_size,
  320. packet_valid_callback is_valid,
  321. uint64_t timeout_ms, int baudrate);
  322. SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device,
  323. const char **serial_options);
  324. SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
  325. int timeout, sr_receive_data_callback cb, void *cb_data);
  326. SR_PRIV int serial_source_remove(struct sr_serial_dev_inst *serial);
  327. SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
  328. #endif
  329. /*--- hardware/common/ezusb.c -----------------------------------------------*/
  330. #ifdef HAVE_LIBUSB_1_0
  331. SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
  332. SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl,
  333. const char *filename);
  334. SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
  335. const char *filename);
  336. #endif
  337. /*--- hardware/common/usb.c -------------------------------------------------*/
  338. #ifdef HAVE_LIBUSB_1_0
  339. SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
  340. SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
  341. SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
  342. sr_receive_data_callback cb, void *cb_data);
  343. SR_PRIV int usb_source_remove(struct sr_context *ctx);
  344. #endif
  345. /*--- hardware/common/scpi.c ------------------------------------------------*/
  346. #define SCPI_CMD_IDN "*IDN?"
  347. #define SCPI_CMD_OPC "*OPC?"
  348. enum {
  349. SCPI_CMD_SET_TRIGGER_SOURCE,
  350. SCPI_CMD_SET_TIMEBASE,
  351. SCPI_CMD_SET_VERTICAL_DIV,
  352. SCPI_CMD_SET_TRIGGER_SLOPE,
  353. SCPI_CMD_SET_COUPLING,
  354. SCPI_CMD_SET_HORIZ_TRIGGERPOS,
  355. SCPI_CMD_GET_ANALOG_CHAN_STATE,
  356. SCPI_CMD_GET_DIG_CHAN_STATE,
  357. SCPI_CMD_GET_TIMEBASE,
  358. SCPI_CMD_GET_VERTICAL_DIV,
  359. SCPI_CMD_GET_VERTICAL_OFFSET,
  360. SCPI_CMD_GET_TRIGGER_SOURCE,
  361. SCPI_CMD_GET_HORIZ_TRIGGERPOS,
  362. SCPI_CMD_GET_TRIGGER_SLOPE,
  363. SCPI_CMD_GET_COUPLING,
  364. SCPI_CMD_SET_ANALOG_CHAN_STATE,
  365. SCPI_CMD_SET_DIG_CHAN_STATE,
  366. SCPI_CMD_GET_DIG_POD_STATE,
  367. SCPI_CMD_SET_DIG_POD_STATE,
  368. SCPI_CMD_GET_ANALOG_DATA,
  369. SCPI_CMD_GET_DIG_DATA,
  370. SCPI_CMD_GET_SAMPLE_RATE,
  371. SCPI_CMD_GET_SAMPLE_RATE_LIVE,
  372. };
  373. struct sr_scpi_hw_info {
  374. char *manufacturer;
  375. char *model;
  376. char *serial_number;
  377. char *firmware_version;
  378. };
  379. struct sr_scpi_dev_inst {
  380. const char *name;
  381. const char *prefix;
  382. int priv_size;
  383. GSList *(*scan)(struct drv_context *drvc);
  384. int (*dev_inst_new)(void *priv, struct drv_context *drvc,
  385. const char *resource, char **params, const char *serialcomm);
  386. int (*open)(void *priv);
  387. int (*source_add)(void *priv, int events,
  388. int timeout, sr_receive_data_callback cb, void *cb_data);
  389. int (*source_remove)(void *priv);
  390. int (*send)(void *priv, const char *command);
  391. int (*read_begin)(void *priv);
  392. int (*read_data)(void *priv, char *buf, int maxlen);
  393. int (*read_complete)(void *priv);
  394. int (*close)(void *priv);
  395. void (*free)(void *priv);
  396. void *priv;
  397. };
  398. SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
  399. struct sr_dev_inst *(*probe_device)(struct sr_scpi_dev_inst *scpi));
  400. SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
  401. const char *resource, const char *serialcomm);
  402. SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
  403. SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
  404. int timeout, sr_receive_data_callback cb, void *cb_data);
  405. SR_PRIV int sr_scpi_source_remove(struct sr_scpi_dev_inst *scpi);
  406. SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
  407. const char *format, ...);
  408. SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi,
  409. const char *format, va_list args);
  410. SR_PRIV int sr_scpi_read_begin(struct sr_scpi_dev_inst *scpi);
  411. SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen);
  412. SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi);
  413. SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi);
  414. SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi);
  415. SR_PRIV int sr_scpi_get_string(struct sr_scpi_dev_inst *scpi,
  416. const char *command, char **scpi_response);
  417. SR_PRIV int sr_scpi_get_bool(struct sr_scpi_dev_inst *scpi,
  418. const char *command, gboolean *scpi_response);
  419. SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi,
  420. const char *command, int *scpi_response);
  421. SR_PRIV int sr_scpi_get_float(struct sr_scpi_dev_inst *scpi,
  422. const char *command, float *scpi_response);
  423. SR_PRIV int sr_scpi_get_double(struct sr_scpi_dev_inst *scpi,
  424. const char *command, double *scpi_response);
  425. SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi);
  426. SR_PRIV int sr_scpi_get_floatv(struct sr_scpi_dev_inst *scpi,
  427. const char *command, GArray **scpi_response);
  428. SR_PRIV int sr_scpi_get_uint8v(struct sr_scpi_dev_inst *scpi,
  429. const char *command, GArray **scpi_response);
  430. SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
  431. struct sr_scpi_hw_info **scpi_response);
  432. SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);
  433. /*--- hardware/common/dmm/es519xx.c -----------------------------------------*/
  434. /**
  435. * All 11-byte es519xx chips repeat each block twice for each conversion cycle
  436. * so always read 2 blocks at a time.
  437. */
  438. #define ES519XX_11B_PACKET_SIZE (11 * 2)
  439. #define ES519XX_14B_PACKET_SIZE 14
  440. struct es519xx_info {
  441. gboolean is_judge, is_voltage, is_auto, is_micro, is_current;
  442. gboolean is_milli, is_resistance, is_continuity, is_diode;
  443. gboolean is_frequency, is_rpm, is_capacitance, is_duty_cycle;
  444. gboolean is_temperature, is_celsius, is_fahrenheit;
  445. gboolean is_adp0, is_adp1, is_adp2, is_adp3;
  446. gboolean is_sign, is_batt, is_ol, is_pmax, is_pmin, is_apo;
  447. gboolean is_dc, is_ac, is_vahz, is_min, is_max, is_rel, is_hold;
  448. gboolean is_digit4, is_ul, is_vasel, is_vbar, is_lpf1, is_lpf0, is_rmr;
  449. uint32_t baudrate;
  450. int packet_size;
  451. gboolean alt_functions, fivedigits, clampmeter, selectable_lpf;
  452. };
  453. SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
  454. SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
  455. struct sr_datafeed_analog *analog, void *info);
  456. SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
  457. SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
  458. float *floatval, struct sr_datafeed_analog *analog, void *info);
  459. SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
  460. SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
  461. float *floatval, struct sr_datafeed_analog *analog, void *info);
  462. SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
  463. SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
  464. float *floatval, struct sr_datafeed_analog *analog, void *info);
  465. SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
  466. SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
  467. struct sr_datafeed_analog *analog, void *info);
  468. SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
  469. SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
  470. struct sr_datafeed_analog *analog, void *info);
  471. SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
  472. SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
  473. float *floatval, struct sr_datafeed_analog *analog, void *info);
  474. /*--- hardware/common/dmm/fs9922.c ------------------------------------------*/
  475. #define FS9922_PACKET_SIZE 14
  476. struct fs9922_info {
  477. gboolean is_auto, is_dc, is_ac, is_rel, is_hold, is_bpn, is_z1, is_z2;
  478. gboolean is_max, is_min, is_apo, is_bat, is_nano, is_z3, is_micro;
  479. gboolean is_milli, is_kilo, is_mega, is_beep, is_diode, is_percent;
  480. gboolean is_z4, is_volt, is_ampere, is_ohm, is_hfe, is_hertz, is_farad;
  481. gboolean is_celsius, is_fahrenheit;
  482. int bargraph_sign, bargraph_value;
  483. };
  484. SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
  485. SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
  486. struct sr_datafeed_analog *analog, void *info);
  487. SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
  488. /*--- hardware/common/dmm/fs9721.c ------------------------------------------*/
  489. #define FS9721_PACKET_SIZE 14
  490. struct fs9721_info {
  491. gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
  492. gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
  493. gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
  494. gboolean is_c2c1_11, is_c2c1_10, is_c2c1_01, is_c2c1_00, is_sign;
  495. };
  496. SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
  497. SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
  498. struct sr_datafeed_analog *analog, void *info);
  499. SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
  500. SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
  501. SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
  502. SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
  503. SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
  504. /*--- hardware/common/dmm/m2110.c -----------------------------------------*/
  505. #define BBCGM_M2110_PACKET_SIZE 9
  506. SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
  507. SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
  508. struct sr_datafeed_analog *analog, void *info);
  509. /*--- hardware/common/dmm/metex14.c -----------------------------------------*/
  510. #define METEX14_PACKET_SIZE 14
  511. struct metex14_info {
  512. gboolean is_ac, is_dc, is_resistance, is_capacity, is_temperature;
  513. gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
  514. gboolean is_hertz, is_ohm, is_celsius, is_pico, is_nano, is_micro;
  515. gboolean is_milli, is_kilo, is_mega, is_gain, is_decibel, is_hfe;
  516. gboolean is_unitless, is_logic;
  517. };
  518. #ifdef HAVE_LIBSERIALPORT
  519. SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
  520. #endif
  521. SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
  522. SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
  523. struct sr_datafeed_analog *analog, void *info);
  524. /*--- hardware/common/dmm/rs9lcd.c ------------------------------------------*/
  525. #define RS9LCD_PACKET_SIZE 9
  526. /* Dummy info struct. The parser does not use it. */
  527. struct rs9lcd_info { int dummy; };
  528. SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
  529. SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
  530. struct sr_datafeed_analog *analog, void *info);
  531. #endif