hci-decoder  1.0
Lightweight Bluetooth HCI decoder library parsing individually HCI frames into JSON format
hci_acl.h
Go to the documentation of this file.
1 /************************************************************************************
2  * The MIT License (MIT) *
3  * *
4  * Copyright (c) 2015 Bertrand Martel *
5  * *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy *
7  * of this software and associated documentation files (the "Software"), to deal *
8  * in the Software without restriction, including without limitation the rights *
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
10  * copies of the Software, and to permit persons to whom the Software is *
11  * furnished to do so, subject to the following conditions: *
12  * *
13  * The above copyright notice and this permission notice shall be included in *
14  * all copies or substantial portions of the Software. *
15  * *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
22  * THE SOFTWARE. *
23  ************************************************************************************/
31 #ifndef HCI_ACL_H
32 #define HCI_ACL_H
33 
34 #include "IHciFrame.h"
35 #include "hci_global.h"
36 #include "json/json.h"
37 
38 typedef struct hci_acl : IHciFrame{
39 
42  uint8_t broadcast_flag;
44  std::vector<uint8_t> acl_data;
45 
46  hci_acl(const std::vector<char> &data){
47  connection_handle = ((data[ACL_FRAME_OFFSET] & 0x0F)<<8) + (data[ACL_FRAME_OFFSET+1]);
48  packet_boundary_flag = (data[ACL_FRAME_OFFSET+1] & 0x30)>>4;
49  broadcast_flag = (data[ACL_FRAME_OFFSET+1] & 0xC0)>>6;
50  data_total_length = data[ACL_FRAME_OFFSET+2] + (data[ACL_FRAME_OFFSET+3]<<8);
51  for (unsigned int i = 0; i < data_total_length;i++){
52  acl_data.push_back(data[i]+ACL_FRAME_OFFSET+4);
53  }
54  }
55 
62  return HCI_TYPE_ACL_DATA;
63  }
64 
65  void print(){
66  std::cout << toJson(true).data() << std::endl;
67  }
68 
69  std::string toJson(bool beautify){
70  return convert_json_to_string(beautify,toJsonObj());
71  }
72 
73  Json::Value toJsonObj(){
74  Json::Value output;
75 
76  Json::Value packet_type;
77  packet_type["code"] = HCI_TYPE_ACL_DATA;
78  packet_type["value"] = HCI_PACKET_TYPE_STRING_ENUM.at(HCI_TYPE_ACL_DATA);
79 
80  output["packet_type"] = packet_type;
81  output["connection_handle"] = connection_handle;
82  output["packet_boundary_flag"] = packet_boundary_flag;
83  output["broadcast_flag"] = broadcast_flag;
84  output["data_total_length"] = data_total_length;
85 
86  Json::Value data_val(Json::arrayValue);
87 
88  for (unsigned int i = 0; i < data_total_length;i++){
89  data_val.append(acl_data[i]);
90  }
91 
92  output["data"] = data_val;
93 
94  return output;
95  };
96 
97 } hci_acl_t;
98 
99 #endif //HCI_ACL_H
#define ACL_FRAME_OFFSET
Definition: hci_global.h:43
The IHciFrame class Interface defining all a generic HCI Frame.
Definition: IHciFrame.h:42
uint16_t data_total_length
Definition: hci_acl.h:43
std::string toJson(bool beautify)
toStyledJson convert frame information to beautiful json format
Definition: hci_acl.h:69
HCI_PACKET_TYPE_ENUM
Definition: hci_global.h:126
Json::Value toJsonObj()
toStyledJson convert frame information to beautiful json format
Definition: hci_acl.h:73
uint16_t connection_handle
Definition: hci_acl.h:40
uint8_t packet_boundary_flag
Definition: hci_acl.h:41
std::string convert_json_to_string(bool beautify, Json::Value output)
Definition: hci_global.h:164
const std::map< int, std::string > HCI_PACKET_TYPE_STRING_ENUM
Definition: hci_global.h:131
HCI_PACKET_TYPE_ENUM getPacketType()
getPacketType retrieve HCI Packet type (HCI_COMMAND / HCI_TYPE_ACL_DATA / HCI_SCO_DATA / HCI_EVENT) ...
Definition: hci_acl.h:61
void print()
Definition: hci_acl.h:65
Definition: hci_acl.h:38
uint8_t broadcast_flag
Definition: hci_acl.h:42
hci_acl(const std::vector< char > &data)
Definition: hci_acl.h:46
std::vector< uint8_t > acl_data
Definition: hci_acl.h:44
hci_acl hci_acl_t