diff options
| author | Tim Redfern <tim@gray.(none)> | 2012-06-27 09:36:16 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@gray.(none)> | 2012-06-27 09:36:16 +0100 |
| commit | 470c897cac4d55c78cd7a08c06442f6e12ad3545 (patch) | |
| tree | df5d1835943ce82eea5271c8c157a38cdee282a5 | |
| parent | 5e3ad78c98cb45bb4f902207d25f4fec6a2bedaa (diff) | |
fps thing
| -rwxr-xr-x | eventStreamer/config.py | 8 | ||||
| -rwxr-xr-x | eventStreamer/eventStreamer.py | 92 | ||||
| -rw-r--r-- | openBTSviz.layout | 12 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/testApp.cpp | 64 | ||||
| -rw-r--r-- | src/testApp.h | 4 |
6 files changed, 141 insertions, 41 deletions
diff --git a/eventStreamer/config.py b/eventStreamer/config.py index 7389ab9..1b9fe51 100755 --- a/eventStreamer/config.py +++ b/eventStreamer/config.py @@ -1,6 +1,6 @@ -mysql_ip="127.0.0.1" -mysql_user="openBTS" -mysql_pword="openBTS" -mysql_db="openBTS" +mysql_ip="134.226.86.120" +mysql_user="tim" +mysql_pword="Visualise this" +mysql_db="openbts" viz_port=7888 viz_ip="127.0.0.1"
\ No newline at end of file diff --git a/eventStreamer/eventStreamer.py b/eventStreamer/eventStreamer.py index 9f062e0..c6f9f1f 100755 --- a/eventStreamer/eventStreamer.py +++ b/eventStreamer/eventStreamer.py @@ -14,6 +14,13 @@ parser.add_option("-a", "--accelerate", type="float", dest="acc", default=1.0,he def sqldatetime(t): return string.replace(t.isoformat(),"T"," ") +outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) +devices={} + +def sendevent(e): + print str(e[3]),str(e[1]),devices[e[3]]['IMSI'] + outsock.sendto( devices[e[3]]['IMSI']+","+str(e[1]), (config.viz_ip, config.viz_port) ) + def main(): startTime=None @@ -25,7 +32,7 @@ def main(): if logtime=="": if date=="": - logtime=str(now.hour)+":"+str(now.minute)+":"+str(now.second+now.microsecond) + logtime=str(now.hour)+":"+str(now.minute)+":"+str(now.second)+"."+str(now.microsecond) else: logtime="0:00:00.0" @@ -38,7 +45,7 @@ def main(): cursor = db.cursor() sql = "SELECT * FROM IMSIs" - devices={} + results=None try: cursor.execute(sql) @@ -50,37 +57,82 @@ def main(): d['ts']=row[3] devices[row[0]]=d except: - print "Error: unable to fetch data" + print "Error: unable to fetch handset list" #get 1st event sql = "SELECT * FROM events Where ts Between '"+sqldatetime(startTime)+"' And '"+sqldatetime(now)+"' LIMIT 1" - outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) - try: cursor.execute(sql) results = cursor.fetchall() - id=long(results[0][0]) + except: + outsock.sendto( "no event data", (config.viz_ip, config.viz_port) ) + print "Error: no event data" + + if len(results) > 0: + #playback mode + id=long(results[0][0])+1 device_id=results[0][3] now=results[0][2] - print str(results[0][3])+" "+str(results[0][1])+" "+devices[results[0][3]]['IMSI'], (config.viz_ip, config.viz_port) - outsock.sendto( str(results[0][3])+" "+str(results[0][1])+" "+devices[results[0][3]]['IMSI'], (config.viz_ip, config.viz_port) ) + print "playback, next id: ",id + outsock.sendto( "openBTSviz: playback mode: starting at: "+sqldatetime(startTime), (config.viz_ip, config.viz_port) ) + sendevent(results[0]) while True: - id+=1 sql = "SELECT * FROM events Where id = "+str(id) - print sql + try: + cursor.execute(sql) + results = cursor.fetchall() + print "waiting ",(((results[0][2]-now).total_seconds()+(results[0][2]-now).microseconds))*options.acc + time.sleep((((results[0][2]-now).total_seconds()+(results[0][2]-now).microseconds))*options.acc) + now=results[0][2] + sendevent(results[0]) + id+=1 + except: + outsock.sendto( "end of data", (config.viz_ip, config.viz_port) ) + print "end of data" + exit(0) + else: + #realtime mode: get id of last event + sql = "SELECT * FROM events ORDER BY id DESC LIMIT 1" + try: cursor.execute(sql) results = cursor.fetchall() - print "waiting ",(((results[0][2]-now).total_seconds()+(results[0][2]-now).microseconds))*options.acc - time.sleep((((results[0][2]-now).total_seconds()+(results[0][2]-now).microseconds))*options.acc) - now=results[0][2] - print str(results[0][3])+" "+str(results[0][1])+" "+devices[results[0][3]]['IMSI'] - outsock.sendto( str(results[0][3])+" "+str(results[0][1])+" "+devices[results[0][3]]['IMSI'], (config.viz_ip, config.viz_port) ) - except: - outsock.sendto( "end of data", (config.viz_ip, config.viz_port) ) - print "Error: unable to fetch data" - - #2 modes of operation depending whether realtime or historical + id=long(results[0][0])+1 + print "realtime, next id: ",id + outsock.sendto( "openBTSviz: realtime mode: next event id: "+str(id), (config.viz_ip, config.viz_port) ) + except: + #empty table + id=1 + while True: + #have to refresh db connection each time + db.close() + db = MySQLdb.connect(config.mysql_ip,config.mysql_user,config.mysql_pword,config.mysql_db) + cursor = db.cursor() + sql = "SELECT * FROM events Where id = "+str(id) + cursor.execute(sql) + results = cursor.fetchall() + if len(results) > 0: + #check if IMSI is new + if not devices.has_key(results[0][3]): + sql = "SELECT * FROM IMSIs Where id = "+str(results[0][3]) + try: + cursor.execute(sql) + imresults = cursor.fetchall() + for row in imresults: + d={} + d['IMSI']=row[1] + d['number']=row[2] + d['ts']=row[3] + devices[row[0]]=d + print "new IMSI: ",d['IMSI'] + except: + print "Error: unable to fetch event handset" + exit() + sendevent(results[0]) + id+=1 + else: + #event doesn't exist: wait and retry + time.sleep(0.05) db.close() diff --git a/openBTSviz.layout b/openBTSviz.layout index f5bc507..c86aac8 100644 --- a/openBTSviz.layout +++ b/openBTSviz.layout @@ -10,13 +10,13 @@ <File name="config.make" open="1" top="0" tabpos="3"> <Cursor position="328" topLine="0" /> </File> - <File name="src/main.cpp" open="0" top="0" tabpos="9"> - <Cursor position="519" topLine="0" /> + <File name="src/main.cpp" open="1" top="0" tabpos="5"> + <Cursor position="219" topLine="0" /> </File> - <File name="src/testApp.cpp" open="1" top="1" tabpos="4"> - <Cursor position="3347" topLine="120" /> + <File name="src/testApp.cpp" open="1" top="1" tabpos="6"> + <Cursor position="3314" topLine="0" /> </File> - <File name="src/testApp.h" open="1" top="0" tabpos="5"> - <Cursor position="570" topLine="0" /> + <File name="src/testApp.h" open="1" top="0" tabpos="4"> + <Cursor position="629" topLine="0" /> </File> </CodeBlocks_layout_file> diff --git a/src/main.cpp b/src/main.cpp index ad74a97..5e84581 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 450,800, OF_WINDOW ); // <-------- setup the GL context + ofSetupOpenGL(&window, 720,400, OF_WINDOW ); // <-------- setup the GL context printf("%ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight()); // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN diff --git a/src/testApp.cpp b/src/testApp.cpp index 3b0b9b1..ae42217 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -35,6 +35,18 @@ function to interpolate position */ +std::vector<std::string> split(std::string l, char delim) +{ + std::istringstream stm(l); + std::vector<std::string> tokens; + for (;;) { + std::string word; + if (!getline(stm, word, delim)) break; + tokens.push_back(word); + } + return tokens; +} + void testApp::setup(){ printf("setup: %ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight()); @@ -59,7 +71,7 @@ void testApp::setup(){ camera.cacheMatrices(); //stop error messages */ - ofSetFrameRate(60); + ofSetFrameRate(25); ofSetCircleResolution(windowWidth); ofEnableSmoothing(); @@ -69,7 +81,7 @@ void testApp::setup(){ camera.setFov(6.5); camera.cacheMatrices(); - numLines=20; + numLines=100; lines = new ofPoint[numLines]; imeis = new string[numLines]; @@ -83,6 +95,9 @@ void testApp::setup(){ } } + start=10; + end=15; + bgimg.allocate(256,256,OF_IMAGE_COLOR); @@ -129,17 +144,33 @@ void testApp::setup(){ //-------------------------------------------------------------- void testApp::update(){ - char udpMessage[1024]; + //check incoming messages + //create device or update as necessary + char udpMessage[1024]; udpConnection.Receive(udpMessage,1024); string message=udpMessage; - if(message!=""){ - printf("%s\n",message.c_str()); + if(message.length()){ + vector<string> tokens=split(message,','); + string imsi=tokens[0].substr(4); + //long dev=atol(n.c_str()); something crazy going on. this always seems to read out 32 bits + if (!tokens[0].substr(0,4).compare("IMSI")) { //not an event + if (!devices.count(imsi)) { + //create a new device at a random position + float a=ofRandom(TWO_PI); + float r=ofRandom(windowWidth/2); + devices[imsi]=obtsDevice(imsi,icons,ofVec2f(a,r)); + } + printf("%s\n",imsi.c_str()); + } + else printf("%s\n",tokens[0].c_str()); } - } //-------------------------------------------------------------- void testApp::draw(){ + if (ofRandom(1.0)>0.99) start=min(99,start+1); + if (ofRandom(1.0)>0.98) end=min(99,end+1); + glDisable(GL_LIGHTING); bgimg.draw(0,0,windowWidth,windowHeight); @@ -166,32 +197,45 @@ void testApp::draw(){ } - for (int i=0;i<numLines;i++) { + /* + for (int i=start;i<end;i++) { float rf=sin((lines[i].y/(windowWidth*0.9))*TWO_PI); ofSetColor(0x8f*rf,0x8f*rf,0x8f*rf); ofLine(cos(lines[i].x)*lines[i].y,sin(lines[i].x)*lines[i].y,0,cos(lines[i].x)*lines[i].y,sin(lines[i].x)*lines[i].y,lines[i].z); } - ofPopMatrix(); - camera.end(); - for (int i=0;i<numLines;i++) { + + for (int i=start;i<end;i++) { float rf=sin((lines[i].y/(windowWidth*0.9))*TWO_PI); ofSetColor(0x8f*rf,0x8f*rf,0x8f*rf); ofVec3f p=camera.worldToScreen(ofVec3f(cos(lines[i].x)*lines[i].y,sin(lines[i].x)*lines[i].y,lines[i].z).rotated(ofGetElapsedTimef(),ofVec3f(0,0,1)),ofGetCurrentViewport()); ofDrawBitmapString(imeis[i],p.x-20,p.y,p.z); } + */ + float timeScale=windowHeight/ofGetElapsedTimef(); + + for (map<string,obtsDevice>::iterator i=devices.begin();i!=devices.end();i++){ + (*i).second.draw(timeScale); + } + + ofPopMatrix(); + camera.end(); ofSetHexColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "fps: %f", ofGetFrameRate()); ofDrawBitmapString(reportStr, 10, windowHeight-10); + + //ofSaveFrame(); } //-------------------------------------------------------------- void testApp::keyPressed(int key){ switch (key){ case ' ': + ofSaveFrame(); + printf("[%8.2f] saved an image\n",ofGetElapsedTimef()); break; } } diff --git a/src/testApp.h b/src/testApp.h index bb7e6b1..29c9d03 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -25,10 +25,14 @@ class testApp : public ofBaseApp{ ofxUDPManager udpConnection; ofCamera camera; + + map<string,obtsDevice> devices; int numLines; ofPoint *lines; string *imeis; + + int start,end; ofImage bgimg; ofColor *cols; |
