30#ifdef VRPN_USE_MOTIONNODE
51#if !defined(MNCAPI_PREVIEW_SIZE)
54# define MNCAPI_IMPORT_API __declspec(dllimport)
55# define MNCAPI_CALL_API __cdecl
57# define MNCAPI_IMPORT_API
58# define MNCAPI_CALL_API
63#define MNCAPI_PREVIEW_SIZE (14)
84# define MOTION_C_API_LIBRARY "MotionCAPI.dll"
88# if defined(__APPLE__)
89# define MOTION_C_API_LIBRARY "libMotionCAPI.dylib"
91# define MOTION_C_API_LIBRARY "libMotionCAPI.so"
93# define GetProcAddress dlsym
114 Sampler(
const std::string &address,
unsigned port);
117 bool get_data_block(data_type &data,
const unsigned &num_sensor);
122 HMODULE m_library_handle;
124 void *m_library_handle;
137 :
vrpn_Tracker(name, c), m_num_sensor(num_sensor), m_handle(NULL)
139#if defined(TRACKER_MOTIONNODE_TEST)
140 printf(
"vrpn_Tracker_MotionNode {\n");
146 std::string remote_address =
"127.0.0.1";
147 unsigned remote_port = 32079;
148 if (NULL != address) {
149 remote_address = address;
164 for (
int i=0; i<4; i++) {
165 sampler_type::data_type data;
166 if (sampler->get_data_block(data, m_num_sensor) && !data.
empty()) {
173 if (NULL == m_handle) {
174 fprintf(stderr,
"MotionNode driver failed to start sampling, device not currently reading\n");
176#if defined(TRACKER_MOTIONNODE_TEST)
179 "Connected to Motion data service at \"%s:%d\"\n",
180 remote_address.c_str(), remote_port);
186 if ((NULL == m_handle) && (NULL != sampler)) {
190 fprintf(stderr,
"vrpn_Tracker_MotionNode::vrpn_Tracker_MotionNode(): delete failed\n");
196 if (NULL != m_handle) {
202#if defined(TRACKER_MOTIONNODE_TEST)
209#if defined(TRACKER_MOTIONNODE_TEST)
210 printf(
"~vrpn_Tracker_MotionNode() {\n");
213 if (NULL != m_handle) {
218 fprintf(stderr,
"vrpn_Tracker_MotionNode::~vrpn_Tracker_MotionNode(): delete failed\n");
225#if defined(TRACKER_MOTIONNODE_TEST)
226 printf(
"} ~vrpn_Tracker_MotionNode()\n");
238void vrpn_Tracker_MotionNode::get_report()
240 if (NULL != m_handle) {
243 sampler_type::data_type data;
244 if (sampler->get_data_block(data, m_num_sensor) && !data.
empty()) {
246 for (std::size_t i=0; i<m_num_sensor; i++) {
248 if (index + 4 < data.
size()) {
265void vrpn_Tracker_MotionNode::send_report()
272 fprintf(stderr,
"MotionNode: cannot write message: tossing\n");
278Sampler::Sampler(
const std::string &address,
unsigned port)
279 : m_handle(0), m_library_handle(NULL), m_mncapi_sample(NULL)
286 if (NULL == library_handle) {
287 library_handle = LoadLibrary(
"C:/Program Files/Motion/tools/plugin/capi/" MOTION_C_API_LIBRARY);
293 const char *SearchPaths[3] = {
296#if defined(__APPLE__)
303 void *library_handle = NULL;
304 for (
int i=0; i<3; i++) {
305 library_handle = dlopen(SearchPaths[i], RTLD_LAZY);
306 if (NULL != library_handle) {
307#if defined(TRACKER_MOTIONNODE_TEST)
308 printf(
"Loaded Motion C API library, \"%s\"\n", SearchPaths[i]);
316 if (NULL != library_handle) {
317 m_library_handle = library_handle;
322 if (NULL != mncapi_open_host) {
324 int handle = mncapi_open_host(
MNCAPI_PREVIEW, address.c_str(),
static_cast<int>(port));
331 if (NULL != mncapi_sample) {
332 m_mncapi_sample = mncapi_sample;
336 "failed to bind function \"mncapi_sample\" from Motion C API library\n");
342 "failed to connect to Motion data service at \"%s:%d\"\n",
343 address.c_str(), port);
349 "failed to bind function \"mncapi_open_host\" from Motion C API library\n");
361 if (NULL != m_library_handle) {
365 if (NULL != mncapi_close) {
366 mncapi_close(m_handle);
371 "failed to bind function \"mncapi_close\" from Motion C API library\n");
375 m_mncapi_sample = NULL;
378 if (FreeLibrary(m_library_handle)) {
380 if (0 == dlclose(m_library_handle)) {
383 fprintf(stderr,
"failed to unload Motion C API library\n");
386 m_library_handle = NULL;
390bool Sampler::get_data_block(data_type &data,
const unsigned &num_sensor)
394 if ((m_handle > 0) && (NULL != m_mncapi_sample) && (num_sensor > 0)) {
398 int sample_result = m_mncapi_sample(m_handle, &data[0], data.size());
vrpn_Connection * d_connection
Connection that this object talks to.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
virtual ~vrpn_Tracker_MotionNode()
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Tracker_MotionNode(const char *name, vrpn_Connection *c, unsigned num_sensor, const char *address, unsigned port)
virtual int encode_to(char *buf)
int register_server_handlers(void)
vrpn_Tracker(const char *name, vrpn_Connection *c=NULL, const char *tracker_cfg_file_name=NULL)
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
const int vrpn_TRACKER_FAIL
const int vrpn_TRACKER_SYNCING
#define MOTION_C_API_LIBRARY
int(MNCAPI_CALL_API * MNCAPI_OPEN_HOST_FN)(enum mncapi_stream_t, const char *, int)
int(MNCAPI_CALL_API * MNCAPI_SAMPLE_FN)(int, float *, int)
void(MNCAPI_CALL_API * MNCAPI_CLOSE_FN)(int)
#define MNCAPI_PREVIEW_SIZE