2 * $Id: ORTEAppSendThread.c,v 0.0.0.1 2003/08/21
4 * DEBUG: section 24 Sending thread
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.
34 /*****************************************************************************/
35 void ORTESendData(ORTEDomain *d,ObjectEntryAID *objectEntryAID,Boolean meta) {
36 struct sockaddr_in des;
37 ObjectEntryOID *object;
40 CDR_Codec *cdrCodec=&d->taskSend.mb.cdrCodec;
43 object=objectEntryAID->aobject;
45 appParams=(AppParams*)object->attributes;
46 if (!ObjectEntryMulticast_is_empty(object)) {
47 for(i=0;i<appParams->metatrafficMulticastIPAddressCount;i++) {
48 des.sin_family=AF_INET;
49 des.sin_addr.s_addr = htonl(appParams->metatrafficMulticastIPAddressList[i]);
50 des.sin_port = htons((uint16_t)object->multicastPort);
51 if (d->taskSend.mb.cdrCodecDirect) {
52 sock_sendto (&d->taskSend.sock,
53 d->taskSend.mb.cdrCodecDirect->buffer,
54 d->taskSend.mb.cdrCodecDirect->wptr,
58 sock_sendto (&d->taskSend.sock,
66 for(i=0;i<appParams->unicastIPAddressCount;i++) {
67 des.sin_family=AF_INET;
68 des.sin_addr.s_addr = htonl(appParams->unicastIPAddressList[i]);
70 port=appParams->metatrafficUnicastPort;
72 port=appParams->userdataUnicastPort;
74 des.sin_port = htons((uint16_t)port);
75 if (d->taskSend.mb.cdrCodecDirect) {
76 sock_sendto (&d->taskSend.sock,
77 d->taskSend.mb.cdrCodecDirect->buffer,
78 d->taskSend.mb.cdrCodecDirect->wptr,
82 sock_sendto (&d->taskSend.sock,
91 debug(24,1) ("ORTEAppSendThread: no aobjectEntryOID connected to objectEntryAID!\n");
93 //prepare buffer for next sending
94 cdrCodec->wptr=RTPS_HEADER_LENGTH;
95 d->taskSend.mb.needSend=ORTE_FALSE;
96 d->taskSend.mb.containsInfoReply=ORTE_FALSE;
97 d->taskSend.mb.cdrCodecDirect=NULL;
100 /*****************************************************************************/
101 void ORTEAppSendThread(TaskProp *tp) {
102 struct timespec wtime;
103 NtpTime actTime,nextExpire,whenExpire,sleepingTime;
107 debug(24,10) ("ORTEAppSendThread: start\n");
108 d->objectEntry.htimNeedWakeUp=ORTE_TRUE;
110 while (!tp->terminate) {
111 actTime=getActualNtpTime();
113 pthread_rwlock_wrlock(&d->objectEntry.htimRootLock);
114 if (htimerRoot_next_expire(&d->objectEntry,&nextExpire)==0) {
115 NTPTIME_BUILD(whenExpire,300); //max time for sleeping (no. events)
116 NtpTimeAdd(nextExpire,actTime,whenExpire);
118 pthread_rwlock_unlock(&d->objectEntry.htimRootLock);
119 NtpTimeDisAssembToUs(wtime.tv_sec,wtime.tv_nsec,nextExpire);
120 wtime.tv_nsec*=1000; //conver to nano seconds
121 NtpTimeSub(sleepingTime,nextExpire,actTime);
122 NtpTimeDisAssembToMs(s,ms,sleepingTime);
125 debug(24,4) ("ORTEAppSendThread: sleeping for %lis %lims\n",s,ms);
126 if (!((wtime.tv_sec==0) && (wtime.tv_nsec==0))) {
127 pthread_mutex_lock(&d->objectEntry.htimSendMutex);
128 if (d->objectEntry.htimSendCondValue==0) {
129 pthread_cond_timedwait(&d->objectEntry.htimSendCond,
130 &d->objectEntry.htimSendMutex,
133 d->objectEntry.htimSendCondValue=0;
134 pthread_mutex_unlock(&d->objectEntry.htimSendMutex);
137 debug(24,7) ("ORTEAppSendThread: fired\n");
138 actTime=getActualNtpTime();
139 pthread_rwlock_wrlock(&d->objectEntry.objRootLock);
140 pthread_rwlock_wrlock(&d->objectEntry.htimRootLock);
141 d->objectEntry.htimNeedWakeUp=ORTE_FALSE;
143 htimerRoot_run_expired(d,&actTime);
145 d->objectEntry.htimNeedWakeUp=ORTE_TRUE;
146 pthread_rwlock_unlock(&d->objectEntry.htimRootLock);
147 pthread_rwlock_unlock(&d->objectEntry.objRootLock);
149 debug(24,10) ("ORTEAppSendThread: finished\n");