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 0x144
114 #define XC_BASE_RATE ((int)57600)
116 #define AHP_XC_PLL_FREQUENCY 400000000
118 #define AHP_XC_LEDS_MASK 0x3
119 
125 typedef enum {
135 
139 typedef enum {
140  R_BASE = 0,
141  R_BASEX2 = 1,
142  R_BASEX4 = 2,
143  R_BASEX8 = 3,
144  R_BASEX16 = 4,
145 } baud_rate;
146 
151 typedef enum {
153 CLEAR = 0,
167 ENABLE_CAPTURE = 13
169 
173 typedef enum {
185 CAP_ALL = 0xf,
187 
191 typedef enum {
195 SCAN_AUTO = 1<<1,
197 SCAN_CROSS = 1<<2,
199 TEST_BCM = 1<<3,
201 TEST_STEP = 3<<4,
203 TEST_ALL = 0xf,
204 } xc_test_flags;
205 
209 typedef struct {
213 int *indexes;
215 double *lags;
217 double lag;
219 int64_t real;
221 int64_t imaginary;
223 uint64_t counts;
225 double magnitude;
227 double phase;
229 
233 typedef struct {
235 uint32_t index;
237 off_t start;
239 size_t len;
241 size_t step;
243 off_t cur_chan;
245 
249 typedef struct {
251 double lag;
253 uint64_t lag_size;
256 } ahp_xc_sample;
257 
261 typedef struct {
263 double timestamp;
265 uint64_t n_lines;
267 uint64_t n_baselines;
269 uint64_t tau;
271 uint64_t bps;
273 uint64_t cross_lag;
275 uint64_t auto_lag;
277 uint64_t* counts;
283 void *lock;
285 const char* buf;
286 } ahp_xc_packet;
287 
301 DLL_EXPORT double* ahp_xc_get_2d_projection(double alt, double az, double *baseline);
302 DLL_EXPORT uint64_t ahp_xc_max_threads(uint64_t value);
308 
321 DLL_EXPORT int32_t ahp_xc_connect(const char *port);
322 
328 DLL_EXPORT int32_t ahp_xc_connect_fd(int32_t fd);
329 
334 DLL_EXPORT int32_t ahp_xc_get_fd();
335 
340 DLL_EXPORT void ahp_xc_disconnect(void);
341 
349 DLL_EXPORT uint32_t ahp_xc_is_connected(void);
350 
358 DLL_EXPORT uint32_t ahp_xc_is_detected(void);
359 
364 DLL_EXPORT int32_t ahp_xc_get_baudrate(void);
365 
370 DLL_EXPORT void ahp_xc_set_baudrate(baud_rate rate);
371 
376 DLL_EXPORT void ahp_xc_set_correlation_order(uint32_t order);
377 
382 DLL_EXPORT int32_t ahp_xc_get_correlation_order();
393 DLL_EXPORT int32_t ahp_xc_get_properties(void);
394 
399 DLL_EXPORT char* ahp_xc_get_header(void);
400 
405 DLL_EXPORT uint32_t ahp_xc_get_bps(void);
406 
411 DLL_EXPORT uint32_t ahp_xc_get_nlines(void);
412 
417 DLL_EXPORT uint32_t ahp_xc_get_nbaselines(void);
418 
425 DLL_EXPORT int32_t ahp_xc_get_crosscorrelation_index(int32_t *lines, int32_t order);
426 
433 DLL_EXPORT int32_t ahp_xc_get_line_index(int32_t idx, int32_t order);
434 
440 DLL_EXPORT uint32_t ahp_xc_get_npolytopes(int32_t order);
441 
446 DLL_EXPORT uint32_t ahp_xc_get_delaysize(void);
447 
452 DLL_EXPORT uint32_t ahp_xc_get_autocorrelator_lagsize(void);
453 
458 DLL_EXPORT uint32_t ahp_xc_get_crosscorrelator_lagsize(void);
459 
464 DLL_EXPORT double ahp_xc_get_frequency(void);
465 
470 DLL_EXPORT double ahp_xc_get_sampletime(void);
471 
476 DLL_EXPORT double ahp_xc_get_packettime(void);
477 
482 DLL_EXPORT uint32_t ahp_xc_get_packetsize(void);
483 
488 DLL_EXPORT void ahp_xc_enable_intensity_crosscorrelator(int32_t enable);
489 
495 
500 DLL_EXPORT void ahp_xc_enable_crosscorrelator(int32_t enable);
501 
506 DLL_EXPORT int32_t ahp_xc_has_crosscorrelator(void);
507 
512 DLL_EXPORT int32_t ahp_xc_has_psu(void);
513 
518 DLL_EXPORT int32_t ahp_xc_has_leds(void);
519 
524 DLL_EXPORT int32_t ahp_xc_has_cumulative_only();
525 
537 
543 
548 DLL_EXPORT void ahp_xc_free_packet(ahp_xc_packet *packet);
549 
560 DLL_EXPORT ahp_xc_sample *ahp_xc_alloc_samples(uint64_t nlines, size_t size);
561 
573 DLL_EXPORT ahp_xc_sample *ahp_xc_copy_samples(ahp_xc_sample* src, uint64_t nlines, size_t size);
574 
584 DLL_EXPORT void ahp_xc_free_samples(uint64_t nlines, ahp_xc_sample *samples);
585 
596 DLL_EXPORT int32_t ahp_xc_get_packet(ahp_xc_packet *packet);
597 
602 DLL_EXPORT void ahp_xc_start_autocorrelation_scan(uint32_t index);
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 
627 DLL_EXPORT void ahp_xc_start_crosscorrelation_scan(uint32_t index);
628 
633 DLL_EXPORT void ahp_xc_end_crosscorrelation_scan(uint32_t index);
634 
646 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);
647 
658 DLL_EXPORT int32_t ahp_xc_set_capture_flags(xc_capture_flags flags);
659 
665 
671 DLL_EXPORT void ahp_xc_set_leds(uint32_t index, int32_t leds);
672 
680 DLL_EXPORT void ahp_xc_set_channel_cross(uint32_t index, off_t value, size_t size, size_t step);
681 
689 DLL_EXPORT void ahp_xc_set_channel_auto(uint32_t index, off_t value, size_t size, size_t step);
690 
695 DLL_EXPORT void ahp_xc_set_frequency_divider(unsigned char value);
696 
702 DLL_EXPORT void ahp_xc_set_voltage(uint32_t index, unsigned char value);
703 
709 DLL_EXPORT void ahp_xc_set_test_flags(uint32_t index, int32_t test);
710 
716 DLL_EXPORT unsigned char ahp_xc_get_test_flags(uint32_t index);
717 
723 DLL_EXPORT unsigned char ahp_xc_get_leds(uint32_t index);
724 
729 DLL_EXPORT void ahp_xc_select_input(uint32_t index);
730 
735 DLL_EXPORT uint32_t ahp_xc_current_input();
736 
743 DLL_EXPORT int32_t ahp_xc_send_command(xc_cmd cmd, unsigned char value);
744 
749 DLL_EXPORT inline uint32_t ahp_xc_get_version(void) { return AHP_XC_VERSION; }
750 
753 #ifdef __cplusplus
754 } // extern "C"
755 #endif
756 
757 #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:749
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 int32_t ahp_xc_connect(const char *port)
Connect to a serial port.
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_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_autocorrelation_scan(uint32_t index)
Initiate an autocorrelation 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_crosscorrelation_scan(uint32_t index)
Initiate a crosscorrelation 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 polytopes 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 uint32_t ahp_xc_get_npolytopes(int32_t order)
Obtain the correlator total polytopes for arbitrary degree of coherence orders.
DLL_EXPORT double ahp_xc_get_packettime(void)
Obtain the serial packet transmission time.
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 polytopes 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:125
xc_cmd
The XC firmare commands.
Definition: ahp_xc.h:151
baud_rate
Baud rate multipliers.
Definition: ahp_xc.h:139
xc_test_flags
The XC firmware commands.
Definition: ahp_xc.h:191
xc_capture_flags
The XC capture flags.
Definition: ahp_xc.h:173
@ HAS_CUMULATIVE_ONLY
Indicates that the correlator has cumulative correlators only.
Definition: ahp_xc.h:133
@ HAS_PSU
Indicates that the correlator has an internal PSU PWM driver on 2nd flag bit.
Definition: ahp_xc.h:131
@ HAS_CROSSCORRELATOR
Indicates that the correlator can cross-correlate its inputs.
Definition: ahp_xc.h:127
@ HAS_LEDS
Indicates if the correlator has led lines available to drive.
Definition: ahp_xc.h:129
@ SET_INDEX
Set the current input line index for following commands.
Definition: ahp_xc.h:155
@ CLEAR
Clear autocorrelation and crosscorrelation delays.
Definition: ahp_xc.h:153
@ ENABLE_TEST
Enables tests on current input.
Definition: ahp_xc.h:165
@ SET_VOLTAGE
Set the indexed input voltage, requires HAS_PSU in header.
Definition: ahp_xc.h:161
@ SET_LEDS
Set on or off current line leds, requires HAS_LEDS.
Definition: ahp_xc.h:157
@ SET_DELAY
Set the autocorrelator or crosscorrelator delay.
Definition: ahp_xc.h:163
@ SET_BAUD_RATE
Set the readout and command baud rate.
Definition: ahp_xc.h:159
@ ENABLE_CAPTURE
Enable capture flags.
Definition: ahp_xc.h:167
@ TEST_ALL
All tests enabled.
Definition: ahp_xc.h:203
@ SCAN_AUTO
Autocorrelator continuum scan.
Definition: ahp_xc.h:195
@ TEST_STEP
Set channel scan step.
Definition: ahp_xc.h:201
@ TEST_NONE
No extra signals or functions.
Definition: ahp_xc.h:193
@ SCAN_CROSS
Crosscorrelator continuum scan.
Definition: ahp_xc.h:197
@ TEST_BCM
BCM modulation on voltage led.
Definition: ahp_xc.h:199
@ CAP_EXTRA_CMD
Enable extra commands.
Definition: ahp_xc.h:183
@ CAP_RESET_TIMESTAMP
Reset timestamp.
Definition: ahp_xc.h:181
@ CAP_ALL
All flags enabled.
Definition: ahp_xc.h:185
@ CAP_ENABLE
Enable capture.
Definition: ahp_xc.h:177
@ CAP_EXT_CLK
Enable external clock.
Definition: ahp_xc.h:179
@ CAP_NONE
No extra signals or functions.
Definition: ahp_xc.h:175
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:209
int num_indexes
number of nodes in this correlation
Definition: ahp_xc.h:211
double lag
Time lag offset.
Definition: ahp_xc.h:217
int64_t imaginary
Q samples count.
Definition: ahp_xc.h:221
double phase
Phase of this sample.
Definition: ahp_xc.h:227
int * indexes
Indices of the nodes.
Definition: ahp_xc.h:213
uint64_t counts
Pulses count.
Definition: ahp_xc.h:223
double magnitude
Magnitude of this sample.
Definition: ahp_xc.h:225
int64_t real
I samples count.
Definition: ahp_xc.h:219
double * lags
Time locations of the nodes.
Definition: ahp_xc.h:215
Packet structure.
Definition: ahp_xc.h:261
uint64_t n_lines
Number of lines in this correlator.
Definition: ahp_xc.h:265
uint64_t n_baselines
Total number of baselines obtainable.
Definition: ahp_xc.h:267
uint64_t bps
Bits capacity in each sample.
Definition: ahp_xc.h:271
uint64_t auto_lag
Autocorrelators channels per packet.
Definition: ahp_xc.h:275
const char * buf
Packet buffer string.
Definition: ahp_xc.h:285
void * lock
Packet lock mutex.
Definition: ahp_xc.h:283
ahp_xc_sample * crosscorrelations
Crosscorrelations in the current packet.
Definition: ahp_xc.h:281
double timestamp
Timestamp of the packet (seconds)
Definition: ahp_xc.h:263
uint64_t tau
Bandwidth inverse frequency.
Definition: ahp_xc.h:269
ahp_xc_sample * autocorrelations
Autocorrelations in the current packet.
Definition: ahp_xc.h:279
uint64_t * counts
Counts in the current packet.
Definition: ahp_xc.h:277
uint64_t cross_lag
Crosscorrelators channels per packet.
Definition: ahp_xc.h:273
Sample structure.
Definition: ahp_xc.h:249
ahp_xc_correlation * correlations
Correlations array, of size lag_size in an ahp_xc_packet.
Definition: ahp_xc.h:255
double lag
Lag offset from sample time.
Definition: ahp_xc.h:251
uint64_t lag_size
Maximum lag in a single shot.
Definition: ahp_xc.h:253
Scan request structure.
Definition: ahp_xc.h:233
off_t cur_chan
Current channel.
Definition: ahp_xc.h:243
size_t step
Separation between channels.
Definition: ahp_xc.h:241
off_t start
Start channel.
Definition: ahp_xc.h:237
uint32_t index
Line index.
Definition: ahp_xc.h:235
size_t len
Number of channels.
Definition: ahp_xc.h:239