AHP® XC Correlators API
AHP XC Correlators
ahp_xc.h
1 
20 #ifndef _AHP_XC_H
21 #define _AHP_XC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 #ifdef _WIN32
27 #define DLL_EXPORT __declspec(dllexport)
28 #else
29 #define DLL_EXPORT extern
30 #endif
31 
32 #include <unistd.h>
33 #include <stdint.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 
68 #ifndef AHP_DEBUG
69 #define AHP_DEBUG
70 #define AHP_DEBUG_INFO 0
71 #define AHP_DEBUG_ERROR 1
72 #define AHP_DEBUG_WARNING 2
73 #define AHP_DEBUG_DEBUG 3
78 DLL_EXPORT void ahp_set_debug_level(int32_t value);
83 DLL_EXPORT int32_t ahp_get_debug_level();
88 DLL_EXPORT void ahp_set_app_name(char* name);
93 DLL_EXPORT char* ahp_get_app_name();
98 DLL_EXPORT void ahp_set_stdout(FILE *f);
103 DLL_EXPORT void ahp_set_stderr(FILE *f);
104 #endif
105 
112 #define AHP_XC_VERSION 0x141
114 #define XC_BASE_RATE ((int)57600)
116 #define XC_HIGH_RATE ((int)2000000)
118 #define AHP_XC_PLL_FREQUENCY 400000000
120 #define AHP_XC_LEDS_MASK 0x3
121 
127 typedef enum {
137 
141 typedef enum {
142  R_BASE = 0,
143  R_BASEX2 = 1,
144  R_BASEX4 = 2,
145  R_BASEX8 = 3,
146  R_BASEX16 = 4,
147 } baud_rate;
148 
153 typedef enum {
155 CLEAR = 0,
169 ENABLE_CAPTURE = 13
171 
175 typedef enum {
187 CAP_ALL = 0xf,
189 
193 typedef enum {
197 SCAN_AUTO = 1<<1,
199 SCAN_CROSS = 1<<2,
201 TEST_BCM = 1<<3,
203 TEST_STEP = 7<<5,
205 TEST_ALL = 0xf,
206 } xc_test_flags;
207 
211 typedef struct {
213 double lag;
215 int64_t real;
217 int64_t imaginary;
219 uint64_t counts;
221 double magnitude;
223 double phase;
225 
229 typedef struct {
231 uint32_t index;
233 off_t start;
235 size_t len;
237 size_t step;
239 off_t cur_chan;
241 
245 typedef struct {
247 double lag;
249 uint64_t lag_size;
252 } ahp_xc_sample;
253 
257 typedef struct {
259 double timestamp;
261 uint64_t n_lines;
263 uint64_t n_baselines;
265 uint64_t tau;
267 uint64_t bps;
269 uint64_t cross_lag;
271 uint64_t auto_lag;
273 uint64_t* counts;
279 void *lock;
281 const char* buf;
282 } ahp_xc_packet;
283 
297 DLL_EXPORT double* ahp_xc_get_2d_projection(double alt, double az, double *baseline);
298 DLL_EXPORT uint64_t ahp_xc_max_threads(uint64_t value);
304 
318 DLL_EXPORT int32_t ahp_xc_connect(const char *port, int32_t high_rate);
319 
325 DLL_EXPORT int32_t ahp_xc_connect_fd(int32_t fd);
326 
331 DLL_EXPORT int32_t ahp_xc_get_fd();
332 
337 DLL_EXPORT void ahp_xc_disconnect(void);
338 
346 DLL_EXPORT uint32_t ahp_xc_is_connected(void);
347 
355 DLL_EXPORT uint32_t ahp_xc_is_detected(void);
356 
361 DLL_EXPORT int32_t ahp_xc_get_baudrate(void);
362 
367 DLL_EXPORT void ahp_xc_set_baudrate(baud_rate rate);
368 
373 DLL_EXPORT void ahp_xc_set_correlation_order(uint32_t order);
374 
379 DLL_EXPORT int32_t ahp_xc_get_correlation_order();
390 DLL_EXPORT int32_t ahp_xc_get_properties(void);
391 
396 DLL_EXPORT char* ahp_xc_get_header(void);
397 
402 DLL_EXPORT uint32_t ahp_xc_get_bps(void);
403 
408 DLL_EXPORT uint32_t ahp_xc_get_nlines(void);
409 
414 DLL_EXPORT uint32_t ahp_xc_get_nbaselines(void);
415 
422 DLL_EXPORT int32_t ahp_xc_get_crosscorrelation_index(int32_t *lines, int32_t order);
423 
430 DLL_EXPORT int32_t ahp_xc_get_line_index(int32_t idx, int32_t order);
431 
437 DLL_EXPORT uint32_t ahp_xc_get_nbaseprisms(int32_t order);
438 
443 DLL_EXPORT uint32_t ahp_xc_get_delaysize(void);
444 
449 DLL_EXPORT uint32_t ahp_xc_get_autocorrelator_lagsize(void);
450 
455 DLL_EXPORT uint32_t ahp_xc_get_crosscorrelator_lagsize(void);
456 
461 DLL_EXPORT double ahp_xc_get_frequency(void);
462 
467 DLL_EXPORT double ahp_xc_get_sampletime(void);
468 
473 DLL_EXPORT double ahp_xc_get_packettime(void);
474 
479 DLL_EXPORT uint32_t ahp_xc_get_packetsize(void);
480 
485 DLL_EXPORT void ahp_xc_enable_intensity_crosscorrelator(int32_t enable);
486 
492 
497 DLL_EXPORT void ahp_xc_enable_crosscorrelator(int32_t enable);
498 
503 DLL_EXPORT int32_t ahp_xc_has_crosscorrelator(void);
504 
509 DLL_EXPORT int32_t ahp_xc_has_psu(void);
510 
515 DLL_EXPORT int32_t ahp_xc_has_leds(void);
516 
521 DLL_EXPORT int32_t ahp_xc_has_cumulative_only();
522 
534 
540 
545 DLL_EXPORT void ahp_xc_free_packet(ahp_xc_packet *packet);
546 
557 DLL_EXPORT ahp_xc_sample *ahp_xc_alloc_samples(uint64_t nlines, size_t size);
558 
570 DLL_EXPORT ahp_xc_sample *ahp_xc_copy_samples(ahp_xc_sample* src, uint64_t nlines, size_t size);
571 
581 DLL_EXPORT void ahp_xc_free_samples(uint64_t nlines, ahp_xc_sample *samples);
582 
593 DLL_EXPORT int32_t ahp_xc_get_packet(ahp_xc_packet *packet);
594 
602 DLL_EXPORT void ahp_xc_start_autocorrelation_scan(uint32_t index, off_t start, size_t size, size_t step);
603 
608 DLL_EXPORT void ahp_xc_end_autocorrelation_scan(uint32_t index);
609 
621 DLL_EXPORT int32_t ahp_xc_scan_autocorrelations(ahp_xc_scan_request *lines, uint32_t nlines, ahp_xc_sample **autocorrelations, int32_t *interrupt, double *percent);
622 
630 DLL_EXPORT void ahp_xc_start_crosscorrelation_scan(uint32_t index, off_t start, size_t size, size_t step);
631 
636 DLL_EXPORT void ahp_xc_end_crosscorrelation_scan(uint32_t index);
637 
649 DLL_EXPORT int32_t ahp_xc_scan_crosscorrelations(ahp_xc_scan_request *lines, uint32_t nlines, ahp_xc_sample **crosscorrelations, int32_t *interrupt, double *percent);
650 
661 DLL_EXPORT int32_t ahp_xc_set_capture_flags(xc_capture_flags flags);
662 
668 
674 DLL_EXPORT void ahp_xc_set_leds(uint32_t index, int32_t leds);
675 
683 DLL_EXPORT void ahp_xc_set_channel_cross(uint32_t index, off_t value, size_t size, size_t step);
684 
692 DLL_EXPORT void ahp_xc_set_channel_auto(uint32_t index, off_t value, size_t size, size_t step);
693 
698 DLL_EXPORT void ahp_xc_set_frequency_divider(unsigned char value);
699 
705 DLL_EXPORT void ahp_xc_set_voltage(uint32_t index, unsigned char value);
706 
712 DLL_EXPORT void ahp_xc_set_test_flags(uint32_t index, int32_t test);
713 
719 DLL_EXPORT unsigned char ahp_xc_get_test_flags(uint32_t index);
720 
726 DLL_EXPORT unsigned char ahp_xc_get_leds(uint32_t index);
727 
732 DLL_EXPORT void ahp_xc_select_input(uint32_t index);
733 
738 DLL_EXPORT uint32_t ahp_xc_current_input();
739 
746 DLL_EXPORT int32_t ahp_xc_send_command(xc_cmd cmd, unsigned char value);
747 
752 DLL_EXPORT inline uint32_t ahp_xc_get_version(void) { return AHP_XC_VERSION; }
753 
756 #ifdef __cplusplus
757 } // extern "C"
758 #endif
759 
760 #endif //_AHP_XC_H
DLL_EXPORT void ahp_xc_set_test_flags(uint32_t index, int32_t test)
Enable tests on the current line.
DLL_EXPORT void ahp_xc_set_voltage(uint32_t index, unsigned char value)
Set the supply voltage on the current line.
DLL_EXPORT unsigned char ahp_xc_get_test_flags(uint32_t index)
Get the current status of the test features.
DLL_EXPORT void ahp_xc_select_input(uint32_t index)
Select the input on which to issue next command.
DLL_EXPORT int32_t ahp_xc_send_command(xc_cmd cmd, unsigned char value)
Send an arbitrary command to the AHP XC device.
DLL_EXPORT void ahp_xc_set_leds(uint32_t index, int32_t leds)
Switch on or off the led lines of the correlator.
DLL_EXPORT void ahp_xc_set_channel_cross(uint32_t index, off_t value, size_t size, size_t step)
Set the channel of the selected input (for cross-correlation)
DLL_EXPORT int32_t ahp_xc_set_capture_flags(xc_capture_flags flags)
Set integration flags.
DLL_EXPORT uint32_t ahp_xc_get_version(void)
Obtain the current libahp-xc version.
Definition: ahp_xc.h:752
DLL_EXPORT unsigned char ahp_xc_get_leds(uint32_t index)
Get the current status of the leds on line.
DLL_EXPORT xc_capture_flags ahp_xc_get_capture_flags()
Get integration flags.
DLL_EXPORT void ahp_xc_set_frequency_divider(unsigned char value)
Set the clock divider for autocorrelation and crosscorrelation.
DLL_EXPORT uint32_t ahp_xc_current_input()
Returns the currently selected input on which next command will be issued.
DLL_EXPORT void ahp_xc_set_channel_auto(uint32_t index, off_t value, size_t size, size_t step)
Set the channel of the selected input (for auto-correlation)
DLL_EXPORT int32_t ahp_xc_connect_fd(int32_t fd)
Connect to a serial port or other stream associated to the given file descriptor.
DLL_EXPORT int32_t ahp_xc_get_correlation_order()
Get the crosscorrelation order.
DLL_EXPORT void ahp_xc_disconnect(void)
Disconnect from the serial port or descriptor opened with ahp_xc_connect.
DLL_EXPORT void ahp_xc_set_correlation_order(uint32_t order)
Set the crosscorrelation order.
DLL_EXPORT int32_t ahp_xc_get_fd()
Obtain the serial port file descriptor.
DLL_EXPORT uint32_t ahp_xc_is_detected(void)
Report if a correlator was detected.
DLL_EXPORT void ahp_xc_set_baudrate(baud_rate rate)
Obtain the current baud rate.
DLL_EXPORT uint32_t ahp_xc_is_connected(void)
Report connection status.
DLL_EXPORT int32_t ahp_xc_connect(const char *port, int32_t high_rate)
Connect to a serial port.
DLL_EXPORT int32_t ahp_xc_get_baudrate(void)
Obtain the current baud rate.
DLL_EXPORT ahp_xc_packet * ahp_xc_alloc_packet(void)
Allocate and return a packet structure.
DLL_EXPORT void ahp_xc_end_autocorrelation_scan(uint32_t index)
End an autocorrelation scan.
DLL_EXPORT ahp_xc_packet * ahp_xc_copy_packet(ahp_xc_packet *packet)
Allocate and return a copy of a packet structure.
DLL_EXPORT void ahp_xc_start_crosscorrelation_scan(uint32_t index, off_t start, size_t size, size_t step)
Initiate a crosscorrelation scan.
DLL_EXPORT ahp_xc_sample * ahp_xc_alloc_samples(uint64_t nlines, size_t size)
Allocate and return a samples array.
DLL_EXPORT void ahp_xc_end_crosscorrelation_scan(uint32_t index)
End a crosscorrelation scan.
DLL_EXPORT int32_t ahp_xc_scan_autocorrelations(ahp_xc_scan_request *lines, uint32_t nlines, ahp_xc_sample **autocorrelations, int32_t *interrupt, double *percent)
Scan all available delay channels and get autocorrelations of each input.
DLL_EXPORT void ahp_xc_start_autocorrelation_scan(uint32_t index, off_t start, size_t size, size_t step)
Initiate an autocorrelation scan.
DLL_EXPORT int32_t ahp_xc_scan_crosscorrelations(ahp_xc_scan_request *lines, uint32_t nlines, ahp_xc_sample **crosscorrelations, int32_t *interrupt, double *percent)
Scan all available delay channels and get crosscorrelations of each input with others.
DLL_EXPORT int32_t ahp_xc_get_packet(ahp_xc_packet *packet)
Grab a data packet.
DLL_EXPORT ahp_xc_sample * ahp_xc_copy_samples(ahp_xc_sample *src, uint64_t nlines, size_t size)
Allocate and return a copy of the passed samples array.
DLL_EXPORT void ahp_xc_free_packet(ahp_xc_packet *packet)
Free a previously allocated packet structure.
DLL_EXPORT void ahp_xc_free_samples(uint64_t nlines, ahp_xc_sample *samples)
Free a previously allocated samples array.
DLL_EXPORT void ahp_set_app_name(char *name)
set the application name
DLL_EXPORT void ahp_set_debug_level(int32_t value)
set the debug level
DLL_EXPORT char * ahp_get_app_name()
get the application name
DLL_EXPORT void ahp_set_stderr(FILE *f)
set the error log stream
DLL_EXPORT int32_t ahp_get_debug_level()
get the debug level
DLL_EXPORT void ahp_set_stdout(FILE *f)
set the output log stream
#define AHP_XC_VERSION
This library version.
Definition: ahp_xc.h:112
DLL_EXPORT int32_t ahp_xc_has_crosscorrelator(void)
Returns the cross-correlation capability of the device.
DLL_EXPORT uint32_t ahp_xc_get_nbaselines(void)
Obtain the correlator total baselines.
DLL_EXPORT int32_t ahp_xc_get_properties(void)
Probe for a correlator and take its properties.
DLL_EXPORT uint32_t ahp_xc_get_packetsize(void)
Obtain the serial packet size.
DLL_EXPORT double ahp_xc_get_frequency(void)
Obtain the correlator maximum readout frequency.
DLL_EXPORT int32_t ahp_xc_intensity_crosscorrelator_enabled()
Return non-zero if intensity crosscorrelation was enabled.
DLL_EXPORT uint32_t ahp_xc_get_crosscorrelator_lagsize(void)
Obtain the correlator lag buffer size for crosscorrelations.
DLL_EXPORT uint32_t ahp_xc_get_bps(void)
Obtain the correlator bits per sample.
DLL_EXPORT int32_t ahp_xc_has_psu(void)
Returns if the device offers internal PSU line.
DLL_EXPORT int32_t ahp_xc_has_cumulative_only()
Returns if the device has cumulative correlators only.
DLL_EXPORT int32_t ahp_xc_get_crosscorrelation_index(int32_t *lines, int32_t order)
Return the cross-correlation index of the baseprism correlating the lines array.
DLL_EXPORT double ahp_xc_get_sampletime(void)
Obtain the sampling time.
DLL_EXPORT uint32_t ahp_xc_get_delaysize(void)
Obtain the correlator maximum delay value.
DLL_EXPORT double ahp_xc_get_packettime(void)
Obtain the serial packet transmission time.
DLL_EXPORT uint32_t ahp_xc_get_nbaseprisms(int32_t order)
Obtain the correlator total baseprisms for arbitrary degree of coherence orders.
DLL_EXPORT uint32_t ahp_xc_get_nlines(void)
Obtain the correlator number of lines.
DLL_EXPORT char * ahp_xc_get_header(void)
Obtain the correlator header.
DLL_EXPORT void ahp_xc_enable_crosscorrelator(int32_t enable)
Enable the cross-correlation capability of the device.
DLL_EXPORT void ahp_xc_enable_intensity_crosscorrelator(int32_t enable)
Enable the intensity cross-correlation feature.
DLL_EXPORT int32_t ahp_xc_get_line_index(int32_t idx, int32_t order)
Return the cross-correlation index of the baseprism correlating the lines array.
DLL_EXPORT uint32_t ahp_xc_get_autocorrelator_lagsize(void)
Obtain the correlator lag buffer size for autocorrelations.
DLL_EXPORT int32_t ahp_xc_has_leds(void)
Returns if the device has led lines to drive.
xc_header_flags
AHP XC header flags.
Definition: ahp_xc.h:127
xc_cmd
The XC firmare commands.
Definition: ahp_xc.h:153
baud_rate
Baud rate multipliers.
Definition: ahp_xc.h:141
xc_test_flags
The XC firmware commands.
Definition: ahp_xc.h:193
xc_capture_flags
The XC capture flags.
Definition: ahp_xc.h:175
@ HAS_CUMULATIVE_ONLY
Indicates that the correlator has cumulative correlators only.
Definition: ahp_xc.h:135
@ HAS_PSU
Indicates that the correlator has an internal PSU PWM driver on 2nd flag bit.
Definition: ahp_xc.h:133
@ HAS_CROSSCORRELATOR
Indicates that the correlator can cross-correlate its inputs.
Definition: ahp_xc.h:129
@ HAS_LEDS
Indicates if the correlator has led lines available to drive.
Definition: ahp_xc.h:131
@ SET_INDEX
Set the current input line index for following commands.
Definition: ahp_xc.h:157
@ CLEAR
Clear autocorrelation and crosscorrelation delays.
Definition: ahp_xc.h:155
@ ENABLE_TEST
Enables tests on current input.
Definition: ahp_xc.h:167
@ SET_VOLTAGE
Set the indexed input voltage, requires HAS_PSU in header.
Definition: ahp_xc.h:163
@ SET_LEDS
Set on or off current line leds, requires HAS_LEDS.
Definition: ahp_xc.h:159
@ SET_DELAY
Set the autocorrelator or crosscorrelator delay.
Definition: ahp_xc.h:165
@ SET_BAUD_RATE
Set the readout and command baud rate.
Definition: ahp_xc.h:161
@ ENABLE_CAPTURE
Enable capture flags.
Definition: ahp_xc.h:169
@ TEST_ALL
All tests enabled.
Definition: ahp_xc.h:205
@ SCAN_AUTO
Autocorrelator continuum scan.
Definition: ahp_xc.h:197
@ TEST_STEP
Set channel scan step.
Definition: ahp_xc.h:203
@ TEST_NONE
No extra signals or functions.
Definition: ahp_xc.h:195
@ SCAN_CROSS
Crosscorrelator continuum scan.
Definition: ahp_xc.h:199
@ TEST_BCM
BCM modulation on voltage led.
Definition: ahp_xc.h:201
@ CAP_EXTRA_CMD
Enable extra commands.
Definition: ahp_xc.h:185
@ CAP_RESET_TIMESTAMP
Reset timestamp.
Definition: ahp_xc.h:183
@ CAP_ALL
All flags enabled.
Definition: ahp_xc.h:187
@ CAP_ENABLE
Enable capture.
Definition: ahp_xc.h:179
@ CAP_EXT_CLK
Enable external clock.
Definition: ahp_xc.h:181
@ CAP_NONE
No extra signals or functions.
Definition: ahp_xc.h:177
DLL_EXPORT double * ahp_xc_get_2d_projection(double alt, double az, double *baseline)
Get 2d projection for intensity interferometry.
DLL_EXPORT uint64_t ahp_xc_max_threads(uint64_t value)
Set or get the maximum number of concurrent threads.
Correlations structure.
Definition: ahp_xc.h:211
double lag
Time lag offset.
Definition: ahp_xc.h:213
int64_t imaginary
Q samples count.
Definition: ahp_xc.h:217
double phase
Phase of this sample.
Definition: ahp_xc.h:223
uint64_t counts
Pulses count.
Definition: ahp_xc.h:219
double magnitude
Magnitude of this sample.
Definition: ahp_xc.h:221
int64_t real
I samples count.
Definition: ahp_xc.h:215
Packet structure.
Definition: ahp_xc.h:257
uint64_t n_lines
Number of lines in this correlator.
Definition: ahp_xc.h:261
uint64_t n_baselines
Total number of baselines obtainable.
Definition: ahp_xc.h:263
uint64_t bps
Bits capacity in each sample.
Definition: ahp_xc.h:267
uint64_t auto_lag
Autocorrelators channels per packet.
Definition: ahp_xc.h:271
const char * buf
Packet buffer string.
Definition: ahp_xc.h:281
void * lock
Packet lock mutex.
Definition: ahp_xc.h:279
ahp_xc_sample * crosscorrelations
Crosscorrelations in the current packet.
Definition: ahp_xc.h:277
double timestamp
Timestamp of the packet (seconds)
Definition: ahp_xc.h:259
uint64_t tau
Bandwidth inverse frequency.
Definition: ahp_xc.h:265
ahp_xc_sample * autocorrelations
Autocorrelations in the current packet.
Definition: ahp_xc.h:275
uint64_t * counts
Counts in the current packet.
Definition: ahp_xc.h:273
uint64_t cross_lag
Crosscorrelators channels per packet.
Definition: ahp_xc.h:269
Sample structure.
Definition: ahp_xc.h:245
ahp_xc_correlation * correlations
Correlations array, of size lag_size in an ahp_xc_packet.
Definition: ahp_xc.h:251
double lag
Lag offset from sample time.
Definition: ahp_xc.h:247
uint64_t lag_size
Maximum lag in a single shot.
Definition: ahp_xc.h:249
Scan request structure.
Definition: ahp_xc.h:229
off_t cur_chan
Current channel.
Definition: ahp_xc.h:239
size_t step
Separation between channels.
Definition: ahp_xc.h:237
off_t start
Start channel.
Definition: ahp_xc.h:233
uint32_t index
Line index.
Definition: ahp_xc.h:231
size_t len
Number of channels.
Definition: ahp_xc.h:235