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.
25 LPDU::fromPacket (const CArray
& c
)
33 l
= new L_BUSY_PDU ();
35 l
= new L_NACK_PDU ();
36 if ((c
[0] & 0x53) == 0x10)
37 l
= new L_Data_PDU ();
43 l
= new L_Unknown_PDU ();
50 L_NACK_PDU::L_NACK_PDU ()
55 L_NACK_PDU::init (const CArray
& c
)
62 CArray
L_NACK_PDU::ToPacket ()
66 return CArray (&c
, 1);
69 String
L_NACK_PDU::Decode ()
76 L_ACK_PDU::L_ACK_PDU ()
81 L_ACK_PDU::init (const CArray
& c
)
88 CArray
L_ACK_PDU::ToPacket ()
92 return CArray (&c
, 1);
95 String
L_ACK_PDU::Decode ()
102 L_BUSY_PDU::L_BUSY_PDU ()
107 L_BUSY_PDU::init (const CArray
& c
)
114 CArray
L_BUSY_PDU::ToPacket ()
118 return CArray (&c
, 1);
121 String
L_BUSY_PDU::Decode ()
128 L_Unknown_PDU::L_Unknown_PDU ()
133 L_Unknown_PDU::init (const CArray
& c
)
140 L_Unknown_PDU::ToPacket ()
146 L_Unknown_PDU::Decode ()
148 String
s ("Unknown LPDU: ");
154 for (i
= 0; i
< pdu (); i
++)
162 L_Busmonitor_PDU::L_Busmonitor_PDU ()
167 L_Busmonitor_PDU::init (const CArray
& c
)
174 L_Busmonitor_PDU::ToPacket ()
180 L_Busmonitor_PDU::Decode ()
188 for (i
= 0; i
< pdu (); i
++)
191 LPDU
*l
= LPDU::fromPacket (pdu
);
199 L_Data_PDU::L_Data_PDU ()
205 AddrType
= IndividualAddress
;
212 L_Data_PDU::init (const CArray
& c
)
218 if ((c
[0] & 0x53) != 0x10)
220 repeated
= (c
[0] & 0x20) ? 0 : 1;
222 switch ((c
[0] >> 2) & 0x3)
240 source
= (c
[1] << 8) | (c
[2]);
241 dest
= (c
[3] << 8) | (c
[4]);
242 len
= (c
[5] & 0x0f) + 1;
243 hopcount
= (c
[5] >> 4) & 0x07;
244 AddrType
= (c
[5] & 0x80) ? GroupAddress
: IndividualAddress
;
247 data
.set (c
.array () + 6, len
);
249 for (i
= 0; i
< c () - 1; i
++)
252 valid_checksum
= (c
[c () - 1] == c1
? 1 : 0);
257 if ((c
[1] & 0x0f) != 0)
261 hopcount
= (c
[1] >> 4) & 0x07;
262 AddrType
= (c
[1] & 0x80) ? GroupAddress
: IndividualAddress
;
263 source
= (c
[2] << 8) | (c
[3]);
264 dest
= (c
[4] << 8) | (c
[5]);
271 data
.set (c
.array () + 7, 8);
277 data
.set (c
.array () + 7, len
);
280 for (i
= 0; i
< c () - 1; i
++)
283 valid_checksum
= (c
[c () - 1] == c1
? 1 : 0);
288 CArray
L_Data_PDU::ToPacket ()
290 assert (data () >= 1);
291 assert (data () <= 0xff);
292 assert ((hopcount
& 0xf8) == 0);
314 if (data () - 1 <= 0x0f)
316 pdu
.resize (7 + data ());
317 pdu
[0] = 0x90 | (c
<< 2) | (repeated
? 0x00 : 0x20);
318 pdu
[1] = (source
>> 8) & 0xff;
319 pdu
[2] = (source
) & 0xff;
320 pdu
[3] = (dest
>> 8) & 0xff;
321 pdu
[4] = (dest
) & 0xff;
323 (hopcount
& 0x07) << 4 | ((data () - 1) & 0x0f) | (AddrType
==
326 pdu
.setpart (data
.array (), 6, 1 + ((data () - 1) & 0x0f));
330 pdu
.resize (8 + data ());
331 pdu
[0] = 0x10 | (c
<< 2) | (repeated
? 0x00 : 0x20);
333 (hopcount
& 0x07) << 4 | (AddrType
== GroupAddress
? 0x80 : 0x00);
334 pdu
[2] = (source
>> 8) & 0xff;
335 pdu
[3] = (source
) & 0xff;
336 pdu
[4] = (dest
>> 8) & 0xff;
337 pdu
[5] = (dest
) & 0xff;
338 pdu
[6] = (data () - 1) & 0xff;
339 pdu
.setpart (data
.array (), 7, 1 + ((data () - 1) & 0xff));
343 for (i
= 0; i
< pdu () - 1; i
++)
345 pdu
[pdu () - 1] = ~c
;
350 String
L_Data_PDU::Decode ()
352 assert (data () >= 1);
353 assert (data () <= 0xff);
354 assert ((hopcount
& 0xf8) == 0);
359 s
+= " (incomplete)";
378 s
+= " INVALID CHECKSUM";
380 s
+ " from " + FormatEIBAddr (source
) + " to " + (AddrType
==
382 FormatGroupAddr (dest
) :
383 FormatEIBAddr (dest
));
385 addHex (s
, hopcount
);
387 d
= TPDU::fromPacket (data
);