-
Notifications
You must be signed in to change notification settings - Fork 0
/
phasespace.c
136 lines (111 loc) · 2.84 KB
/
phasespace.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* $Id: phasespace.c 37 2010-10-04 22:27:01Z nicb $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "psOSCd.h"
#include "phasespace.h"
void
phasespace_connect()
{
int init_flags = slave() ? (OWL_SLAVE | PHASESPACE_INIT_FLAGS) : PHASESPACE_INIT_FLAGS;
if (owlInit(phasespace_server(), init_flags) < 0)
{
psOSCd_log("Connection to PhaseSpace Server \"%s\" failed, aborting.\n", phasespace_server());
exit(-1);
}
else
psOSCd_debug("Connection to PhaseSpace Server \"%s\" succeeded.\n", phasespace_server());
}
void
phasespace_initialize()
{
PhaseSpaceData *d = data();
phasespace_connect();
if (!slave()) /* slave may not setup anything */
(*d->initialize)();
d->status = PHASESPACE_INITIALIZED;
}
void
phasespace_close()
{
PhaseSpaceData *d = data();
owlDone();
(*d->destroy)();
d->status = PHASESPACE_CLEAN;
}
void
phasespace_send_data()
{
PhaseSpaceData *d = data();
(*d->put)();
}
int
phasespace_load_data()
{
PhaseSpaceData *d = data();
return (*d->get)();
}
void
phasespace_update_frequency()
{
owlSetFloat(OWL_FREQUENCY, system_frequency());
}
void
phasespace_start_streaming()
{
owlSetInteger(OWL_STREAMING, OWL_ENABLE);
}
void
phasespace_stop_streaming()
{
owlSetInteger(OWL_STREAMING, OWL_DISABLE);
}
const char *
phasespace_error(int n)
{
static char result[PSOSCD_BUFSIZE] = { '\0' };
if (n < 0)
sprintf(result, "%d", n);
else
switch(n)
{
case OWL_NO_ERROR: strcpy(result, "No Error");
break;
case OWL_INVALID_VALUE: strcpy(result, "Invalid Value");
break;
case OWL_INVALID_ENUM: strcpy(result, "Invalid Enum");
break;
case OWL_INVALID_OPERATION: strcpy(result, "Invalid Operation");
break;
default: sprintf(result, "0x%x", (unsigned int) n);
break;
}
return result;
}
static void
phasespace_switch(PhaseSpaceTrackingType t, void (*init)(), void (*free)(), int (*query)(), void (*send)())
{
PhaseSpaceData *d = data();
if (d->status == PHASESPACE_INITIALIZED)
phasespace_close();
d->type = t;
d->initialize = init;
d->destroy = free;
d->get = query;
d->put = send;
}
void
phasespace_switch_to_marker_tracking()
{
phasespace_switch(PHASESPACE_TRACKS_MARKERS, phasespace_initialize_markers,
phasespace_destroy_markers, phasespace_load_markers, phasespace_send_markers);
}
void
phasespace_switch_to_rigid_tracking()
{
phasespace_switch(PHASESPACE_TRACKS_RIGIDS, phasespace_initialize_rigids,
phasespace_destroy_rigids, phasespace_load_rigids, phasespace_send_rigids);
}