some refactoring

This commit is contained in:
Lennart Buhl 2013-11-02 21:16:12 +01:00
parent 38ca85a7b3
commit 174082b281
7 changed files with 20 additions and 18 deletions

View File

@ -46,9 +46,9 @@ static void print_current_image(const struct message* msg, int start, int end) {
void callback(const struct message *msg, const struct prog_info *pinfo) {
printf("in callback, tst=%d\n", msg->timestamp);
int start;
// calculate the actual offset to use
int start = msg->timestamp % msg->width + pinfo->client_offset;
print_current_image(msg, start, start+80);
}

View File

@ -13,19 +13,19 @@
int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
pinfo->mode = MODE_SERVER;
pinfo->client_num = 1;
pinfo->client_offset = 1;
pinfo->port = 4711;
pinfo->fps = 10;
if (argc <= 1) {
printf("usage: %s [-s|-c <off>] [-p <port>] [-t <fps>]\n", argv[0]);
printf("where:\n -s run in server mode\n");
printf( " -c <num> run in client mode\n");
printf( " num is the column offset to use.\n");
printf( " -c <off> run in client mode\n");
printf( " off is the column offset to use.\n");
printf( " -p <port> use the specified port\n");
printf( " -t <fps> when in server mode: update <fps> times\n");
printf( " per second. Valid range: 2 - 99\n");
printf( " no use in client mode\n");
printf( " ignored in client mode\n");
printf( " -v \n");
printf("\n\n");
return -1;
@ -42,8 +42,8 @@ int parseArgs(struct prog_info *pinfo, int argc, char **argv) {
printf("client number not specified\n");
return -2;
}
pinfo->client_num = (int)strtol(argv[++i], NULL, 10);
if (pinfo->client_num <= 0) {
pinfo->client_offset = (int)strtol(argv[++i], NULL, 10);
if (pinfo->client_offset <= 0) {
printf("invalid client number!\n");
return -3;
}
@ -89,10 +89,10 @@ int main(int argc, char **argv) {
printf("port: %d\n", prog_info.port);
if (prog_info.mode == MODE_SERVER) {
printf("runnin 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);
} else {
printf("running in CLIENT mode, using client number %d\n", prog_info.client_num);
printf("running in CLIENT mode, using client number %d\n", prog_info.client_offset);
ret = run_client(&prog_info, callback);
}

View File

@ -1,5 +1,5 @@
// nüscht ...
//
//
//
//
//

View File

@ -1,11 +1,12 @@
#ifndef __MISC
# define __MISC
#define __MISC
struct prog_info {
int mode;
int client_num;
int client_offset;
int port;
int fps;
} prog_info;
#endif

View File

@ -13,7 +13,7 @@ void serialize (char *buf, struct message *msg) {
memcpy(&buf[0], &msg->timestamp, 4);
memcpy(&buf[4], &msg->width, 4);
memcpy(&buf[8], &msg->height, 4);
if (msg->width * msg->height)
if (msg->width * msg->height)
memcpy(&buf[12], msg->image, msg->width * msg->height);
}
@ -90,4 +90,3 @@ int main() {
}
*/

View File

@ -1,5 +1,5 @@
#ifndef __MSG
# define __MSG
#define __MSG
#include <stdint.h>
@ -34,3 +34,4 @@ void serialize_message(struct message *msg,Buffer *b);
*/
#endif

View File

@ -1,5 +1,5 @@
#ifndef __NET
# define __NET
#define __NET
#include <sys/socket.h> // struct sockaddr
#include "misc.h" // prog_info
@ -11,3 +11,4 @@ int run_server(const struct prog_info *pinfo);
int run_client(const struct prog_info *pinfo,void(*framecallback)(const struct message *, const struct prog_info *));
#endif