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() void Server::listen()
{ {
int packetcounter = 0; long packetcounter = 0;
try try
{ {
boost::asio::io_service io_service; boost::asio::io_service io_service;
@ -54,13 +54,8 @@ void Server::listen()
socket.receive_from(boost::asio::buffer(recv_buf), socket.receive_from(boost::asio::buffer(recv_buf),
remote_endpoint, 0, error); remote_endpoint, 0, error);
packetcounter++;
if( packetcounter % 1000 == 0 )
cout << endl << packetcounter << endl;
// have we encountered this source before? // bufnum is used further down
// DEBUG
// cout << remote_endpoint << endl;
int bufnum = 0; int bufnum = 0;
{ {
Glib::Mutex::Lock lock(mutex_); Glib::Mutex::Lock lock(mutex_);
@ -68,6 +63,7 @@ void Server::listen()
bool known = false; bool known = false;
for(bufnum = 0; bufnum < size; bufnum++) for(bufnum = 0; bufnum < size; bufnum++)
{ {
// have we encountered this source before?
if(endpoints[bufnum] == remote_endpoint) if(endpoints[bufnum] == remote_endpoint)
{ {
known = true; known = true;
@ -75,7 +71,7 @@ void Server::listen()
} }
} }
if( !known && size+1 < NUMBUFS ) if( !known && size < NUMBUFS )
{ {
// create a new buffer make a note of the endpoint // create a new buffer make a note of the endpoint
std::stringstream endpointstring; std::stringstream endpointstring;
@ -86,23 +82,44 @@ void Server::listen()
} }
// discard packet, we're not accepting any more sources! // discard packet, we're not accepting any more sources!
else if( size+1 >= NUMBUFS ) else if( !known && size >= NUMBUFS )
break; {
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 i = 0; i < HEIGHT; i++)
{ {
for(int j = 0; j < WIDTH; j++) 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]; for(int n = 0;n < SEGNUM; n++)
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 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 // this part needs to be made threadsafe because buffers will be accessed
@ -164,15 +181,22 @@ void Server::mix()
{ {
for(int j = 0; j < WIDTH; j++) 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; for(int n = 0;n < SEGNUM; n++)
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 a = 0; a < SEGCHANNELS; a++)
{
frame.segments[w][n][a] = temp_frame.segments[w][n][a];
}
} }
} }
@ -183,20 +207,28 @@ void Server::mix()
{ {
for(int j = 0; j < WIDTH; j++) for(int j = 0; j < WIDTH; j++)
{ {
cout << frame.windows[i][j]; cout << frame.windows[i][j][0];
} }
cout << endl; cout << endl;
} }
cout << endl; cout << endl;
for(int i = 0; i < SEGWIDTH; i++) for(int w = 0; w < SEGWIDTH; w++)
{ {
cout << frame.segments[i].r; for(int n = 0; n < SEGNUM; n++)
{
cout << frame.segments[w][n][0];
}
cout << endl;
} }
cout << endl << endl; cout << endl << endl;
} //*/ } //*/
}
usleep( 25000 ); usleep( 25000 );
} }
} }
void Server::control()
{
}

View File

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

View File

@ -1,22 +1,32 @@
#ifndef __DEFINES_H_ #ifndef __DEFINES_H_
#define __DEFINES_H_ #define __DEFINES_H_
#define BUFLEN 1024
#define BUFLEN 572
#define NUMBUFS 100 #define NUMBUFS 100
// one number + newline
#define HEADEROFFSET 2
// 12 windows per floor, 7 floors, Value:Alpha
#define WIDTH 12 #define WIDTH 12
#define HEIGHT 7 #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 SEGWIDTH 12
#define SEGCHANNELS 4
// not used for simplicity // not used for simplicity
//#define SEGHEIGHT 1 //#define SEGHEIGHT 1
struct segment_t {
char r,g,b;
};
struct frame_t struct frame_t
{ {
char windows[HEIGHT][WIDTH]; char z;
segment_t segments[SEGWIDTH]; char windows[HEIGHT][WIDTH][CHANNELS];
char segments[SEGWIDTH][SEGNUM][SEGCHANNELS];
}; };
#endif #endif

View File

@ -1,10 +1,19 @@
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc 1c2b3a495867768594a3b2c1
123456789abc rgbargbargbargbargbargbargbargba
123456789abc rgbargbargbargbargbargbargbargba
123456789abc rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba
rgbargbargbargbargbargbargbargba

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

@ -9,7 +9,7 @@ do
pids=( ${pids[@]} $! ) pids=( ${pids[@]} $! )
echo ${pids["$i"]} echo ${pids["$i"]}
i=$((i+1)) i=$((i+1))
sleep 1 sleep 0.1
done done
#wait for input to exit #wait for input to exit

View File

@ -1,22 +1,37 @@
# Client program # Client program
from socket import * from socket import *
import sys
import time
# Set the socket parameters # Set the socket parameters
host = "localhost" local_port = 5000 + int( sys.argv[1] )
port = 4321 remote_port = 4321
buf = 382
addr = (host,port)
# Create socket # 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 = 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 # Send messages
while (1): while (1):
data = raw_input('>> ')
if not data: if not data:
break break
else: 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 #!/bin/bash
n=0
while [ 1 ] while [ 1 ]
do 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 done