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)
85# define MOTION_C_API_LIBRARY "MotionCAPI.dll"
89# if defined(__APPLE__)
90# define MOTION_C_API_LIBRARY "libMotionCAPI.dylib"
92# define MOTION_C_API_LIBRARY "libMotionCAPI.so"
94# define GetProcAddress dlsym
113 typedef std::vector<float> data_type;
115 Sampler(
const std::string &address,
unsigned port);
118 bool get_data_block(data_type &data,
const unsigned &num_sensor);
123 HMODULE m_library_handle;
125 void *m_library_handle;
138 :
vrpn_Tracker(name, c), m_num_sensor(num_sensor), m_handle(NULL)
140#if defined(TRACKER_MOTIONNODE_TEST)
141 printf(
"vrpn_Tracker_MotionNode {\n");
147 std::string remote_address =
"127.0.0.1";
148 unsigned remote_port = 32079;
149 if (NULL != address) {
150 remote_address = address;
165 for (
int i=0; i<4; i++) {
166 sampler_type::data_type data;
167 if (sampler->get_data_block(data, m_num_sensor) && !data.empty()) {
174 if (NULL == m_handle) {
175 fprintf(stderr,
"MotionNode driver failed to start sampling, device not currently reading\n");
177#if defined(TRACKER_MOTIONNODE_TEST)
180 "Connected to Motion data service at \"%s:%d\"\n",
181 remote_address.c_str(), remote_port);
187 if ((NULL == m_handle) && (NULL != sampler)) {
191 fprintf(stderr,
"vrpn_Tracker_MotionNode::vrpn_Tracker_MotionNode(): delete failed\n");
197 if (NULL != m_handle) {
203#if defined(TRACKER_MOTIONNODE_TEST)
210#if defined(TRACKER_MOTIONNODE_TEST)
211 printf(
"~vrpn_Tracker_MotionNode() {\n");
214 if (NULL != m_handle) {
219 fprintf(stderr,
"vrpn_Tracker_MotionNode::~vrpn_Tracker_MotionNode(): delete failed\n");
226#if defined(TRACKER_MOTIONNODE_TEST)
227 printf(
"} ~vrpn_Tracker_MotionNode()\n");
239void vrpn_Tracker_MotionNode::get_report()
241 if (NULL != m_handle) {
244 sampler_type::data_type data;
245 if (sampler->get_data_block(data, m_num_sensor) && !data.empty()) {
247 for (std::size_t i=0; i<m_num_sensor; i++) {
249 if (index + 4 < data.size()) {
266void vrpn_Tracker_MotionNode::send_report()
273 fprintf(stderr,
"MotionNode: cannot write message: tossing\n");
279Sampler::Sampler(
const std::string &address,
unsigned port)
280 : m_handle(0), m_library_handle(NULL), m_mncapi_sample(NULL)
287 if (NULL == library_handle) {
288 library_handle = LoadLibrary(
"C:/Program Files/Motion/tools/plugin/capi/" MOTION_C_API_LIBRARY);
294 const char *SearchPaths[3] = {
297#if defined(__APPLE__)
304 void *library_handle = NULL;
305 for (
int i=0; i<3; i++) {
306 library_handle = dlopen(SearchPaths[i], RTLD_LAZY);
307 if (NULL != library_handle) {
308#if defined(TRACKER_MOTIONNODE_TEST)
309 printf(
"Loaded Motion C API library, \"%s\"\n", SearchPaths[i]);
317 if (NULL != library_handle) {
318 m_library_handle = library_handle;
323 if (NULL != mncapi_open_host) {
325 int handle = mncapi_open_host(
MNCAPI_PREVIEW, address.c_str(),
static_cast<int>(port));
332 if (NULL != mncapi_sample) {
333 m_mncapi_sample = mncapi_sample;
337 "failed to bind function \"mncapi_sample\" from Motion C API library\n");
343 "failed to connect to Motion data service at \"%s:%d\"\n",
344 address.c_str(), port);
350 "failed to bind function \"mncapi_open_host\" from Motion C API library\n");
362 if (NULL != m_library_handle) {
366 if (NULL != mncapi_close) {
367 mncapi_close(m_handle);
372 "failed to bind function \"mncapi_close\" from Motion C API library\n");
376 m_mncapi_sample = NULL;
379 if (FreeLibrary(m_library_handle)) {
381 if (0 == dlclose(m_library_handle)) {
384 fprintf(stderr,
"failed to unload Motion C API library\n");
387 m_library_handle = NULL;
391bool Sampler::get_data_block(data_type &data,
const unsigned &num_sensor)
395 if ((m_handle > 0) && (NULL != m_mncapi_sample) && (num_sensor > 0)) {
399 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)
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