Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • danc/MicroCART
  • snawerdt/MicroCART_17-18
  • bbartels/MicroCART_17-18
  • jonahu/MicroCART
4 results
Show changes
Showing
with 0 additions and 3389 deletions
#include <stdio.h> // for printf
#include <stdlib.h> // for exit
#include <vrpn_Connection.h> // for vrpn_Connection, etc
#include <vrpn_SharedObject.h> // for vrpn_Shared_int32_Remote, etc
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Shared.h" // for timeval
#include "vrpn_Types.h" // for vrpn_bool, vrpn_int32
int VRPN_CALLBACK noteChange (void * userdata, vrpn_int32 newValue, vrpn_bool isLocal) {
vrpn_Shared_int32_Remote * ip;
ip = (vrpn_Shared_int32_Remote *) userdata;
printf("Remote %s set to %d.\n", ip->name(), newValue);
return 0;
}
int main (int argc, char ** argv) {
vrpn_Connection * c;
timeval qsec;
qsec.tv_sec = 0L;
qsec.tv_usec = 250000L;
c = vrpn_get_connection_by_name(argv[1]);
if (!c) {
exit(0);
}
vrpn_Shared_int32_Remote a ("a", 0, VRPN_SO_DEFER_UPDATES);
a.bindConnection(c);
a.register_handler(noteChange, &a);
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
c->mainloop(&qsec);
a = 3;
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
c->mainloop(&qsec);
a = -3;
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
a.becomeSerializer();
c->mainloop(&qsec);
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
c->mainloop(&qsec);
a = 3;
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
c->mainloop(&qsec);
a = -3;
c->mainloop(&qsec);
printf("a = %d.\n", a.value());
while (1) {
c->mainloop();
}
}
#include <signal.h> // for signal, SIGINT
#include <stdio.h> // for printf, fprintf, NULL, etc
#include <stdlib.h> // for exit
#include "vrpn_Analog.h" // for vrpn_Analog_Remote, etc
#include "vrpn_Analog_Output.h" // for vrpn_Analog_Output_Remote
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Shared.h" // for timeval, vrpn_gettimeofday, etc
#include "vrpn_Types.h" // for vrpn_float64
#define POLL_INTERVAL (2000000) // time to poll if no response in a while (usec)
vrpn_Analog_Remote *ana;
vrpn_Analog_Output_Remote *anaout;
int done = 0;
bool analog_0_set = false;
vrpn_float64 analog_0;
/*****************************************************************************
*
Callback handlers
*
*****************************************************************************/
void VRPN_CALLBACK handle_analog (void *, const vrpn_ANALOGCB a)
{
int i;
printf("Analogs: ");
for (i = 0; i < a.num_channel; i++) {
printf("%4.2f ",a.channel[i]);
}
analog_0 = a.channel[0];
analog_0_set = true;
printf("\n");
}
/*****************************************************************************
*
init - initialize everything
*
*****************************************************************************/
void init (const char * devicename)
{
fprintf(stderr, "Zaber's name is %s.\n", devicename);
ana = new vrpn_Analog_Remote (devicename);
anaout = new vrpn_Analog_Output_Remote(devicename);
// Set up the callback handlers
printf("Analog update: Analogs: [new values listed]\n");
ana->register_change_handler(NULL, handle_analog);
} /* init */
void handle_cntl_c (int) {
done = 1;
}
void shutdown (void) {
fprintf(stderr, "\nIn control-c handler.\n");
if (ana) delete ana;
if (anaout) delete anaout;
exit(0);
}
int main (int argc, char * argv [])
{
struct timeval timestamp;
vrpn_gettimeofday(&timestamp, NULL);
#ifdef hpux
char default_station_name [100];
strcpy(default_station_name, "Analog0@localhost");
#else
char default_station_name [] = { "Analog0@localhost" };
#endif
const char * station_name = default_station_name;
if (argc < 2) {
fprintf(stderr, "Usage: %s Device_name\n"
" Device_name: VRPN name of data source to contact\n"
" example: Analog0@localhost\n",
argv[0]);
exit(0);
}
// parse args
station_name = argv[1];
// initialize the PC/station
init(station_name);
// signal handler so logfiles get closed right
signal(SIGINT, handle_cntl_c);
// Wait until we hear a value from analog0 so we know where
// to start.
analog_0_set = false;
while (!analog_0_set) {
ana->mainloop();
}
/*
* main interactive loop
*/
while ( ! done ) {
// Once every two seconds, ask the first analog to move
// 10000 steps bigger (if it is less than 10000) or
// 10000 steps shorter (if it is more than 10000)
struct timeval current_time;
vrpn_gettimeofday(&current_time, NULL);
if ( vrpn_TimevalDuration(current_time,timestamp) > POLL_INTERVAL) {
if (analog_0_set) {
double newval;
if (analog_0 > 10000) {
newval = analog_0-10000;
} else {
newval = analog_0+10000;
}
printf("Requesting change to %lf\n", newval);
anaout->request_change_channel_value(0, newval);
} else {
printf("No value yet from Zaber, not sending change request\n");
}
vrpn_gettimeofday(&timestamp, NULL);
}
// Let the devices do their things
anaout->mainloop();
ana->mainloop();
// Sleep for 1ms so we don't eat the CPU
vrpn_SleepMsecs(1);
}
shutdown();
return 0;
} /* main */
#include <math.h> // for pow
#include <stdio.h> // for fprintf, stderr, NULL, etc
#include <stdlib.h> // for rand
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Connection.h"
#include "vrpn_Imager.h" // for vrpn_IMAGERREGIONCB, etc
#include "vrpn_Types.h" // for vrpn_uint16
//-----------------------------------------------------------------
// This section contains a copy of an image that is shared between
// the client and server. It is completely an artifact of this test
// program. The program works by sending the whole image one piece
// at a time from the server to the client; the client then compares
// with the image to make sure it matches.
vrpn_uint16 *image = NULL; //< Holds the image to be sent and tested
const vrpn_uint16 image_x_size = 256;
const vrpn_uint16 image_y_size = 128;
// Allocate the image and fill it with random numbers
bool init_test_image(void)
{
vrpn_uint16 x,y;
if ( (image = new vrpn_uint16[image_x_size * image_y_size]) == NULL) {
fprintf(stderr, "Could not allocate image\n");
return false;
}
for (x = 0; x < image_x_size; x++) {
for (y = 0; y < image_y_size; y++) {
image[x + y*image_x_size] = rand();
}
}
return true;
}
//-----------------------------------------------------------------
// This section contains code that does what the server should do
vrpn_Connection *svrcon; //< Connection for server to talk on
vrpn_Imager_Server *svr; //< Image server to be used to send
int svrchan; //< Server channel index for image data
bool init_server_code(void)
{
if ( (svrcon = vrpn_create_server_connection()) == NULL) {
fprintf(stderr, "Could not open server connection\n");
return false;
}
if ( (svr = new vrpn_Imager_Server("TestImage", svrcon,
image_x_size, image_y_size)) == NULL) {
fprintf(stderr, "Could not open Imager Server\n");
return false;
}
if ( (svrchan = svr->add_channel("value", "unsigned16bit", 0, (float)(pow(2.0,16)-1))) == -1) {
fprintf(stderr, "Could not add channel to server image\n");
return false;
}
return true;
}
void mainloop_server_code(void)
{
static vrpn_uint16 y = 0; //< Loops through the image and sends data
// Send the current row over to the client.
svr->send_region_using_base_pointer(svrchan, 0, image_x_size-1, y,y, image, 1, image_x_size);
svr->mainloop();
printf("Sent a region\n");
// Go to the next line for next time.
if (++y == image_y_size) { y = 0; }
// Mainloop the server connection (once per server mainloop, not once per object)
svrcon->mainloop();
}
//-----------------------------------------------------------------
// This section contains code that does what the client should do.
// It listens until it has gotten twice as many rows as there are in
// the image and then indicates that it is done.
vrpn_Imager_Remote *clt; //< Client imager
int client_rows_gotten = 0; //< Keeps track of how many rows we've gotten
bool client_done = false; //< Lets us know if the client wants to quit
// Handler to get an image region in and check it against the image to make
// sure it came over okay. Also keeps track of how many rows we have.
void VRPN_CALLBACK handle_region_data(void *, const vrpn_IMAGERREGIONCB info)
{
unsigned x,y;
const vrpn_Imager_Channel *chan;
// Find out the scale and offset for this channel.
if ( (chan = clt->channel(info.region->d_chanIndex)) == NULL) {
fprintf(stderr, "Warning: Illegal channel index (%d) in region report\n", info.region->d_chanIndex);
return;
}
double scale = chan->scale;
double offset = chan->offset;
// Check the image data against the image to make sure it matches.
for (y = info.region->d_rMin; y <= info.region->d_rMax; y++) {
for (x = info.region->d_cMin; x <= info.region->d_cMax; x++) {
vrpn_uint16 val;
if (!info.region->read_unscaled_pixel(x,y,val)) {
fprintf(stderr, "Error indexing region that was read\n");
client_done = true;
return;
}
val = (vrpn_uint16)(val * scale + offset);
if (image[x+y*image_x_size] != val) {
fprintf(stderr, "Error: Read pixel (%d) does not match stored pixel (%d)\n",
val, image[x+y*image_x_size]);
client_done = true;
return;
}
}
}
// One more region... are we done?
printf("Got a region\n");
if (++client_rows_gotten >= 2*image_y_size) {
printf("Got %d rows -- success!\n", client_rows_gotten);
client_done = true;
}
}
bool init_client_code(void)
{
// Open the client object and set the callback handler for new region data
if ( (clt = new vrpn_Imager_Remote("TestImage@localhost")) == NULL) {
fprintf(stderr, "Error: Cannot create remote image object\n");
return false;
}
if (clt->register_region_handler(NULL, handle_region_data) == -1) {
fprintf(stderr, "Error: cannot register handler for regions\n");
return false;
}
// Set callback handler for new description data (user code might not do this).
return true;
}
void mainloop_client_code(void)
{
clt->mainloop();
}
//-----------------------------------------------------------------
// Mostly just calls the above functions; split into client and
// server parts is done clearly to help people who want to use this
// as example code. You could pull the above functions down into
// the main() program body without trouble (except for the callback
// handler, of course).
int main(int argc, char *argv[])
{
if (!init_test_image()) { return -1; }
if (!init_server_code()) { return -1; }
if (!init_client_code()) { return -1; }
while (!client_done) {
mainloop_server_code();
mainloop_client_code();
}
if (clt) { delete clt; }
if (svr) { delete svr; }
return 0;
}
# Microsoft Developer Studio Project File - Name="test_imager" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test_imager - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test_imager.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test_imager.mak" CFG="test_imager - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test_imager - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test_imager - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test_imager - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../pc_win32/server_src/test_imager/Release"
# PROP Intermediate_Dir "../pc_win32/server_src/test_imager/Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c /Tp
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../pc_win32/Release" /libpath:"../pc_win32/DLL/Release"
!ELSEIF "$(CFG)" == "test_imager - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../pc_win32/server_src/test_imager/Debug"
# PROP Intermediate_Dir "../pc_win32/server_src/test_imager/Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c /Tp
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../pc_win32/Debug" /libpath:"../pc_win32/DLL/Debug"
!ENDIF
# Begin Target
# Name "test_imager - Win32 Release"
# Name "test_imager - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=test_imager.C
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="test_imager"
ProjectGUID="{3A77BE37-0660-4CC9-A7F8-CE83070278CB}"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\../pc_win32/server_src/test_imager/Release"
IntermediateDirectory=".\../pc_win32/server_src/test_imager/Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/server_src/test_imager/Release/test_imager.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK\Include,..\"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\../pc_win32/server_src/test_imager/Release/test_imager.pch"
AssemblerListingLocation=".\../pc_win32/server_src/test_imager/Release/"
ObjectFile=".\../pc_win32/server_src/test_imager/Release/"
ProgramDataBaseFileName=".\../pc_win32/server_src/test_imager/Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\../pc_win32/server_src/test_imager/Release/test_imager.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
ProgramDatabaseFile=".\../pc_win32/server_src/test_imager/Release/test_imager.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/server_src/test_imager/Release/test_imager.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\../pc_win32/server_src/test_imager/Debug"
IntermediateDirectory=".\../pc_win32/server_src/test_imager/Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/server_src/test_imager/Debug/test_imager.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK\Include,..\"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\../pc_win32/server_src/test_imager/Debug/test_imager.pch"
AssemblerListingLocation=".\../pc_win32/server_src/test_imager/Debug/"
ObjectFile=".\../pc_win32/server_src/test_imager/Debug/"
ProgramDataBaseFileName=".\../pc_win32/server_src/test_imager/Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\../pc_win32/server_src/test_imager/Debug/test_imager.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../pc_win32/server_src/test_imager/Debug/test_imager.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/server_src/test_imager/Debug/test_imager.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="test_imager.C"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
#include <stdio.h>
#include <string.h>
#include <stdlib.h> // for exit(), atoi()
#include <vrpn_Mutex.h>
int rg (void *) {
printf("callback - Mutex granted.\n");
return 0;
}
int rd (void *) {
printf("callback - Mutex denied.\n");
return 0;
}
int rel (void *) {
printf("callback - Mutex released.\n");
return 0;
}
int main (int argc, char ** argv) {
vrpn_Mutex_Remote * me;
char inputLine [100];
me = new vrpn_Mutex_Remote (argv[1]);
me->addRequestGrantedCallback(NULL, rg);
me->addRequestDeniedCallback(NULL, rd);
me->addReleaseCallback(NULL, rel);
printf("req - request the mutex.\n");
printf("rel - release the mutex.\n");
printf("? - get current mutex state.\n");
printf("quit - exit.\n");
while (1) {
me->mainloop();
memset(inputLine, 0, 100);
if (fgets(inputLine, 100, stdin) == NULL) {
perror("Could not read line");
exit(-1);
}
if (!strncmp(inputLine, "req", 3)) {
printf("test_mutex: sending request.\n");
me->request();
} else if (!strncmp(inputLine, "rel", 3)) {
printf("test_mutex: sending release.\n");
me->release();
} else if (!strncmp(inputLine, "?", 1)) {
printf("isAvailable: %d.\n", me->isAvailable());
printf("isHeldLocally: %d.\n", me->isHeldLocally());
printf("isHeldRemotely: %d.\n", me->isHeldRemotely());
} else if (!strncmp(inputLine, "quit", 4)) {
delete me;
exit(0);
} else {
printf(".\n");
}
}
}
# Microsoft Developer Studio Project File - Name="test_zaber" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test_zaber - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test_zaber.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test_zaber.mak" CFG="test_zaber - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test_zaber - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test_zaber - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test_zaber - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I ".." /I "..\..\quat" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c /Tp
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../pc_win32/Release" /libpath:"../pc_win32/DLL/Release"
!ELSEIF "$(CFG)" == "test_zaber - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../pc_win32/client_src/test_Zaber/Debug"
# PROP Intermediate_Dir "../pc_win32/client_src/test_Zaber/Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".." /I "..\..\quat" /D "_CONSOLE" /D "_DEBUG" /D "_MBCS" /D "WIN32" /YX /FD /GZ /c /Tp
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../pc_win32/Debug" /libpath:"../pc_win32/DLL/Debug"
!ENDIF
# Begin Target
# Name "test_zaber - Win32 Release"
# Name "test_zaber - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\test_Zaber.C
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="test_zaber"
ProjectGUID="{218270DA-87E3-4DF5-9550-FE9A9B07BFBB}"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/test_zaber.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,.."
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/test_zaber.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/test_zaber.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
ProgramDatabaseFile=".\Release/test_zaber.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/test_zaber.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\../pc_win32/client_src/test_Zaber/Debug"
IntermediateDirectory=".\../pc_win32/client_src/test_Zaber/Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/client_src/test_Zaber/Debug/test_zaber.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,.."
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\../pc_win32/client_src/test_Zaber/Debug/test_zaber.pch"
AssemblerListingLocation=".\../pc_win32/client_src/test_Zaber/Debug/"
ObjectFile=".\../pc_win32/client_src/test_Zaber/Debug/"
ProgramDataBaseFileName=".\../pc_win32/client_src/test_Zaber/Debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\../pc_win32/client_src/test_Zaber/Debug/test_zaber.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../pc_win32/client_src/test_Zaber/Debug/test_zaber.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/client_src/test_Zaber/Debug/test_zaber.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="test_Zaber.C"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
//----------------------------------------------------------------------------
// Example program to read pixels from a vrpn_Imager server and display
// them in an OpenGL window. It assumes that the size of the imager does
// not change during the run. It asks for unsigned 8-bit pixels.
#include <stdio.h> // for printf, NULL, fprintf, etc
#include <stdlib.h> // for exit
#include <string.h> // for strcmp
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Shared.h" // for timeval, vrpn_SleepMsecs, etc
#include <vrpn_Connection.h> // for vrpn_Connection, etc
#include <vrpn_FileConnection.h>
#include <vrpn_Imager.h> // for vrpn_Imager_Remote, etc
#ifdef __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#else
#include <GL/gl.h> // for glClear, glClearColor, etc
#include <GL/glut.h> // for glutCreateWindow, etc // IWYU pragma: keep
#endif
//----------------------------------------------------------------------------
// Glut insists on taking over the whole application, leaving us to use
// global variables to pass information between the various callback
// handlers.
bool g_quit = false; //< Set to true when time to quit
vrpn_Connection *g_connection; //< Set if logging is enabled.
vrpn_Imager_Remote *g_imager; //< Imager client object
bool g_got_dimensions = false; //< Heard image dimensions from server?
int g_Xdim, g_Ydim; //< Dimensions in X and Y
bool g_ready_for_region = false; //< Everything set up to handle a region?
unsigned char *g_image = NULL; //< Pointer to the storage for the image
bool g_already_posted = false; //< Posted redisplay since the last display?
bool g_autoscale = false; //< Should we auto-scale the brightness and contrast?
//----------------------------------------------------------------------------
// Imager callback handlers.
void VRPN_CALLBACK handle_discarded_frames(void *, const vrpn_IMAGERDISCARDEDFRAMESCB info)
{
printf("Server discarded %d frames\n", (int)(info.count));
}
void VRPN_CALLBACK handle_description_message(void *, const struct timeval)
{
// This method is different from other VRPN callbacks because it simply
// reports that values have been filled in on the Imager_Remote class.
// It does not report what the new values are, only the time at which
// they changed.
// If we have already heard the dimensions, then check and make sure they
// have not changed. Also ensure that there is at least one channel. If
// not, then print an error and exit.
if (g_got_dimensions) {
if ( (g_Xdim != g_imager->nCols()) || (g_Ydim != g_imager->nRows()) ) {
fprintf(stderr,"Error -- different image dimensions reported\n");
exit(-1);
}
if (g_imager->nChannels() <= 0) {
fprintf(stderr,"Error -- No channels to display!\n");
exit(-1);
}
}
// Record that the dimensions are filled in. Fill in the globals needed
// to store them.
g_Xdim = g_imager->nCols();
g_Ydim = g_imager->nRows();
g_got_dimensions = true;
}
void myDisplayFunc();
// New pixels coming: fill them into the image and tell Glut to redraw.
void VRPN_CALLBACK handle_region_change(void *userdata, const vrpn_IMAGERREGIONCB info)
{
const vrpn_Imager_Region *region=info.region;
const vrpn_Imager_Remote *imager = (const vrpn_Imager_Remote *)userdata;
// Just leave things alone if we haven't set up the drawable things
// yet.
if (!g_ready_for_region) { return; }
// Copy pixels into the image buffer.
// Flip the image over in Y so that the image coordinates
// display correctly in OpenGL.
// Figure out which color to put the data in depending on the name associated
// with the channel index. If it is one of "red", "green", or "blue" then put
// it into that channel.
if (strcmp(imager->channel(region->d_chanIndex)->name, "red") == 0) {
region->decode_unscaled_region_using_base_pointer(g_image+0, 3, 3*g_Xdim, 0, g_Ydim, true);
} else if (strcmp(imager->channel(region->d_chanIndex)->name, "green") == 0) {
region->decode_unscaled_region_using_base_pointer(g_image+1, 3, 3*g_Xdim, 0, g_Ydim, true);
} else if (strcmp(imager->channel(region->d_chanIndex)->name, "blue") == 0) {
region->decode_unscaled_region_using_base_pointer(g_image+2, 3, 3*g_Xdim, 0, g_Ydim, true);
} else {
// This uses a repeat count of three to put the data into all channels.
// NOTE: This copies each channel into all buffers, rather
// than just a specific one (overwriting all with the last one written). A real
// application will probably want to provide a selector to choose which
// is drawn. It can check region->d_chanIndex to determine which channel
// is being reported for each callback.
region->decode_unscaled_region_using_base_pointer(g_image, 3, 3*g_Xdim, 0, g_Ydim, true, 3);
}
// If we're logging, save to disk. This is needed to keep up with
// logging and because the program is killed to exit.
if (g_connection) { g_connection->save_log_so_far(); }
// We do not post a redisplay here, because we want to do that only
// when we've gotten the end of a frame. It is done in the
// end_of_frame message handler.
}
void VRPN_CALLBACK handle_end_of_frame(void *,const struct _vrpn_IMAGERENDFRAMECB)
{
// Tell Glut it is time to draw. Make sure that we don't post the redisplay
// operation more than once by checking to make sure that it has been handled
// since the last time we posted it. If we don't do this check, it gums
// up the works with tons of redisplay requests and the program won't
// even handle windows events.
// NOTE: This exposes a race condition. If more video messages arrive
// before the frame-draw is executed, then we'll end up drawing some of
// the new frame along with this one. To make really sure there is not tearing,
// double buffer: fill partial frames into one buffer and draw from the
// most recent full frames in another buffer. You could use an OpenGL texture
// as the second buffer, sending each full frame into texture memory and
// rendering a textured polygon.
if (!g_already_posted) {
g_already_posted = true;
glutPostRedisplay();
}
}
//----------------------------------------------------------------------------
// Capture timing information and print out how many frames per second
// are being drawn. Remove this function if you don't want timing info.
void print_timing_info(void)
{ static struct timeval last_print_time;
struct timeval now;
static bool first_time = true;
static int frame_count = 0;
if (first_time) {
vrpn_gettimeofday(&last_print_time, NULL);
first_time = false;
} else {
frame_count++;
vrpn_gettimeofday(&now, NULL);
double timesecs = 0.001 * vrpn_TimevalMsecs(vrpn_TimevalDiff(now, last_print_time));
if (timesecs >= 5) {
double frames_per_sec = frame_count / timesecs;
frame_count = 0;
printf("Displayed frames per second = %lg\n", frames_per_sec);
last_print_time = now;
}
}
}
//----------------------------------------------------------------------------
// Auto-scale the image so that the darkest pixel is 0 and the brightest
// is 255. This is to provide a function that someone using this program
// to watch a microscope video wanted -- we're starting down the slippery
// slope of turning this from an example program into an application...
void do_autoscale(void)
{
// Find the minimum and maximum value of all pixels of all colors
// in the image.
unsigned char min_val = g_image[0];
unsigned char max_val = min_val;
int x,y,c;
for (x = 0; x < g_Xdim; x++) {
for (y = 0; y < g_Ydim; y++) {
for (c = 0; c < 3; c++) {
unsigned char val = g_image[c + 3 * ( x + g_Xdim * ( y ) )];
if (val < min_val) { min_val = val; }
if (val > max_val) { max_val = val; }
}
}
}
// Compute the scale and offset to apply to map the minimum value to
// zero and the maximum value to 255.
float offset = min_val;
float scale;
if (max_val == min_val) {
scale = 1;
} else {
scale = 255.0 / (max_val - min_val);
}
// Apply this scaling to each pixel.
for (x = 0; x < g_Xdim; x++) {
for (y = 0; y < g_Ydim; y++) {
for (c = 0; c < 3; c++) {
float val = g_image[c + 3 * ( x + g_Xdim * ( y ) )];
val = (val - offset) * scale;
g_image[c + 3 * ( x + g_Xdim * ( y ) )] = static_cast<unsigned char>(val);
}
}
}
}
//----------------------------------------------------------------------------
// Glut callback handlers.
void myDisplayFunc(void)
{
// Clear the window and prepare to draw in the back buffer.
// This is not strictly necessary, because we're going to overwrite
// the entire window without Z buffering turned on.
glDrawBuffer(GL_BACK);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
// If we're auto-scaling the image, do so now.
if (g_autoscale) {
do_autoscale();
}
// Store the pixels from the image into the frame buffer
// so that they cover the entire image (starting from lower-left
// corner, which is at (-1,-1)).
glRasterPos2f(-1, -1);
glDrawPixels(g_imager->nCols(),g_imager->nRows(), GL_RGB, GL_UNSIGNED_BYTE, g_image);
// Swap buffers so we can see it.
glutSwapBuffers();
// Capture timing information and print out how many frames per second
// are being drawn.
print_timing_info();
// We've no longer posted redisplay since the last display.
g_already_posted = false;
}
void myIdleFunc(void)
{
// See if there are any more messages from the server and then sleep
// a little while so that we don't eat the whole CPU.
g_imager->mainloop();
vrpn_SleepMsecs(5);
if (g_quit) {
delete g_imager;
if (g_image) { delete [] g_image; g_image = NULL; };
exit(0);
}
}
void myKeyboardFunc(unsigned char key, int x, int y)
{
switch (key) {
case 27: // Escape
case 'q':
case 'Q':
g_quit = 1;
break;
case 'a':
case 'A':
g_autoscale = !g_autoscale;
printf("Turning autoscaling %s\n", g_autoscale?"on":"off" );
break;
case '0': // For a number, set the throttle to that number
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
printf("Throttling after %d frames\n", key - '0');
g_imager->throttle_sender(key - '0');
break;
case '-': // For the '-' sign, set the throttle to unlimited
printf("Turning off frame throttle\n");
g_imager->throttle_sender(-1);
break;
}
}
int main(int argc, char **argv)
{
char default_imager[] = "TestImage@localhost";
char *device_name = default_imager;
char *logfile_name = NULL;
int i;
// Parse the command line. If there is one argument, it is the device
// name. If there is a second, it is a logfile name.
if (argc >= 2) { device_name = argv[1]; }
if (argc >= 3) { logfile_name = argv[2]; }
if (argc > 3) { fprintf(stderr, "Usage: %s [device_name [logfile_name]]\n", argv[0]); exit(-1); }
// In case we end up loading an video from a file, make sure we
// neither pre-load nor accumulate the images.
vrpn_FILE_CONNECTIONS_SHOULD_PRELOAD = false;
vrpn_FILE_CONNECTIONS_SHOULD_ACCUMULATE = false;
// Say that we've posted a redisplay so that the callback handler
// for endframe doesn't try to post one before glut is open.
g_already_posted = true;
// Create a log file of the video if we've been asked to do logging.
// This has the side effect of having the imager also use this same
// connection, because VRPN maps the same connection name to the
// same one rather than creating a new one.
if (logfile_name) {
g_connection = vrpn_get_connection_by_name(device_name, logfile_name);
}
// Open the Imager client and set the callback
// for new data and for information about the size of
// the image.
printf("Opening %s\n", device_name);
g_imager = new vrpn_Imager_Remote(device_name);
g_imager->register_description_handler(NULL, handle_description_message);
g_imager->register_region_handler(g_imager, handle_region_change);
g_imager->register_discarded_frames_handler(NULL, handle_discarded_frames);
g_imager->register_end_frame_handler(g_imager, handle_end_of_frame);
printf("Waiting to hear the image dimensions...\n");
while (!g_got_dimensions) {
g_imager->mainloop();
vrpn_SleepMsecs(1);
}
// Because the vrpn_Imager server doesn't follow "The VRPN Way" in that
// it will continue to attempt to flood the network with more data than
// can be sent, we need to tell the client's connection to stop handling
// incoming messages after some finite number, to avoid getting stuck down
// in the imager's mainloop() and never returning control to the main
// program. This strange-named function does this for us. If the camera
// is not sending too many messages for the network, this should not have
// any effect.
g_imager->connectionPtr()->Jane_stop_this_crazy_thing(50);
// Allocate memory for the image and clear it, so that things that
// don't get filled in will be black.
if ( (g_image = new unsigned char[g_Xdim * g_Ydim * 3]) == NULL) {
fprintf(stderr,"Out of memory when allocating image!\n");
return -1;
}
for (i = 0; i < g_Xdim * g_Ydim * 3; i++) {
g_image[i] = 0;
}
g_ready_for_region = true;
printf("Receiving images at size %dx%d\n", g_Xdim, g_Ydim);
printf("Press '0'-'9' in OpenGL window to throttle incoming images.\n");
printf("Press '-' to disable throttling.\n");
printf("Press 'a' to enable/disable autoscaling of brightness.\n");
printf("Press 'q' or 'Q' or ESC to quit.\n");
// Initialize GLUT and create the window that will display the
// video -- name the window after the device that has been
// opened in VRPN.
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(g_Xdim, g_Ydim);
glutInitWindowPosition(100, 100);
glutCreateWindow(vrpn_copy_service_name(device_name));
// Set the display function and idle function for GLUT (they
// will do all the work) and then give control over to GLUT.
glutDisplayFunc(myDisplayFunc);
glutIdleFunc(myIdleFunc);
glutKeyboardFunc(myKeyboardFunc);
glutMainLoop();
// Clean up objects and return. This code is never called because
// glutMainLoop() never returns.
return 0;
}
# Microsoft Developer Studio Project File - Name="testimager_client" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=testimager_client - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "testimager_client.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "testimager_client.mak" CFG="testimager_client - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "testimager_client - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "testimager_client - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "testimager_client - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../pc_win32/client_src/testimager_client/Release"
# PROP Intermediate_Dir "../pc_win32/client_src/testimager_client/Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "../" /I "C:\nsrg\external\pc_win32\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c /Tp
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 glut32.lib opengl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../pc_win32/Release" /libpath:"../pc_win32/DLL/Release" /libpath:"C:\nsrg\external\pc_win32\lib"
!ELSEIF "$(CFG)" == "testimager_client - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../pc_win32/client_src/testimager_client/Debug"
# PROP Intermediate_Dir "../pc_win32/client_src/testimager_client/Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../" /I "C:\nsrg\external\pc_win32\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c /Tp
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 glut32.lib opengl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../pc_win32/Debug" /libpath:"../pc_win32/DLL/Debug" /libpath:"C:\nsrg\external\pc_win32\lib"
!ENDIF
# Begin Target
# Name "testimager_client - Win32 Release"
# Name "testimager_client - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\testimager_client.C
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="testimager_client"
ProjectGUID="{AC3D4ACE-C143-484A-B4E7-2EC70AA12781}"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\../pc_win32/client_src/testimager_client/Release"
IntermediateDirectory=".\../pc_win32/client_src/testimager_client/Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/client_src/testimager_client/Release/testimager_client.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include&quot;;&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK\Include&quot;;../;C:\nsrg\external\pc_win32\GL\include"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\../pc_win32/client_src/testimager_client/Release/testimager_client.pch"
AssemblerListingLocation=".\../pc_win32/client_src/testimager_client/Release/"
ObjectFile=".\../pc_win32/client_src/testimager_client/Release/"
ProgramDataBaseFileName=".\../pc_win32/client_src/testimager_client/Release/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="glut32.lib opengl32.lib"
OutputFile=".\../pc_win32/client_src/testimager_client/Release/testimager_client.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib&quot;;C:\nsrg\external\pc_win32\GL\lib;&quot;C:\Program Files (x86)\CISMM\external\GL\lib&quot;"
ProgramDatabaseFile=".\../pc_win32/client_src/testimager_client/Release/testimager_client.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="true"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/client_src/testimager_client/Release/testimager_client.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\../pc_win32/client_src/testimager_client/Debug"
IntermediateDirectory=".\../pc_win32/client_src/testimager_client/Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/client_src/testimager_client/Debug/testimager_client.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include&quot;;&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK\Include&quot;;../;C:\nsrg\external\pc_win32\GL\include"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\../pc_win32/client_src/testimager_client/Debug/testimager_client.pch"
AssemblerListingLocation=".\../pc_win32/client_src/testimager_client/Debug/"
ObjectFile=".\../pc_win32/client_src/testimager_client/Debug/"
ProgramDataBaseFileName=".\../pc_win32/client_src/testimager_client/Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="glut32.lib opengl32.lib"
OutputFile=".\../pc_win32/client_src/testimager_client/Debug/testimager_client.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib&quot;;C:\nsrg\external\pc_win32\GL\lib;&quot;C:\Program Files (x86)\CISMM\external\GL\lib&quot;"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../pc_win32/client_src/testimager_client/Debug/testimager_client.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="true"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/client_src/testimager_client/Debug/testimager_client.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="testimager_client.C"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
#include <signal.h> // for signal, SIGINT
#include <stdio.h> // for printf, NULL
#include <stdlib.h> // for exit
#include <vrpn_Connection.h> // for vrpn_Connection
#include <vrpn_Text.h> // for vrpn_Text_Receiver, etc
#include "vrpn_Configure.h" // for VRPN_CALLBACK
vrpn_Connection * c;
void handle_cntl_c (int) {
const char * n;
long i;
if (c)
for (i = 0L; (n = c->sender_name(i)); i++)
printf("Knew sender \"%s\".\n", n);
// print out type names
if (c)
for (i = 0L; (n = c->message_type_name(i)); i++)
printf("Knew type \"%s\".\n", n);
exit(0);
}
void VRPN_CALLBACK my_handler(void * userdata, const vrpn_TEXTCB info){
printf("%d %d %s\n", info.type, info.level, info.message);
}
int main(int argc, char* argv[])
{
vrpn_Text_Receiver * r = new vrpn_Text_Receiver (argv[1]);
r->register_message_handler(NULL, my_handler);
// DEBUGGING - TCH 8 Sept 98
c = r->connectionPtr();
signal(SIGINT, handle_cntl_c);
while (1)
r->mainloop();
}
#include <stdio.h> // for fprintf, stderr, printf, etc
#include <stdlib.h> // for atoi, exit
#include <string.h> // for strcmp
#include <vrpn_Shared.h> // for vrpn_gettimeofday, vrpn_SleepMsecs, timeval
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Poser.h" // for vrpn_Poser_Remote
#include "vrpn_Tracker.h" // for vrpn_TRACKERCB, etc
static bool g_verbose = false;
void Usage (const char * s)
{
fprintf(stderr,"Usage: %s [-v] [-millisleep n] [trackername [posername]]\n",s);
fprintf(stderr," -millisleep: Sleep n milliseconds each loop cycle\n");
fprintf(stderr," (if no option is specified, the Windows architecture\n");
fprintf(stderr," will free the rest of its time slice on each loop\n");
fprintf(stderr," but leave the processes available to be run immediately;\n");
fprintf(stderr," a 1ms sleep is the default on all other architectures).\n");
fprintf(stderr," -millisleep 0 is recommended when using this server and\n");
fprintf(stderr," a client on the same uniprocessor CPU Win32 PC.\n");
fprintf(stderr," -millisleep -1 will cause the server process to use the\n");
fprintf(stderr," whole CPU on any uniprocessor machine.\n");
fprintf(stderr," -v: Verbose.\n");
fprintf(stderr," trackername: String name of the tracker device (default Tracker0@localhost)\n");
fprintf(stderr," posername: String name of the poser device (default Poser0@localhost)\n");
exit(0);
}
//--------------------------------------------------------------------------------------
// This function takes the pose reported by the tracker and sends it
// directly to the poser, without changing it in any way. For this to
// work properly, the tracker must report translations in just the right
// space for the poser.
void VRPN_CALLBACK handle_tracker_update(void *userdata, const vrpn_TRACKERCB t)
{
// Turn the pointer into a poser pointer.
vrpn_Poser_Remote *psr= (vrpn_Poser_Remote*)userdata;
// Get the data from the tracker and send it to the poser.
struct timeval now;
vrpn_gettimeofday(&now, NULL);
psr->request_pose(now, t.pos, t.quat);
}
int main (int argc, char * argv[])
{
char default_tracker[] = "Tracker0@localhost";
char default_poser[] = "Poser0@localhost";
char *tracker_client_name = default_tracker;
char *poser_client_name = default_poser;
int realparams = 0;
int i;
#ifdef _WIN32
// On Windows, the millisleep with 0 option frees up the CPU time slice for other jobs
// but does not sleep for a specific time. On Unix, this returns immediately and does
// not do anything but waste cycles.
int milli_sleep_time = 0; // How long to sleep each iteration (default: free the timeslice but be runnable again immediately)
#else
int milli_sleep_time = 1; // How long to sleep each iteration (default: 1ms)
#endif
#ifdef WIN32
WSADATA wsaData;
int status;
if ((status = WSAStartup(MAKEWORD(1,1), &wsaData)) != 0) {
fprintf(stderr, "WSAStartup failed with %d\n", status);
return(1);
}
#endif // not WIN32
//--------------------------------------------------------------------------------------
// Parse the command line
i = 1;
while (i < argc) {
if (!strcmp(argv[i], "-v")) { // Specify config-file name
g_verbose = true;
} else if (!strcmp(argv[i], "-millisleep")) { // How long to sleep each loop?
if (++i > argc) { Usage(argv[0]); }
milli_sleep_time = atoi(argv[i]);
} else if (argv[i][0] == '-') { // Unknown flag
Usage(argv[0]);
} else switch (realparams) { // Non-flag parameters
case 0:
tracker_client_name = argv[i];
realparams++;
break;
case 1:
poser_client_name = argv[i];
realparams++;
break;
default:
Usage(argv[0]);
}
i++;
}
if (realparams > 2) {
Usage(argv[0]);
}
//--------------------------------------------------------------------------------------
// Open the tracker and poser objects that we're going to use.
if (g_verbose) {
printf("Opening tracker %s, poser %s\n", tracker_client_name, poser_client_name);
}
vrpn_Tracker_Remote *tkr = new vrpn_Tracker_Remote(tracker_client_name);
vrpn_Poser_Remote *psr = new vrpn_Poser_Remote(poser_client_name);
//--------------------------------------------------------------------------------------
// Set up the callback handler on the tracker object and pass it
// a pointer to the poser it is to use. Only ask for data from
// sensor 0.
tkr->register_change_handler(psr, handle_tracker_update, 0);
//--------------------------------------------------------------------------------------
// Loop forever until killed.
while (1) {
tkr->mainloop();
psr->mainloop();
vrpn_SleepMsecs(milli_sleep_time);
}
return 0;
}
# Microsoft Developer Studio Project File - Name="tracker_to_poser" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=tracker_to_poser - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "tracker_to_poser.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "tracker_to_poser.mak" CFG="tracker_to_poser - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "tracker_to_poser - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "tracker_to_poser - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "tracker_to_poser - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../quat" /I "../" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c /Tp
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../pc_win32/Release" /libpath:"../pc_win32/DLL/Release"
!ELSEIF "$(CFG)" == "tracker_to_poser - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../quat" /I "../" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c /Tp
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../pc_win32/Debug" /libpath:"../pc_win32/DLL/Debug"
!ENDIF
# Begin Target
# Name "tracker_to_poser - Win32 Release"
# Name "tracker_to_poser - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\tracker_to_poser.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="tracker_to_poser"
ProjectGUID="{1AC1C1EB-400A-4838-AC5E-48F3F9CE7D5C}"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/tracker_to_poser.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,../quat,../"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/tracker_to_poser.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/tracker_to_poser.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
ProgramDatabaseFile=".\Release/tracker_to_poser.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/tracker_to_poser.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/tracker_to_poser.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include,../quat,../"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/tracker_to_poser.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Debug/tracker_to_poser.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/tracker_to_poser.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/tracker_to_poser.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="tracker_to_poser.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
// Test code for vrpn_LamportClock
#ifdef VRPN_USE_OLD_STREAMS
#include <iostream.h>
#else
#include <iostream>
using namespace std;
#endif
#include <assert.h>
#include <vrpn_LamportClock.h>
vrpn_LamportClock * clockA;
vrpn_LamportClock * clockB;
void setUp (void) {
clockA = new vrpn_LamportClock (2, 0);
clockB = new vrpn_LamportClock (2, 1);
}
void tearDown (void) {
if (clockA) delete clockA;
if (clockB) delete clockB;
}
void test_one_getTimestampAndAdvance (void) {
vrpn_LamportTimestamp * t1 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp tc (*t1);
assert(t1);
assert(t1->size() == 2);
assert((*t1)[0] == 1);
assert((*t1)[1] == 0);
assert(!(*t1 < *t1));
assert(!(tc < *t1));
assert(!(*t1 < tc));
vrpn_LamportTimestamp * t2 = clockA->getTimestampAndAdvance();
assert(t2);
assert((*t1)[0] == 1);
assert((*t1)[1] == 0);
assert(t2->size() == 2);
assert((*t2)[0] == 2);
assert((*t2)[1] == 0);
assert(*t1 < *t2);
assert(!(*t2 < *t1));
vrpn_LamportTimestamp * t3 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * t4 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * t5 = clockA->getTimestampAndAdvance();
assert(t5->size() == 2);
assert((*t5)[0] == 5);
assert((*t5)[1] == 0);
delete t1;
delete t2;
delete t3;
delete t4;
delete t5;
}
void test_two (void) {
vrpn_LamportTimestamp * ta1 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * tb1 = clockB->getTimestampAndAdvance();
clockA->receive(*tb1);
vrpn_LamportTimestamp * ta2 = clockA->getTimestampAndAdvance();
assert((*ta2)[0] == 2);
assert((*ta2)[1] == 1);
assert(*ta1 < *ta2);
assert(*tb1 < *ta2);
assert(!(*tb1 < *ta1));
assert(!(*ta1 < *tb1));
delete ta1;
delete tb1;
delete ta2;
}
int main (int argc, char ** argv) {
setUp();
test_one_getTimestampAndAdvance();
tearDown();
setUp();
test_two();
tearDown();
cout << "OK" << endl;
}
/* This program will ping a VRPN server and time how long it takes the server
that is being pinged to respond. It makes use of the VRPN ping/pong
mechanism by which objects detect if they have connected to servers.
It gives an indication of the round-trip time from a message at the user
level from a client through the user level at a server.
*/
#include <signal.h> // for signal, SIGINT
#include <stdio.h> // for NULL, printf
#include <stdlib.h> // for exit
#include <vrpn_Connection.h> // for vrpn_Connection, etc
#include <vrpn_Text.h> // for vrpn_Text_Receiver
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Shared.h" // for timeval, vrpn_gettimeofday, etc
#include "vrpn_Types.h" // for vrpn_int32
vrpn_Text_Receiver *r;
vrpn_Connection *c;
vrpn_int32 ping_message_id;
vrpn_int32 pong_message_id;
vrpn_int32 sender;
struct timeval now;
struct timeval last_ping;
void handle_cntl_c(int) { exit(0); }
int VRPN_CALLBACK my_pong_handler(void *userdata, vrpn_HANDLERPARAM p)
{
static int count = 0;
static double min = 10000, max = 0, sum = 0;
// See how long it has been between the ping request and
// the pong response.
struct timeval diff;
vrpn_gettimeofday(&now, NULL);
double msecs;
diff = vrpn_TimevalDiff(now, last_ping);
msecs = vrpn_TimevalMsecs(vrpn_TimevalNormalize(diff));
// Keep statistics on the length (min, max, average)
if (msecs < min) {
min = msecs;
};
if (msecs > max) {
max = msecs;
};
sum += msecs;
// Print and reset the statistics every once in a while
if (++count == 500) {
printf("Min = %4.2g, Max = %4.2g, Mean = %4.2g\n", min, max,
sum / count);
count = 0;
min = 10000;
max = sum = 0.0;
}
// Send a new ping request, and record when we sent it.
// REMEMBER not to call mainloop() within the handler.
vrpn_gettimeofday(&last_ping, NULL);
c->pack_message(0, last_ping, ping_message_id, sender, NULL,
vrpn_CONNECTION_RELIABLE);
c->send_pending_reports();
return 0;
}
int main(int argc, char *argv[])
{
// Declare a new text receiver (all objects are text senders)
// and find out what connection it is using.
r = new vrpn_Text_Receiver(argv[1]);
c = r->connectionPtr();
// Declare the same sender and message types that the BaseClass
// will use for doing the ping/pong, so we can use the same
// mechanism. Register a handler for the pong message, so we
// can deal with them.
ping_message_id = c->register_message_type("Server, are you there?");
pong_message_id = c->register_message_type("Server is here!");
sender = c->register_sender(vrpn_copy_service_name(argv[1]));
c->register_handler(pong_message_id, my_pong_handler, NULL, sender);
// Let the user kill the program "nicely."
signal(SIGINT, handle_cntl_c);
// Wait a few seconds (spinning while we do) in order to allow the
// real pong message to clear from the system.
struct timeval then, diff;
vrpn_gettimeofday(&then, NULL);
do {
vrpn_gettimeofday(&now, NULL);
r->mainloop();
diff = vrpn_TimevalDiff(now, then);
} while (vrpn_TimevalMsecs(vrpn_TimevalNormalize(diff)) < 2000);
// Send a new ping request to the server, and start counting how
// long it takes to respond.
vrpn_gettimeofday(&last_ping, NULL);
c->pack_message(0, last_ping, ping_message_id, sender, NULL,
vrpn_CONNECTION_RELIABLE);
// Loop forever.
while (1) {
r->mainloop();
}
}
/* vrpn_print_devices.C
This is a VRPN client program that will connect to one or more VRPN
server devices and print out descriptions of any of a number of
message types. These include at least tracker, button, dial and analog
messages. It is useful for testing whether a server is up and running,
and perhaps for simple debugging.
*/
#include <stdio.h> // for printf, fprintf, NULL, etc
#include <stdlib.h> // for exit, atoi
#ifndef _WIN32_WCE
#include <signal.h> // for signal, SIGINT
#endif
#include <string.h> // for strcmp, strncpy
#include <vrpn_Analog.h> // for vrpn_ANALOGCB, etc
#include <vrpn_Button.h> // for vrpn_Button_Remote, etc
#include <vrpn_Dial.h> // for vrpn_Dial_Remote, etc
#include <vrpn_FileConnection.h> // For preload and accumulate settings
#include <vrpn_Shared.h> // for vrpn_SleepMsecs
#include <vrpn_Text.h> // for vrpn_Text_Receiver, etc
#include <vrpn_Tracker.h> // for vrpn_TRACKERACCCB, etc
#include <vector> // for vector
#include "vrpn_BaseClass.h" // for vrpn_System_TextPrinter, etc
#include "vrpn_Configure.h" // for VRPN_CALLBACK
#include "vrpn_Types.h" // for vrpn_float64, vrpn_int32
using namespace std;
int done = 0; // Signals that the program should exit
unsigned tracker_stride = 1; // Every nth report will be printed
//-------------------------------------
// This section contains the data structure that holds information on
// the devices that are created. For each named device, a remote of each
// type (tracker, button, analog, dial, text) is created. A particular device
// may only report a subset of these values, but that doesn't hurt anything --
// there simply will be no messages of the other types to receive and so
// nothing is printed.
class device_info {
public:
char *name;
vrpn_Tracker_Remote *tkr;
vrpn_Button_Remote *btn;
vrpn_Analog_Remote *ana;
vrpn_Dial_Remote *dial;
vrpn_Text_Receiver *text;
};
const unsigned MAX_DEVICES = 50;
//-------------------------------------
// This section contains the data structure that is used to determine how
// often to print a report for each sensor of each tracker. Each element
// contains a counter that is used by the callback routine to keep track
// of how many it has skipped. There is an element for each possible sensor.
// A new array of elements is created for each new tracker object, and a
// pointer to it is passed as the userdata pointer to the callback handlers.
// A separate array is kept for the position, velocity, and acceleration for
// each
// tracker. The structure passed to the callback handler also has a
// string that is the name of the tracker.
class t_user_callback {
public:
char t_name[vrpn_MAX_TEXT_LEN];
vector<unsigned> t_counts;
};
/*****************************************************************************
*
Callback handlers
*
*****************************************************************************/
void VRPN_CALLBACK
handle_tracker_pos_quat(void *userdata, const vrpn_TRACKERCB t)
{
t_user_callback *t_data = static_cast<t_user_callback *>(userdata);
// Make sure we have a count value for this sensor
while (t_data->t_counts.size() <= static_cast<unsigned>(t.sensor)) {
t_data->t_counts.push_back(0);
}
// See if we have gotten enough reports from this sensor that we should
// print this one. If so, print and reset the count.
if (++t_data->t_counts[t.sensor] >= tracker_stride) {
t_data->t_counts[t.sensor] = 0;
printf("Tracker %s, sensor %d:\n pos (%5.2f, %5.2f, %5.2f); "
"quat (%5.2f, %5.2f, %5.2f, %5.2f)\n",
t_data->t_name, t.sensor, t.pos[0], t.pos[1], t.pos[2],
t.quat[0], t.quat[1], t.quat[2], t.quat[3]);
}
}
void VRPN_CALLBACK handle_tracker_vel(void *userdata, const vrpn_TRACKERVELCB t)
{
t_user_callback *t_data = static_cast<t_user_callback *>(userdata);
// Make sure we have a count value for this sensor
while (t_data->t_counts.size() <= static_cast<unsigned>(t.sensor)) {
t_data->t_counts.push_back(0);
}
// See if we have gotten enough reports from this sensor that we should
// print this one. If so, print and reset the count.
if (++t_data->t_counts[t.sensor] >= tracker_stride) {
t_data->t_counts[t.sensor] = 0;
printf("Tracker %s, sensor %d:\n vel (%5.2f, %5.2f, %5.2f); "
"quatvel (%5.2f, %5.2f, %5.2f, %5.2f)\n",
t_data->t_name, t.sensor, t.vel[0], t.vel[1], t.vel[2],
t.vel_quat[0], t.vel_quat[1], t.vel_quat[2], t.vel_quat[3]);
}
}
void VRPN_CALLBACK handle_tracker_acc(void *userdata, const vrpn_TRACKERACCCB t)
{
t_user_callback *t_data = static_cast<t_user_callback *>(userdata);
// Make sure we have a count value for this sensor
while (t_data->t_counts.size() <= static_cast<unsigned>(t.sensor)) {
t_data->t_counts.push_back(0);
}
// See if we have gotten enough reports from this sensor that we should
// print this one. If so, print and reset the count.
if (++t_data->t_counts[t.sensor] >= tracker_stride) {
t_data->t_counts[t.sensor] = 0;
printf("Tracker %s, sensor %d:\n acc (%5.2f, %5.2f, %5.2f); "
"quatacc (%5.2f, %5.2f, %5.2f, %5.2f)\n",
t_data->t_name, t.sensor, t.acc[0], t.acc[1], t.acc[2],
t.acc_quat[0], t.acc_quat[1], t.acc_quat[2], t.acc_quat[3]);
}
}
void VRPN_CALLBACK handle_button(void *userdata, const vrpn_BUTTONCB b)
{
const char *name = (const char *)userdata;
printf("##########################################\r\n"
"Button %s, number %d was just %s\n"
"##########################################\r\n",
name, b.button, b.state ? "pressed" : "released");
}
void VRPN_CALLBACK
handle_button_states(void *userdata, const vrpn_BUTTONSTATESCB b)
{
const char *name = (const char *)userdata;
printf("Button %s has %d buttons with states:", name, b.num_buttons);
int i;
for (i = 0; i < b.num_buttons; i++) {
printf(" %d", b.states[i]);
}
printf("\n");
}
void VRPN_CALLBACK handle_analog(void *userdata, const vrpn_ANALOGCB a)
{
int i;
const char *name = (const char *)userdata;
printf("Analog %s:\n %5.2f", name, a.channel[0]);
for (i = 1; i < a.num_channel; i++) {
printf(", %5.2f", a.channel[i]);
}
printf(" (%d chans)\n", a.num_channel);
}
void VRPN_CALLBACK handle_dial(void *userdata, const vrpn_DIALCB d)
{
const char *name = (const char *)userdata;
printf("Dial %s, number %d was moved by %5.2f\n", name, d.dial, d.change);
}
void VRPN_CALLBACK handle_text(void *userdata, const vrpn_TEXTCB t)
{
const char *name = (const char *)userdata;
// Warnings and errors are printed by the system text printer.
if (t.type == vrpn_TEXT_NORMAL) {
printf("%s: Text message: %s\n", name, t.message);
}
}
// WARNING: On Windows systems, this handler is called in a separate
// thread from the main program (this differs from Unix). To avoid all
// sorts of chaos as the main program continues to handle packets, we
// set a done flag here and let the main program shut down in its own
// thread by calling shutdown() to do all of the stuff we used to do in
// this handler.
void handle_cntl_c(int) { done = 1; }
void Usage(const char *arg0)
{
fprintf(
stderr,
"Usage: %s [-notracker] [-nobutton] [-noanalog] [-nodial]\n"
" [-trackerstride n]\n"
" [-notext] device1 [device2] [device3] [device4] [...]\n"
" -trackerstride: Print every nth report from each tracker sensor\n"
" -notracker: Don't print tracker reports for following devices\n"
" -nobutton: Don't print button reports for following devices\n"
" -noanalog: Don't print analog reports for following devices\n"
" -nodial: Don't print dial reports for following devices\n"
" -notext: Don't print text messages (warnings, errors) for "
"following devices\n"
" deviceX: VRPN name of device to connect to (eg: Tracker0@ioglab)\n"
" The default behavior is to print all message types for all devices "
"listed\n"
" The order of the parameters can be changed to suit\n",
arg0);
exit(0);
}
int main(int argc, char *argv[])
{
int print_for_tracker = 1; // Print tracker reports?
int print_for_button = 1; // Print button reports?
int print_for_analog = 1; // Print analog reports?
int print_for_dial = 1; // Print dial reports?
int print_for_text = 1; // Print warning/error messages?
// If we happen to open a file, neither preload nor accumulate the
// messages in memory, to avoid crashing for huge files.
vrpn_FILE_CONNECTIONS_SHOULD_PRELOAD = false;
vrpn_FILE_CONNECTIONS_SHOULD_ACCUMULATE = false;
device_info device_list[MAX_DEVICES];
unsigned num_devices = 0;
int i;
// Parse arguments, creating objects as we go. Arguments that
// change the way a device is treated affect all devices that
// follow on the command line.
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-notracker")) {
print_for_tracker = 0;
}
else if (!strcmp(argv[i], "-nobutton")) {
print_for_button = 0;
}
else if (!strcmp(argv[i], "-noanalog")) {
print_for_analog = 0;
}
else if (!strcmp(argv[i], "-nodial")) {
print_for_dial = 0;
}
else if (!strcmp(argv[i], "-notext")) {
print_for_text = 0;
}
else if (!strcmp(argv[i], "-trackerstride")) {
if (++i >= argc) {
Usage(argv[0]);
}
if (atoi(argv[i]) <= 0) {
fprintf(stderr,
"-trackerstride argument must be 1 or greater\n");
return -1;
}
tracker_stride = atoi(argv[i]);
}
else { // Create a device and connect to it.
device_info *dev;
// Make sure we have enough room for the new device
if (num_devices == MAX_DEVICES) {
fprintf(stderr, "Too many devices!\n");
exit(-1);
}
// Name the device and open it as everything
dev = &device_list[num_devices];
dev->name = argv[i];
dev->tkr = new vrpn_Tracker_Remote(dev->name);
dev->ana = new vrpn_Analog_Remote(dev->name);
dev->btn = new vrpn_Button_Remote(dev->name);
dev->dial = new vrpn_Dial_Remote(dev->name);
dev->text = new vrpn_Text_Receiver(dev->name);
if ((dev->ana == NULL) || (dev->btn == NULL) ||
(dev->dial == NULL) || (dev->tkr == NULL) ||
(dev->text == NULL)) {
fprintf(stderr, "Error opening %s\n", dev->name);
return -1;
}
else {
printf("Opened %s as:", dev->name);
}
// If we are printing the tracker reports, prepare the
// user-data callbacks and hook them up to be called with
// the correct data for this device.
if (print_for_tracker) {
vrpn_Tracker_Remote *tkr = dev->tkr;
t_user_callback *tc1 = new t_user_callback;
t_user_callback *tc2 = new t_user_callback;
t_user_callback *tc3 = new t_user_callback;
if ((tc1 == NULL) || (tc2 == NULL) || (tc3 == NULL)) {
fprintf(stderr, "Out of memory\n");
}
printf(" Tracker");
// Fill in the user-data callback information
strncpy(tc1->t_name, dev->name, sizeof(tc1->t_name));
strncpy(tc2->t_name, dev->name, sizeof(tc2->t_name));
strncpy(tc3->t_name, dev->name, sizeof(tc3->t_name));
// Set up the tracker callback handlers
tkr->register_change_handler(tc1, handle_tracker_pos_quat);
tkr->register_change_handler(tc2, handle_tracker_vel);
tkr->register_change_handler(tc3, handle_tracker_acc);
}
if (print_for_button) {
printf(" Button");
dev->btn->register_change_handler(dev->name, handle_button);
dev->btn->register_states_handler(dev->name,
handle_button_states);
}
if (print_for_analog) {
printf(" Analog");
dev->ana->register_change_handler(dev->name, handle_analog);
}
if (print_for_dial) {
printf(" Dial");
dev->dial->register_change_handler(dev->name, handle_dial);
}
if (print_for_text) {
printf(" Text");
dev->text->register_message_handler(dev->name, handle_text);
}
else {
vrpn_System_TextPrinter.remove_object(dev->tkr);
vrpn_System_TextPrinter.remove_object(dev->btn);
vrpn_System_TextPrinter.remove_object(dev->ana);
vrpn_System_TextPrinter.remove_object(dev->dial);
vrpn_System_TextPrinter.remove_object(dev->text);
}
printf(".\n");
num_devices++;
}
}
if (num_devices == 0) {
Usage(argv[0]);
}
#ifndef _WIN32_WCE
// signal handler so logfiles get closed right
signal(SIGINT, handle_cntl_c);
#endif
/*
* main interactive loop
*/
printf("Press ^C to exit.\n");
while (!done) {
unsigned i;
// Let all the devices do their things
for (i = 0; i < num_devices; i++) {
device_list[i].tkr->mainloop();
device_list[i].btn->mainloop();
device_list[i].ana->mainloop();
device_list[i].dial->mainloop();
device_list[i].text->mainloop();
}
// Sleep for 1ms so we don't eat the CPU
vrpn_SleepMsecs(1);
}
// Delete all devices.
{
unsigned i;
for (i = 0; i < num_devices; i++) {
delete device_list[i].tkr;
delete device_list[i].btn;
delete device_list[i].ana;
delete device_list[i].dial;
delete device_list[i].text;
}
}
return 0;
} /* main */
# Microsoft Developer Studio Project File - Name="vrpn_print_devices" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=vrpn_print_devices - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "vrpn_print_devices.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "vrpn_print_devices.mak" CFG="vrpn_print_devices - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "vrpn_print_devices - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "vrpn_print_devices - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "vrpn_print_devices - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../pc_win32/client_src/vrpn_print_devices/Release"
# PROP Intermediate_Dir "../pc_win32/client_src/vrpn_print_devices/Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I ".." /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "WIN32" /FR /YX /FD /c /Tp
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../pc_win32/Release" /libpath:"../pc_win32/DLL/Release"
!ELSEIF "$(CFG)" == "vrpn_print_devices - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../pc_win32/client_src/vrpn_print_devices/Debug"
# PROP Intermediate_Dir "../pc_win32/client_src/vrpn_print_devices/Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I ".." /D "_CONSOLE" /D "_DEBUG" /D "_MBCS" /D "WIN32" /FR /YX /FD /GZ /c /Tp
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../pc_win32/Debug" /libpath:"../pc_win32/DLL/Debug"
!ENDIF
# Begin Target
# Name "vrpn_print_devices - Win32 Release"
# Name "vrpn_print_devices - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=vrpn_print_devices.C
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="vrpn_print_devices"
ProjectGUID="{AED1729B-0600-4ECD-BE20-9F1964FFD2C8}"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\../pc_win32/client_src/vrpn_print_devices/Debug"
IntermediateDirectory=".\../pc_win32/client_src/vrpn_print_devices/Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/client_src/vrpn_print_devices/Debug/vrpn_print_devices.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include&quot;;.."
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\../pc_win32/client_src/vrpn_print_devices/Debug/vrpn_print_devices.pch"
AssemblerListingLocation=".\../pc_win32/client_src/vrpn_print_devices/Debug/"
ObjectFile=".\../pc_win32/client_src/vrpn_print_devices/Debug/"
ProgramDataBaseFileName=".\../pc_win32/client_src/vrpn_print_devices/Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\../pc_win32/client_src/vrpn_print_devices/Debug/vrpn_print_devices.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../pc_win32/client_src/vrpn_print_devices/Debug/vrpn_print_devices.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/client_src/vrpn_print_devices/Debug/vrpn_print_devices.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\../pc_win32/client_src/vrpn_print_devices/Release"
IntermediateDirectory=".\../pc_win32/client_src/vrpn_print_devices/Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../pc_win32/client_src/vrpn_print_devices/Release/vrpn_print_devices.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="&quot;$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include&quot;;.."
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\../pc_win32/client_src/vrpn_print_devices/Release/vrpn_print_devices.pch"
AssemblerListingLocation=".\../pc_win32/client_src/vrpn_print_devices/Release/"
ObjectFile=".\../pc_win32/client_src/vrpn_print_devices/Release/"
ProgramDataBaseFileName=".\../pc_win32/client_src/vrpn_print_devices/Release/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\../pc_win32/client_src/vrpn_print_devices/Release/vrpn_print_devices.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(SYSTEMDRIVE)\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib"
ProgramDatabaseFile=".\../pc_win32/client_src/vrpn_print_devices/Release/vrpn_print_devices.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../pc_win32/client_src/vrpn_print_devices/Release/vrpn_print_devices.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="vrpn_print_devices.C"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>