implemented configuring at startup via cfg file. Implemented RUN_FINITE, RUN_INFINITE, RUN_TEST modes.

This commit is contained in:
2025-11-13 21:36:49 +03:00
parent aff8a37a74
commit 32cbb041b8
3 changed files with 120 additions and 107 deletions

Binary file not shown.

Binary file not shown.

77
main.c
View File

@ -702,20 +702,8 @@ int main(int argc, char** argv) {
int32_t err = X502_ERR_OK;
uint32_t ver;
t_x502_hnd hnd = NULL;
#ifndef _WIN32
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
// В ОС Linux устанавливаем свой обработчик на сигнал закрытия,
// чтобы завершить сбор корректно //
sa.sa_handler = f_abort_handler;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGABRT, &sa, NULL);
#endif
#ifdef _WIN32
// для вывода русских букв в консоль для ОС Windows в CP1251 без перевода в OEM //
setlocale(LC_CTYPE, "");
#endif
// читаем имя командного файла из аргументов CLI
const char* cmd_filename = "default.cmd";
if (argc > 1 && argv[1] != NULL && argv[1][0] != '\0') {
@ -842,8 +830,32 @@ int main(int argc, char** argv) {
// освобождаем описатель
X502_Free(hnd);
return 0;
}else if (state.run_mode == RUN_MODE_INF){
state.run_I = 0;
char tmp_data_filename[] = " ";
struct timespec ts;
uint32_t max_total_words = 0;
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
while (1){ //should be infinite. because it is RUN_MODE_INF
//while(state.run_I < state.runs_N){
max_total_words = 10000000;
timespec_get(&ts, TIME_UTC);
// 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, "data/received_data_%ld.csv", seconds);
snprintf(tmp_data_filename, sizeof(tmp_data_filename), "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec);
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);
state.run_I++;
}
}
free(inp_buff);
X502_Close(hnd);
// освобождаем описатель
X502_Free(hnd);
return 0;
}else{ //TEST mode as default
@ -864,7 +876,7 @@ int main(int argc, char** argv) {
fclose(logfile_ptr);
// printf("dumping to file: %s\n", logfilename);
// printf("dumping to file: %s\n", logfilename);
printf("\n");
//printf("start streams sampling\n");
@ -883,8 +895,8 @@ int main(int argc, char** argv) {
BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
// printf("\n\nget a some data made by sport isr handler\n");
// BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 1);
// printf("\n\nget a some data made by sport isr handler\n");
// BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 1);
//BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 3);
@ -908,11 +920,11 @@ int main(int argc, char** argv) {
uint32_t max_total_words = 100000;
/* Removed unused data_receive_trys_counter */
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
// receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000);
// receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000);
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
@ -921,7 +933,7 @@ int main(int argc, char** argv) {
//*
//*
@ -940,22 +952,22 @@ int main(int argc, char** argv) {
BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
X502_StreamsStop(hnd);
X502_StreamsStart(hnd);
// 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("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
// BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
// printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
// BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
//fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n");
@ -1003,13 +1015,13 @@ int main(int argc, char** argv) {
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
// printf("\n dbg value: ");
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
// printf("\n dbg value: ");
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000);
printf("\n dbg value: ");
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
//*/
//*/
@ -1023,10 +1035,11 @@ int main(int argc, char** argv) {
// освобождаем описатель
X502_Free(hnd);
return 0;
}
}
return -1;
}