2 * $Id: ortespy.c,v 0.0.0.1 2003/10/07
4 * DEBUG: section ortespy
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
33 #include <unistd.h> //getopt.h for DarWin, Solaris, ...
41 NtpTime deadline,minimumSeparation;
45 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
46 char lbuff[MAX_STRING_NTPTIME_LENGTH];
47 char rbuff[MAX_STRING_NTPTIME_LENGTH];
48 switch (info->status) {
50 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
54 NtpTimeToStringUs(info->localTimeReceived, lbuff),
55 NtpTimeToStringUs(info->remoteTimePublished, rbuff));
58 // printf("deadline occurred\n");
64 subscriptionCallBack(const char *topic, const char *type, void *param) {
65 ORTETypeRegisterAdd(d,type,NULL,NULL,NULL,0);
66 if (strcmp(topic,"Red")==0) return NULL;
67 return ORTESubscriptionCreate(
81 static void usage(void) {
82 printf("usage: ortespy <parameters> \n");
83 printf(" -d, --domain <domain> working manager domain\n");
84 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
85 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
86 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
87 printf(" -R, --refresh <s> refresh period in second(s)\n");
88 printf(" -P, --purge <s> purge time in second(s)\n");
89 printf(" -e, --expiration <s> expiration time of manager in second(s)\n");
90 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
91 printf(" -l, --logfile <filename> set log file name\n");
92 printf(" -V, --version show version\n");
93 printf(" -h, --help this usage screen\n");
96 int main(int argc,char *argv[]) {
97 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
98 static struct option long_opts[] = {
99 { "domain",1,0, 'd' },
100 { "verbosity",1,0, 'v' },
101 { "refresh",1,0, 'R' },
102 { "purge",1,0, 'P' },
103 { "expiration",1,0, 'E' },
104 { "metaMulticast",1,0, 'I' },
105 { "logfile",1,0, 'l' },
106 { "version",0,0, 'V' },
107 { "help", 0, 0, 'h' },
112 int opt,domain=ORTE_DEFAULT_DOMAIN;
115 ORTEDomainPropDefaultGet(&dp);
116 NTPTIME_BUILD(deadline,3);
117 NTPTIME_BUILD(minimumSeparation,0);
119 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
120 while ((opt = getopt_long(argc, argv, "d:v:R:E:I:P:l:Vh",&long_opts[0], NULL)) != EOF) {
122 while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
126 domain=strtol(optarg,NULL,0);
129 ORTEVerbositySetOptions(optarg);
132 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
135 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
138 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
141 dp.multicast.enabled=ORTE_TRUE;
142 dp.multicast.ipAddress=StringToIPAddress(optarg);
145 ORTEVerbositySetLogFile(optarg);
147 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
153 exit(opt == 'h' ? 0 : 1);
157 printf("|------------------------------------------------------------------------------|\n");
158 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
159 "status", "type","topic","time received", "time sent");
160 printf("|------------------------------------------------------------------------------|\n");
161 d=ORTEDomainAppCreate(domain,&dp,NULL,ORTE_TRUE);
162 ORTEDomainAppSubscriptionPatternAdd(d,"*","*",subscriptionCallBack,NULL);
163 ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE);