Код: Выделить всё
void receive_data(int fd, const char *filename, int num_channels, int mode) {
FILE *file = fopen(filename, "w");
if (!file) {
perror("Errore nell'apertura del file");
return;
}
uint8_t buffer[MAX_BUFFER_SIZE];
int bytes_per_sample = num_channels * 3; // 1 byte di sincronizzazione + 2 bytes per canale
int buffer_offset = 0;
time_t start_time = time(NULL);
//unsigned int sample_count = 0; // Contatore dei campioni
printf("Campionamento in corso per 10 secondi...\n");
while (time(NULL) - start_time < 10) {
int bytes_read = read(fd, buffer + buffer_offset, sizeof(buffer) - buffer_offset);
if (bytes_read > 0) {
bytes_read += buffer_offset;
int i = 0;
while (i
Подробнее здесь: [url]https://stackoverflow.com/questions/79034227/arduino-mega-2560-oscilloscope[/url]