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.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, ...
50 #define main orte_ping_main
54 Boolean quite=ORTE_FALSE;
59 onRegFail(void *param) {
60 printf("registration to a manager failed\n");
65 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
66 uint32_t *instance=(uint32_t*)vinstance;
68 switch (info->status) {
71 printf("received fresh issue %d\n",*instance);
74 printf("deadline occurred\n");
80 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) {
81 uint32_t *instance=(uint32_t*)vinstance;
83 switch (info->status) {
87 printf("sent issue %d\n",*instance);
89 case CQL: //criticalQueueLevel
94 static void usage(void) {
95 printf("usage: orteping <parameters> \n");
96 printf(" -d, --domain <domain> working application domain\n");
97 printf(" -p, --publisher create publisher Ping,PingData\n");
98 printf(" -S, --strength strength of publisher <1>\n");
99 printf(" -D, --delay <ms> delay between two publications <1000>\n");
100 printf(" -s, --subscriber create subscriber Ping,PingData\n");
101 printf(" -R, --refresh <s> refresh period of application\n");
102 printf(" -P, --purge <s> purge time for services\n");
103 printf(" -E, --expiration <s> expiration time of application\n");
104 printf(" -m, --minimumSeparation <s> minimumSeparation between two issues\n");
105 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
106 printf(" -i, --dataMulticast <IPAdd> use multicast IPAddr for userdata comm.\n");
107 printf(" -t, --timetolive <number> time-to-live for multicast packets\n");
108 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
109 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
110 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
111 printf(" -q --quiet \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");
117 int main(int argc,char *argv[]) {
118 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
119 static struct option long_opts[] = {
120 { "domain",1,0, 'd' },
121 { "publisher",0,0, 'p' },
122 { "strength",1,0, 'S' },
123 { "subscriber",0,0, 's' },
124 { "refresh",1,0, 'R' },
125 { "purge",1,0, 'P' },
126 { "expiration",1,0, 'E' },
127 { "minimumSeparation",1,0, 'm' },
128 { "metaMulticast",1,0, 'I' },
129 { "dataMulticast",1,0, 'i' },
130 { "timetolive",1,0, 't' },
131 { "delay",1,0, 'D' },
132 { "verbosity",1,0, 'v' },
133 { "quiet",0,0, 'q' },
134 { "logfile",1,0, 'l' },
135 { "version",0,0, 'V' },
136 { "help", 0, 0, 'h' },
142 ORTEPublication *p=NULL;
143 ORTESubscription *s=NULL;
144 int opt,domain=ORTE_DEFAULT_DOMAIN;
146 int32_t instanceSend=0,instanceRecv=0;
147 NtpTime persistence,deadline,minimumSeparation,delay;
148 Boolean havePublisher=ORTE_FALSE;
149 Boolean haveSubscriber=ORTE_FALSE;
150 IPAddress smIPAddress=IPADDRESS_INVALID;
151 ORTEDomainAppEvents events;
154 ORTEDomainPropDefaultGet(&dp);
155 NTPTIME_BUILD(minimumSeparation,0);
156 NTPTIME_BUILD(delay,1); //1s
158 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
159 while ((opt = getopt_long(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq",&long_opts[0], NULL)) != EOF) {
161 while ((opt = getopt(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq")) != EOF) {
165 strength=strtol(optarg,NULL,0);
168 domain=strtol(optarg,NULL,0);
171 havePublisher=ORTE_TRUE;
174 haveSubscriber=ORTE_TRUE;
177 ORTEVerbositySetOptions(optarg);
180 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
183 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
186 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
189 NtpTimeAssembFromMs(minimumSeparation,strtol(optarg,NULL,0),0);
192 NtpTimeAssembFromMs(delay,strtol(optarg,NULL,0)/1000,strtol(optarg,NULL,0)%1000);
195 dp.multicast.enabled=ORTE_TRUE;
196 dp.multicast.ipAddress=StringToIPAddress(optarg);
199 dp.multicast.enabled=ORTE_TRUE;
200 smIPAddress=StringToIPAddress(optarg);
203 dp.multicast.ttl=strtol(optarg,NULL,0);
206 ORTEVerbositySetLogFile(optarg);
211 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
217 exit(opt == 'h' ? 0 : 1);
221 //initiate event system
222 ORTEDomainInitEvents(&events);
223 events.onRegFail=onRegFail;
226 d=ORTEDomainAppCreate(domain,&dp,&events,ORTE_FALSE);
227 //Register ser./deser. rutines with maximal size 4 Bytes
228 ORTETypeRegisterAdd(d,"PingData",NULL,NULL,NULL,4);
231 NTPTIME_BUILD(persistence,5);
232 p=ORTEPublicationCreate(
243 if (haveSubscriber) {
244 NTPTIME_BUILD(deadline,3);
245 s=ORTESubscriptionCreate(