00001 /** 00002 * @file Platform/Aperios1.3.2/GTCamHandler.cpp 00003 * @author Matthias Meyer 00004 * 00005 */ 00006 00007 #include "GTCamHandler.h" 00008 00009 #include <stdio.h> 00010 #include <iostream.h> 00011 00012 #include <tools/debugging/debugging.h> 00013 #include "NetConfig.h" 00014 00015 00016 /** 00017 * Constructor 00018 */ 00019 GTCamHandler::GTCamHandler() : 00020 UDPEndpoint(2048,2048) 00021 { 00022 00023 } 00024 00025 00026 /** 00027 * Init the handler 00028 */ 00029 void GTCamHandler::initGTCamHandler(GTCamWorldState* myState, GTCamTimeSyncHandler* myHandler) 00030 { 00031 // timeOffset = 0; 00032 // lastPackageRevievedLocal = 0; 00033 // lastPackageRevievedRemote = 0; 00034 state = myState; 00035 timeSyncHandler = myHandler; 00036 packageCounter = 0; 00037 00038 int camport = GTCAMPORT;//std port 00039 int syncport = GTCAMSYNCPORT; 00040 double version; 00041 00042 //read port 00043 InConfigFile file("gtcam.cfg"); 00044 // format: 00045 // Version x.x 00046 // CAMPORT x 00047 // SYNCPORT x 00048 // spaces and nl are ignored 00049 if(file.exists()) 00050 { 00051 char buf[250]; 00052 cout << "gtcam.cfg "; 00053 while(!file.eof()) 00054 { 00055 file >> buf; 00056 cout << "gtcam.cfg " << buf; 00057 if ( strcmp(buf,"Version")==0 ) 00058 { 00059 file >> version; 00060 cout << "Version " << version; 00061 }else 00062 if ( strcmp(buf,"CAMPORT")==0 ) 00063 { 00064 file >> camport; 00065 cout << "CAMPORT " << camport; 00066 } 00067 if ( strcmp(buf,"SYNCPORT")==0 ) 00068 { 00069 file >> syncport; 00070 cout << "SYNCPORT " << syncport; 00071 } 00072 } 00073 } 00074 00075 00076 bind(camport); // GTCam data 00077 } 00078 00079 00080 /** 00081 * Receive data 00082 */ 00083 void GTCamHandler::onReceive(void* data, int size) 00084 { 00085 memcpy(state->camWorldstate,data,size); 00086 packageCounter++; 00087 00088 // Start TimeSync every 100 packages 00089 if (packageCounter >= 100) { 00090 packageCounter = 0; 00091 timeSyncHandler->timeServer = this->ipOfLastPackage; 00092 timeSyncHandler->startTimeSync(); 00093 } 00094 00095 00096 00097 state->frameNumber = (unsigned long)(state->getTimestamp()/8) - timeSyncHandler->frameOffset; 00098 /*cout << "Calc: " << state->frameNumber << " = (" 00099 << state->getTimestamp()/8 << ") " 00100 << (unsigned long)(state->getTimestamp()/8) << " - " 00101 << timeSyncHandler->frameOffset << " ----- " 00102 << timeSyncHandler->image->frameNumber << " \n"; 00103 */ 00104 state->setTimestamp(state->getTimestamp() - timeSyncHandler->offset); 00105 00106 }
1.3.6