From 74b9797991ceaabf98613a70a10a4b329a254c93 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 28 Jun 2012 20:48:25 +0100 Subject: drawing calls and sms --- eventStreamer/eventStreamer.py | 16 ++++-- openBTSviz.cbp | 6 ++ openBTSviz.layout | 12 +++- src/main.cpp | 2 +- src/obtsDevice.cpp | 96 +++++++++++++++++++++++++++---- src/obtsDevice.h | 60 ++++++++++++++++++-- src/testApp.cpp | 126 ++++++++++++++++++++++++++++++++--------- src/testApp.h | 6 -- 8 files changed, 268 insertions(+), 56 deletions(-) diff --git a/eventStreamer/eventStreamer.py b/eventStreamer/eventStreamer.py index c6f9f1f..ca64542 100755 --- a/eventStreamer/eventStreamer.py +++ b/eventStreamer/eventStreamer.py @@ -1,4 +1,11 @@ #!/usr/bin/python +# +#Translates openBTS logs into UDP event packets. +# +#http://openhere.data.ie/ +# +#TJR June 2012 +# import MySQLdb,datetime,string,time,socket import config @@ -18,8 +25,9 @@ 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) ) + #send all data in each event to avoid translation script having a state + print str(e[3]),devices[e[3]]['IMSI'],devices[e[3]]['IMEI'],devices[e[3]]['number'],str(e[1]) + outsock.sendto( devices[e[3]]['IMSI']+","+devices[e[3]]['IMEI']+","+devices[e[3]]['number']+","+str(e[1]), (config.viz_ip, config.viz_port) ) def main(): @@ -53,8 +61,8 @@ def main(): for row in results: d={} d['IMSI']=row[1] - d['number']=row[2] - d['ts']=row[3] + d['IMEI']=row[2] + d['number']=row[3] devices[row[0]]=d except: print "Error: unable to fetch handset list" diff --git a/openBTSviz.cbp b/openBTSviz.cbp index 35145bd..dd13611 100644 --- a/openBTSviz.cbp +++ b/openBTSviz.cbp @@ -39,6 +39,12 @@ + + + + diff --git a/openBTSviz.layout b/openBTSviz.layout index c86aac8..3a0aa18 100644 --- a/openBTSviz.layout +++ b/openBTSviz.layout @@ -11,10 +11,16 @@ - + - - + + + + + + + + diff --git a/src/main.cpp b/src/main.cpp index 5e84581..ad74a97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 720,400, OF_WINDOW ); // <-------- setup the GL context + ofSetupOpenGL(&window, 450,800, 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/obtsDevice.cpp b/src/obtsDevice.cpp index 70e60c3..85d5f18 100644 --- a/src/obtsDevice.cpp +++ b/src/obtsDevice.cpp @@ -4,30 +4,82 @@ obtsDevice::obtsDevice() { } -obtsDevice::obtsDevice(string &imsi,ofImage *_icon,ofVec2f _coords) +obtsDevice::obtsDevice(string &imsi,string &imei,string &num,ofImage *_icon,ofVec2f _coords) { IMSI=imsi; + IMEI=imei; + number=num; coords=_coords; icon=_icon; - connect(); + active=false; + calling=false; + exciteLevel=1.0; + lastTime=ofGetElapsedTimef(); printf("new device: IMSI%s\n",IMSI.c_str()); } +obtsDevice::~obtsDevice() +{ + //dtor +} + + void obtsDevice::connect(){ - connectionHistory.push_back(timeseg(ofGetElapsedTimef(),0.0f)); + if (!active) { + connectionHistory.push_back(timeseg()); + active=true; + } } void obtsDevice::disconnect(){ - connectionHistory[connectionHistory.size()-1].endTime=ofGetElapsedTimef(); + if (active) { + connectionHistory[connectionHistory.size()-1].endTime=ofGetElapsedTimef(); + active=false; + } } -obtsDevice::~obtsDevice() -{ - //dtor +void obtsDevice::ringing(obtsDevice *to){ + if (!calling) { + callHistory.push_back(tcall(to,false)); + calling=true; + } +} + +void obtsDevice::connectCall(){ + if (calling) { + callHistory[callHistory.size()-1].connect(); + } +} + +void obtsDevice::call(obtsDevice *to){ + if (!calling) { + callHistory.push_back(tcall(to,true)); + calling=true; + } +} + +void obtsDevice::endCall(){ + if (calling) { + callHistory[callHistory.size()-1].endTime=ofGetElapsedTimef(); + callHistory[callHistory.size()-1].connected=false; + calling=false; + } +} + +void obtsDevice::sms(obtsDevice *to){ + smsHistory.push_back(tsms(to)); +} + +void obtsDevice::excite(float amount) { + exciteLevel=amount; } void obtsDevice::draw(float timeScale) { + float decay=1.0; + float now=ofGetElapsedTimef(); + float timeSeg=now-lastTime; + lastTime=now; //draw a line at the angular position of the device //z=0 is the 'surface' i.e. now. //the device know the time now and when it was created @@ -37,11 +89,35 @@ void obtsDevice::draw(float timeScale) //for fixed/dynamic, pass a scaling parameter when drawing float rf=sin((coords.y/(ofGetWidth()*0.9))*TWO_PI); ofSetColor(0x8f*rf,0x8f*rf,0x8f*rf); - float now=ofGetElapsedTimef(); + float endPos; for (vector::iterator i=connectionHistory.begin();i!=connectionHistory.end();i++){ - float startPos=(-now+(*i).startTime)/timeScale; - float endPos=(*i).endTime>0.0f?(-now+(*i).endTime)/timeScale:0.0f; + float startPos=((*i).startTime-now)/timeScale; + endPos=(*i).endTime>0.0f?((*i).endTime-now)/timeScale:0.0f; ofLine(cos(coords.x)*coords.y,sin(coords.x)*coords.y,startPos,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos); //printf("%f drawing %f,%f,%f to %f,%f,%f\n",ofGetElapsedTimef(),cos(coords.x)*coords.y,sin(coords.x)*coords.y,startPos,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos); } + ofSetColor(0xff,0x8f,0x8f); + for (vector::iterator i=smsHistory.begin();i!=smsHistory.end();i++){ + float timepos=((*i).time-now)/timeScale; + ofLine(cos(coords.x)*coords.y,sin(coords.x)*coords.y,timepos,cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,timepos); + } + + for (vector::iterator i=callHistory.begin();i!=callHistory.end();i++){ + ofSetColor(0xff,0xff,0x8f); + float stimepos=((*i).startTime-now)/timeScale; + float etimepos=((*i).endTime>0.0f?((*i).endTime-now)/timeScale:0.0f); + glBegin(GL_QUADS); + glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,stimepos); + glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,stimepos); + glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,etimepos); + glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,etimepos); + glEnd(); + } + + int greylev=0x7f+((int)(128.0f*exciteLevel)); + ofSetHexColor(greylev+(greylev<<8)+(greylev<<16)); + ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD); + ofDrawBitmapString(number,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos); + ofSetDrawBitmapMode(OF_BITMAPMODE_SIMPLE); + exciteLevel=pow(exciteLevel,1+(timeSeg*decay)); } diff --git a/src/obtsDevice.h b/src/obtsDevice.h index 884600b..b300d64 100644 --- a/src/obtsDevice.h +++ b/src/obtsDevice.h @@ -16,15 +16,50 @@ functions: draw(time) getPosition(time) variables: pointer to icon image +//draw the icons - passed the IMEI +//colours for networks +//connect & disconnect + */ +class obtsDevice; //forward declaration + struct timeseg{ - timeseg(float _st,float _et){ - startTime=_st; - endTime=_et; + timeseg(){ + startTime=ofGetElapsedTimef(); + endTime=0.0f; + } + float startTime; + float endTime; +}; + +struct tsms{ + tsms(obtsDevice* to){ + recipient=to; + time=ofGetElapsedTimef(); } + obtsDevice *recipient; + float time; +}; + +struct tcall{ + tcall(obtsDevice* to,bool _connected){ + recipient=to; + startTime=ofGetElapsedTimef(); + endTime=0.0f; + connected=_connected; + if (connected) connectedTime=startTime; + else connectedTime=0.0f; + } + void connect(){ + connected=true; + connectedTime=ofGetElapsedTimef(); + } + obtsDevice *recipient; float startTime; + float connectedTime; float endTime; + bool connected; }; @@ -32,17 +67,32 @@ class obtsDevice { public: obtsDevice(); - obtsDevice(string &imsi,ofImage *_icon,ofVec2f _coords); + obtsDevice(string &imsi,string &imei,string &num,ofImage *_icon,ofVec2f _coords); virtual ~obtsDevice(); void draw(float timeScale); //units per second void connect(); void disconnect(); + void ringing(obtsDevice *to); + void call(obtsDevice *to); + void connectCall(); + void endCall(); + void sms(obtsDevice *to); + void excite(float amount=1.0); protected: private: - string IMSI; + float exciteLevel; + string IMSI,IMEI,number; ofVec2f coords; //angular coords vector connectionHistory; + vector smsHistory; //argle + vector callHistory; ofImage *icon; + bool active,calling; + + float lastTime; }; + + + #endif // OBTSDEVICE_H diff --git a/src/testApp.cpp b/src/testApp.cpp index ae42217..3ce4f36 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -33,6 +33,12 @@ position update function to interpolate position +basically working +-antialisaing on polys in crazy +-colours of everything pretty naff +-fading feature +-draw incoming events text + */ std::vector split(std::string l, char delim) @@ -71,7 +77,7 @@ void testApp::setup(){ camera.cacheMatrices(); //stop error messages */ - ofSetFrameRate(25); + //ofSetFrameRate(25); ofSetCircleResolution(windowWidth); ofEnableSmoothing(); @@ -81,24 +87,6 @@ void testApp::setup(){ camera.setFov(6.5); camera.cacheMatrices(); - numLines=100; - - lines = new ofPoint[numLines]; - imeis = new string[numLines]; - for (int i=0;i" at call commence. + * "GSM disconnect" and then "GSM release" at call end. + + b.) To a mobile number: + + * "GSM alerting " when ringing. + * "GSM call confirmed to " when ringing at both ends. + * "GSM connect to " at pickup. + * "GSM disconnect" as above at end, then "GSM release from mysql -u tim -h 134.226.86.120 -p + + > use openbts + + */ char udpMessage[1024]; udpConnection.Receive(udpMessage,1024); string message=udpMessage; if(message.length()){ vector 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)) { + if (!tokens[0].substr(0,4).compare("IMSI")) { //this is an event + string number=tokens[2]; + if (!devices.count(number)) { + string imei=string(tokens[1]); + string imsi=string(tokens[0].substr(4)); //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)); + float r=ofRandom(windowWidth/3)+(windowWidth/6); + devices[number]=obtsDevice(imsi,imei,number,icons,ofVec2f(a,r)); + } + devices[number].excite(); //whenever an event concerns a device it brightens + + if(tokens[3].find("joined network")!=string::npos) devices[number].connect(); + if(tokens[3].find("leaving network")!=string::npos) devices[number].disconnect(); + if(tokens[3].find("queued")!=string::npos) { + string t_number=split(tokens[3],' ')[2]; + printf("SMS from %s to %s\n",number.c_str(),t_number.c_str()); + if (devices.count(t_number)) { + devices[number].sms(&devices[t_number]); + } + } + if(tokens[3].find("connect acknowledge")!=string::npos) { + string t_number=split(tokens[3],' ')[3]; + printf("call from %s to %s\n",number.c_str(),t_number.c_str()); + if (devices.count(t_number)) { + devices[number].call(&devices[t_number]); + } + else devices[number].call(&devices["default"]); + } + if(tokens[3].find("call confirmed")!=string::npos) { + string t_number=split(tokens[3],' ')[4]; + printf("ringing from %s to %s\n",number.c_str(),t_number.c_str()); + if (devices.count(t_number)) { + devices[number].ringing(&devices[t_number]); + } + } + if(tokens[3].find("connect to")!=string::npos) { + string t_number=split(tokens[3],' ')[3]; + printf("call connected from %s to %s\n",number.c_str(),t_number.c_str()); + if (devices.count(t_number)) { + devices[number].connectCall(); + } } - printf("%s\n",imsi.c_str()); + if(tokens[3].find("GSM release")!=string::npos) devices[number].endCall(); + + } else printf("%s\n",tokens[0].c_str()); } @@ -168,9 +241,8 @@ void testApp::update(){ //-------------------------------------------------------------- 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); + ofSetLineWidth(1.5f); glDisable(GL_LIGHTING); bgimg.draw(0,0,windowWidth,windowHeight); diff --git a/src/testApp.h b/src/testApp.h index 29c9d03..cfb6f0a 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -28,12 +28,6 @@ class testApp : public ofBaseApp{ map devices; - int numLines; - ofPoint *lines; - string *imeis; - - int start,end; - ofImage bgimg; ofColor *cols; -- cgit v1.2.3