]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/RTPSHeader.c
48c6649e8453fee2c01d347ff747014cc3c28cd8
[orte.git] / orte / liborte / RTPSHeader.c
1 /*
2  *  $Id: RTPSHeader.c,v 0.0.0.1  2003/08/21 
3  *
4  *  DEBUG:  section 40          Operations with header of RTPS
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 RTPSHeaderCreate(CDR_Codec *cdrCodec,HostId hid,AppId aid) {
37   CDR_Endianness  data_endian;
38   ProtocolVersion pv;
39   VendorId vid;
40
41   CDR_put_octet(cdrCodec,'R');
42   CDR_put_octet(cdrCodec,'T');
43   CDR_put_octet(cdrCodec,'P');
44   CDR_put_octet(cdrCodec,'S');
45
46   /* Protocol version */
47   PROTOCOL_VERSION_1_0(pv);
48   CDR_put_octet(cdrCodec,pv.major);
49   CDR_put_octet(cdrCodec,pv.minor);
50
51   //Vendor id
52   VENDOR_ID_UNKNOWN(vid);
53   CDR_put_octet(cdrCodec,vid.major);
54   CDR_put_octet(cdrCodec,vid.minor);
55
56   /* next data are sent in big endianing */
57   data_endian=cdrCodec->data_endian;
58   cdrCodec->data_endian=FLAG_BIG_ENDIAN;
59
60   /* Host Id */
61   CDR_put_ulong(cdrCodec,hid);
62
63   /* App Id */
64   CDR_put_ulong(cdrCodec,aid);
65
66   cdrCodec->data_endian=data_endian;
67
68   return 16;
69
70 /**********************************************************************************/
71 int
72 RTPSHeaderCheck(CDR_Codec *cdrCodec,int32_t len,MessageInterpret *mi) {
73   CDR_Endianness  data_endian;
74   CORBA_octet c;
75
76   if (len<16) return -1;                            /* message is too small */
77   CDR_get_octet(cdrCodec, (CORBA_octet *)&c);
78   if (c!='R') return -2;                            /* header is invalid */
79   CDR_get_octet(cdrCodec, (CORBA_octet *)&c);
80   if (c!='T') return -2;                            
81   CDR_get_octet(cdrCodec, (CORBA_octet *)&c);
82   if (c!='P') return -2;                            
83   CDR_get_octet(cdrCodec, (CORBA_octet *)&c);
84   if (c!='S') return -2;                            
85
86   /* Protocol Version */
87   CDR_get_octet(cdrCodec, (CORBA_octet *)&mi->sourceVersion.major);
88   CDR_get_octet(cdrCodec, (CORBA_octet *)&mi->sourceVersion.minor);
89
90    /* Vendor Id */
91   CDR_get_octet(cdrCodec, (CORBA_octet *)&mi->sourceVendorId.major);
92   CDR_get_octet(cdrCodec, (CORBA_octet *)&mi->sourceVendorId.minor);
93
94   /* next data are sent in big endianing */
95   data_endian=cdrCodec->data_endian;
96   cdrCodec->data_endian=FLAG_BIG_ENDIAN;
97
98   /* Host Id */
99   CDR_get_ulong(cdrCodec, (CORBA_unsigned_long *)&mi->sourceHostId);
100
101   /* App Id */
102   CDR_get_ulong(cdrCodec, (CORBA_unsigned_long *)&mi->sourceAppId);
103
104   cdrCodec->data_endian=data_endian;
105
106   mi->haveTimestamp=ORTE_FALSE;                     /* false */
107   return 0;
108 }
109
110