Copyright update for 2011
[bcusdk.git] / eibd / libserver / lpdu.h
blob00e80860db91e1e832517d1266bf27ee87425bf6
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef LPDU_H
21 #define LPDU_H
23 #include "common.h"
25 /** enumartion of Layer 2 frame types*/
26 typedef enum
28 /** unknown frame */
29 L_Unknown,
30 /** L_Data */
31 L_Data,
32 L_Data_Ind,
33 /** L_Data incomplete */
34 L_Data_Part,
35 /** ACK */
36 L_ACK,
37 /** NACK */
38 L_NACK,
39 /** BUSY */
40 L_BUSY,
41 /** busmonitor or vBusmonitor frame */
42 L_Busmonitor,
44 LPDU_Type;
46 /** represents a Layer 2 frame */
47 class LPDU
49 public:
50 virtual ~ LPDU ()
54 virtual bool init (const CArray & c) = 0;
55 /** convert to a character array */
56 virtual CArray ToPacket () = 0;
57 /** decode content as string */
58 virtual String Decode () = 0;
59 /** get frame type */
60 virtual LPDU_Type getType () const = 0;
61 /** converts a character array to a Layer 2 frame */
62 static LPDU *fromPacket (const CArray & c);
65 /* L_Unknown */
67 class L_Unknown_PDU:public LPDU
69 public:
70 /** real content*/
71 CArray pdu;
73 L_Unknown_PDU ();
75 bool init (const CArray & c);
76 CArray ToPacket ();
77 String Decode ();
78 LPDU_Type getType () const
80 return L_Unknown;
84 /* L_Data */
86 class L_Data_PDU:public LPDU
88 public:
89 /** priority*/
90 EIB_Priority prio;
91 /** is repreated */
92 bool repeated;
93 /** checksum ok */
94 bool valid_checksum;
95 /** length ok */
96 bool valid_length;
97 /** to group/individual address*/
98 EIB_AddrType AddrType;
99 eibaddr_t source, dest;
100 uchar hopcount;
101 /** payload of Layer 4 */
102 CArray data;
104 L_Data_PDU ();
106 bool init (const CArray & c);
107 CArray ToPacket ();
108 String Decode ();
109 LPDU_Type getType () const
111 return (valid_length ? L_Data : L_Data_Part);
115 /* L_Busmonitor */
117 class L_Busmonitor_PDU:public LPDU
119 public:
120 /** content of the TP1 frame */
121 CArray pdu;
123 L_Busmonitor_PDU ();
125 bool init (const CArray & c);
126 CArray ToPacket ();
127 String Decode ();
128 LPDU_Type getType () const
130 return L_Busmonitor;
134 /* L_Data_Ind */
136 class L_Data_Ind_PDU:public L_Data_PDU
138 public:
139 L_Data_Ind_PDU ()
142 L_Data_Ind_PDU (const L_Data_PDU & c):L_Data_PDU (c)
146 LPDU_Type getType () const
148 return L_Data_Ind;
152 class L_ACK_PDU:public LPDU
154 public:
156 L_ACK_PDU ();
158 bool init (const CArray & c);
159 CArray ToPacket ();
160 String Decode ();
161 LPDU_Type getType () const
163 return L_ACK;
167 class L_NACK_PDU:public LPDU
169 public:
171 L_NACK_PDU ();
173 bool init (const CArray & c);
174 CArray ToPacket ();
175 String Decode ();
176 LPDU_Type getType () const
178 return L_NACK;
182 class L_BUSY_PDU:public LPDU
184 public:
186 L_BUSY_PDU ();
188 bool init (const CArray & c);
189 CArray ToPacket ();
190 String Decode ();
191 LPDU_Type getType () const
193 return L_BUSY;
197 #endif