Skip to content
This repository has been archived by the owner on Aug 16, 2018. It is now read-only.

Commit

Permalink
Fixed a bug I added to osceleton where orient path is not added to th…
Browse files Browse the repository at this point in the history
…e orient message properly. Also added osc2text command line tool for debugging
  • Loading branch information
AdbC99 committed Jul 3, 2011
1 parent bda293b commit 020c98d
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 10 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
all: osceleton
all: osceleton osc2file osc2text file2osc

liblo:
cd liblo-0.26;./configure;make
cd liblo-0.26-modified;./configure;make

osceleton: liblo
g++ src/OSCeleton.cpp src/viewer.cpp -O3 -Wno-write-strings -Iliblo-0.26 -I/usr/X11/include -I/usr/include/ni -lOpenNI -lstdc++ -L/usr/X11/lib -lGL -lGLU -lglut liblo-0.26/src/.libs/*.o -o osceleton
g++ src/OSCeleton.cpp src/viewer.cpp -O3 -Wno-write-strings -Iliblo-0.26-modified -I/usr/X11/include -I/usr/include/ni -lOpenNI -lstdc++ -L/usr/X11/lib -lGL -lGLU -lglut liblo-0.26-modified/src/.libs/*.o -o osceleton

osc2file: liblo
g++ osc_tools/osc2file.c -O3 -Wno-write-strings -Iliblo-0.26-modified liblo-0.26-modified/src/.libs/*.o -o osc2file

osc2text: liblo
g++ osc_tools/osc2text.c -O3 -Wno-write-strings -Iliblo-0.26-modified liblo-0.26-modified/src/.libs/*.o -o osc2text

file2osc: liblo
g++ osc_tools/file2osc.c -O3 -Wno-write-strings -Iliblo-0.26-modified liblo-0.26-modified/src/.libs/*.o -o file2osc

clean:
rm -f osceleton ; cd liblo-0.26; make clean
rm -f osceleton; rm -f os2file; rm -f file2osc ; cd liblo-0.26-modified; make clean
132 changes: 132 additions & 0 deletions osc_tools/osc2text.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (C) 2004 Steve Harris, Uwe Koloska
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* $Id$
*/

/* Minimal Modifications made to make this listen on a provided port */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "lo/lo.h"

int done = 0;

void error(int num, const char *m, const char *path);

int generic_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data);

int foo_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data);

int quit_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data);

int main(int argc, char * argv[])
{
if (argc < 2)
{
printf("- Missing Argument -\nUsage: osc2text port\n");
exit(1);
}

char port[6];
int ret;

/* TODO: We could have some better port number checks here, rather than letting
* liblo handle it
*/
if ((ret = snprintf(port,6,"%s",argv[1])) < 0)
{
printf("- Invalid port -");
exit(ret);
}

/* start a new server on port 7770 */
lo_server_thread st = lo_server_thread_new(port, error);

/* add method that will match any path and args */
lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);

/* add method that will match the path /foo/bar, with two numbers, coerced
* to float and int */
lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, NULL);

/* add method that will match the path /quit with no args */
lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL);

lo_server_thread_start(st);

while (!done) {
#ifdef WIN32
Sleep(1);
#else
usleep(1000);
#endif
}

lo_server_thread_free(st);

return 0;
}

void error(int num, const char *msg, const char *path)
{
printf("liblo server error %d in path %s: %s\n", num, path, msg);
fflush(stdout);
}

/* catch any incoming messages and display them. returning 1 means that the
* message has not been fully handled and the server should try other methods */
int generic_handler(const char *path, const char *types, lo_arg **argvx,
int argc, void *data, void *user_data)
{
int i;

printf("path: <%s>\n", path);
for (i=0; i<argc; i++) {
printf("arg %d '%c' ", i, types[i]);
lo_arg_pp((lo_type)types[i], argvx[i]);
printf("\n");
}
printf("\n");
fflush(stdout);

return 1;
}

int foo_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data)
{
/* example showing pulling the argument values out of the argv array */
printf("%s <- f:%f, i:%d\n\n", path, argv[0]->f, argv[1]->i);
fflush(stdout);

return 0;
}

int quit_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data)
{
done = 1;
printf("quiting\n\n");
fflush(stdout);

return 0;
}

/* vi:set ts=8 sts=4 sw=4: */
8 changes: 2 additions & 6 deletions src/OSCeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ void genOscMsg(lo_bundle *bundle, char *name) {

if (handMode || posConfidence >= 0.5f)
{
sprintf(tmp, "/joint");

lo_message msg = lo_message_new();

lo_message_add_string(msg, name);
Expand All @@ -227,13 +225,11 @@ void genOscMsg(lo_bundle *bundle, char *name) {
for (int i = 0; i < nDimensions; i++)
lo_message_add_float(msg, jointCoords[i]);

lo_bundle_add_message(*bundle, tmp, msg);
lo_bundle_add_message(*bundle, "/joint", msg);
}

if (!kitchenMode && sendOrient && orientConfidence >= 0.5f)
{
sprintf(tmp, "/orient");

lo_message msg = lo_message_new();

lo_message_add_string(msg, name);
Expand All @@ -256,7 +252,7 @@ void genOscMsg(lo_bundle *bundle, char *name) {
lo_message_add_float(msg, jointOrients[2+3]);
lo_message_add_float(msg, jointOrients[2+6]);

lo_bundle_add_message(*bundle, tmp, msg);
lo_bundle_add_message(*bundle, "/orient", msg);
}
}

Expand Down

0 comments on commit 020c98d

Please sign in to comment.