transmission of image transfer

This commit is contained in:
tkarrass 2013-11-02 22:54:28 +01:00
parent cea99d03df
commit 80e2179bcf
5 changed files with 60 additions and 22 deletions

4
pic
View File

@ -1,10 +1,6 @@
(******) (******)
(*****) (*****)
(****) (****)

View File

@ -8,6 +8,7 @@
#include "misc.h" #include "misc.h"
#include "net.h" #include "net.h"
#include "display.h" #include "display.h"
#include "image.h"
#define MODE_SERVER 0 #define MODE_SERVER 0
#define MODE_CLIENT 1 #define MODE_CLIENT 1
@ -18,9 +19,11 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
pinfo->client_offset = 1; pinfo->client_offset = 1;
pinfo->port = 4711; pinfo->port = 4711;
pinfo->fps = 10; pinfo->fps = 10;
pinfo->width = -1;
pinfo->filename = NULL;
if (argc <= 1) { if (argc <= 1) {
printf("usage: %s [-s|-c <off>] [-p <port>] [-t <fps>]\n", argv[0]); printf("usage: %s [-s|-c <off>] [-p <port>] [-t <fps>] [-w <width>] -i <img>\n", argv[0]);
printf("where:\n -s run in server mode\n"); printf("where:\n -s run in server mode\n");
printf( " -c <off> run in client mode\n"); printf( " -c <off> run in client mode\n");
printf( " off is the column offset to use.\n"); printf( " off is the column offset to use.\n");
@ -28,7 +31,8 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
printf( " -t <fps> when in server mode: update <fps> times\n"); printf( " -t <fps> when in server mode: update <fps> times\n");
printf( " per second. Valid range: 2 - 99\n"); printf( " per second. Valid range: 2 - 99\n");
printf( " ignored in client mode\n"); printf( " ignored in client mode\n");
printf( " -v \n"); printf( " -w <width> maximum width of the whole field. server only.\n");
printf( " -i <img> image fielname. server only\n");
printf("\n\n"); printf("\n\n");
return -1; return -1;
} }
@ -74,10 +78,29 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
return -7; return -7;
} }
continue; continue;
}
if (strncmp(argv[i], "-w", 2) == 0) {
if (argc <= i+1) {
printf("width not specified\n");
return -8;
}
pinfo->width = (int)strtol(argv[++i], NULL, 10);
if (pinfo->width <= 1) {
printf("width invalid!\n");
return -9;
}
continue;
}
if (strncmp(argv[i], "-i", 2) == 0) {
if (argc <= i+1) {
printf("image filename not specified\n");
return -10;
}
pinfo->filename = argv[++i];
continue;
} }
printf("unknown argument %s\n", argv[i]); printf("unknown argument %s\n", argv[i]);
return -6; return -11;
} }
return 0; return 0;
@ -92,7 +115,18 @@ int main(int argc, char **argv) {
printf("port: %d\n", prog_info.port); printf("port: %d\n", prog_info.port);
if (prog_info.mode == MODE_SERVER) { if (prog_info.mode == MODE_SERVER) {
printf("running in SERVER mode @%d FPS\n", prog_info.fps); printf("running in SERVER mode @%d FPS\n", prog_info.fps);
ret = run_server(&prog_info); if (!prog_info.filename) {
printf("no image given\n");
return -12;
}
int w, h;
char *image = readImage(prog_info.filename, &w, &h);
if (!image) {
printf("could not read image!\n");
return -13;
}
prog_info.width = prog_info.width>(w*2)?prog_info.width:(w*2);
ret = run_server(&prog_info, image, w, h);
} else { } else {
printf("running in CLIENT mode, using client number %d\n", prog_info.client_offset); printf("running in CLIENT mode, using client number %d\n", prog_info.client_offset);
signal(SIGINT,&cleanup_display); signal(SIGINT,&cleanup_display);

View File

@ -6,6 +6,8 @@ struct prog_info {
int client_offset; int client_offset;
int port; int port;
int fps; int fps;
int width;
char *filename;
} prog_info; } prog_info;
#endif #endif

View File

@ -33,7 +33,7 @@ void *get_in_addr(struct sockaddr *sa)
// server mode // server mode
// pumpt im for(;;) den status ins eth // pumpt im for(;;) den status ins eth
// //
int run_server(const struct prog_info *pinfo) { int run_server(const struct prog_info *pinfo, char *img, int w, int h) {
struct addrinfo hints, *servinfo, *p; struct addrinfo hints, *servinfo, *p;
int ret; int ret;
int sockfd; int sockfd;
@ -81,12 +81,18 @@ int run_server(const struct prog_info *pinfo) {
// TODO: Hier den Messageblock erstellen und serialisieren. // TODO: Hier den Messageblock erstellen und serialisieren.
t++; t++;
t %= 10000; t %= pinfo->width;
struct message *outmsg = (struct message *)malloc(sizeof(struct message)); struct message *outmsg = (struct message *)malloc(sizeof(struct message));
outmsg->timestamp = (uint32_t)t; //(uint32_t)time(NULL); 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->width = 0;
outmsg->height = 0; outmsg->height = 0;
outmsg->image = NULL; outmsg->image = NULL;
}
int buflen = getBufferSize(outmsg); int buflen = getBufferSize(outmsg);
char *outbuf = (char *)malloc(buflen); char *outbuf = (char *)malloc(buflen);
serialize(outbuf, outmsg); serialize(outbuf, outmsg);

View File

@ -7,7 +7,7 @@
#include "display.h" // callback #include "display.h" // callback
void *get_in_addr(struct sockaddr *sa); void *get_in_addr(struct sockaddr *sa);
int run_server(const struct prog_info *pinfo); int run_server(const struct prog_info *pinfo, char *img, int w, int h);
int run_client(const struct prog_info *pinfo,void(*framecallback)(const struct message *, const struct prog_info *)); int run_client(const struct prog_info *pinfo,void(*framecallback)(const struct message *, const struct prog_info *));
#endif #endif