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)
62 char lbuff[MAX_STRING_NTPTIME_LENGTH];
63 char rbuff[MAX_STRING_NTPTIME_LENGTH];
65 switch (info->status) {
67 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
71 NtpTimeToStringUs(info->localTimeReceived, lbuff),
72 NtpTimeToStringUs(info->remoteTimePublished, rbuff));
75 // printf("deadline occurred\n");
81 subscriptionCallBack(const char *topic, const char *type, void *param)
83 ORTETypeRegisterAdd(d, type, NULL, NULL, NULL, 0);
84 if (strcmp((const char *)topic, (const char *)"Red") == 0)
86 return ORTESubscriptionCreate(
103 printf("usage: ortespy <parameters> \n");
104 printf(" -d, --domain <domain> working manager domain\n");
105 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
106 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
107 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
108 printf(" -R, --refresh <s> refresh period in second(s)\n");
109 printf(" -P, --purge <s> purge time in second(s)\n");
110 printf(" -e, --expiration <s> expiration time of manager in second(s)\n");
111 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
112 printf(" -l, --logfile <filename> set log file name\n");
113 printf(" -V, --version show version\n");
114 printf(" -h, --help this usage screen\n");
118 main(int argc, char *argv[])
120 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
121 static struct option long_opts[] = {
122 { "domain", 1, 0, 'd' },
123 { "verbosity", 1, 0, 'v' },
124 { "refresh", 1, 0, 'R' },
125 { "purge", 1, 0, 'P' },
126 { "expiration", 1, 0, 'E' },
127 { "metaMulticast", 1, 0, 'I' },
128 { "logfile", 1, 0, 'l' },
129 { "version", 0, 0, 'V' },
130 { "help", 0, 0, 'h' },
135 int opt, domain = ORTE_DEFAULT_DOMAIN;
138 ORTEDomainPropDefaultGet(&dp);
139 NTPTIME_BUILD(deadline, 3);
140 NTPTIME_BUILD(minimumSeparation, 0);
142 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
143 while ((opt = getopt_long(argc, argv, "d:v:R:E:I:P:l:Vh", &long_opts[0], NULL)) != EOF) {
145 while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
149 domain = strtol(optarg, NULL, 0);
152 ORTEVerbositySetOptions(optarg);
155 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod, strtol(optarg, NULL, 0), 0);
158 NtpTimeAssembFromMs(dp.baseProp.purgeTime, strtol(optarg, NULL, 0), 0);
161 NtpTimeAssembFromMs(dp.baseProp.expirationTime, strtol(optarg, NULL, 0), 0);
164 dp.multicast.enabled = ORTE_TRUE;
165 dp.multicast.ipAddress = StringToIPAddress(optarg);
168 ORTEVerbositySetLogFile(optarg);
170 printf("Open Real-Time Ethernet (%s).\n", dp.version);
176 exit(opt == 'h' ? 0 : 1);
180 printf("|------------------------------------------------------------------------------|\n");
181 printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
182 "status", "type", "topic", "time received", "time sent");
183 printf("|------------------------------------------------------------------------------|\n");
184 d = ORTEDomainAppCreate(domain, &dp, NULL, ORTE_TRUE);
185 ORTEDomainAppSubscriptionPatternAdd(d, "*", "*", subscriptionCallBack, NULL);
186 ORTEDomainStart(d, ORTE_TRUE, ORTE_FALSE, ORTE_TRUE, ORTE_FALSE, ORTE_TRUE);