File: HandleMetaDataC.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 (60 lines) | stat: -rw-r--r-- 2,364 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
53
54
55
56
57
58
59
60
#include <lsl_c.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
	int c;							  /* channel index */
	lsl_xml_ptr desc, chns, chn, cap; /* some xml element pointers */
	lsl_outlet outlet;				  /* stream outlet */
	lsl_streaminfo info, inf;		  /* streaminfo objects */
	lsl_inlet inlet;				  /* a stream inlet to get samples from */
	int errcode;					  /* error code (lsl_lost_error or timeouts) */
	const char *labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"};

	/* create a new streaminfo and declare some meta-data (in accordance with XDF format) */
	const char *name = argc > 1 ? argv[1] : "MetaTester";
	info = lsl_create_streaminfo(name, "EEG", 8, 100, cft_float32, "myuid323457");
	desc = lsl_get_desc(info);
	chns = lsl_append_child(desc, "channels");
	for (c = 0; c < 8; c++) {
		chn = lsl_append_child(chns, "channel");
		lsl_append_child_value(chn, "label", labels[c]);
		lsl_append_child_value(chn, "unit", "microvolts");
		lsl_append_child_value(chn, "type", "EEG");
	}
	lsl_append_child_value(desc, "manufacturer", "SCCN");
	cap = lsl_append_child(desc, "cap");
	lsl_append_child_value(cap, "name", "EasyCap");
	lsl_append_child_value(cap, "size", "54");
	lsl_append_child_value(cap, "labelscheme", "10-20");

	/* create outlet for the stream */
	outlet = lsl_create_outlet(info, 0, 360);

	/*  === the following could run on another computer === */

	/* resolve the stream and open an inlet */
	lsl_resolve_byprop(&info, 1, "name", "MetaTester", 1, LSL_FOREVER);
	inlet = lsl_create_inlet(info, 360, LSL_NO_PREFERENCE, 1);
	inf = lsl_get_fullinfo(inlet, LSL_FOREVER, &errcode);
	printf("The stream's XML meta-data is: \n");
	printf("%s\n", lsl_get_xml(inf));
	printf("The manufacturer is: %s\n", lsl_child_value_n(lsl_get_desc(inf), "manufacturer"));
	printf("The cap circumference is: %s\n",
		lsl_child_value_n(lsl_child(lsl_get_desc(inf), "cap"), "size"));
	printf("The channel labels are as follows:\n");
	chn = lsl_child(lsl_child(lsl_get_desc(inf), "channels"), "channel");
	for (c = 0; c < lsl_get_channel_count(inf); c++) {
		printf("  %s\n", lsl_child_value_n(chn, "label"));
		chn = lsl_next_sibling(chn);
	}

	/* destroy objects and free memory */
	lsl_destroy_streaminfo(inf);
	lsl_destroy_inlet(inlet);
	lsl_destroy_outlet(outlet);
	lsl_destroy_streaminfo(info);

	/* wait for keypress */
	getchar();
	return 0;
}