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.
 
 
 

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