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@smoliku.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 #define main orte_spy_main
56 static NtpTime deadline,minimumSeparation;
57 static int32_t instanceRecv;
60 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
61 char lbuff[MAX_STRING_NTPTIME_LENGTH];
62 char rbuff[MAX_STRING_NTPTIME_LENGTH];
63 switch (info->status) {
65 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
69 NtpTimeToStringUs(info->localTimeReceived, lbuff),
70 NtpTimeToStringUs(info->remoteTimePublished, rbuff));
73 // printf("deadline occurred\n");
79 subscriptionCallBack(const char *topic, const char *type, void *param) {
80 ORTETypeRegisterAdd(d,type,NULL,NULL,NULL,0);
81 if (strcmp((const char *)topic, (const char*)"Red")==0) return NULL;
82 return ORTESubscriptionCreate(
96 static void usage(void) {
97 printf("usage: ortespy <parameters> \n");
98 printf(" -d, --domain <domain> working manager domain\n");
99 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
100 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
101 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
102 printf(" -R, --refresh <s> refresh period in second(s)\n");
103 printf(" -P, --purge <s> purge time in second(s)\n");
104 printf(" -e, --expiration <s> expiration time of manager in second(s)\n");
105 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
106 printf(" -l, --logfile <filename> set log file name\n");
107 printf(" -V, --version show version\n");
108 printf(" -h, --help this usage screen\n");
111 int main(int argc,char *argv[]) {
112 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
113 static struct option long_opts[] = {
114 { "domain",1,0, 'd' },
115 { "verbosity",1,0, 'v' },
116 { "refresh",1,0, 'R' },
117 { "purge",1,0, 'P' },
118 { "expiration",1,0, 'E' },
119 { "metaMulticast",1,0, 'I' },
120 { "logfile",1,0, 'l' },
121 { "version",0,0, 'V' },
122 { "help", 0, 0, 'h' },
127 int opt,domain=ORTE_DEFAULT_DOMAIN;
130 ORTEDomainPropDefaultGet(&dp);
131 NTPTIME_BUILD(deadline,3);
132 NTPTIME_BUILD(minimumSeparation,0);
134 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
135 while ((opt = getopt_long(argc, argv, "d:v:R:E:I:P:l:Vh",&long_opts[0], NULL)) != EOF) {
137 while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
141 domain=strtol(optarg,NULL,0);
144 ORTEVerbositySetOptions(optarg);
147 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
150 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
153 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
156 dp.multicast.enabled=ORTE_TRUE;
157 dp.multicast.ipAddress=StringToIPAddress(optarg);
160 ORTEVerbositySetLogFile(optarg);
162 printf("Open Real-Time Ethernet (%s).\n",dp.version);
168 exit(opt == 'h' ? 0 : 1);
172 printf("|------------------------------------------------------------------------------|\n");
173 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
174 "status", "type","topic","time received", "time sent");
175 printf("|------------------------------------------------------------------------------|\n");
176 d=ORTEDomainAppCreate(domain,&dp,NULL,ORTE_TRUE);
177 ORTEDomainAppSubscriptionPatternAdd(d,"*","*",subscriptionCallBack,NULL);
178 ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE);