some refactoring
This commit is contained in:
parent
38ca85a7b3
commit
174082b281
|
@ -46,8 +46,8 @@ 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);
|
||||
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user