23 Commits

Author SHA1 Message Date
awe
4eb2da17ab data path upd 2025-12-04 18:48:10 +03:00
awe
c8dd8553ba add firmware file 2025-12-04 16:21:24 +03:00
awe
21038c1f8e gitignore upd 2025-12-04 16:21:06 +03:00
awe
11cf03910b remobe build from git 2025-12-04 16:20:33 +03:00
awe
613fdb998f gitignore upd 2025-12-04 16:19:59 +03:00
awe
d0578a0c0d remove build files 2025-12-04 16:19:41 +03:00
d979f45179 implemented cleanup of streams every 10 run. Now it works stable and fast. Next step -- adjust runs_since_streams_clean max value 2025-11-14 02:03:37 +03:00
a726babc1c implemented BF mode switching 2025-11-14 00:18:15 +03:00
4e2d8d4b22 examples of cmd files. If it is provided via CLI arg -- it sets run mode 2025-11-13 22:49:51 +03:00
bec5e29e2c implemented atomary writing to the output files (by creating tmp file and renaming it). 2025-11-13 22:47:40 +03:00
a1c727c71f now chart is saved before showing. Because showing may be long 2025-11-13 22:45:41 +03:00
9ad09ee77b uncommented chart.show() at the end 2025-11-13 22:30:41 +03:00
87954d40d9 now path to data storage is configurable by .cmd file 2025-11-13 22:30:17 +03:00
e2eac4dd48 implemented configuring at startup via cfg file. Implemented RUN_FINITE, RUN_INFINITE, RUN_TEST modes. 2025-11-13 21:36:49 +03:00
850a66e620 compiles 2025-11-13 21:00:42 +03:00
d1bd233399 removed old unacessible code from the end. Implemented main_state struct, filling it from the CLI arg file. Also implemented FINITE_RUNS mode. 2025-11-13 20:55:53 +03:00
b7eae9d469 cleaned more unused code (by codex) 2025-11-13 19:31:56 +03:00
b80ad585da moved libs to the lib directory 2025-11-13 18:40:06 +03:00
4d1f7fdbe9 added run_cyclic script. It mounts tmpfs in ./tmp, runs BF_companion for some cycles, cleans ./tmp 2025-11-13 18:22:38 +03:00
a44043593c deleted unused funcs and commented outdated code 2025-11-13 18:20:19 +03:00
b7ba42765b manually merged with ARM version 2025-11-13 17:43:55 +03:00
77005d7863 included SDK folder and included it to the git three 2025-10-30 21:53:19 +03:00
bf25bed9aa just save 2025-10-30 19:57:30 +03:00
28 changed files with 256 additions and 176 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.csv
*.tmp
build
BF_companion

Binary file not shown.

Binary file not shown.

View File

@ -1 +0,0 @@
../BFfirmware_0/build/release/bin/l502-BFfirmware0.ldr

BIN
l502-BFfirmware0.ldr Normal file

Binary file not shown.

10
long_trace_AVG_RPI.cmd Normal file
View File

@ -0,0 +1,10 @@
// Default configuration for BF_companion main_state
// Format: field value // optional comment
run_mode INF_RUN // TEST | FINITE_RUN | INF_RUN
BF_mode FFT // TRANSPARENT | AVG | FFT
run_length 50 // milliseconds
runs_N 1000 // total runs (used in FINITE_RUN)
run_I 0 // starting run index
//data_path /home/feda/MIPT/RadioPhotonic_Subserface_radar/Receiver_GUI/data // base directory for output files
data_path tmp

347
main.c
View File

