You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Labjack Tools
  3. * Copyright (c) 2003-2007 Jim Paris <jim@jtan.com>
  4. *
  5. * This is free software; you can redistribute it and/or modify it and
  6. * it is provided under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation; see COPYING.
  8. */
  9. #ifndef UE9_H
  10. #define UE9_H
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13. #include "netutil.h"
  14. /* Calibration data */
  15. struct ue9Calibration {
  16. double unipolarSlope[4];
  17. double unipolarOffset[4];
  18. double bipolarSlope;
  19. double bipolarOffset;
  20. double DACSlope[2];
  21. double DACOffset[2];
  22. double tempSlope;
  23. double tempSlopeLow;
  24. double calTemp;
  25. double Vref;
  26. double VrefDiv2;
  27. double VsSlope;
  28. double hiResUnipolarSlope;
  29. double hiResUnipolarOffset;
  30. double hiResBipolarSlope;
  31. double hiResBipolarOffset;
  32. };
  33. /* Comm config */
  34. struct ue9CommConfig {
  35. uint8_t local_id;
  36. uint8_t power_level;
  37. in_addr_t address;
  38. in_addr_t gateway;
  39. in_addr_t subnet;
  40. in_port_t portA;
  41. in_port_t portB;
  42. uint8_t dhcp_enabled;
  43. uint8_t product_id;
  44. uint8_t mac_address[6];
  45. double hw_version;
  46. double comm_fw_version;
  47. };
  48. /* Control config */
  49. struct ue9ControlConfig {
  50. uint8_t power_level;
  51. uint8_t reset_source;
  52. double control_fw_version;
  53. double control_bl_version;
  54. uint8_t hires;
  55. uint8_t fio_dir;
  56. uint8_t fio_state;
  57. uint8_t eio_dir;
  58. uint8_t eio_state;
  59. uint8_t cio_dirstate;;
  60. uint8_t mio_dirstate;
  61. uint16_t dac0;
  62. uint16_t dac1;
  63. };
  64. /* These are correct! 0, 1, 2, 3, 8 */
  65. #define UE9_UNIPOLAR_GAIN1 0x00
  66. #define UE9_UNIPOLAR_GAIN2 0x01
  67. #define UE9_UNIPOLAR_GAIN4 0x02
  68. #define UE9_UNIPOLAR_GAIN8 0x03
  69. #define UE9_BIPOLAR_GAIN1 0x08
  70. #define UE9_MAX_CHANNEL_COUNT 128
  71. #define UE9_MAX_CHANNEL 255
  72. #define UE9_MAX_ANALOG_CHANNEL 13
  73. #define UE9_TIMERS 6
  74. /* Fill checksums in data buffers */
  75. void ue9_checksum_normal(uint8_t * buffer, size_t len);
  76. void ue9_checksum_extended(uint8_t * buffer, size_t len);
  77. /* Verify checksums in data buffers. Returns 0 on error. */
  78. int ue9_verify_normal(uint8_t * buffer, size_t len);
  79. int ue9_verify_extended(uint8_t * buffer, size_t len);
  80. /* Open/close TCP/IP connection to the UE9 */
  81. int ue9_open(const char *host, int port);
  82. void ue9_close(int fd);
  83. /* Read a memory block from the device. Returns -1 on error. */
  84. int ue9_memory_read(int fd, int blocknum, uint8_t * buffer, int len);
  85. /* Convert 64-bit fixed point to double type */
  86. double ue9_fp64_to_double(uint8_t * data);
  87. /* Retrieve calibration data or configuration from the device */
  88. int ue9_get_calibration(int fd, struct ue9Calibration *calib);
  89. int ue9_get_comm_config(int fd, struct ue9CommConfig *config);
  90. int ue9_get_control_config(int fd, struct ue9ControlConfig *config);
  91. /* Data conversion. If calib is NULL, use uncalibrated conversions. */
  92. double ue9_binary_to_analog(struct ue9Calibration *calib,
  93. int gain, uint8_t resolution, uint16_t data);
  94. /* Temperature conversion. If calib is NULL, use uncalibrated conversions. */
  95. double ue9_binary_to_temperature(struct ue9Calibration *calib, uint16_t data);
  96. /* Compute scanrate based on the provided values. */
  97. double ue9_compute_rate(uint8_t scanconfig, uint16_t scaninterval);
  98. /* Choose the best ScanConfig and ScanInterval parameters for the
  99. desired scanrate. Returns 0 if nothing can be chosen. */
  100. int ue9_choose_scan(double desired_rate, double *actual_rate,
  101. uint8_t * scanconfig, uint16_t * scaninterval);
  102. /* Flush data buffers */
  103. void ue9_buffer_flush(int fd);
  104. /* Stop stream. Returns < 0 on failure. */
  105. int ue9_stream_stop(int fd);
  106. /* Start stream. Returns < 0 on failure. */
  107. int ue9_stream_start(int fd);
  108. /* Execute a command on the UE9. Returns -1 on error. Fills the
  109. checksums on the outgoing packets, and verifies them on the
  110. incoming packets. Data in "out" is transmitted, data in "in" is
  111. received. */
  112. int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen);
  113. /* "Simple" stream configuration, assumes the channels are all
  114. configured with the same gain. */
  115. int ue9_streamconfig_simple(int fd, int *channel_list, int channel_count,
  116. uint8_t scanconfig, uint16_t scaninterval,
  117. uint8_t gain);
  118. /* Stream configuration, each Analog Input channel can have its own gain. */
  119. int ue9_streamconfig(int fd, int *channel_list, int channel_count,
  120. uint8_t scanconfig, uint16_t scaninterval,
  121. int *gain_list, int gain_count);
  122. /* Timer configuration */
  123. int ue9_timer_config(int fd, int *mode_list, int *value_list, int count, int divisor);
  124. /* Stream data and pass it to the data callback. If callback returns
  125. negative, stops reading and returns 0. Returns < 0 on error. */
  126. typedef int (*ue9_stream_cb_t) (int channels, int *channel_list, int gain_count, int *gain_list, uint16_t * data, void *context);
  127. int ue9_stream_data(int fd, int channels, int *channel_list, int gain_count, int *gain_list,
  128. ue9_stream_cb_t callback, void *context);
  129. #endif