displaytest.c

Go to the documentation of this file.
00001 /*
00002  * File Name: displaytest.c
00003  */
00004 
00005 /*
00006  * This file is part of sysd.
00007  *
00008  * sysd is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * sysd is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <stdio.h>
00035 #include <unistd.h>
00036 #include <string.h> 
00037 #include <arpa/inet.h>
00038 
00039 // ereader include files, between < >
00040 
00041 // local include files, between " "
00042 #include "delta.h"
00043 #include "log.h"
00044 
00045 
00046 //----------------------------------------------------------------------------
00047 // Type Declarations
00048 //----------------------------------------------------------------------------
00049 
00050 
00051 //----------------------------------------------------------------------------
00052 // Global Constants
00053 //----------------------------------------------------------------------------
00054 
00055 #define DMPORT      50555
00056 #define DMSERVER    "127.0.0.1"
00057 #define MESSAGEFULL "0,0,0,768,1024,0,1,1,displaytest"
00058 
00059 
00060 //----------------------------------------------------------------------------
00061 // Static Variables
00062 //----------------------------------------------------------------------------
00063 
00064 
00065 //============================================================================
00066 // Local Function Definitions
00067 //============================================================================
00068 
00069 void displayHelp(void);
00070 
00071 
00072 //============================================================================
00073 // Functions Implementation
00074 //============================================================================
00075 
00076 void displayHelp()
00077 {
00078     printf("Usage: displaytest -<option> <argument>\n");
00079     printf("  no arguments : send full display update message to local host\n");
00080     printf("  -m <formatted display string>  : message to send (x,y,width,height,is_window,window_type,widget_type)\n");
00081     printf("  -d <dotted decimal ip address> : destination IP address\n");
00082     printf("  -h : display this message\n");
00083 }
00084 
00085 int main(int argc, char **argv)
00086 {
00087     char    destination[INET_ADDRSTRLEN] = DMSERVER;
00088     char    message[256]                 = MESSAGEFULL;
00089     char    msg[256]                     = {0};
00090     struct  sockaddr_in server_addr      = {0};
00091     int     nArg = 1;
00092     int     fd   = 0;
00093 
00094     // work our way through all possible options
00095     while (nArg < argc)
00096     {
00097         if (argv[nArg][0] == '-')
00098         {
00099             switch (argv[nArg][1])
00100             {
00101             case 'h':
00102                 displayHelp();
00103                 return 0;
00104                 break;
00105 
00106             case 'd':
00107                 // What address ?
00108                 if (++nArg >= argc)
00109                 {
00110                     // not enough arguments supplied
00111                     ERRORPRINTF("Supply a dotted decimal IP address after option -d");
00112                     displayHelp();
00113                     return -1;
00114                 }
00115                 else
00116                 {
00117                     strncpy(destination, argv[nArg], INET_ADDRSTRLEN);
00118                     nArg++;
00119                 }
00120                 break;
00121 
00122             case 'm':
00123                 if (++nArg >= argc)
00124                 {
00125                     // not enough arguments supplied
00126                     ERRORPRINTF("Supply a message string after option -m");
00127                     displayHelp();
00128                     return -1;
00129                 }
00130                 else
00131                 {
00132                     strncpy(message, argv[nArg], sizeof(message));
00133                     nArg++;
00134                 }
00135                 break;
00136 
00137             default:
00138                 ERRORPRINTF("Option %s not known", argv[nArg]);
00139                 displayHelp();
00140                 return -1;
00141             }
00142         }
00143         else
00144         {
00145             ERRORPRINTF("Argument supplied not proceded by option");
00146             displayHelp();
00147             return -1;
00148         }
00149     }
00150 
00151     // create and bind socket
00152     fd = socket(PF_INET, SOCK_DGRAM, 0);
00153     server_addr.sin_family = AF_INET;
00154     server_addr.sin_port = htons(DMPORT);
00155     server_addr.sin_addr.s_addr = inet_addr(destination);
00156     memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
00157     
00158     // send display update message
00159     snprintf(msg, sizeof(msg)-1, "!I,%s", message);
00160     sendto(fd, msg, strlen(msg), 0, (struct sockaddr*) &server_addr, sizeof(server_addr));
00161 
00162     LOGPRINTF("Sent message: %s to %s", msg, destination);
00163     
00164     close(fd);
00165     
00166     return 0;
00167 }
Generated by  doxygen 1.6.2-20100208