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) {
68 printf("registration to a manager failed\n");
73 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
74 uint32_t *instance=(uint32_t*)vinstance;
76 switch (info->status) {
79 printf("received fresh issue %"PRIu32"\n",*instance);
82 printf("deadline occurred\n");
88 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) {
89 uint32_t *instance=(uint32_t*)vinstance;
91 switch (info->status) {
95 printf("sent issue %"PRIu32"\n",*instance);
97 case CQL: //criticalQueueLevel
102 static void usage(void) {
103 printf("usage: orteping <parameters> \n");
104 printf(" -d, --domain <domain> working application domain\n");
105 printf(" -p, --publisher create publisher Ping,PingData\n");
106 printf(" -S, --strength strength of publisher <1>\n");
107 printf(" -D, --delay <ms> delay between two publications <1000>\n");
108 printf(" -s, --subscriber create subscriber Ping,PingData\n");
109 printf(" -R, --refresh <s> refresh period of application\n");
110 printf(" -P, --purge <s> purge time for services\n");
111 printf(" -E, --expiration <s> expiration time of application\n");
112 printf(" -m, --minimumSeparation <s> minimumSeparation between two issues\n");
113 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
114 printf(" -i, --dataMulticast <IPAdd> use multicast IPAddr for userdata comm.\n");
115 printf(" -t, --timetolive <number> time-to-live for multicast packets\n");
116 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
117 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
118 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
119 printf(" -q --quiet \n");
120 printf(" -l, --logfile <filename> set log file name\n");
121 printf(" -V, --version show version\n");
122 printf(" -h, --help this usage screen\n");
125 int main(int argc,char *argv[]) {
126 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
127 static struct option long_opts[] = {
128 { "domain",1,0, 'd' },
129 { "publisher",0,0, 'p' },
130 { "strength",1,0, 'S' },
131 { "subscriber",0,0, 's' },
132 { "refresh",1,0, 'R' },
133 { "purge",1,0, 'P' },
134 { "expiration",1,0, 'E' },
135 { "minimumSeparation",1,0, 'm' },
136 { "metaMulticast",1,0, 'I' },
137 { "dataMulticast",1,0, 'i' },
138 { "timetolive",1,0, 't' },
139 { "delay",1,0, 'D' },
140 { "verbosity",1,0, 'v' },
141 { "quiet",0,0, 'q' },
142 { "logfile",1,0, 'l' },
143 { "version",0,0, 'V' },
144 { "help", 0, 0, 'h' },
150 ORTEPublication *p=NULL;
151 ORTESubscription *s=NULL;
152 int opt,domain=ORTE_DEFAULT_DOMAIN;
154 int32_t instanceSend=0,instanceRecv=0;
155 NtpTime persistence,deadline,minimumSeparation,delay;
156 Boolean havePublisher=ORTE_FALSE;
157 Boolean haveSubscriber=ORTE_FALSE;
158 IPAddress smIPAddress=IPADDRESS_INVALID;
159 ORTEDomainAppEvents events;
162 ORTEDomainPropDefaultGet(&dp);
163 NTPTIME_BUILD(minimumSeparation,0);
164 NTPTIME_BUILD(delay,1); //1s
166 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
167 while ((opt = getopt_long(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq",&long_opts[0], NULL)) != EOF) {
169 while ((opt = getopt(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq")) != EOF) {
173 strength=strtol(optarg,NULL,0);
176 domain=strtol(optarg,NULL,0);
179 havePublisher=ORTE_TRUE;
182 haveSubscriber=ORTE_TRUE;
185 ORTEVerbositySetOptions(optarg);
188 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
191 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
194 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
197 NtpTimeAssembFromMs(minimumSeparation,strtol(optarg,NULL,0),0);
200 NtpTimeAssembFromMs(delay,strtol(optarg,NULL,0)/1000,strtol(optarg,NULL,0)%1000);
203 dp.multicast.enabled=ORTE_TRUE;
204 dp.multicast.ipAddress=StringToIPAddress(optarg);
207 dp.multicast.enabled=ORTE_TRUE;
208 smIPAddress=StringToIPAddress(optarg);
211 dp.multicast.ttl=strtol(optarg,NULL,0);
214 ORTEVerbositySetLogFile(optarg);
219 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
225 exit(opt == 'h' ? 0 : 1);
229 //initiate event system
230 ORTEDomainInitEvents(&events);
231 events.onRegFail=onRegFail;
234 d=ORTEDomainAppCreate(domain,&dp,&events,ORTE_FALSE);
235 //Register ser./deser. rutines with maximal size 4 Bytes
236 ORTETypeRegisterAdd(d,"PingData",NULL,NULL,NULL,4);
239 NTPTIME_BUILD(persistence,5);
240 p=ORTEPublicationCreate(
251 printf("ORTEPublicationCreate failed\n");
255 if (haveSubscriber) {
256 NTPTIME_BUILD(deadline,3);
257 s=ORTESubscriptionCreate(
270 printf("ORTESubscriptionCreate failed\n");