@ -68,21 +68,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 +125,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 +143,123 @@ 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; } main_state;
static void main_state_set_defaults(main_state* st) { static void main_state_set_defaults(main_state* st) {
st->run_mode = RUN_MODE_TEST; st->run_mode = RUN_MODE_TEST;
st->BF_mode = BF_MODE_TRANSPARENT; st->BF_mode = BF_MODE_TRANSPARENT;
st->BlackFin_mode = BFMODE_TRANSPARENT; st->BlackFin_mode = BFMODE_TRANSPARENT;
st->run_length = 1000; st->run_length = 1000;
st->run_I = 0; st->run_I = 0;
st->runs_N = 1; st->runs_N = 1;
strncpy(st->data_path, "data", sizeof(st->data_path)); strncpy(st->data_path, "data", sizeof(st->data_path));
st->data_path[sizeof(st->data_path)-1] = '\0'; st->data_path[sizeof(st->data_path)-1] = '\0';
} }
static char* f_trim(char* s) { static char* f_trim(char* s) {
char* end; char* end;
while (*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++; while (*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++;
if (*s == 0) return s; if (*s == 0) return s;
end = s + strlen(s) - 1; end = s + strlen(s) - 1;
while (end > s && (*end==' ' || *end=='\t' || *end=='\r' || *end=='\n')) end--; while (end > s && (*end==' ' || *end=='\t' || *end=='\r' || *end=='\n')) end--;
end[1] = '\0'; end[1] = '\0';
return s; return s;
} }
static void parse_cmd_file(const char* filename, main_state* st) { static void parse_cmd_file(const char* filename, main_state* st) {
FILE* f = fopen(filename, "r"); FILE* f = fopen(filename, "r");
if (f == NULL) { if (f == NULL) {
printf("Command file '%s' not found. Using defaults.\n", filename); printf("Command file '%s' not found. Using defaults.\n", filename);
return; return;
} }
char line[512]; char line[512];
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
char* p = line; char* p = line;
char* comment = strstr(p, "//"); char* comment = strstr(p, "//");
if (comment) *comment = '\0'; if (comment) *comment = '\0';
p = f_trim(p); p = f_trim(p);
if (*p == '\0') continue; if (*p == '\0') continue;
char* field = strtok(p, "\t \r\n"); char* field = strtok(p, "\t \r\n");
char* value = strtok(NULL, "\t \r\n"); char* value = strtok(NULL, "\t \r\n");
if (!field || !value) continue; if (!field || !value) continue;
if (strcmp(field, "run_mode") == 0) { if (strcmp(field, "run_mode") == 0) {
if (strcmp(value, "FINITE_RUN") == 0) { if (strcmp(value, "FINITE_RUN") == 0) {
st->run_mode = RUN_MODE_FINITE; st->run_mode = RUN_MODE_FINITE;
} else if (strcmp(value, "INF_RUN") == 0) { } else if (strcmp(value, "INF_RUN") == 0) {
st->run_mode = RUN_MODE_INF; st->run_mode = RUN_MODE_INF;
} else if (strcmp(value, "TEST") == 0) { } else if (strcmp(value, "TEST") == 0) {
st->run_mode = RUN_MODE_TEST; st->run_mode = RUN_MODE_TEST;
} else { } else {
st->run_mode = RUN_MODE_TEST; // default on mismatch st->run_mode = RUN_MODE_TEST; // default on mismatch
} }
} else if (strcmp(field, "BF_mode") == 0) { } else if (strcmp(field, "BF_mode") == 0) {
if (strcmp(value, "TRANSPARENT") == 0) { if (strcmp(value, "TRANSPARENT") == 0) {
st->BF_mode = BF_MODE_TRANSPARENT; st->BF_mode = BF_MODE_TRANSPARENT;
} else if (strcmp(value, "AVG") == 0) { } 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';
} }
} }
fclose(f); fclose(f);
} }
/* Unused SIGINT handler and flag removed */ /* Unused SIGINT handler and flag removed */
/* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и /* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и
@ -705,7 +705,7 @@ void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint
// fprintf(logfile_ptr, "0xFF00000 \n"); // fprintf(logfile_ptr, "0xFF00000 \n");
// uint32_t timeout = 100; // uint32_t timeout = 100;
uint32_t recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, timeout); int32_t recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, timeout);
printf("receive code: %d\n", recv_Err_code); printf("receive code: %d\n", recv_Err_code);
if (recv_Err_code > 0){ if (recv_Err_code > 0){
@ -726,6 +726,7 @@ void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint
}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{
sleep(1);
printf("receive error: %d\n======================\n", recv_Err_code); printf("receive error: %d\n======================\n", recv_Err_code);
} }
} }
@ -767,33 +768,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\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 */
@ -863,8 +864,8 @@ int main(int argc, char** argv) {
} }
printf("\n\n\n"); printf("\n\n\n");
//setup ADC: //setup ADC:
@ -895,21 +896,21 @@ 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);
if (runs_since_streams_clean >= 10){ if (runs_since_streams_clean >= 10){
runs_since_streams_clean = 0; runs_since_streams_clean = 0;
@ -917,13 +918,13 @@ int main(int argc, char** argv) {
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); X502_Close(hnd);
// освобождаем описатель // освобождаем описатель
X502_Free(hnd); X502_Free(hnd);
return 0; 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,20 +946,20 @@ 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);
if (runs_since_streams_clean >= 10){ if (runs_since_streams_clean >= 10){
runs_since_streams_clean = 0; runs_since_streams_clean = 0;
@ -974,15 +975,15 @@ int main(int argc, char** argv) {
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 +1023,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 +1036,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 +1093,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);

66
pipe_reader_test.py Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env python3
"""
Test script to read radar data from named pipe (FIFO)
This script demonstrates how to read binary data from the named pipe
created by the radar acquisition program.
"""
import struct
import sys
import os
def read_from_pipe(pipe_path="/tmp/radar_data_pipe"):
"""
Read uint32_t data from named pipe
Args:
pipe_path: Path to the named pipe (FIFO)
"""
print(f"Opening pipe: {pipe_path}")
print("Waiting for radar data...")
try:
# Open pipe for reading (this will block until writer connects)
with open(pipe_path, 'rb') as pipe:
print("Connected to pipe! Reading data...")
word_count = 0
while True:
# Read 4 bytes (one uint32_t)
data = pipe.read(4)
if not data:
print("\nEnd of stream or pipe closed")
break
if len(data) < 4:
print(f"\nWarning: incomplete data read ({len(data)} bytes)")
break
# Unpack as uint32_t (little-endian)
value = struct.unpack('<I', data)[0]
# Print first 10 values and then every 1000th value
if word_count < 10 or word_count % 1000 == 0:
print(f"Word {word_count}: 0x{value:08X} ({value})")
word_count += 1
# Optional: process the data here
# For example, convert to voltage, apply filters, etc.
print(f"\nTotal words received: {word_count}")
except KeyboardInterrupt:
print("\n\nInterrupted by user")
print(f"Total words received: {word_count}")
except FileNotFoundError:
print(f"Error: Pipe {pipe_path} does not exist")
print("Make sure the radar acquisition program is running first")
except Exception as e:
print(f"Error reading from pipe: {e}")
if __name__ == "__main__":
pipe_path = sys.argv[1] if len(sys.argv) > 1 else "/tmp/radar_data_pipe"
read_from_pipe(pipe_path)

View File

@ -1,4 +1,3 @@
#!/usr/bin/bash #!/usr/bin/bash
sudo mount -t tmpfs -o size=1G tmpfs tmp # sudo mount -t tmpfs -o size=1G tmpfs tmp
./BF_companion 100 #should generate approx 500 MB of data by running 10 secs ./BF_companion long_trace_AVG_RPI.cmd
rm tmp/*