From 80e2179bcf9d5a9e7575c7da653f826d0d758277 Mon Sep 17 00:00:00 2001 From: tkarrass Date: Sat, 2 Nov 2013 22:54:28 +0100 Subject: [PATCH] transmission of image transfer --- pic | 4 ---- src/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++----------- src/misc.h | 2 ++ src/net.c | 16 ++++++++++----- src/net.h | 2 +- 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/pic b/pic index 0a4d883..f2bcf08 100644 --- a/pic +++ b/pic @@ -1,10 +1,6 @@ - - - - (******) (*****) (****) diff --git a/src/main.c b/src/main.c index 91ff411..0aedce2 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "misc.h" #include "net.h" #include "display.h" +#include "image.h" #define MODE_SERVER 0 #define MODE_CLIENT 1 @@ -18,17 +19,20 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) { pinfo->client_offset = 1; pinfo->port = 4711; pinfo->fps = 10; + pinfo->width = -1; + pinfo->filename = NULL; if (argc <= 1) { - printf("usage: %s [-s|-c ] [-p ] [-t ]\n", argv[0]); - printf("where:\n -s run in server mode\n"); - printf( " -c run in client mode\n"); - printf( " off is the column offset to use.\n"); - printf( " -p use the specified port\n"); - printf( " -t when in server mode: update times\n"); - printf( " per second. Valid range: 2 - 99\n"); - printf( " ignored in client mode\n"); - printf( " -v \n"); + printf("usage: %s [-s|-c ] [-p ] [-t ] [-w ] -i \n", argv[0]); + printf("where:\n -s run in server mode\n"); + printf( " -c run in client mode\n"); + printf( " off is the column offset to use.\n"); + printf( " -p use the specified port\n"); + printf( " -t when in server mode: update times\n"); + printf( " per second. Valid range: 2 - 99\n"); + printf( " ignored in client mode\n"); + printf( " -w maximum width of the whole field. server only.\n"); + printf( " -i image fielname. server only\n"); printf("\n\n"); return -1; } @@ -74,10 +78,29 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) { return -7; } 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]); - return -6; + return -11; } return 0; @@ -92,7 +115,18 @@ int main(int argc, char **argv) { printf("port: %d\n", prog_info.port); if (prog_info.mode == MODE_SERVER) { 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 { printf("running in CLIENT mode, using client number %d\n", prog_info.client_offset); signal(SIGINT,&cleanup_display); diff --git a/src/misc.h b/src/misc.h index 288e3c8..fa8f428 100644 --- a/src/misc.h +++ b/src/misc.h @@ -6,6 +6,8 @@ struct prog_info { int client_offset; int port; int fps; + int width; + char *filename; } prog_info; #endif diff --git a/src/net.c b/src/net.c index 63410a1..34fe41c 100644 --- a/src/net.c +++ b/src/net.c @@ -33,7 +33,7 @@ void *get_in_addr(struct sockaddr *sa) // server mode // 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; int ret; int sockfd; @@ -81,12 +81,18 @@ int run_server(const struct prog_info *pinfo) { // TODO: Hier den Messageblock erstellen und serialisieren. t++; - t %= 10000; + t %= pinfo->width; struct message *outmsg = (struct message *)malloc(sizeof(struct message)); outmsg->timestamp = (uint32_t)t; //(uint32_t)time(NULL); - outmsg->width = 0; - outmsg->height = 0; - outmsg->image = NULL; + if ((t % 100) == 0) { + outmsg->width = w; + outmsg->height = h; + outmsg->image = img; + } else { + outmsg->width = 0; + outmsg->height = 0; + outmsg->image = NULL; + } int buflen = getBufferSize(outmsg); char *outbuf = (char *)malloc(buflen); serialize(outbuf, outmsg); diff --git a/src/net.h b/src/net.h index 0baf860..fc3584b 100644 --- a/src/net.h +++ b/src/net.h @@ -7,7 +7,7 @@ #include "display.h" // callback 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 *)); #endif