Merge branch 'master' of ssh://bitsetter.de:8090/netsl

This commit is contained in:
tkarrass 2013-11-13 18:28:45 +01:00
commit 0b9005ff27
4 changed files with 28 additions and 65 deletions

View File

@ -5,7 +5,6 @@
#include "msg.h"
#include "display.h"
#include "ger.h"
void setup_display() {
initscr(); // ncurses initialization
@ -23,20 +22,20 @@ void cleanup_display() {
uint32_t height; // normally 25, may vary
char *image; // dimension is width x height
*/
statisch nichts print_current_image(konstant struktur message* msg, zahl start, zahl end) {
static void print_current_image(const struct message* msg, int start, int end) {
end = 80; // end is ignored and 80 is used, should be handled properly later
//move(0,0); // start in the upper left corner
zeichen *pic = msg->image; // get a ptr to the actual image
char *pic = msg->image; // get a ptr to the actual image
fuer (zahl row=0; row < 25; row++) { // iterate over rows
zeichen *original_line = pic + row * msg->width; // pointer to the start of the line to print
zeichen *line = (zeichen*) reserviere(end-start+1); // allocate a line because we modify it
for (int row=0; row < 25; row++) { // iterate over rows
char *original_line = pic + row * msg->width; // pointer to the start of the line to print
char *line = (char*) malloc(end-start+1); // allocate a line because we modify it
strcpy(line, original_line + start); // get a line from the right start
line[end-start] = '\0'; // terminate it
mvprintw(row, 0, "%s", line); // print it
befreie(line); // free it
free(line); // free it
}
refresh(); // refresh the screen
@ -50,8 +49,8 @@ void callback(const struct message *msg, const struct prog_info *pinfo) {
// calculate the actual offset to use
//int start = msg->timestamp % msg->width + pinfo->client_offset;
//print_current_image(msg, start, start+80);
prntscreen(msg, pinfo);
}
@ -79,6 +78,7 @@ void prntscreen(const struct message *msg, const struct prog_info *pinfo) {
if (!init) {
// printf("init start\n");
initscr();
curs_set(0); // invisible cursor
getmaxyx(stdscr, rows, cols);
init = 1;
@ -96,7 +96,7 @@ void prntscreen(const struct message *msg, const struct prog_info *pinfo) {
// printf("loop\n");
int rowoffset = (rows-h)/2;
int coloffset = left-frame;
//int coloffset = left-frame;
for (int y=0; y<h; y++) { // y<msg->height; y++) {
for (int x=left-frame; x<cols; x++) {
if (x<0)

View File

@ -1,35 +0,0 @@
#ifndef __GER
#define __GER
#define wenn if
#define sonst else
#define fuer for
#define waehrend while
#define tue do
#define statisch static
#define konstant const
#define struktur struct
#define nichts void
#define wahrheitswert bool
#define zeichen char
#define kurz short
#define zahl int
#define lang long
#define fliess float
#define doppel double
#define wahr true
#define falsch false
#define zurueckliefern return
#define haupt main
#define druckenf printf
#define schlaf sleep
#define uschlaf usleep
#define reserviere malloc
#define befreie free
#endif

View File

@ -36,7 +36,7 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
printf( " per second. Valid range: 2 - 99\n");
printf( " ignored in client mode\n");
printf( " -w <width> maximum width of the whole field. server only.\n");
printf( " -i <img> image fielname. server only\n");
printf( " -i <img> image filename. server only\n");
printf("\n\n");
return -1;
}

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h> // ?
#include <errno.h> // geguttenbergt aus bejees networking guide
@ -40,8 +41,8 @@ int run_server(const struct prog_info *pinfo, char *img, int w, int h) {
struct addrinfo hints, *servinfo, *p;
int ret;
int sockfd;
char portbuf[6];
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
@ -86,15 +87,12 @@ int run_server(const struct prog_info *pinfo, char *img, int w, int h) {
t %= pinfo->width;
struct message *outmsg = (struct message *) malloc(sizeof(struct message));
outmsg->timestamp = (uint32_t)t; //(uint32_t)time(NULL);
if ((t % 100) == 0) {
outmsg->width = w;
outmsg->height = h;
outmsg->image = img;
} else {
outmsg->width = 0;
outmsg->height = 0;
outmsg->image = NULL;
}
// send image every 100 frames
bool sendimg = (t % 100) == 0;
outmsg->width = sendimg ? w : 0;
outmsg->height = sendimg ? h : 0;
outmsg->image = sendimg ? img : NULL;
int buflen = getBufferSize(outmsg);
char *outbuf = (char *) malloc(buflen);
serialize(outbuf, outmsg);