es51984.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef ES51984_H_
  2. #define ES51984_H_
  3. /* Cyrustek ES 51984 digital multimeter RS232 signal interpreter. */
  4. /** struct es51984 - ES51984 device data structure.
  5. * This structure is opaque to the API user. */
  6. struct es51984;
  7. /** enum es51984_board_type - The board type the chip is soldered onto.
  8. */
  9. enum es51984_board_type {
  10. ES51984_BOARD_UNKNOWN,
  11. ES51984_BOARD_AMPROBE_35XPA, /* The Amprobe 35XP-A multimeter */
  12. };
  13. #define ES51984_PACK(value) ((0x30 | (value)) & 0x7F)
  14. /** enum es51984_func - The active device function */
  15. enum es51984_func {
  16. ES51984_FUNC_VOLTAGE = ES51984_PACK(0xB), /* Voltage measurement */
  17. ES51984_FUNC_UA_CURRENT = ES51984_PACK(0xD), /* Micro-amps current measurement */
  18. ES51984_FUNC_MA_CURRENT = ES51984_PACK(0xF), /* Milli-amps current measurement */
  19. ES51984_FUNC_AUTO_CURRENT = ES51984_PACK(0x0), /* Auto current measurement */
  20. ES51984_FUNC_MAN_CURRENT = ES51984_PACK(0x9), /* Manual current measurement */
  21. ES51984_FUNC_OHMS = ES51984_PACK(0x3), /* Resistance measurement */
  22. ES51984_FUNC_CONT = ES51984_PACK(0x5), /* Continuity measurement */
  23. ES51984_FUNC_DIODE = ES51984_PACK(0x1), /* Diode measurement */
  24. ES51984_FUNC_FREQUENCY = ES51984_PACK(0x2), /* Frequency measurement */
  25. ES51984_FUNC_CAPACITOR = ES51984_PACK(0x6), /* Capacitor measurement */
  26. ES51984_FUNC_TEMP = ES51984_PACK(0x4), /* Temperature measurement */
  27. ES51984_FUNC_ADP0 = ES51984_PACK(0xE), /* ADP0 */
  28. ES51984_FUNC_ADP1 = ES51984_PACK(0xC), /* ADP1 */
  29. ES51984_FUNC_ADP2 = ES51984_PACK(0x8), /* ADP2 */
  30. ES51984_FUNC_ADP3 = ES51984_PACK(0xA), /* ADP3 */
  31. };
  32. /** struct es51984_sample - Data sample of a measurement.
  33. *
  34. * @function: The active device function.
  35. * @value: The measured value.
  36. * @dc_mode: Boolean. DC or AC mode.
  37. * @auto_mode: Boolean. Automatic or manual mode.
  38. * @overflow: Boolean. Overflow condition present.
  39. * @degree: Boolean. Degree or Farenheit. Only for FUNC_TEMP.
  40. * @batt_low: Boolean. Battery low condition.
  41. * @hold: Boolean. Hold is activated. This does not influence the measurement.
  42. */
  43. struct es51984_sample {
  44. enum es51984_func function;
  45. double value;
  46. int dc_mode;
  47. int auto_mode;
  48. int overflow;
  49. int degree;
  50. int batt_low;
  51. int hold;
  52. enum es51984_board_type board;
  53. };
  54. /** es51984_get_units - Get units identifier string for the value of a sample.
  55. * @sample: The sample.
  56. */
  57. const char * es51984_get_units(const struct es51984_sample *sample);
  58. /** es51984_get_sample - Read a sample.
  59. *
  60. * Returns zero on success, or a negative error on failure.
  61. * If non-blocking and no sample is available, returns -EAGAIN.
  62. * Returns -EPIPE, if synchronization was lost. es51984_sync() must
  63. * be called to resolve this error condition.
  64. *
  65. * @es: The interface.
  66. * @sample: Pointer to the sample buffer.
  67. * @blocking: If true, block until a sample arrives.
  68. * @debug: If true, enable debug messages.
  69. */
  70. int es51984_get_sample(struct es51984 *es,
  71. struct es51984_sample *sample,
  72. int blocking,
  73. int debug);
  74. /** es51984_discard - Discard all pending samples
  75. *
  76. * This will discard all pending samples from the input buffer.
  77. * Returns -EPIPE, if the interface is not synchronized.
  78. *
  79. * @es: The interface.
  80. */
  81. int es51984_discard(struct es51984 *es);
  82. /** es51984_sync - Sync to the device.
  83. *
  84. * This will discard all pending samples and resynchronize
  85. * to the datastream. This must be called before requesting a sample.
  86. *
  87. * @es: The interface.
  88. */
  89. int es51984_sync(struct es51984 *es);
  90. /** es51984_init - Initialize the interface.
  91. * @board: The board the device is soldered onto.
  92. * @tty: The serial TTY device node.
  93. */
  94. struct es51984 * es51984_init(enum es51984_board_type board,
  95. const char *tty);
  96. /** es51984_exit - Destroy the interface. */
  97. void es51984_exit(struct es51984 *es);
  98. #endif /* ES51984_H_ */