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