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.
 
 
 

145 lines
4.1 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. {
  17. double unipolarSlope[4];
  18. double unipolarOffset[4];
  19. double bipolarSlope;
  20. double bipolarOffset;
  21. double DACSlope[2];
  22. double DACOffset[2];
  23. double tempSlope;
  24. double tempSlopeLow;
  25. double calTemp;
  26. double Vref;
  27. double VrefDiv2;
  28. double VsSlope;
  29. double hiResUnipolarSlope;
  30. double hiResUnipolarOffset;
  31. double hiResBipolarSlope;
  32. double hiResBipolarOffset;
  33. };
  34. /* Comm config */
  35. struct ue9CommConfig
  36. {
  37. uint8_t local_id;
  38. uint8_t power_level;
  39. in_addr_t address;
  40. in_addr_t gateway;
  41. in_addr_t subnet;
  42. in_port_t portA;
  43. in_port_t portB;
  44. uint8_t dhcp_enabled;
  45. uint8_t product_id;
  46. uint8_t mac_address[6];
  47. double hw_version;
  48. double comm_fw_version;
  49. };
  50. /* Control config */
  51. struct ue9ControlConfig
  52. {
  53. uint8_t power_level;
  54. uint8_t reset_source;
  55. double control_fw_version;
  56. double control_bl_version;
  57. uint8_t hires;
  58. uint8_t fio_dir;
  59. uint8_t fio_state;
  60. uint8_t eio_dir;
  61. uint8_t eio_state;
  62. uint8_t cio_dirstate;;
  63. uint8_t mio_dirstate;
  64. uint16_t dac0;
  65. uint16_t dac1;
  66. };
  67. #define UE9_UNIPOLAR_GAIN1 0x00
  68. #define UE9_UNIPOLAR_GAIN2 0x01
  69. #define UE9_UNIPOLAR_GAIN4 0x02
  70. #define UE9_UNIPOLAR_GAIN8 0x03
  71. #define UE9_BIPOLAR_GAIN1 0x08
  72. #define UE9_CHANNELS 14
  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. /* Stream data and pass it to the data callback. If callback returns
  116. negative, stops reading and returns 0. Returns < 0 on error. */
  117. typedef int (*ue9_stream_cb_t) (int channels, uint16_t * data, void *context);
  118. int ue9_stream_data (int fd, int channels,
  119. ue9_stream_cb_t callback, void *context);
  120. #endif