2 * $Id: orteping.c,v 0.0.0.1 2003/10/07
4 * DEBUG: section orteping
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, ...
49 #ifdef HAVE_INTTYPES_H
51 #endif /*HAVE_INTTYPES_H*/
58 #define main orte_ping_main
62 Boolean quite = ORTE_FALSE;
67 onRegFail(void *param)
69 printf("registration to a manager failed\n");
74 recvCallBack(const ORTERecvInfo *info, void *vinstance, void *recvCallBackParam)
76 uint32_t *instance = (uint32_t *)vinstance;
78 switch (info->status) {
81 printf("received fresh issue %" PRIu32 "\n", *instance);
84 printf("deadline occurred\n");
90 sendCallBack(const ORTESendInfo *info, void *vinstance, void *sendCallBackParam)
92 uint32_t *instance = (uint32_t *)vinstance;
94 switch (info->status) {
98 printf("sent issue %" PRIu32 "\n", *instance);
100 case CQL: //criticalQueueLevel
108 printf("usage: orteping <parameters> \n");
109 printf(" -d, --domain <domain> working application domain\n");
110 printf(" -p, --publisher create publisher Ping,PingData\n");
111 printf(" -S, --strength strength of publisher <1>\n");
112 printf(" -D, --delay <ms> delay between two publications <1000>\n");
113 printf(" -s, --subscriber create subscriber Ping,PingData\n");
114 printf(" -R, --refresh <s> refresh period of application\n");
115 printf(" -P, --purge <s> purge time for services\n");
116 printf(" -E, --expiration <s> expiration time of application\n");
117 printf(" -m, --minimumSeparation <s> minimumSeparation between two issues\n");
118 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
119 printf(" -i, --dataMulticast <IPAdd> use multicast IPAddr for userdata comm.\n");
120 printf(" -t, --timetolive <number> time-to-live for multicast packets\n");
121 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
122 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
123 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
124 printf(" -q --quiet \n");
125 printf(" -l, --logfile <filename> set log file name\n");
126 printf(" -V, --version show version\n");
127 printf(" -h, --help this usage screen\n");
131 main(int argc, char *argv[])
133 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
134 static struct option long_opts[] = {
135 { "domain", 1, 0, 'd' },
136 { "publisher", 0, 0, 'p' },
137 { "strength", 1, 0, 'S' },
138 { "subscriber", 0, 0, 's' },
139 { "refresh", 1, 0, 'R' },
140 { "purge", 1, 0, 'P' },
141 { "expiration", 1, 0, 'E' },
142 { "minimumSeparation", 1, 0, 'm' },
143 { "metaMulticast", 1, 0, 'I' },
144 { "dataMulticast", 1, 0, 'i' },
145 { "timetolive", 1, 0, 't' },
146 { "delay", 1, 0, 'D' },
147 { "verbosity", 1, 0, 'v' },
148 { "quiet", 0, 0, 'q' },
149 { "logfile", 1, 0, 'l' },
150 { "version", 0, 0, 'V' },
151 { "help", 0, 0, 'h' },
157 ORTEPublication *p = NULL;
158 ORTESubscription *s = NULL;
159 int opt, domain = ORTE_DEFAULT_DOMAIN;
160 int32_t strength = 1;
161 int32_t instanceSend = 0, instanceRecv = 0;
162 NtpTime persistence, deadline, minimumSeparation, delay;
163 Boolean havePublisher = ORTE_FALSE;
164 Boolean haveSubscriber = ORTE_FALSE;
165 IPAddress smIPAddress = IPADDRESS_INVALID;
166 ORTEDomainAppEvents events;
169 ORTEDomainPropDefaultGet(&dp);
170 NTPTIME_BUILD(minimumSeparation, 0);
171 NTPTIME_BUILD(delay, 1); //1s
173 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
174 while ((opt = getopt_long(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq", &long_opts[0], NULL)) != EOF) {
176 while ((opt = getopt(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq")) != EOF) {
180 strength = strtol(optarg, NULL, 0);
183 domain = strtol(optarg, NULL, 0);
186 havePublisher = ORTE_TRUE;
189 haveSubscriber = ORTE_TRUE;
192 ORTEVerbositySetOptions(optarg);
195 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod, strtol(optarg, NULL, 0), 0);
198 NtpTimeAssembFromMs(dp.baseProp.purgeTime, strtol(optarg, NULL, 0), 0);
201 NtpTimeAssembFromMs(dp.baseProp.expirationTime, strtol(optarg, NULL, 0), 0);
204 NtpTimeAssembFromMs(minimumSeparation, strtol(optarg, NULL, 0), 0);
207 NtpTimeAssembFromMs(delay, strtol(optarg, NULL, 0)/1000, strtol(optarg, NULL, 0)%1000);
210 dp.multicast.enabled = ORTE_TRUE;
211 dp.multicast.ipAddress = StringToIPAddress(optarg);
214 dp.multicast.enabled = ORTE_TRUE;
215 smIPAddress = StringToIPAddress(optarg);
218 dp.multicast.ttl = strtol(optarg, NULL, 0);
221 ORTEVerbositySetLogFile(optarg);
226 printf("Ocera Real-Time Ethernet (%s).\n", dp.version);
232 exit(opt == 'h' ? 0 : 1);
236 //initiate event system
237 ORTEDomainInitEvents(&events);
238 events.onRegFail = onRegFail;
241 d = ORTEDomainAppCreate(domain, &dp, &events, ORTE_FALSE);
242 //Register ser./deser. rutines with maximal size 4 Bytes
243 ORTETypeRegisterAdd(d, "PingData", NULL, NULL, NULL, 4);
246 NTPTIME_BUILD(persistence, 5);
247 p = ORTEPublicationCreate(
258 printf("ORTEPublicationCreate failed\n");
262 if (haveSubscriber) {
263 NTPTIME_BUILD(deadline, 3);
264 s = ORTESubscriptionCreate(
277 printf("ORTESubscriptionCreate failed\n");