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.
 
 
 

148 lines
4.2 KiB

  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. #define UE9_UNIPOLAR_GAIN1 0x00
  65. #define UE9_UNIPOLAR_GAIN2 0x01
  66. #define UE9_UNIPOLAR_GAIN4 0x02
  67. #define UE9_UNIPOLAR_GAIN8 0x03
  68. #define UE9_BIPOLAR_GAIN1 0x08
  69. #define UE9_MAX_CHANNEL_COUNT 128
  70. #define UE9_MAX_CHANNEL 255
  71. #define UE9_MAX_ANALOG_CHANNEL 13
  72. #define UE9_TIMERS 6
  73. /* Fill checksums in data buffers */
  74. void ue9_checksum_normal(uint8_t * buffer, size_t len);
  75. void ue9_checksum_extended(uint8_t * buffer, size_t len);
  76. /* Verify checksums in data buffers. Returns 0 on error. */
  77. int ue9_verify_normal(uint8_t * buffer, size_t len);
  78. int ue9_verify_extended(uint8_t * buffer, size_t len);
  79. /* Open/close TCP/IP connection to the UE9 */
  80. int ue9_open(const char *host, int port);
  81. void ue9_close(int fd);
  82. /* Read a memory block from the device. Returns -1 on error. */
  83. int ue9_memory_read(int fd, int blocknum, uint8_t * buffer, int len);
  84. /* Convert 64-bit fixed point to double type */
  85. double ue9_fp64_to_double(uint8_t * data);
  86. /* Retrieve calibration data or configuration from the device */
  87. int ue9_get_calibration(int fd, struct ue9Calibration *calib);
  88. int ue9_get_comm_config(int fd, struct ue9CommConfig *config);
  89. int ue9_get_control_config(int fd, struct ue9ControlConfig *config);
  90. /* Data conversion. If calib is NULL, use uncalibrated conversions. */
  91. double ue9_binary_to_analog(struct ue9Calibration *calib,
  92. uint8_t gain, uint8_t resolution, uint16_t data);
  93. /* Compute scanrate based on the provided values. */
  94. double ue9_compute_rate(uint8_t scanconfig, uint16_t scaninterval);
  95. /* Choose the best ScanConfig and ScanInterval parameters for the
  96. desired scanrate. Returns 0 if nothing can be chosen. */
  97. int ue9_choose_scan(double desired_rate, double *actual_rate,
  98. uint8_t * scanconfig, uint16_t * scaninterval);
  99. /* Flush data buffers */
  100. void ue9_buffer_flush(int fd);
  101. /* Stop stream. Returns < 0 on failure. */
  102. int ue9_stream_stop(int fd);
  103. /* Start stream. Returns < 0 on failure. */
  104. int ue9_stream_start(int fd);
  105. /* Execute a command on the UE9. Returns -1 on error. Fills the
  106. checksums on the outgoing packets, and verifies them on the
  107. incoming packets. Data in "out" is transmitted, data in "in" is
  108. received. */
  109. int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen);
  110. /* "Simple" stream configuration, assumes the channels are all
  111. configured with the same gain. */
  112. int ue9_streamconfig_simple(int fd, int *channel_list, int channel_count,
  113. uint8_t scanconfig, uint16_t scaninterval,
  114. uint8_t gain);
  115. /* Timer configuration */
  116. int ue9_timer_config(int fd, int *mode_list, int mode_count, int divisor);
  117. /* Stream data and pass it to the data callback. If callback returns
  118. negative, stops reading and returns 0. Returns < 0 on error. */
  119. typedef int (*ue9_stream_cb_t) (int channels, uint16_t * data, void *context);
  120. int ue9_stream_data(int fd, int channels,
  121. ue9_stream_cb_t callback, void *context);
  122. #endif