2 * $Id: ortespy.c,v 0.0.0.1 2003/10/07
4 * DEBUG: section ortespy
6 * -------------------------------------------------------------------
8 * Open Real-Time Ethernet
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
15 * Author: Petr Smolik petr.smolik@wo.cz
17 * Project Responsible: Zdenek Hanzalek
18 * --------------------------------------------------------------------
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.
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.
43 #include <unistd.h> //getopt.h for DarWin, Solaris, ...
51 NtpTime deadline,minimumSeparation;
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) {
60 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
64 NtpTimeToStringUs(info->localTimeReceived, lbuff),
65 NtpTimeToStringUs(info->remoteTimePublished, rbuff));
68 // printf("deadline occurred\n");
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(
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");
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' },
122 int opt,domain=ORTE_DEFAULT_DOMAIN;
125 ORTEDomainPropDefaultGet(&dp);
126 NTPTIME_BUILD(deadline,3);
127 NTPTIME_BUILD(minimumSeparation,0);
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) {
132 while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
136 domain=strtol(optarg,NULL,0);
139 ORTEVerbositySetOptions(optarg);
142 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
145 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
148 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
151 dp.multicast.enabled=ORTE_TRUE;
152 dp.multicast.ipAddress=StringToIPAddress(optarg);
155 ORTEVerbositySetLogFile(optarg);
157 printf("Open Real-Time Ethernet (%s).\n",dp.version);
163 exit(opt == 'h' ? 0 : 1);
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);