|
| 1 | +#include <lsl_c.h> |
| 2 | +#include <signal.h> |
| 3 | +#include <stdio.h> |
| 4 | +#include <stdlib.h> |
| 5 | +#include <string.h> |
| 6 | +#include <unistd.h> |
| 7 | + |
| 8 | +static double start_t; |
| 9 | +static int64_t samples_pushed = 0; |
| 10 | + |
| 11 | +void handle_signal(int signal) { |
| 12 | + double time = lsl_local_clock() - start_t; |
| 13 | + printf("%ld samples pushed in %fs, %d samples/s\n", samples_pushed, time, |
| 14 | + (int)(samples_pushed / time)); |
| 15 | + if (signal == SIGTERM || signal == SIGINT) exit(0); |
| 16 | + start_t = lsl_local_clock(); |
| 17 | + samples_pushed = 0; |
| 18 | +} |
| 19 | + |
| 20 | +int main(int argc, char *argv[]) { |
| 21 | + signal(SIGTERM, handle_signal); |
| 22 | + signal(SIGINT, handle_signal); |
| 23 | +#ifdef SIGUSR1 |
| 24 | + signal(SIGUSR1, handle_signal); |
| 25 | +#endif |
| 26 | +#ifdef SIGCONT |
| 27 | + signal(SIGCONT, handle_signal); |
| 28 | +#endif |
| 29 | + printf("LSL inlet stress tester. Sends [nchan] uint16 channels as fast as possible.\n"); |
| 30 | + printf("Usage: %s [streamname] [nchan=56] [chunksize=500]\n", argv[0]); |
| 31 | + printf("Using lsl %d, lsl_library_info: %s\n\n", lsl_library_version(), lsl_library_info()); |
| 32 | + |
| 33 | + const char *name = argc > 1 ? argv[1] : "Flood"; |
| 34 | + const int nchan = argc > 2 ? strtol(argv[2], NULL, 10) : 56; |
| 35 | + const int samples_per_chunk = argc > 3 ? strtol(argv[3], NULL, 10) : 500; |
| 36 | + const char uid[] = "325wqer4354"; |
| 37 | + |
| 38 | + /* declare a new streaminfo (name: SendDataC / argument 1, content type: EEG, 8 channels, 500 |
| 39 | + * Hz, float values, some made-up device id (can also be empty) */ |
| 40 | + lsl_streaminfo info = lsl_create_streaminfo(name, "Bench", nchan, 50000, cft_int16, uid); |
| 41 | + |
| 42 | + /* make a new outlet (chunking: default, buffering: 360 seconds) */ |
| 43 | + lsl_outlet outlet = lsl_create_outlet_ex(info, 0, 360, transp_sync_blocking); |
| 44 | + char *infoxml = lsl_get_xml(lsl_get_info(outlet)); |
| 45 | + printf("Streaminfo: %s\n", infoxml); |
| 46 | + lsl_destroy_string(infoxml); |
| 47 | + |
| 48 | + const int buf_elements = nchan * samples_per_chunk; |
| 49 | + int16_t *buf = malloc(buf_elements * 2); |
| 50 | + memset(buf, 0xab, buf_elements * sizeof(buf[0])); |
| 51 | + |
| 52 | + printf("Now sending data...\n"); |
| 53 | + start_t = lsl_local_clock(); |
| 54 | + |
| 55 | + for (int t = 0;; t++) { |
| 56 | + lsl_push_chunk_s(outlet, buf, buf_elements); |
| 57 | + samples_pushed += samples_per_chunk; |
| 58 | + } |
| 59 | + lsl_destroy_outlet(outlet); |
| 60 | + return 0; |
| 61 | +} |
0 commit comments