void* DrawThreadFunction(void* cam) { cout << "\nStarting Draw Function"; CameraThread* camera = static_cast<CameraThread *>(cam); string buffer; // FPS Calculation struct timeval tim; double t, dt; int fps; gettimeofday(&tim, NULL); t = tim.tv_sec + (tim.tv_usec/1000000.0); while(camera->Continue()) { buffer.clear(); while(!camera->display); buffer.append("{"); buffer.append("\"fabric\":"); buffer.append("["); buffer.append("{"); buffer.append("\"id\":101"); buffer.append(","); buffer.append("\"x\":"); buffer.append(to_string((camera->fabricPosition.x - camera->frameCenter.x)*camera->pixelToRealx)); buffer.append(","); buffer.append("\"y\":"); buffer.append(to_string((camera->frameSize.height - camera->fabricPosition.y - camera->frameCenter.y)*camera->pixelToRealy)); buffer.append(","); buffer.append("\"theta\":"); buffer.append(to_string(camera->fabricAngle)); buffer.append("}"); buffer.append("]"); buffer.append(","); buffer.append("\"budger\":[]"); buffer.append("}\n"); for(auto client : camera->serverSocket->clients) camera->serverSocket->Write(client.first, buffer.c_str(), buffer.size()); camera->display = false; gettimeofday(&tim, NULL); dt = tim.tv_sec + (tim.tv_usec/1000000.0) - t; gettimeofday(&tim, NULL); t = tim.tv_sec + (tim.tv_usec/1000000.0); fps = (int)(1/dt); cout << "\nComm FPS: " << fps; } pthread_exit(NULL); }
void* ConnectToClient(void* cam) { CameraThread* camera = static_cast<CameraThread *>(cam); while(camera->Continue()) { cout << "Waiting for new client\n"; if(!camera->serverSocket->ConnectClient()) cout << "Could not connect to client\n"; } pthread_exit(NULL); }