]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/spy/ortespy.c
The uLUt files included in ORTE updated to actual version from uLan repository.
[orte.git] / orte / examples / spy / ortespy.c
1 /*
2  *  $Id: ortespy.c,v 0.0.0.1            2003/10/07 
3  *
4  *  DEBUG:  section                     ortespy
5  *
6  *  -------------------------------------------------------------------  
7  *                                ORTE                                 
8  *                      Open Real-Time Ethernet                       
9  *                                                                    
10  *                      Copyright (C) 2001-2006                       
11  *  Department of Control Engineering FEE CTU Prague, Czech Republic  
12  *                      http://dce.felk.cvut.cz                       
13  *                      http://www.ocera.org                          
14  *                                                                    
15  *  Author:              Petr Smolik    petr.smolik@wo.cz             
16  *  Advisor:             Pavel Pisa                                   
17  *  Project Responsible: Zdenek Hanzalek                              
18  *  --------------------------------------------------------------------
19  *
20  *  This program is free software; you can redistribute it and/or modify
21  *  it under the terms of the GNU General Public License as published by
22  *  the Free Software Foundation; either version 2 of the License, or
23  *  (at your option) any later version.
24  *  
25  *  This program is distributed in the hope that it will be useful,
26  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *  GNU General Public License for more details.
29  *  
30  */ 
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #ifndef _WIN32
35   #include <signal.h>
36 #endif
37 #include "orte.h"
38 #ifdef HAVE_CONFIG_H
39   #ifdef HAVE_GETOPT_H
40     #include <getopt.h>
41   #endif
42   #ifdef HAVE_UNISTD_H
43     #include <unistd.h> //getopt.h for DarWin, Solaris, ...
44   #endif
45 #else
46   #include <getopt.h>
47 #endif
48 #include "string.h"
49
50 ORTEDomain              *d;
51 NtpTime                 deadline,minimumSeparation;
52 int32_t                 instanceRecv;
53
54 void
55 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
56   char lbuff[MAX_STRING_NTPTIME_LENGTH];
57   char rbuff[MAX_STRING_NTPTIME_LENGTH];
58   switch (info->status) {
59     case NEW_DATA:
60       printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
61              "NEW_DATA",
62              info->topic,
63              info->type,
64              NtpTimeToStringUs(info->localTimeReceived, lbuff),
65              NtpTimeToStringUs(info->remoteTimePublished, rbuff));
66       break;
67     case DEADLINE:
68 //      printf("deadline occurred\n");
69       break;
70   }
71 }
72
73 ORTESubscription*
74 subscriptionCallBack(const char *topic, const char *type, void *param) {
75   ORTETypeRegisterAdd(d,type,NULL,NULL,NULL,0);   
76   if (strcmp(topic,"Red")==0) return NULL;
77   return ORTESubscriptionCreate(
78         d,
79         IMMEDIATE,
80         BEST_EFFORTS,
81         topic,
82         type,
83         &instanceRecv,
84         &deadline,
85         &minimumSeparation,
86         recvCallBack,
87         NULL,
88         IPADDRESS_INVALID);
89 }
90
91 static void usage(void) {
92   printf("usage: ortespy <parameters> \n");
93   printf("  -d, --domain <domain>         working manager domain\n");
94   printf("  -v, --verbosity <level>       set verbosity level SECTION, up to LEVEL:...\n");
95   printf("      examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
96   printf("                ORTEManager -v ALL.7     all sections up to level 7\n");
97   printf("  -R, --refresh <s>             refresh period in second(s)\n");
98   printf("  -P, --purge <s>               purge time in second(s)\n");
99   printf("  -e, --expiration <s>          expiration time of manager in second(s)\n");
100   printf("  -I, --metaMulticast <IPAdd>   use multicast IPAddr for metatraffic comm.\n");
101   printf("  -l, --logfile <filename>      set log file name\n");
102   printf("  -V, --version                 show version\n");
103   printf("  -h, --help                    this usage screen\n");
104 }
105
106 int main(int argc,char *argv[]) {
107 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
108   static struct option long_opts[] = {
109     { "domain",1,0, 'd' },
110     { "verbosity",1,0, 'v' },
111     { "refresh",1,0, 'R' },
112     { "purge",1,0, 'P' },
113     { "expiration",1,0, 'E' },
114     { "metaMulticast",1,0, 'I' },
115     { "logfile",1,0, 'l' },
116     { "version",0,0, 'V' },
117     { "help",  0, 0, 'h' },
118     { 0, 0, 0, 0}
119   };
120 #endif
121   ORTEDomainProp          dp; 
122   int                     opt,domain=ORTE_DEFAULT_DOMAIN;
123   
124   ORTEInit();
125   ORTEDomainPropDefaultGet(&dp);
126   NTPTIME_BUILD(deadline,3); 
127   NTPTIME_BUILD(minimumSeparation,0); 
128
129 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
130   while ((opt = getopt_long(argc, argv, "d:v:R:E:I:P:l:Vh",&long_opts[0], NULL)) != EOF) {
131 #else
132   while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
133 #endif
134     switch (opt) {
135       case 'd':
136         domain=strtol(optarg,NULL,0);
137         break;
138       case 'v':
139         ORTEVerbositySetOptions(optarg);
140         break;
141       case 'R':
142         NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
143         break;
144       case 'P':
145         NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
146         break;
147       case 'E':
148         NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
149         break;
150       case 'I':
151         dp.multicast.enabled=ORTE_TRUE;
152         dp.multicast.ipAddress=StringToIPAddress(optarg);
153         break;  
154       case 'l':
155         ORTEVerbositySetLogFile(optarg);
156       case 'V':
157         printf("Open Real-Time Ethernet (%s).\n",dp.version);
158         exit(0);
159         break;
160       case 'h':
161       default:
162         usage();
163         exit(opt == 'h' ? 0 : 1);
164     }
165   }
166   //Create application     
167   printf("|------------------------------------------------------------------------------|\n");
168   printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n", 
169          "status", "type","topic","time received", "time sent");
170   printf("|------------------------------------------------------------------------------|\n");
171   d=ORTEDomainAppCreate(domain,&dp,NULL,ORTE_TRUE);
172   ORTEDomainAppSubscriptionPatternAdd(d,"*","*",subscriptionCallBack,NULL);
173   ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE);
174   while (1) {
175     ORTESleepMs(1000);
176   }
177   exit(0);
178 }
179