Working on client -> frameserver -> ws_udp.js -> visionneuse.html stack
parent
bffff1a33a
commit
e760498b3b
|
@ -0,0 +1,11 @@
|
||||||
|
The goal is to make a nice python client library that allows us to quickly make new clients.
|
||||||
|
|
||||||
|
First goal is to get cellular.py and plasma.py to work through full stack.
|
||||||
|
|
||||||
|
plasma.py sends packets to:
|
||||||
|
frameserver, which sends packets to:
|
||||||
|
ws_udp.js, which sends it to the visionneuse.html client.
|
||||||
|
|
||||||
|
PROBLEMS:
|
||||||
|
- For some reason the cellular.py packet is not being processed by the frameserver
|
||||||
|
- When running plasma.py there is an alignment error in visionneuse.hml
|
|
@ -84,7 +84,7 @@ def i2c(rgba):
|
||||||
def send_update():
|
def send_update():
|
||||||
#zero out the data buffer
|
#zero out the data buffer
|
||||||
data = hash
|
data = hash
|
||||||
data = data + z_buffer
|
data = data + z_buffer # 12 bytes
|
||||||
|
|
||||||
# write frame data
|
# write frame data
|
||||||
for y in xrange(height):
|
for y in xrange(height):
|
||||||
|
@ -106,7 +106,7 @@ def send_update():
|
||||||
UDPSock.sendto(data,(remote_host,remote_port))
|
UDPSock.sendto(data,(remote_host,remote_port))
|
||||||
|
|
||||||
# initialize map
|
# initialize map
|
||||||
set_wdata(0,0,0)
|
set_wdata(67,67,67)
|
||||||
set_sdata(0,0,255)
|
set_sdata(0,0,255)
|
||||||
|
|
||||||
# set start seed
|
# set start seed
|
||||||
|
|
|
@ -7,6 +7,9 @@ from math import *
|
||||||
|
|
||||||
# Set the socket parameters
|
# Set the socket parameters
|
||||||
local_port = 5001
|
local_port = 5001
|
||||||
|
# direct html udp port
|
||||||
|
#remote_port = 4422
|
||||||
|
# production port
|
||||||
remote_port = 4321
|
remote_port = 4321
|
||||||
|
|
||||||
# TODO: autodetect interface address for remote application
|
# TODO: autodetect interface address for remote application
|
||||||
|
@ -26,20 +29,20 @@ UDPSock.bind((outgoing_if, local_port))
|
||||||
|
|
||||||
segmentsfile = open('segments','r')
|
segmentsfile = open('segments','r')
|
||||||
|
|
||||||
hash = "abcdefghij"
|
hash = "s2l\n<8<18 " # 10 bytes
|
||||||
|
|
||||||
alpha = chr(255)
|
alpha = chr(255)
|
||||||
|
|
||||||
z_buffer = chr(1) + "\n"
|
z_buffer = chr(1) + "\n"
|
||||||
|
|
||||||
width = 7
|
width = 12
|
||||||
height = 12
|
height = 8
|
||||||
|
|
||||||
segments = 8
|
segments = 8
|
||||||
segwidth = 12
|
segwidth = 12
|
||||||
segchannels = 4
|
segchannels = 3
|
||||||
|
|
||||||
sleeptime = 0.02
|
sleeptime = 0.2
|
||||||
t = 0
|
t = 0
|
||||||
|
|
||||||
#timer will hold the elapsed time in seconds
|
#timer will hold the elapsed time in seconds
|
||||||
|
@ -49,15 +52,22 @@ while (1):
|
||||||
#zero out the data buffer
|
#zero out the data buffer
|
||||||
data = hash
|
data = hash
|
||||||
data += z_buffer
|
data += z_buffer
|
||||||
for i in range(0,width):
|
|
||||||
for j in range(0,height):
|
# windows
|
||||||
pixel = 0.5+0.5*sin(2*pi*(float(i+1)/width)+t*frequency)*sin(2*pi*(float(j+1)/height)+t*frequency)
|
for j in range(0,height):
|
||||||
data = data + chr(int(255*pixel)) + alpha
|
for i in range(0,width):
|
||||||
data = data + "\n"
|
pixel = 0.5 + 0.5*sin(2*pi*(float(i+1)/width)+t*frequency)*sin(2*pi*(float(j+1)/height)+t*frequency)
|
||||||
|
char = chr(int(127 * pixel))
|
||||||
|
data += char + char + char + alpha
|
||||||
|
data += "\n"
|
||||||
|
|
||||||
|
# segment/text display
|
||||||
for i in range(0,segwidth):
|
for i in range(0,segwidth):
|
||||||
for j in range(0,segments):
|
for j in range(0,segments):
|
||||||
for a in range(0,segchannels):
|
for a in range(0,segchannels):
|
||||||
data += chr( 127 + int(128*sin(2*pi*(1+i)*(1+j)*(1+a)*t*frequency/200)))
|
val = 63 + int(63*sin(2*pi*(1+i)*(1+j)*t*frequency/200))
|
||||||
|
data += chr(val)
|
||||||
|
data += alpha
|
||||||
data += "\n"
|
data += "\n"
|
||||||
t+=1
|
t+=1
|
||||||
if not data:
|
if not data:
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
||||||
rgbargbargbargbargbargbargbargba
|
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
Server::Server(int _port )
|
Server::Server(int _port )
|
||||||
{
|
{
|
||||||
port = _port;
|
port = _port;
|
||||||
displaycounter = 0;
|
displaycounter = 0;
|
||||||
packetcounter = 0;
|
packetcounter = 0;
|
||||||
consoleinit = false;
|
consoleinit = false;
|
||||||
mode = FRAME;
|
mode = FRAME;
|
||||||
selected_buffer=0;
|
selected_buffer=0;
|
||||||
launch_threads();
|
launch_threads();
|
||||||
|
@ -68,7 +68,7 @@ void Server::listen()
|
||||||
|
|
||||||
|
|
||||||
// DEBUG OUTPUT RAW BUFFER DATA from packet
|
// DEBUG OUTPUT RAW BUFFER DATA from packet
|
||||||
// std::cout << recv_buf.data() << std::endl;
|
//std::cout << recv_buf.data() << std::endl;
|
||||||
|
|
||||||
// check whether this is a valid packet and discard it if it isn't
|
// check whether this is a valid packet and discard it if it isn't
|
||||||
// note, this is a very hack way of comparing strings...
|
// note, this is a very hack way of comparing strings...
|
||||||
|
@ -173,7 +173,7 @@ void Server::listen()
|
||||||
void Server::send()
|
void Server::send()
|
||||||
{
|
{
|
||||||
|
|
||||||
const int length = WIDTH*HEIGHT*CHANNELS + SEGWIDTH*SEGNUM*SEGCHANNELS;
|
const int length = 12 + HEIGHT*(WIDTH*CHANNELS+1) + SEGWIDTH*(SEGNUM*SEGCHANNELS+1);
|
||||||
static char data[length];
|
static char data[length];
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -188,9 +188,10 @@ void Server::send()
|
||||||
{
|
{
|
||||||
for(int k = 0; k < CHANNELS; k++)
|
for(int k = 0; k < CHANNELS; k++)
|
||||||
{
|
{
|
||||||
data[i*WIDTH*CHANNELS + CHANNELS*j + k] = frame.windows[i][j][k];
|
data[i*(WIDTH*CHANNELS+1) + j*CHANNELS + k] = frame.windows[i][j][k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data[i*(WIDTH*CHANNELS+1) + (WIDTH*CHANNELS)] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < SEGWIDTH; i++)
|
for(int i = 0; i < SEGWIDTH; i++)
|
||||||
|
@ -199,10 +200,12 @@ void Server::send()
|
||||||
{
|
{
|
||||||
for(int k = 0; k < SEGCHANNELS; k++)
|
for(int k = 0; k < SEGCHANNELS; k++)
|
||||||
{
|
{
|
||||||
data[WIDTH*HEIGHT*CHANNELS +
|
data[HEIGHT*(WIDTH*CHANNELS+1) +
|
||||||
i*SEGNUM*SEGCHANNELS + SEGCHANNELS*j + k] = frame.segments[i][j][k];
|
i*(SEGNUM*SEGCHANNELS+1) + j*SEGCHANNELS + k] = frame.segments[i][j][k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data[HEIGHT*(WIDTH*CHANNELS+1) +
|
||||||
|
i*(SEGNUM*SEGCHANNELS+1) + (SEGNUM*SEGCHANNELS)] = '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,12 +285,12 @@ void Server::mix()
|
||||||
// implement alpha blending
|
// implement alpha blending
|
||||||
for(int x = 0; x < size; x++)
|
for(int x = 0; x < size; x++)
|
||||||
{
|
{
|
||||||
temp_frame = buffers[x]->get();
|
temp_frame = buffers[x]->get();
|
||||||
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++)
|
||||||
{
|
{
|
||||||
temp_alpha = (float)temp_frame.windows[i][j][CHANNELS-1]/255;
|
temp_alpha = (float)temp_frame.windows[i][j][CHANNELS-1]/255;
|
||||||
for(int a = 0; a < CHANNELS; a++)
|
for(int a = 0; a < CHANNELS; a++)
|
||||||
{
|
{
|
||||||
// this works for the colors and for the alpha channel
|
// this works for the colors and for the alpha channel
|
||||||
|
@ -350,53 +353,55 @@ void Server::console()
|
||||||
noecho();
|
noecho();
|
||||||
|
|
||||||
if(has_colors() == FALSE)
|
if(has_colors() == FALSE)
|
||||||
{ endwin();
|
{
|
||||||
|
endwin();
|
||||||
printf("Your terminal does not support color\n");
|
printf("Your terminal does not support color\n");
|
||||||
// not sure what happens here because of threads!
|
// not sure what happens here because of threads!
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
start_color(); /* Start color */
|
start_color(); /* Start color */
|
||||||
|
|
||||||
init_pair(1,COLOR_RED,COLOR_BLACK);
|
init_pair(1,COLOR_RED,COLOR_BLACK);
|
||||||
init_pair(2,COLOR_GREEN,COLOR_BLACK);
|
init_pair(2,COLOR_GREEN,COLOR_BLACK);
|
||||||
init_pair(3,COLOR_BLUE,COLOR_BLACK);
|
init_pair(3,COLOR_BLUE,COLOR_BLACK);
|
||||||
init_pair(4,COLOR_BLACK,COLOR_WHITE);
|
init_pair(4,COLOR_BLACK,COLOR_WHITE);
|
||||||
|
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Mutex::Lock lock(mutex_);
|
||||||
consoleinit = true;
|
consoleinit = true;
|
||||||
threads.push_back( Glib::Thread::create( sigc::mem_fun(this, &Server::input), false) );
|
threads.push_back( Glib::Thread::create( sigc::mem_fun(this, &Server::input), false) );
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// we'll be accessing some data to provide statistics, lock the Server!!!
|
// we'll be accessing some data to provide statistics, lock the Server!!!
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Mutex::Lock lock(mutex_);
|
||||||
mvprintw(0,0,"Clients %d | F2 Frame | F3 Values | F4 Clients | F5 Stats | input: %d ", buffers.size(),console_input );
|
mvprintw(0,0,"Clients %d | F2 Frame | F3 Values | F4 Clients | F5 Stats | input: %d ", buffers.size(),console_input );
|
||||||
switch(mode)
|
switch(mode)
|
||||||
{
|
{
|
||||||
case FRAME:
|
case FRAME:
|
||||||
console_printframe(frame);
|
console_printframe(frame);
|
||||||
break;
|
break;
|
||||||
case FRAME_VALUES:
|
case FRAME_VALUES:
|
||||||
console_printframe_values(frame);
|
console_printframe_values(frame);
|
||||||
break;
|
break;
|
||||||
case CLIENTS:
|
case CLIENTS:
|
||||||
console_printclients();
|
console_printclients();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console_printframe(frame);
|
console_printframe(frame);
|
||||||
}
|
}
|
||||||
refresh(); /* Print it on to the real screen */
|
refresh(); /* Print it on to the real screen */
|
||||||
}
|
}
|
||||||
usleep( 20000 );
|
usleep( 20000 );
|
||||||
}
|
}
|
||||||
endwin(); /* End curses mode */
|
endwin(); /* End curses mode */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::input()
|
void Server::input()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
// get the number of buffers in a threadsafe manner (see Server::get_size() )
|
// get the number of buffers in a threadsafe manner (see Server::get_size() )
|
||||||
int size = get_size();
|
int size = get_size();
|
||||||
|
@ -432,7 +437,7 @@ void Server::input()
|
||||||
case '0':
|
case '0':
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Mutex::Lock lock(mutex_);
|
||||||
console_input = c;
|
console_input = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,7 +573,6 @@ void Server::console_printclients()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Server::console_printstats()
|
void Server::console_printstats()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
|
|
||||||
#define WINDOWOFFSET (WIDTH*CHANNELS+1)*HEIGHT
|
#define WINDOWOFFSET (WIDTH*CHANNELS+1)*HEIGHT
|
||||||
|
|
||||||
// 8 segments per window, 12 segments per floor, RGBA
|
// 12 windows wide, 8 segment per window, RGBA
|
||||||
#define SEGNUM 8
|
|
||||||
#define SEGWIDTH 12
|
#define SEGWIDTH 12
|
||||||
|
#define SEGNUM 8
|
||||||
#define SEGCHANNELS 4
|
#define SEGCHANNELS 4
|
||||||
|
|
||||||
#define BUFLEN HEADEROFFSET+WINDOWOFFSET+(SEGNUM*SEGCHANNELS+1)*SEGWIDTH
|
#define BUFLEN HEADEROFFSET+WINDOWOFFSET+(SEGNUM*SEGCHANNELS+1)*SEGWIDTH
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
struct frame_t
|
struct frame_t
|
||||||
{
|
{
|
||||||
unsigned char z;
|
unsigned char z;
|
||||||
unsigned char windows[HEIGHT][WIDTH][CHANNELS];
|
unsigned char windows[HEIGHT][WIDTH][CHANNELS];
|
||||||
unsigned char segments[SEGWIDTH][SEGNUM][SEGCHANNELS];
|
unsigned char segments[SEGWIDTH][SEGNUM][SEGCHANNELS];
|
||||||
// int windows[HEIGHT][WIDTH][CHANNELS];
|
// int windows[HEIGHT][WIDTH][CHANNELS];
|
||||||
|
|
Loading…
Reference in New Issue