AHP® XC Correlators API
AHP XC Correlators
Loading...
Searching...
No Matches
ahp_xc.h
1
20#ifndef _AHP_XC_H
21#define _AHP_XC_H
22
23#ifdef __cplusplus
24extern "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
78DLL_EXPORT void ahp_set_debug_level(int32_t value);
83DLL_EXPORT int32_t ahp_get_debug_level();
88DLL_EXPORT void ahp_set_app_name(char* name);
93DLL_EXPORT char* ahp_get_app_name();
98DLL_EXPORT void ahp_set_stdout(FILE *f);
103DLL_EXPORT void ahp_set_stderr(FILE *f);
104#endif
105
112#define AHP_XC_VERSION 0x138
114#define XC_BASE_RATE ((int)57600)
116#define XC_HIGH_RATE ((int)230400)
118#define AHP_XC_PLL_FREQUENCY 400000000
120#define AHP_XC_LEDS_MASK 0x3
121
127typedef enum {
137
141typedef 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
153typedef enum {
171
175typedef enum {
189
193typedef enum {
201TEST_BCM = 1<<3,
207
211typedef struct {
213double lag;
215int64_t real;
217int64_t imaginary;
219uint64_t counts;
223double phase;
225
229typedef struct {
231double lag;
233uint64_t lag_size;
237
241typedef struct {
245uint64_t n_lines;
247uint64_t n_baselines;
249uint64_t tau;
251uint64_t bps;
253uint64_t cross_lag;
255uint64_t auto_lag;
257uint64_t* counts;
263void *lock;
265const char* buf;
267
281DLL_EXPORT double* ahp_xc_get_2d_projection(double alt, double az, double *baseline);
282DLL_EXPORT uint64_t ahp_xc_max_threads(uint64_t value);
288
302DLL_EXPORT int32_t ahp_xc_connect(const char *port, int32_t high_rate);
303
309DLL_EXPORT int32_t ahp_xc_connect_fd(int32_t fd);
310
315DLL_EXPORT int32_t ahp_xc_get_fd();
316
321DLL_EXPORT void ahp_xc_disconnect(void);
322
330DLL_EXPORT uint32_t ahp_xc_is_connected(void);
331
339DLL_EXPORT uint32_t ahp_xc_is_detected(void);
340
345DLL_EXPORT int32_t ahp_xc_get_baudrate(void);
346
351DLL_EXPORT void ahp_xc_set_baudrate(baud_rate rate);
352
357DLL_EXPORT void ahp_xc_set_correlation_order(uint32_t order);
358
363DLL_EXPORT int32_t ahp_xc_get_correlation_order();
374DLL_EXPORT int32_t ahp_xc_get_properties(void);
375
380DLL_EXPORT char* ahp_xc_get_header(void);
381
386DLL_EXPORT uint32_t ahp_xc_get_bps(void);
387
392DLL_EXPORT uint32_t ahp_xc_get_nlines(void);
393
398DLL_EXPORT uint32_t ahp_xc_get_nbaselines(void);
399
406DLL_EXPORT int32_t ahp_xc_get_crosscorrelation_index(int32_t *lines, int32_t order);
407
414DLL_EXPORT int32_t ahp_xc_get_line_index(int32_t idx, int32_t order);
415
421DLL_EXPORT uint32_t ahp_xc_get_nbaseprisms(int32_t order);
422
427DLL_EXPORT uint32_t ahp_xc_get_delaysize(void);
428
433DLL_EXPORT uint32_t ahp_xc_get_autocorrelator_lagsize(void);
434
439DLL_EXPORT uint32_t ahp_xc_get_crosscorrelator_lagsize(void);
440
445DLL_EXPORT double ahp_xc_get_frequency(void);
446
451DLL_EXPORT double ahp_xc_get_sampletime(void);
452
457DLL_EXPORT double ahp_xc_get_packettime(void);
458
463DLL_EXPORT uint32_t ahp_xc_get_packetsize(void);
464
469DLL_EXPORT void ahp_xc_enable_intensity_crosscorrelator(int32_t enable);
470
476
481DLL_EXPORT void ahp_xc_enable_crosscorrelator(int32_t enable);
482
487DLL_EXPORT int32_t ahp_xc_has_crosscorrelator(void);
488
493DLL_EXPORT int32_t ahp_xc_has_psu(void);
494
499DLL_EXPORT int32_t ahp_xc_has_leds(void);
500
505DLL_EXPORT int32_t ahp_xc_has_cumulative_only();
506
518
524
529DLL_EXPORT void ahp_xc_free_packet(ahp_xc_packet *packet);
530
541DLL_EXPORT ahp_xc_sample *ahp_xc_alloc_samples(uint64_t nlines, size_t size);
542
554DLL_EXPORT ahp_xc_sample *ahp_xc_copy_samples(ahp_xc_sample* src, uint64_t nlines, size_t size);
555
565DLL_EXPORT void ahp_xc_free_samples(uint64_t nlines, ahp_xc_sample *samples);
566
577DLL_EXPORT int32_t ahp_xc_get_packet(ahp_xc_packet *packet);
578
586DLL_EXPORT void ahp_xc_start_autocorrelation_scan(uint32_t index, off_t start, size_t size, size_t step);
587
592DLL_EXPORT void ahp_xc_end_autocorrelation_scan(uint32_t index);
593
608DLL_EXPORT int32_t ahp_xc_scan_autocorrelations(uint32_t nlines, uint32_t *indexes, ahp_xc_sample **autocorrelations, off_t *starts, size_t *sizes, size_t *steps, int32_t *interrupt, double *percent);
609
617DLL_EXPORT void ahp_xc_start_crosscorrelation_scan(uint32_t index, off_t start, size_t size, size_t step);
618
623DLL_EXPORT void ahp_xc_end_crosscorrelation_scan(uint32_t index);
624
641DLL_EXPORT int32_t ahp_xc_scan_crosscorrelations(uint32_t index1, uint32_t index2, ahp_xc_sample **crosscorrelations, off_t start1, size_t size1, off_t start2, size_t size2, size_t step, int32_t *interrupt, double *percent);
642
654
660
666DLL_EXPORT void ahp_xc_set_leds(uint32_t index, int32_t leds);
667
675DLL_EXPORT void ahp_xc_set_channel_cross(uint32_t index, off_t value, size_t size, size_t step);
676
684DLL_EXPORT void ahp_xc_set_channel_auto(uint32_t index, off_t value, size_t size, size_t step);
685
690DLL_EXPORT void ahp_xc_set_frequency_divider(unsigned char value);
691
697DLL_EXPORT void ahp_xc_set_voltage(uint32_t index, unsigned char value);
698
704DLL_EXPORT void ahp_xc_set_test_flags(uint32_t index, int32_t test);
705
711DLL_EXPORT unsigned char ahp_xc_get_test_flags(uint32_t index);
712
718DLL_EXPORT unsigned char ahp_xc_get_leds(uint32_t index);
719
724DLL_EXPORT void ahp_xc_select_input(uint32_t index);
725
730DLL_EXPORT uint32_t ahp_xc_current_input();
731
738DLL_EXPORT int32_t ahp_xc_send_command(xc_cmd cmd, unsigned char value);
739
744DLL_EXPORT inline uint32_t ahp_xc_get_version(void) { return AHP_XC_VERSION; }
745
748#ifdef __cplusplus
749} // extern "C"
750#endif
751
752#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:744
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 void ahp_xc_end_autocorrelation_scan(uint32_t index)
End an autocorrelation scan.
DLL_EXPORT int32_t ahp_xc_scan_autocorrelations(uint32_t nlines, uint32_t *indexes, ahp_xc_sample **autocorrelations, off_t *starts, size_t *sizes, size_t *steps, 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, off_t start, size_t size, size_t step)
Initiate a crosscorrelation scan.
DLL_EXPORT ahp_xc_packet * ahp_xc_alloc_packet(void)
Allocate and return a packet structure.
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_end_crosscorrelation_scan(uint32_t index)
End a crosscorrelation scan.
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(uint32_t index1, uint32_t index2, ahp_xc_sample **crosscorrelations, off_t start1, size_t size1, off_t start2, size_t size2, size_t step, 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 void ahp_xc_free_packet(ahp_xc_packet *packet)
Free a previously allocated packet structure.
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_free_samples(uint64_t nlines, ahp_xc_sample *samples)
Free a previously allocated samples array.
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_set_app_name(char *name)
set the application name
DLL_EXPORT char * ahp_get_app_name()
get the application name
DLL_EXPORT void ahp_set_debug_level(int32_t value)
set the debug level
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 char * ahp_xc_get_header(void)
Obtain the correlator header.
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 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:241
uint64_t n_lines
Number of lines in this correlator.
Definition ahp_xc.h:245
uint64_t n_baselines
Total number of baselines obtainable.
Definition ahp_xc.h:247
uint64_t bps
Bits capacity in each sample.
Definition ahp_xc.h:251
uint64_t auto_lag
Autocorrelators channels per packet.
Definition ahp_xc.h:255
const char * buf
Packet buffer string.
Definition ahp_xc.h:265
void * lock
Packet lock mutex.
Definition ahp_xc.h:263
ahp_xc_sample * crosscorrelations
Crosscorrelations in the current packet.
Definition ahp_xc.h:261
double timestamp
Timestamp of the packet (seconds)
Definition ahp_xc.h:243
uint64_t tau
Bandwidth inverse frequency.
Definition ahp_xc.h:249
ahp_xc_sample * autocorrelations
Autocorrelations in the current packet.
Definition ahp_xc.h:259
uint64_t * counts
Counts in the current packet.
Definition ahp_xc.h:257
uint64_t cross_lag
Crosscorrelators channels per packet.
Definition ahp_xc.h:253
Sample structure.
Definition ahp_xc.h:229
ahp_xc_correlation * correlations
Correlations array, of size lag_size in an ahp_xc_packet.
Definition ahp_xc.h:235
double lag
Lag offset from sample time.
Definition ahp_xc.h:231
uint64_t lag_size
Maximum lag in a single shot.
Definition ahp_xc.h:233