forgot to add some files to commit

master
Bartosz Kostrzewa 2010-11-15 12:44:10 +01:00
parent f0ed60e5d2
commit 75e29a6f66
7 changed files with 173 additions and 96 deletions

View File

@ -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()
{
}

View File

@ -25,6 +25,7 @@ public:
void listen();
void mix();
void launch_threads();
void control();
private:
Glib::Mutex mutex_;

View File

@ -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

View File

@ -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

4
frameserver/launchpythons.sh Normal file → Executable file
View File

@ -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

View File

@ -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()
UDPSock.close()

View File

@ -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