// Callback for the connect-to-NatNet dialog. Gets the server and local IP // addresses and attempts to initialize the NatNet client. LRESULT CALLBACK NatNetDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char szBuf[512]; switch (message) { case WM_INITDIALOG: SetDlgItemText(hDlg, IDC_EDIT1, _itoa(IPAddress[0], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT2, _itoa(IPAddress[1], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT3, _itoa(IPAddress[2], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT4, _itoa(IPAddress[3], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT5, _itoa(IPAddress[0], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT6, _itoa(IPAddress[1], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT7, _itoa(IPAddress[2], szBuf,10)); SetDlgItemText(hDlg, IDC_EDIT8, _itoa(IPAddress[3], szBuf,10)); return true; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CONNECT: { char szMyIPAddress[30], szServerIPAddress[30]; char ip1[5], ip2[5], ip3[5], ip4[5]; GetDlgItemText(hDlg, IDC_EDIT1, ip1, 4); GetDlgItemText(hDlg, IDC_EDIT2, ip2, 4); GetDlgItemText(hDlg, IDC_EDIT3, ip3, 4); GetDlgItemText(hDlg, IDC_EDIT4, ip4, 4); sprintf_s(szMyIPAddress, 30, "%s.%s.%s.%s", ip1,ip2,ip3,ip4); GetDlgItemText(hDlg, IDC_EDIT5, ip1, 4); GetDlgItemText(hDlg, IDC_EDIT6, ip2, 4); GetDlgItemText(hDlg, IDC_EDIT7, ip3, 4); GetDlgItemText(hDlg, IDC_EDIT8, ip4, 4); sprintf_s(szServerIPAddress, 30, "%s.%s.%s.%s", ip1,ip2,ip3,ip4); // Try and intialize the NatNet client. if (InitNatNet(szMyIPAddress, szServerIPAddress) == false) { natnetClient.Uninitialize(); MessageBox(hDlg, "Failed to connect", "", MB_OK); } } case IDOK: case IDCANCEL: EndDialog(hDlg, LOWORD(wParam)); return true; } } return false; }
void resetClient() { int iSuccess; printf("\n\nre-setting Client\n\n."); iSuccess = theClient.Uninitialize(); if(iSuccess != 0) printf("error un-initting Client\n"); iSuccess = theClient.Initialize(szMyIPAddress, szServerIPAddress); if(iSuccess != 0) printf("error re-initting Client\n"); }
int _tmain(int argc, _TCHAR* argv[]) { splash(argv[0]); if((argc < 4) || ((argc > 5) && (strcmp("log", argv[5])))){ printf("Usage: %s <ServerIP> <ClientIP> <OSCIP> <OSCPort> [\"log\"]", argv[0]); }else{ int retCode; char* OSCIP = argv[3]; int OSCPort = atoi(argv[4]); //EU printf("\n\nBanana hammock!!\n\n"); // Set callback handlers theClient.SetMessageCallback(MessageHandler); theClient.SetVerbosityLevel(Verbosity_Debug); theClient.SetDataCallback( DataHandler, &theClient ); // this function will receive data from the server // Connect to NatNet server strcpy(szServerIPAddress, argv[1]); // specified on command line strcpy(szMyIPAddress, argv[2]); // specified on command line printf("Connecting to server at %s from %s...\n", szServerIPAddress, szMyIPAddress); // Connect to NatNet server retCode = theClient.Initialize(szMyIPAddress, szServerIPAddress); if (retCode != ErrorCode_OK) { printf("Unable to connect to server. Error code: %d. Exiting", retCode); return 1; } else { // print server info sServerDescription ServerDescription; memset(&ServerDescription, 0, sizeof(ServerDescription)); theClient.GetServerDescription(&ServerDescription); if(!ServerDescription.HostPresent) { printf("Unable to connect to server. Host not present. Exiting."); return 1; } printf("[OSCNatNetClient] Server application info:\n"); printf("Application: %s (ver. %d.%d.%d.%d)\n", ServerDescription.szHostApp, ServerDescription.HostAppVersion[0], ServerDescription.HostAppVersion[1], ServerDescription.HostAppVersion[2], ServerDescription.HostAppVersion[3]); printf("NatNet Version: %d.%d.%d.%d\n", ServerDescription.NatNetVersion[0], ServerDescription.NatNetVersion[1], ServerDescription.NatNetVersion[2], ServerDescription.NatNetVersion[3]); printf("Server IP:%s\n", szServerIPAddress); printf("Server Name:%s\n\n", ServerDescription.szHostComputerName); //EU - init UDP socket transmitSocket = new UdpTransmitSocket(IpEndpointName(OSCIP, OSCPort)); printf("OSC IP:%s\n", OSCIP); printf("OSC Port:%d\n", OSCPort); } // send/receive test request printf("[OSCNatNetClient] Sending Test Request\n"); void* response; int nBytes; retCode = theClient.SendMessageAndWait("TestRequest", &response, &nBytes); if (retCode == ErrorCode_OK) { printf("[OSCNatNetClient] Received: %s", (char*)response); } //Writing Session data to file char szFile[MAX_PATH]; char szFolder[MAX_PATH]; #ifdef __linux__ sprintf(szFolder, "./"); #else GetCurrentDirectory(MAX_PATH, szFolder); #endif char timeLabel[50]; time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); //create time label for files strftime (timeLabel,80,"%d.%m.%y %H.%M.%S",timeinfo); // Retrieve MarkerSets from server printf("\n\n[OSCNatNetClient] Requesting all data definitions for current session..."); sDataDescriptions* pDataDefs = NULL; theClient.GetDataDescriptions(&pDataDefs); if(!pDataDefs){ printf("[OSCNatNetClient] Unable to retrieve current session."); //return 1; }else{ sprintf(szFile, "%s\\SessionData %s.txt", szFolder, timeLabel); fps = fopen(szFile, "w"); if(!fps) { printf("error opening output file %s. Exiting.", szFile); exit(1); } _WriteHeader(fps, pDataDefs); fclose(fps); } // Prepare data file for frame info if(argc > 5){ sprintf(szFile, "%s\\FrameData %s.txt", szFolder, timeLabel); fpf = fopen(szFile, "w"); if(!fpf){ printf("error opening output file %s. Exiting.", szFile); exit(1); } } // Ready to receive marker stream! printf("\nOSCNatNetClient is connected to server and listening for data... press 'q' for quitting\n"); int c; bool bExit = false; while(c =_getch()){ switch(c){ case 'q': bExit = true; printf("\nQuitting...\n\n"); break; case 'r': printf("\nReseting Client...\n\n"); resetClient(); break; default: printf("not an option\n\n"); break; } if(bExit) break; } printf("clean up\n\n"); // Done - clean up. theClient.Uninitialize(); if(fpf != NULL) fclose(fpf); return ErrorCode_OK; } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_CONNECT: DialogBox(g_hInst, (LPCTSTR)IDD_NATNET, hWnd, (DLGPROC)NatNetDlgProc); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); wglMakeCurrent(hdc, g_hRenderContext); Render(); SwapBuffers(hdc); wglMakeCurrent(0, 0); EndPaint(hWnd, &ps); break; case WM_SIZE: { int cx = LOWORD(lParam), cy = HIWORD(lParam); if(cx==0 || cy ==0 || hWnd==NULL) break; GLfloat fFovy = 40.0f; // Field-of-view GLfloat fZNear = 1.0f; // Near clipping plane GLfloat fZFar = 10000.0f; // Far clipping plane HDC hDC = GetDC(hWnd); wglMakeCurrent(hDC, g_hRenderContext); // Calculate viewport aspect RECT rv; GetClientRect(hWnd, &rv); GLfloat fAspect = (GLfloat)(rv.right-rv.left) / (GLfloat)(rv.bottom-rv.top); // Define viewport glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fFovy, fAspect, fZNear, fZFar); glViewport(rv.left, rv.top, rv.right-rv.left, rv.bottom-rv.top); glMatrixMode(GL_MODELVIEW); wglMakeCurrent(0, 0); ReleaseDC(hWnd, hDC); } break; case WM_DESTROY: { HDC hDC = GetDC(hWnd); wglMakeCurrent(hDC, g_hRenderContext); natnetClient.Uninitialize(); wglMakeCurrent(0, 0); wglDeleteContext(g_hRenderContext); ReleaseDC(hWnd, hDC); PostQuitMessage(0); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }