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, ...
49 Boolean quite=ORTE_FALSE;
54 onRegFail(void *param) {
55 printf("registration to a manager failed\n");
60 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
61 uint32_t *instance=(uint32_t*)vinstance;
63 switch (info->status) {
66 printf("received fresh issue %d\n",*instance);
69 printf("deadline occurred\n");
75 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) {
76 uint32_t *instance=(uint32_t*)vinstance;
78 switch (info->status) {
82 printf("sent issue %d\n",*instance);
84 case CQL: //criticalQueueLevel
89 static void usage(void) {
90 printf("usage: orteping <parameters> \n");
91 printf(" -d, --domain <domain> working application domain\n");
92 printf(" -p, --publisher create publisher Ping,PingData\n");
93 printf(" -S, --strength strength of publisher <1>\n");
94 printf(" -D, --delay <ms> delay between two publications <1000>\n");
95 printf(" -s, --subscriber create subscriber Ping,PingData\n");
96 printf(" -R, --refresh <s> refresh period of application\n");
97 printf(" -P, --purge <s> purge time for services\n");
98 printf(" -E, --expiration <s> expiration time of application\n");
99 printf(" -m, --minimumSeparation <s> minimumSeparation between two issues\n");
100 printf(" -I, --metaMulticast <IPAdd> use multicast IPAddr for metatraffic comm.\n");
101 printf(" -i, --dataMulticast <IPAdd> use multicast IPAddr for userdata comm.\n");
102 printf(" -t, --timetolive <number> time-to-live for multicast packets\n");
103 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
104 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
105 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
106 printf(" -q --quiet \n");
107 printf(" -l, --logfile <filename> set log file name\n");
108 printf(" -V, --version show version\n");
109 printf(" -h, --help this usage screen\n");
112 int main(int argc,char *argv[]) {
113 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
114 static struct option long_opts[] = {
115 { "domain",1,0, 'd' },
116 { "publisher",0,0, 'p' },
117 { "strength",1,0, 'S' },
118 { "subscriber",0,0, 's' },
119 { "refresh",1,0, 'R' },
120 { "purge",1,0, 'P' },
121 { "expiration",1,0, 'E' },
122 { "minimumSeparation",1,0, 'm' },
123 { "metaMulticast",1,0, 'I' },
124 { "dataMulticast",1,0, 'i' },
125 { "timetolive",1,0, 't' },
126 { "delay",1,0, 'D' },
127 { "verbosity",1,0, 'v' },
128 { "quiet",0,0, 'q' },
129 { "logfile",1,0, 'l' },
130 { "version",0,0, 'V' },
131 { "help", 0, 0, 'h' },
137 ORTEPublication *p=NULL;
138 ORTESubscription *s=NULL;
139 int opt,domain=ORTE_DEFAULT_DOMAIN;
141 int32_t instanceSend=0,instanceRecv=0;
142 NtpTime persistence,deadline,minimumSeparation,delay;
143 Boolean havePublisher=ORTE_FALSE;
144 Boolean haveSubscriber=ORTE_FALSE;
145 IPAddress smIPAddress=IPADDRESS_INVALID;
146 ORTEDomainAppEvents events;
149 ORTEDomainPropDefaultGet(&dp);
150 NTPTIME_BUILD(minimumSeparation,0);
151 NTPTIME_BUILD(delay,1); //1s
153 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
154 while ((opt = getopt_long(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq",&long_opts[0], NULL)) != EOF) {
156 while ((opt = getopt(argc, argv, "m:S:d:v:R:E:P:l:I:i:t:D:Vhpsq")) != EOF) {
160 strength=strtol(optarg,NULL,0);
163 domain=strtol(optarg,NULL,0);
166 havePublisher=ORTE_TRUE;
169 haveSubscriber=ORTE_TRUE;
172 ORTEVerbositySetOptions(optarg);
175 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
178 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
181 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
184 NtpTimeAssembFromMs(minimumSeparation,strtol(optarg,NULL,0),0);
187 NtpTimeAssembFromMs(delay,strtol(optarg,NULL,0)/1000,strtol(optarg,NULL,0)%1000);
190 dp.multicast.enabled=ORTE_TRUE;
191 dp.multicast.ipAddress=StringToIPAddress(optarg);
194 dp.multicast.enabled=ORTE_TRUE;
195 smIPAddress=StringToIPAddress(optarg);
198 dp.multicast.ttl=strtol(optarg,NULL,0);
201 ORTEVerbositySetLogFile(optarg);
206 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
212 exit(opt == 'h' ? 0 : 1);
216 //initiate event system
217 ORTEDomainInitEvents(&events);
218 events.onRegFail=onRegFail;
221 d=ORTEDomainAppCreate(domain,&dp,&events,ORTE_FALSE);
222 //Register ser./deser. rutines with maximal size 4 Bytes
223 ORTETypeRegisterAdd(d,"PingData",NULL,NULL,NULL,4);
226 NTPTIME_BUILD(persistence,5);
227 p=ORTEPublicationCreate(
238 if (haveSubscriber) {
239 NTPTIME_BUILD(deadline,3);
240 s=ORTESubscriptionCreate(