knx
ETS configurable knx-stack
apdu.cpp
Go to the documentation of this file.
1 #include "apdu.h"
2 #include "cemi_frame.h"
3 #include "bits.h"
4 
5 APDU::APDU(uint8_t* data, CemiFrame& frame): _data(data), _frame(frame)
6 {
7 }
8 
10 {
11  uint16_t apci;
12  apci = getWord(_data);
13  popWord(apci, _data);
14  apci &= 0x3ff;
15 
16  if ((apci >> 6) < 11 && (apci >> 6) != 7) //short apci
17  apci &= 0x3c0;
18 
19  return (ApduType)apci;
20 }
21 
22 void APDU::type(ApduType atype)
23 {
24  // ApduType is in big endian so convert to host first, pushWord converts back
25  pushWord((uint16_t)atype, _data);
26 }
27 
28 uint8_t* APDU::data()
29 {
30  return _data + 1;
31 }
32 
34 {
35  return _frame;
36 }
37 
38 uint8_t APDU::length() const
39 {
40  return _frame.npdu().octetCount();
41 }
42 
44 {
45  print("APDU: ");
46  print(type(), HEX);
47  print(" ");
48  print(_data[0] & 0x3, HEX);
49 
50  for (uint8_t i = 1; i < length() + 1; ++i)
51  {
52  if (i)
53  print(" ");
54 
55  print(_data[i], HEX);
56  }
57 
58  println();
59 }
void print(const char *s)
void println(const char *s)
uint8_t * pushWord(uint16_t w, uint8_t *data)
Definition: bits.cpp:64
uint16_t getWord(const uint8_t *data)
Definition: bits.cpp:91
const uint8_t * popWord(uint16_t &w, const uint8_t *data)
Definition: bits.cpp:34
APDU(uint8_t *data, CemiFrame &frame)
The constructor.
Definition: apdu.cpp:5
void printPDU()
Print the contents of the APDU to console.
Definition: apdu.cpp:43
ApduType type()
Get the type of the APDU.
Definition: apdu.cpp:9
uint8_t * data()
Get a pointer to the data.
Definition: apdu.cpp:28
uint8_t length() const
Get the length of the APDU.
Definition: apdu.cpp:38
CemiFrame & frame()
Get the CemiFrame this APDU is part of.
Definition: apdu.cpp:33
NPDU & npdu()
Definition: cemi_frame.cpp:357
uint8_t octetCount() const
Definition: npdu.cpp:11
ApduType
Definition: knx_types.h:142