pipe
This commit is contained in:
459
main.c
459
main.c
@ -59,6 +59,9 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -68,21 +71,21 @@
|
|||||||
#include "l502_fpga_regs.h"
|
#include "l502_fpga_regs.h"
|
||||||
|
|
||||||
|
|
||||||
/* Remove unused enums/structs and constants that are not referenced anywhere */
|
/* Remove unused enums/structs and constants that are not referenced anywhere */
|
||||||
|
|
||||||
// количество используемых логических каналов //
|
// количество используемых логических каналов //
|
||||||
#define ADC_LCH_CNT 1
|
#define ADC_LCH_CNT 1
|
||||||
|
|
||||||
/* Unused frequency/timing defines removed */
|
/* Unused frequency/timing defines removed */
|
||||||
|
|
||||||
|
|
||||||
// сколько отсчетов считываем за блок //
|
// сколько отсчетов считываем за блок //
|
||||||
#define READ_BLOCK_SIZE 4096*200
|
#define READ_BLOCK_SIZE 4096*200
|
||||||
// таймаут на прием блока (мс) //
|
// таймаут на прием блока (мс) //
|
||||||
#define READ_TIMEOUT 2000
|
#define READ_TIMEOUT 2000
|
||||||
|
|
||||||
|
|
||||||
/* Unused BF user command define removed */
|
/* Unused BF user command define removed */
|
||||||
|
|
||||||
|
|
||||||
// номера используемых физических каналов //
|
// номера используемых физических каналов //
|
||||||
@ -125,7 +128,7 @@ static uint32_t f_ch_ranges[ADC_LCH_CNT] = {X502_ADC_RANGE_02, X502_ADC_RANGE_5,
|
|||||||
|
|
||||||
|
|
||||||
// признак необходимости завершить сбор данных //
|
// признак необходимости завершить сбор данных //
|
||||||
static int f_out = 0;
|
static int f_out = 0;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
// Обработчик сигнала завершения для Linux //
|
// Обработчик сигнала завершения для Linux //
|
||||||
@ -143,123 +146,139 @@ typedef struct {
|
|||||||
} ip_dev_list_t;
|
} ip_dev_list_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RUN_MODE_TEST = 0,
|
RUN_MODE_TEST = 0,
|
||||||
RUN_MODE_FINITE = 1,
|
RUN_MODE_FINITE = 1,
|
||||||
RUN_MODE_INF = 2
|
RUN_MODE_INF = 2
|
||||||
} run_mode_t;
|
} run_mode_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BF_MODE_TRANSPARENT = 0,
|
BF_MODE_TRANSPARENT = 0,
|
||||||
BF_MODE_AVG = 1,
|
BF_MODE_AVG = 1,
|
||||||
BF_MODE_FFT = 2
|
BF_MODE_FFT = 2
|
||||||
} bf_mode_t;
|
} bf_mode_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BFMODE_TRANSPARENT = 0,
|
BFMODE_TRANSPARENT = 0,
|
||||||
BFMODE_AVG = 1,
|
BFMODE_AVG = 1,
|
||||||
BFMODE_FFT = 2
|
BFMODE_FFT = 2
|
||||||
} blackfin_mode_t;
|
} blackfin_mode_t;
|
||||||
|
|
||||||
typedef struct main_state_typedef{
|
typedef struct main_state_typedef{
|
||||||
run_mode_t run_mode; // TEST, FINITE_RUN, INF_RUN
|
run_mode_t run_mode; // TEST, FINITE_RUN, INF_RUN
|
||||||
bf_mode_t BF_mode; // TRANSPARENT, AVG
|
bf_mode_t BF_mode; // TRANSPARENT, AVG
|
||||||
blackfin_mode_t BlackFin_mode; // TRANSPARENT, AVG, FFT
|
blackfin_mode_t BlackFin_mode; // TRANSPARENT, AVG, FFT
|
||||||
uint32_t run_length; // in ms. Used as timeout for receive_to_file
|
uint32_t run_length; // in ms. Used as timeout for receive_to_file
|
||||||
uint32_t run_I; // № current run
|
uint32_t run_I; // № current run
|
||||||
uint32_t runs_N; // total number of runs
|
uint32_t runs_N; // total number of runs
|
||||||
char data_path[200]; // base directory for data files
|
char data_path[200]; // base directory for data files
|
||||||
} main_state;
|
char pipe_path[200]; // path to named pipe (FIFO) for streaming data
|
||||||
|
int pipe_fd; // file descriptor for the pipe
|
||||||
static void main_state_set_defaults(main_state* st) {
|
int save_to_files; // flag: save data to files (0=false, 1=true)
|
||||||
st->run_mode = RUN_MODE_TEST;
|
} main_state;
|
||||||
st->BF_mode = BF_MODE_TRANSPARENT;
|
|
||||||
st->BlackFin_mode = BFMODE_TRANSPARENT;
|
static void main_state_set_defaults(main_state* st) {
|
||||||
st->run_length = 1000;
|
st->run_mode = RUN_MODE_TEST;
|
||||||
st->run_I = 0;
|
st->BF_mode = BF_MODE_TRANSPARENT;
|
||||||
st->runs_N = 1;
|
st->BlackFin_mode = BFMODE_TRANSPARENT;
|
||||||
strncpy(st->data_path, "data", sizeof(st->data_path));
|
st->run_length = 1000;
|
||||||
st->data_path[sizeof(st->data_path)-1] = '\0';
|
st->run_I = 0;
|
||||||
}
|
st->runs_N = 1;
|
||||||
|
strncpy(st->data_path, "data", sizeof(st->data_path));
|
||||||
static char* f_trim(char* s) {
|
st->data_path[sizeof(st->data_path)-1] = '\0';
|
||||||
char* end;
|
strncpy(st->pipe_path, "/tmp/radar_data_pipe", sizeof(st->pipe_path));
|
||||||
while (*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++;
|
st->pipe_path[sizeof(st->pipe_path)-1] = '\0';
|
||||||
if (*s == 0) return s;
|
st->pipe_fd = -1;
|
||||||
end = s + strlen(s) - 1;
|
st->save_to_files = 0; // default: false
|
||||||
while (end > s && (*end==' ' || *end=='\t' || *end=='\r' || *end=='\n')) end--;
|
}
|
||||||
end[1] = '\0';
|
|
||||||
return s;
|
static char* f_trim(char* s) {
|
||||||
}
|
char* end;
|
||||||
|
while (*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++;
|
||||||
static void parse_cmd_file(const char* filename, main_state* st) {
|
if (*s == 0) return s;
|
||||||
FILE* f = fopen(filename, "r");
|
end = s + strlen(s) - 1;
|
||||||
if (f == NULL) {
|
while (end > s && (*end==' ' || *end=='\t' || *end=='\r' || *end=='\n')) end--;
|
||||||
printf("Command file '%s' not found. Using defaults.\n", filename);
|
end[1] = '\0';
|
||||||
return;
|
return s;
|
||||||
}
|
}
|
||||||
char line[512];
|
|
||||||
while (fgets(line, sizeof(line), f)) {
|
static void parse_cmd_file(const char* filename, main_state* st) {
|
||||||
char* p = line;
|
FILE* f = fopen(filename, "r");
|
||||||
char* comment = strstr(p, "//");
|
if (f == NULL) {
|
||||||
if (comment) *comment = '\0';
|
printf("Command file '%s' not found. Using defaults.\n", filename);
|
||||||
p = f_trim(p);
|
return;
|
||||||
if (*p == '\0') continue;
|
}
|
||||||
char* field = strtok(p, "\t \r\n");
|
char line[512];
|
||||||
char* value = strtok(NULL, "\t \r\n");
|
while (fgets(line, sizeof(line), f)) {
|
||||||
if (!field || !value) continue;
|
char* p = line;
|
||||||
|
char* comment = strstr(p, "//");
|
||||||
if (strcmp(field, "run_mode") == 0) {
|
if (comment) *comment = '\0';
|
||||||
if (strcmp(value, "FINITE_RUN") == 0) {
|
p = f_trim(p);
|
||||||
st->run_mode = RUN_MODE_FINITE;
|
if (*p == '\0') continue;
|
||||||
} else if (strcmp(value, "INF_RUN") == 0) {
|
char* field = strtok(p, "\t \r\n");
|
||||||
st->run_mode = RUN_MODE_INF;
|
char* value = strtok(NULL, "\t \r\n");
|
||||||
} else if (strcmp(value, "TEST") == 0) {
|
if (!field || !value) continue;
|
||||||
st->run_mode = RUN_MODE_TEST;
|
|
||||||
} else {
|
if (strcmp(field, "run_mode") == 0) {
|
||||||
st->run_mode = RUN_MODE_TEST; // default on mismatch
|
if (strcmp(value, "FINITE_RUN") == 0) {
|
||||||
}
|
st->run_mode = RUN_MODE_FINITE;
|
||||||
} else if (strcmp(field, "BF_mode") == 0) {
|
} else if (strcmp(value, "INF_RUN") == 0) {
|
||||||
if (strcmp(value, "TRANSPARENT") == 0) {
|
st->run_mode = RUN_MODE_INF;
|
||||||
st->BF_mode = BF_MODE_TRANSPARENT;
|
} else if (strcmp(value, "TEST") == 0) {
|
||||||
} else if (strcmp(value, "AVG") == 0) {
|
st->run_mode = RUN_MODE_TEST;
|
||||||
|
} else {
|
||||||
|
st->run_mode = RUN_MODE_TEST; // default on mismatch
|
||||||
|
}
|
||||||
|
} else if (strcmp(field, "BF_mode") == 0) {
|
||||||
|
if (strcmp(value, "TRANSPARENT") == 0) {
|
||||||
|
st->BF_mode = BF_MODE_TRANSPARENT;
|
||||||
|
} else if (strcmp(value, "AVG") == 0) {
|
||||||
st->BF_mode = BF_MODE_AVG;
|
st->BF_mode = BF_MODE_AVG;
|
||||||
} else if (strcmp(value, "FFT") == 0) {
|
} else if (strcmp(value, "FFT") == 0) {
|
||||||
st->BF_mode = BF_MODE_FFT;
|
st->BF_mode = BF_MODE_FFT;
|
||||||
} else {
|
} else {
|
||||||
st->BF_mode = BF_MODE_TRANSPARENT; // default on mismatch
|
st->BF_mode = BF_MODE_TRANSPARENT; // default on mismatch
|
||||||
}
|
}
|
||||||
} else if (strcmp(field, "BlackFin_mode") == 0) {
|
} else if (strcmp(field, "BlackFin_mode") == 0) {
|
||||||
if (strcmp(value, "TRANSPARENT") == 0) {
|
if (strcmp(value, "TRANSPARENT") == 0) {
|
||||||
st->BlackFin_mode = BFMODE_TRANSPARENT;
|
st->BlackFin_mode = BFMODE_TRANSPARENT;
|
||||||
} else if (strcmp(value, "AVG") == 0) {
|
} else if (strcmp(value, "AVG") == 0) {
|
||||||
st->BlackFin_mode = BFMODE_AVG;
|
st->BlackFin_mode = BFMODE_AVG;
|
||||||
} else if (strcmp(value, "FFT") == 0) {
|
} else if (strcmp(value, "FFT") == 0) {
|
||||||
st->BlackFin_mode = BFMODE_FFT;
|
st->BlackFin_mode = BFMODE_FFT;
|
||||||
} else {
|
} else {
|
||||||
st->BlackFin_mode = BFMODE_TRANSPARENT; // default on mismatch
|
st->BlackFin_mode = BFMODE_TRANSPARENT; // default on mismatch
|
||||||
}
|
}
|
||||||
} else if (strcmp(field, "run_length") == 0) {
|
} else if (strcmp(field, "run_length") == 0) {
|
||||||
char* endp = NULL;
|
char* endp = NULL;
|
||||||
unsigned long v = strtoul(value, &endp, 0);
|
unsigned long v = strtoul(value, &endp, 0);
|
||||||
if (endp != value) st->run_length = (uint32_t)v;
|
if (endp != value) st->run_length = (uint32_t)v;
|
||||||
} else if (strcmp(field, "runs_N") == 0) {
|
} else if (strcmp(field, "runs_N") == 0) {
|
||||||
char* endp = NULL;
|
char* endp = NULL;
|
||||||
unsigned long v = strtoul(value, &endp, 0);
|
unsigned long v = strtoul(value, &endp, 0);
|
||||||
if (endp != value) st->runs_N = (uint32_t)v;
|
if (endp != value) st->runs_N = (uint32_t)v;
|
||||||
} else if (strcmp(field, "run_I") == 0) {
|
} else if (strcmp(field, "run_I") == 0) {
|
||||||
char* endp = NULL;
|
char* endp = NULL;
|
||||||
unsigned long v = strtoul(value, &endp, 0);
|
unsigned long v = strtoul(value, &endp, 0);
|
||||||
if (endp != value) st->run_I = (uint32_t)v;
|
if (endp != value) st->run_I = (uint32_t)v;
|
||||||
} else if (strcmp(field, "data_path") == 0) {
|
} else if (strcmp(field, "data_path") == 0) {
|
||||||
strncpy(st->data_path, value, sizeof(st->data_path));
|
strncpy(st->data_path, value, sizeof(st->data_path));
|
||||||
st->data_path[sizeof(st->data_path)-1] = '\0';
|
st->data_path[sizeof(st->data_path)-1] = '\0';
|
||||||
}
|
} else if (strcmp(field, "pipe_path") == 0) {
|
||||||
}
|
strncpy(st->pipe_path, value, sizeof(st->pipe_path));
|
||||||
fclose(f);
|
st->pipe_path[sizeof(st->pipe_path)-1] = '\0';
|
||||||
}
|
} else if (strcmp(field, "save_to_files") == 0) {
|
||||||
|
if (strcmp(value, "true") == 0 || strcmp(value, "1") == 0) {
|
||||||
|
st->save_to_files = 1;
|
||||||
|
} else if (strcmp(value, "false") == 0 || strcmp(value, "0") == 0) {
|
||||||
|
st->save_to_files = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
/* Unused SIGINT handler and flag removed */
|
/* Unused SIGINT handler and flag removed */
|
||||||
|
|
||||||
|
|
||||||
/* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и
|
/* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и
|
||||||
@ -367,6 +386,7 @@ static t_x502_hnd f_dev_select_open(int argc, char** argv) {
|
|||||||
fnd_devcnt = f_get_all_devrec(&devrec_list, ip_dev_list, ip_cnt);
|
fnd_devcnt = f_get_all_devrec(&devrec_list, ip_dev_list, ip_cnt);
|
||||||
|
|
||||||
if (fnd_devcnt == 0) {
|
if (fnd_devcnt == 0) {
|
||||||
|
|
||||||
printf("Не найдено ни одного модуля\n");
|
printf("Не найдено ни одного модуля\n");
|
||||||
} else {
|
} else {
|
||||||
// выводим информацию по списку модулей //
|
// выводим информацию по списку модулей //
|
||||||
@ -694,9 +714,64 @@ void insert_marker_to_file(char* logfilename, char* marker_text){
|
|||||||
fclose(logfile_ptr);
|
fclose(logfile_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
// Function to initialize named pipe (FIFO)
|
||||||
|
int init_pipe(const char* pipe_path) {
|
||||||
|
// Remove existing pipe if it exists
|
||||||
|
unlink(pipe_path);
|
||||||
|
|
||||||
|
// Create named pipe with read/write permissions
|
||||||
|
if (mkfifo(pipe_path, 0666) != 0) {
|
||||||
|
if (errno != EEXIST) {
|
||||||
|
fprintf(stderr, "Error creating pipe %s: %s\n", pipe_path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint32_t max_total_words, uint32_t timeout){
|
printf("Named pipe created: %s\n", pipe_path);
|
||||||
|
|
||||||
|
// Try to open in non-blocking mode first to check if reader is present
|
||||||
|
int fd = open(pipe_path, O_WRONLY | O_NONBLOCK);
|
||||||
|
if (fd < 0) {
|
||||||
|
if (errno == ENXIO) {
|
||||||
|
// No reader present, try blocking mode
|
||||||
|
printf("No reader detected. Waiting for reader to connect...\n");
|
||||||
|
printf("(You can start the reader program now, e.g.: ./pipe_reader_test.py)\n");
|
||||||
|
|
||||||
|
// Open in blocking mode - will wait for reader
|
||||||
|
fd = open(pipe_path, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "Error opening pipe for writing: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("Reader connected!\n");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Warning: Could not open pipe for writing: %s\n", strerror(errno));
|
||||||
|
fprintf(stderr, "Pipe will be skipped. Data will only be saved to file.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Reader already connected!\n");
|
||||||
|
// Set back to blocking mode for writes
|
||||||
|
int flags = fcntl(fd, F_GETFL);
|
||||||
|
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Pipe opened successfully (fd=%d)\n", fd);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to close pipe
|
||||||
|
void close_pipe(int pipe_fd, const char* pipe_path) {
|
||||||
|
if (pipe_fd >= 0) {
|
||||||
|
close(pipe_fd);
|
||||||
|
unlink(pipe_path);
|
||||||
|
printf("Pipe closed and removed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint32_t max_total_words, uint32_t timeout, int pipe_fd){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -723,6 +798,23 @@ void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint
|
|||||||
printf("received %ld words\n", received_words);
|
printf("received %ld words\n", received_words);
|
||||||
fclose(logfile_ptr);
|
fclose(logfile_ptr);
|
||||||
rename(logfilename_tmp, logfilename);
|
rename(logfilename_tmp, logfilename);
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
// Write data to pipe if it's open
|
||||||
|
if (pipe_fd >= 0) {
|
||||||
|
// Write raw binary data to pipe
|
||||||
|
ssize_t bytes_written = write(pipe_fd, inp_buff, received_words * sizeof(uint32_t));
|
||||||
|
if (bytes_written < 0) {
|
||||||
|
if (errno == EPIPE) {
|
||||||
|
fprintf(stderr, "Warning: Broken pipe (reader disconnected)\n");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Warning: Error writing to pipe: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Written %zd bytes to pipe\n", bytes_written);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}else if (recv_Err_code == 0){
|
}else if (recv_Err_code == 0){
|
||||||
printf("no data received. timeout\n");
|
printf("no data received. timeout\n");
|
||||||
}else{
|
}else{
|
||||||
@ -767,33 +859,33 @@ void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int32_t err = X502_ERR_OK;
|
int32_t err = X502_ERR_OK;
|
||||||
uint32_t ver;
|
uint32_t ver;
|
||||||
t_x502_hnd hnd = NULL;
|
t_x502_hnd hnd = NULL;
|
||||||
|
|
||||||
|
|
||||||
// читаем имя командного файла из аргументов CLI
|
// читаем имя командного файла из аргументов CLI
|
||||||
const char* cmd_filename = "default.cmd";
|
const char* cmd_filename = "default.cmd";
|
||||||
if (argc > 1 && argv[1] != NULL && argv[1][0] != '\0') {
|
if (argc > 1 && argv[1] != NULL && argv[1][0] != '\0') {
|
||||||
cmd_filename = argv[1];
|
cmd_filename = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// получаем версию библиотеки //
|
|
||||||
ver = X502_GetLibraryVersion();
|
|
||||||
printf("Версия библиотеки: %d.%d.%d\n", (ver >> 24)&0xFF, (ver>>16)&0xFF, (ver>>8)&0xFF);
|
|
||||||
printf("Command file: %s\n", cmd_filename);
|
|
||||||
|
|
||||||
// загружаем состояние из командного файла
|
|
||||||
main_state state;
|
|
||||||
main_state_set_defaults(&state);
|
|
||||||
parse_cmd_file(cmd_filename, &state);
|
|
||||||
// отладочный вывод принятых значений
|
|
||||||
printf("Parsed state: run_mode=%d, BF_mode=%d, BlackFin_mode=%d, run_length=%u, runs_N=%u, run_I=%u, data_path=%s\n",
|
|
||||||
(int)state.run_mode, (int)state.BF_mode, (int)state.BlackFin_mode,
|
|
||||||
state.run_length, state.runs_N, state.run_I, state.data_path);
|
|
||||||
|
|
||||||
/* Removed unused temporary buffers and FFT/LFSM placeholders */
|
// получаем версию библиотеки //
|
||||||
|
ver = X502_GetLibraryVersion();
|
||||||
|
printf("Версия библиотеки: %d.%d.%d\n", (ver >> 24)&0xFF, (ver>>16)&0xFF, (ver>>8)&0xFF);
|
||||||
|
printf("Command file: %s\n", cmd_filename);
|
||||||
|
|
||||||
|
// загружаем состояние из командного файла
|
||||||
|
main_state state;
|
||||||
|
main_state_set_defaults(&state);
|
||||||
|
parse_cmd_file(cmd_filename, &state);
|
||||||
|
// отладочный вывод принятых значений
|
||||||
|
printf("Parsed state: run_mode=%d, BF_mode=%d, BlackFin_mode=%d, run_length=%u, runs_N=%u, run_I=%u, data_path=%s, save_to_files=%d\n",
|
||||||
|
(int)state.run_mode, (int)state.BF_mode, (int)state.BlackFin_mode,
|
||||||
|
state.run_length, state.runs_N, state.run_I, state.data_path, state.save_to_files);
|
||||||
|
|
||||||
|
/* Removed unused temporary buffers and FFT/LFSM placeholders */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -863,8 +955,8 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
//setup ADC:
|
//setup ADC:
|
||||||
|
|
||||||
|
|
||||||
@ -876,6 +968,13 @@ int main(int argc, char** argv) {
|
|||||||
streams_start_Err = X502_StreamsStart(hnd);
|
streams_start_Err = X502_StreamsStart(hnd);
|
||||||
printf("Streams start err: %d \n", streams_start_Err);
|
printf("Streams start err: %d \n", streams_start_Err);
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
// Initialize named pipe
|
||||||
|
printf("Initializing named pipe: %s\n", state.pipe_path);
|
||||||
|
state.pipe_fd = init_pipe(state.pipe_path);
|
||||||
|
#else
|
||||||
|
state.pipe_fd = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (state.run_mode == RUN_MODE_FINITE){
|
if (state.run_mode == RUN_MODE_FINITE){
|
||||||
if (state.BF_mode == BF_MODE_TRANSPARENT){
|
if (state.BF_mode == BF_MODE_TRANSPARENT){
|
||||||
@ -895,35 +994,38 @@ int main(int argc, char** argv) {
|
|||||||
// for(uint32_t wait_i = 1e6; wait_i; --wait_i){;}
|
// for(uint32_t wait_i = 1e6; wait_i; --wait_i){;}
|
||||||
|
|
||||||
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||||
|
|
||||||
state.run_I = 0;
|
state.run_I = 0;
|
||||||
char tmp_data_filename[256];
|
char tmp_data_filename[256];
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
uint32_t max_total_words = 1000000;
|
uint32_t max_total_words = 1000000;
|
||||||
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
||||||
uint32_t runs_since_streams_clean = 0;
|
uint32_t runs_since_streams_clean = 0;
|
||||||
while(state.run_I < state.runs_N){
|
while(state.run_I < state.runs_N){
|
||||||
max_total_words = 10000000;
|
max_total_words = 10000000;
|
||||||
timespec_get(&ts, TIME_UTC);
|
timespec_get(&ts, TIME_UTC);
|
||||||
// sprintf(&tmp_data_filename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
// sprintf(&tmp_data_filename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
||||||
// sprintf(&logfilename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
// sprintf(&logfilename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
||||||
//sprintf(&logfilename, "data/received_data_%ld.csv", seconds);
|
//sprintf(&logfilename, "data/received_data_%ld.csv", seconds);
|
||||||
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
|
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
|
||||||
printf("%u/%u dumping to file: %s\n", (unsigned)state.run_I, (unsigned)state.runs_N, tmp_data_filename);
|
printf("%u/%u dumping to file: %s\n", (unsigned)state.run_I, (unsigned)state.runs_N, tmp_data_filename);
|
||||||
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length);
|
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length, state.pipe_fd);
|
||||||
if (runs_since_streams_clean >= 10){
|
if (runs_since_streams_clean >= 10){
|
||||||
runs_since_streams_clean = 0;
|
runs_since_streams_clean = 0;
|
||||||
X502_StreamsStop(hnd);
|
X502_StreamsStop(hnd);
|
||||||
X502_StreamsStart(hnd);
|
X502_StreamsStart(hnd);
|
||||||
}
|
}
|
||||||
state.run_I++;
|
state.run_I++;
|
||||||
runs_since_streams_clean++; }
|
runs_since_streams_clean++; }
|
||||||
free(inp_buff);
|
free(inp_buff);
|
||||||
X502_Close(hnd);
|
#ifndef _WIN32
|
||||||
// освобождаем описатель
|
close_pipe(state.pipe_fd, state.pipe_path);
|
||||||
X502_Free(hnd);
|
#endif
|
||||||
return 0;
|
X502_Close(hnd);
|
||||||
|
// освобождаем описатель
|
||||||
|
X502_Free(hnd);
|
||||||
|
return 0;
|
||||||
|
|
||||||
}else if (state.run_mode == RUN_MODE_INF){
|
}else if (state.run_mode == RUN_MODE_INF){
|
||||||
if (state.BF_mode == BF_MODE_TRANSPARENT){
|
if (state.BF_mode == BF_MODE_TRANSPARENT){
|
||||||
printf("\nStart transparent mode\n");
|
printf("\nStart transparent mode\n");
|
||||||
@ -945,21 +1047,21 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
|
|
||||||
state.run_I = 0;
|
state.run_I = 0;
|
||||||
char tmp_data_filename[256];
|
char tmp_data_filename[256];
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
uint32_t max_total_words = 10000000;
|
uint32_t max_total_words = 10000000;
|
||||||
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
||||||
uint32_t runs_since_streams_clean = 0;
|
uint32_t runs_since_streams_clean = 0;
|
||||||
while (1){ //should be infinite. because it is RUN_MODE_INF
|
while (1){ //should be infinite. because it is RUN_MODE_INF
|
||||||
//while(state.run_I < state.runs_N){
|
//while(state.run_I < state.runs_N){
|
||||||
max_total_words = 10000000;
|
max_total_words = 10000000;
|
||||||
timespec_get(&ts, TIME_UTC);
|
timespec_get(&ts, TIME_UTC);
|
||||||
// sprintf(&tmp_data_filename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
// sprintf(&tmp_data_filename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
||||||
// sprintf(&logfilename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
// sprintf(&logfilename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
|
||||||
//sprintf(&logfilename, "data/received_data_%ld.csv", seconds);
|
//sprintf(&logfilename, "data/received_data_%ld.csv", seconds);
|
||||||
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
|
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "%s/received_data_%ld.%ld.csv", state.data_path, ts.tv_sec, ts.tv_nsec);
|
||||||
printf("%u dumping to file: %s\n", (unsigned)state.run_I, tmp_data_filename);
|
printf("%u dumping to file: %s\n", (unsigned)state.run_I, tmp_data_filename);
|
||||||
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length);
|
receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length, state.pipe_fd);
|
||||||
if (runs_since_streams_clean >= 10){
|
if (runs_since_streams_clean >= 10){
|
||||||
runs_since_streams_clean = 0;
|
runs_since_streams_clean = 0;
|
||||||
X502_StreamsStop(hnd);
|
X502_StreamsStop(hnd);
|
||||||
@ -969,20 +1071,23 @@ int main(int argc, char** argv) {
|
|||||||
runs_since_streams_clean++;
|
runs_since_streams_clean++;
|
||||||
}
|
}
|
||||||
free(inp_buff);
|
free(inp_buff);
|
||||||
|
#ifndef _WIN32
|
||||||
|
close_pipe(state.pipe_fd, state.pipe_path);
|
||||||
|
#endif
|
||||||
X502_Close(hnd);
|
X502_Close(hnd);
|
||||||
// освобождаем описатель
|
// освобождаем описатель
|
||||||
X502_Free(hnd);
|
X502_Free(hnd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}else{ //TEST mode as default
|
}else{ //TEST mode as default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
time_t seconds;
|
time_t seconds;
|
||||||
time(&seconds);
|
time(&seconds);
|
||||||
char logfilename[256];
|
char logfilename[256];
|
||||||
snprintf(logfilename, sizeof(logfilename), "%s/received_data_%ld.csv", state.data_path, (long)seconds);
|
snprintf(logfilename, sizeof(logfilename), "%s/received_data_%ld.csv", state.data_path, (long)seconds);
|
||||||
//logfile_ptr = fopen(logfilename, "w");
|
//logfile_ptr = fopen(logfilename, "w");
|
||||||
FILE *logfile_ptr;
|
FILE *logfile_ptr;
|
||||||
logfile_ptr = fopen(logfilename, "a");
|
logfile_ptr = fopen(logfilename, "a");
|
||||||
@ -1022,7 +1127,7 @@ int main(int argc, char** argv) {
|
|||||||
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
||||||
double *adc_data = malloc(1024*1024*sizeof(double));
|
double *adc_data = malloc(1024*1024*sizeof(double));
|
||||||
//uint32_t inp_buff[1024*2048] = {0,};
|
//uint32_t inp_buff[1024*2048] = {0,};
|
||||||
/* Removed unused counters */
|
/* Removed unused counters */
|
||||||
|
|
||||||
|
|
||||||
insert_marker_to_file(logfilename, "start transparent");
|
insert_marker_to_file(logfilename, "start transparent");
|
||||||
@ -1035,10 +1140,10 @@ int main(int argc, char** argv) {
|
|||||||
printf("receiving data...\n");
|
printf("receiving data...\n");
|
||||||
|
|
||||||
|
|
||||||
/* Removed unused readiness checks */
|
/* Removed unused readiness checks */
|
||||||
|
|
||||||
uint32_t max_total_words = 100000;
|
uint32_t max_total_words = 100000;
|
||||||
/* Removed unused data_receive_trys_counter */
|
/* Removed unused data_receive_trys_counter */
|
||||||
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
||||||
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
||||||
|
|
||||||
@ -1092,7 +1197,7 @@ int main(int argc, char** argv) {
|
|||||||
//fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n");
|
//fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n");
|
||||||
|
|
||||||
|
|
||||||
max_total_words = 100000;
|
max_total_words = 100000;
|
||||||
|
|
||||||
//printf("\n dbg value: ");
|
//printf("\n dbg value: ");
|
||||||
//BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
//BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||||
@ -1100,7 +1205,7 @@ int main(int argc, char** argv) {
|
|||||||
struct timespec time_receive_started, time_receive_ended;
|
struct timespec time_receive_started, time_receive_ended;
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &time_receive_started);
|
clock_gettime(CLOCK_MONOTONIC, &time_receive_started);
|
||||||
receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000);
|
receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000, state.pipe_fd);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &time_receive_ended);
|
clock_gettime(CLOCK_MONOTONIC, &time_receive_ended);
|
||||||
|
|
||||||
|
|
||||||
@ -1136,7 +1241,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
// printf("\n dbg value: ");
|
// printf("\n dbg value: ");
|
||||||
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||||
receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000);
|
receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000, state.pipe_fd);
|
||||||
printf("\n dbg value: ");
|
printf("\n dbg value: ");
|
||||||
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user