File: SendStringMarkersC.c

package info (click to toggle)
liblsl 1.16.2b1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,724 kB
  • sloc: cpp: 12,515; ansic: 666; python: 28; sh: 25; makefile: 18
file content (52 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <lsl_c.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
void sleep_(int ms) { Sleep(ms); }
#else
#include <unistd.h>
void sleep_(int ms) { usleep(ms * 1000); }
#endif

/**
 * This example program offers a 1-channel stream which contains strings.
 * The stream has the "Marker" content type and irregular rate.
 */

int main(int argc, char *argv[]) {
	lsl_streaminfo info; /* out stream declaration object */
	lsl_outlet outlet;	 /* stream outlet */
	const char *mrk;	 /* marker to send next */

	/* declare a new streaminfo (name: "MyEventStream", content type: "Markers", 1 channel,
	 * irregular rate, ... */
	/* ... string values, some made-up source id (can also be empty) */
	const char *name = argc > 1 ? argv[1] : "MyEventStream";
	info = lsl_create_streaminfo(name, "Markers", 1, LSL_IRREGULAR_RATE, cft_string, "id23443");

	/* make a new outlet (chunking: default, buffering: 360k markers) */
	outlet = lsl_create_outlet(info, 0, 360);

	/* send random marker streams (note: this loop is keeping the CPU busy, normally one would sleep
	 * or yield here) */
	printf("Now sending markers...\n");

	const char *markertypes[] = {"Test", "Blah", "Marker", "XXX", "Testtest", "Test-1-2-3"};

	while (1) {
		/* wait for a random period of time */
		sleep_(rand() % 1000);
		/* and choose the marker to send */
		mrk = markertypes[rand() % (sizeof(markertypes) / sizeof(markertypes[0]))];
		printf("now sending: %s\n", mrk);
		/* now send it (note the &, since this function takes an array of char*) */
		lsl_push_sample_str(outlet, &mrk);
	}

	/* we never get here, buy anyway */
	lsl_destroy_outlet(outlet);

	return 0;
}