From 75e29a6f66f0316cf0dc4776ac729f04365b1592 Mon Sep 17 00:00:00 2001 From: Bartosz Kostrzewa Date: Mon, 15 Nov 2010 12:44:10 +0100 Subject: [PATCH] forgot to add some files to commit --- frameserver/Server.cpp | 164 +++++++++++++++++++++-------------- frameserver/Server.h | 1 + frameserver/defines.h | 24 +++-- frameserver/display | 29 ++++--- frameserver/launchpythons.sh | 4 +- frameserver/servertest.py | 33 +++++-- frameserver/servertest.sh | 14 ++- 7 files changed, 173 insertions(+), 96 deletions(-) mode change 100644 => 100755 frameserver/launchpythons.sh diff --git a/frameserver/Server.cpp b/frameserver/Server.cpp index 08652d4..0bccc2c 100644 --- a/frameserver/Server.cpp +++ b/frameserver/Server.cpp @@ -31,7 +31,7 @@ void Server::launch_threads() void Server::listen() { - int packetcounter = 0; + long packetcounter = 0; try { boost::asio::io_service io_service; @@ -54,55 +54,72 @@ void Server::listen() socket.receive_from(boost::asio::buffer(recv_buf), remote_endpoint, 0, error); - packetcounter++; - if( packetcounter % 1000 == 0 ) - cout << endl << packetcounter << endl; - - // have we encountered this source before? - // DEBUG - // cout << remote_endpoint << endl; + + // bufnum is used further down int bufnum = 0; { - Glib::Mutex::Lock lock(mutex_); - int size = endpoints.size(); - bool known = false; - for(bufnum = 0; bufnum < size; bufnum++) - { - if(endpoints[bufnum] == remote_endpoint) - { - known = true; - break; - } - } + Glib::Mutex::Lock lock(mutex_); + int size = endpoints.size(); + bool known = false; + for(bufnum = 0; bufnum < size; bufnum++) + { + // have we encountered this source before? + if(endpoints[bufnum] == remote_endpoint) + { + known = true; + break; + } + } - if( !known && size+1 < NUMBUFS ) - { - // create a new buffer make a note of the endpoint - std::stringstream endpointstring; - endpointstring << remote_endpoint; - cout << "adding new buffer for " << remote_endpoint << endl; - buffers.push_back( new Buffer( endpointstring.str() ) ); - endpoints.push_back( remote_endpoint ); - } - - // discard packet, we're not accepting any more sources! - else if( size+1 >= NUMBUFS ) - break; - } + if( !known && size < NUMBUFS ) + { + // create a new buffer make a note of the endpoint + std::stringstream endpointstring; + endpointstring << remote_endpoint; + cout << "adding new buffer for " << remote_endpoint << endl; + buffers.push_back( new Buffer( endpointstring.str() ) ); + endpoints.push_back( remote_endpoint ); + } + + // discard packet, we're not accepting any more sources! + else if( !known && size >= NUMBUFS ) + { + cout << "no more buffers left! " << bufnum << endl; + continue; + } + } + if( packetcounter % 10000 == 0 ) + { + cout << endl << "packets received " << packetcounter << endl; + /*cout << remote_endpoint << endl; + for(int i = 0; i < BUFLEN; i++) + cout << recv_buf[i]; + cout << endl;//*/ + } + packetcounter++; + + frame.z = recv_buf[0]; for(int i = 0; i < HEIGHT; i++) { for(int j = 0; j < WIDTH; j++) { - frame.windows[i][j] = recv_buf[2+i*(WIDTH+1)+j]; + for(int a = 0; a < CHANNELS; a++) + { + frame.windows[i][j][a] = recv_buf[HEADEROFFSET+ i*(CHANNELS*WIDTH+1) + j*CHANNELS + a]; + } } } - for(int i = 0; i < SEGWIDTH; i++ ) + for(int w = 0; w < SEGWIDTH; w++ ) { - frame.segments[i].r = recv_buf[2+(WIDTH+1)*HEIGHT+i]; - frame.segments[i].g = recv_buf[2+(WIDTH+1)*HEIGHT+(SEGWIDTH+1)*1+i]; - frame.segments[i].b = recv_buf[2+(WIDTH+1)*HEIGHT+(SEGWIDTH+1)*2+i]; + for(int n = 0;n < SEGNUM; n++) + { + for(int a = 0; a < SEGCHANNELS; a++) + { + frame.segments[w][n][a] = recv_buf[HEADEROFFSET+WINDOWOFFSET+ w*(SEGCHANNELS*SEGNUM+1) + n*SEGCHANNELS + a]; + } + } } // this part needs to be made threadsafe because buffers will be accessed @@ -164,39 +181,54 @@ void Server::mix() { for(int j = 0; j < WIDTH; j++) { - frame.windows[i][j] = (frame.windows[i][j] + temp_frame.windows[i][j])/2; + for(int a = 0; a < CHANNELS; a++) + { + // do something interesting here + frame.windows[i][j][a] = temp_frame.windows[i][j][a]; + } } } - for(int i = 0; i < SEGWIDTH; i++) + for(int w = 0; w < SEGWIDTH; w++ ) { - frame.segments[i].r = (temp_frame.segments[i].r + frame.segments[i].r)/2; - frame.segments[i].g = (temp_frame.segments[i].g + frame.segments[i].g)/2; - frame.segments[i].b = (temp_frame.segments[i].b + frame.segments[i].b)/2; + for(int n = 0;n < SEGNUM; n++) + { + for(int a = 0; a < SEGCHANNELS; a++) + { + frame.segments[w][n][a] = temp_frame.segments[w][n][a]; + } + } } - } - if( counter % 100 == 0 ) - { - cout << counter << endl; - for(int i = 0; i < HEIGHT; i++) - { - for(int j = 0; j < WIDTH; j++) - { - cout << frame.windows[i][j]; - } - cout << endl; - } - cout << endl; - - for(int i = 0; i < SEGWIDTH; i++) - { - cout << frame.segments[i].r; - } - cout << endl << endl; - } //*/ - - usleep( 25000 ); - } + if( counter % 100 == 0 ) + { + cout << counter << endl; + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + cout << frame.windows[i][j][0]; + } + cout << endl; + } + cout << endl; + + for(int w = 0; w < SEGWIDTH; w++) + { + for(int n = 0; n < SEGNUM; n++) + { + cout << frame.segments[w][n][0]; + } + cout << endl; + } + cout << endl << endl; + } //*/ + } + + usleep( 25000 ); + } } +void Server::control() +{ +} diff --git a/frameserver/Server.h b/frameserver/Server.h index 292d063..2271388 100644 --- a/frameserver/Server.h +++ b/frameserver/Server.h @@ -25,6 +25,7 @@ public: void listen(); void mix(); void launch_threads(); + void control(); private: Glib::Mutex mutex_; diff --git a/frameserver/defines.h b/frameserver/defines.h index 291a5ab..8d57239 100644 --- a/frameserver/defines.h +++ b/frameserver/defines.h @@ -1,22 +1,32 @@ #ifndef __DEFINES_H_ #define __DEFINES_H_ -#define BUFLEN 1024 + +#define BUFLEN 572 #define NUMBUFS 100 + +// one number + newline +#define HEADEROFFSET 2 + +// 12 windows per floor, 7 floors, Value:Alpha #define WIDTH 12 #define HEIGHT 7 +#define CHANNELS 2 + +#define WINDOWOFFSET (WIDTH*CHANNELS+1)*HEIGHT + +// 8 segments per window, 12 segments per floor, RGBA +#define SEGNUM 8 #define SEGWIDTH 12 +#define SEGCHANNELS 4 // not used for simplicity //#define SEGHEIGHT 1 -struct segment_t { - char r,g,b; -}; - struct frame_t { - char windows[HEIGHT][WIDTH]; - segment_t segments[SEGWIDTH]; + char z; + char windows[HEIGHT][WIDTH][CHANNELS]; + char segments[SEGWIDTH][SEGNUM][SEGCHANNELS]; }; #endif diff --git a/frameserver/display b/frameserver/display index a402e94..1045025 100644 --- a/frameserver/display +++ b/frameserver/display @@ -1,10 +1,19 @@ -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc -123456789abc +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +1c2b3a495867768594a3b2c1 +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba +rgbargbargbargbargbargbargbargba diff --git a/frameserver/launchpythons.sh b/frameserver/launchpythons.sh old mode 100644 new mode 100755 index 13af460..84454ab --- a/frameserver/launchpythons.sh +++ b/frameserver/launchpythons.sh @@ -7,9 +7,9 @@ while [ "$i" -lt "$processes" ] do python servertest.py "$i" & pids=( ${pids[@]} $! ) - echo ${pids["$i"]} + echo ${pids["$i"]} i=$((i+1)) - sleep 1 + sleep 0.1 done #wait for input to exit diff --git a/frameserver/servertest.py b/frameserver/servertest.py index 3f681b6..9a8a132 100644 --- a/frameserver/servertest.py +++ b/frameserver/servertest.py @@ -1,22 +1,37 @@ # Client program from socket import * +import sys +import time # Set the socket parameters -host = "localhost" -port = 4321 -buf = 382 -addr = (host,port) +local_port = 5000 + int( sys.argv[1] ) +remote_port = 4321 -# Create socket -UDPSock = socket(AF_INET,SOCK_DGRAM) +# TODO: autodetect interface address for remote application +outgoing_if = "127.0.0.1" +remote_host = "127.0.0.1" + +# udp is the default for DGRAM +UDPSock = socket(AF_INET, SOCK_DGRAM) +UDPSock.bind((outgoing_if, local_port)) + +# we will not use connections so we can keep working even if the server +# goes down or refuses connection +#UDPSock.connect((remote_host, remote_port)) + +display = open('display', 'r') +z_buffer = "1" + "\n" + +data = z_buffer + display.read() # Send messages while (1): - data = raw_input('>> ') if not data: break else: - UDPSock.sendto(data,addr) + UDPSock.sendto(data,(remote_host,remote_port)) + #send ~100 packets per second + time.sleep(0.01) -UDPSock.close() \ No newline at end of file +UDPSock.close() diff --git a/frameserver/servertest.sh b/frameserver/servertest.sh index 1015d21..7738434 100644 --- a/frameserver/servertest.sh +++ b/frameserver/servertest.sh @@ -1,6 +1,16 @@ #!/bin/bash - +n=0 while [ 1 ] do - echo "$1" | cat - display | netcat -p5000$1 -q 0.1 -u 127.0.0.1 4321 + while [ 1 ] + do + echo $1 + cat display + #sleep 0.01 + n=$((n+1)) + printf "$n \r" >&2 + done | + netcat -p500$1 -u 127.0.0.1 4321 +sleep 2 done +