]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/RTPSInfoTS.c
dbea6c87ead469acd81b1270734ceedb8ff4656b
[orte.git] / orte / liborte / RTPSInfoTS.c
1 /*
2  *  $Id: RTPSInfoTS.c,v 0.0.0.1         2003/09/10
3  *
4  *  DEBUG:  section 45                  message INFO TS
5  *
6  *  -------------------------------------------------------------------  
7  *                                ORTE                                 
8  *                      Open Real-Time Ethernet                       
9  *                                                                    
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                          
14  *                                                                    
15  *  Author:              Petr Smolik    petr@smoliku.cz             
16  *  Advisor:             Pavel Pisa                                   
17  *  Project Responsible: Zdenek Hanzalek                              
18  *  --------------------------------------------------------------------
19  *
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.
24  *  
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.
29  *  
30  */ 
31
32 #include "orte_all.h"
33
34 /**********************************************************************************/
35 int
36 RTPSInfoTSCreate(CDR_Codec *cdrCodec,NtpTime time) {
37   CORBA_octet flags;
38
39   if (cdrCodec->buf_len<cdrCodec->wptr+12) return -1;
40
41   /* submessage id */
42   CDR_put_octet(cdrCodec,INFO_TS);
43
44   /* flags - I-bit=0 */
45   flags=cdrCodec->data_endian;
46   CDR_put_octet(cdrCodec,flags);
47
48   /* length */
49   CDR_put_ushort(cdrCodec,8);
50
51   /* time in seconds */
52   CDR_put_long(cdrCodec,time.seconds);
53
54   /* time in seconds / 2^32 */
55   CDR_put_ulong(cdrCodec,time.fraction);
56
57   return 12;
58 }
59
60 /**********************************************************************************/
61 void 
62 RTPSInfoTS(CDR_Codec *cdrCodec,MessageInterpret *mi) {
63   char               buff[MAX_STRING_NTPTIME_LENGTH];
64   CORBA_octet        flags;  
65
66   /* restore flag possition in submessage */
67   cdrCodec->rptr-=3;
68
69   /* flags */
70   CDR_get_octet(cdrCodec, (CORBA_octet *)&flags);
71
72   /* move reading possition to begin of submessage */
73   cdrCodec->rptr+=2;
74
75
76   if ((flags & 0x02)==0) {              /* I = bit */
77     mi->haveTimestamp=ORTE_TRUE;
78
79     /* time in seconds */
80     CDR_get_long(cdrCodec,&mi->timestamp.seconds);
81
82     /* time in seconds / 2^32 */
83     CDR_get_ulong(cdrCodec, (CORBA_unsigned_long *)&mi->timestamp.fraction);
84   } else {
85     mi->haveTimestamp=ORTE_FALSE;
86     NTPTIME_ZERO(mi->timestamp);
87   }
88   if (mi->haveTimestamp)
89     debug(45,3) ("recv: RTPSInfoTS, timestamp %s\n",
90                   NtpTimeToStringUs(mi->timestamp, buff));
91   else
92     debug(45,3) ("recv: RTPSInfoTS\n");
93 }