-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhollong.cpp
More file actions
383 lines (312 loc) · 8.91 KB
/
hollong.cpp
File metadata and controls
383 lines (312 loc) · 8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/**
****************************************************************************************
*
* @file hollong.cpp
*
*
* Copyright (C) ViewTool 2018
*
* $Rev: $
*
****************************************************************************************
*/
#include "common.h"
#include "app_config.h"
#include "hollong.h"
#include "ui_hollong.h"
//#include <QtGui>
#include <QtWidgets>
#include "asGlobalFunc.h"
#include "setcom.h"
#include "vtcom.h"
#include "bledll.h"
#include <stdio.h>
#include "am_aci.h"
extern vtble myBLE;
extern int slaveCounter;
extern struct gap_dev_inq_result_rep inqInf;
extern struct app_env_tag *app_env;
extern struct gap_le_create_conn_req_cmp_evt conn_inf;
extern volatile rx_round_buf rxBuf;
extern cmd_buf cmdBuf;
extern struct app_dev_record *dev_rec;
extern struct gap_read_ver_req_cmp_evt verInf;
extern struct gap_read_bdaddr_req_cmp_evt bdaddrInf;
extern struct gatt_disc_char_rec *char_inf, charInf;
extern struct gatt_svc_rec svc_rec_info;
struct app_env_tag appEnv;
extern volatile int ota_state;
extern volatile int tx_ready_to_send_data;
extern int ota_bulk_mode;
extern volatile int bootloader_ready;
extern volatile int bootLoader_flag;
extern void rxbuf_retrieve_cmd();
extern int rxbuf_to_be_processed();
#ifndef WINDOWS
extern void Sleep(int ms);
#endif
vtool::vtool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::vtool)
{
ui->setupUi(this);
autoUpdateGUITimerID = 0;
autoUpdateGUITimerID = startTimer(50);
QTimer *timer = new QTimer(this);
// set timer for one second (1000ms)
timer->start(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(timeup()));
done_task = -1; // NO task done yet
seconds_tick = 0;
stopScanTimerID = 0;
discServiceTimerID = 0;
discCharsTimerID = 0;
createActions();
createMenus();
createToolBars();
Local = new LocalTab;
Generic = new GenericTab;
Generic->receTreeFromVt(ui->treeWidget);
Generic->receLocalFromVT(Local);
connect(Generic, SIGNAL(userGenericSet(S_GENERIC)),
Local, SLOT(receive_userGenericSet(S_GENERIC)));
connect(Generic, SIGNAL(rx_data_to_display(cmd_buf*)),
Local, SLOT(rx_raw_data_display(cmd_buf*)));
ui->tracestabWidget->addTab(Local, tr("Local Device Traces"));
masterFlags = true;
if (masterFlags == true)
{
ui->settingstabWidget->clear();
ui->settingstabWidget->addTab(Generic, tr("Generic"));
}
treeWidgetHeaderList << tr("Address") << tr("Name") << tr("Address Type") << tr("State") << tr("Role")
<< tr("Authentication") << tr("Encryption") << tr("Version") << tr("Found");
ui->treeWidget->setHeaderLabels(treeWidgetHeaderList);
ui->treeWidget->setColumnWidth(0, 130);
ui->treeWidget->setColumnWidth(1, 50);
ui->treeWidget->setColumnWidth(2, 50);
ui->treeWidget->setColumnWidth(3, 60);
ui->treeWidget->setColumnWidth(4, 65);
ui->treeWidget->setColumnWidth(5, 70);
ui->treeWidget->setColumnWidth(6, 70);
ui->treeWidget->setColumnWidth(7, 60);
ui->treeWidget->setColumnWidth(8, 40);
#pragma comment(lib, "./release/bledll.lib")
#ifdef WINDOWS
QLibrary myLib1("vtble.dll");
if (myLib1.load()) {
}
else {
QMessageBox::warning(this, "Warning",
"vtble.dll loading failed!", QMessageBox::Ok);
return;
}
#endif
connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
this, SLOT(showmasterSelected(QTreeWidgetItem*,int)));
settingCOM();
}
void vtool::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(saveAction);
deviceMenu = menuBar()->addMenu(tr("&Device"));
deviceMenu->addAction(COMAction);
}
void vtool::createActions()
{
saveAction = new QAction(tr("&Save"), this);
saveAction->setIcon(QIcon(":/images/save.png"));
saveAction->setShortcut(QKeySequence::SaveAs);
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveAs()));
COMAction = new QAction(tr("&Set COM"), this);
connect(COMAction, SIGNAL(triggered()), this, SLOT(settingCOM()));
}
void vtool::createToolBars()
{
fileToolBar = addToolBar(tr("&File"));
fileToolBar->addAction(saveAction);
deviceToolBar = addToolBar(tr("&Device"));
}
void vtool::saveAs()
{
QString str = QDate::currentDate().toString("yyyy.MM.dd-") + QTime::currentTime().toString("hh.mm.ss");
QString fileName = QFileDialog::getSaveFileName (this, tr("Save File"), str,
"Text files (*.txt);;Excel files (*.xls);;Any files (*)");
if(fileName.isNull()) {
return;
}
QFile file(fileName);
if(!file.open(QFile::WriteOnly | QFile::Text))
{
QMessageBox::warning (this, tr("save file"),
tr("can not save file %1:\n %2").arg(fileName).arg(file.errorString()));
}
else
{
QTextStream out(&file);
out << Local->logTextEdit->toPlainText();
}
}
bool isLiteral(unsigned char c)
{
if((c == 0x20) || (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) )
{
return true;
}
else
{
return false;
}
}
void vtool::showmasterSelected(QTreeWidgetItem * item, int column)
{
}
int master_device_ready = 0;
extern int com_port_open_success;
extern int com_port_setting_done;
extern QStringList masterInfoLists;
extern int comOpenSucIndex;
int _com, _baudrate;
extern volatile int threadLife;
#ifdef Q_OS_MACOS
QString com;
#endif
void vtool::settingCOM()
{
}
extern QStringList masterInfoLists;
void vtool::receive_bdaddrInf(struct gap_read_bdaddr_req_cmp_evt bdaddrInfo)
{
}
// mode: 0=hex, 1=decimal
int convA2I(const char *string, int mode)
{
int i, j=0, num = 0;
if(string[0] == '\0') /* null string */
return -1;
while(string[j] == ' ')
j++;
if( j== (int)strlen(string)) /* string with only spaces */
return -2;
switch(mode) {
case 0:
for (i=j; i<(int)strlen(string); i++) {
if(string[i] >= '0' && string[i] <= '9') {
num = num*16 + string[i]-'0';
} else if(string[i] >= 'A' && string[i] <= 'F') {
num = num*16 + string[i]-'A'+10;
} else if(string[i] >= 'a' && string[i] <= 'f') {
num = num*16 + string[i]-'a'+10;
} else {
return -1;
}
}
break;
case 1:
for (i=j; i<(int)strlen(string); i++) {
num = num*10 + string[i]-'0';
}
break;
default:
break;
}
return num;
}
#define KEYWORDS_SCAN_RESPONSE "BD Addr:"
#define KEYWORDS_CONNECTION_RESPONSE "BD"
/***
int strcspn(string, control) - search for init substring w/o control chars
Purpose:
returns the index of the first character in string that belongs
to the set of characters specified by control. This is equivalent
to the length of the length of the initial substring of string
composed entirely of characters not in control. Null chars not
considered.
Entry:
char *string - string to search
char *control - set of characters not allowed in init substring
Exit:
returns the index of the first char in string
that is in the set of characters specified by control.
Uses:
Exceptions:
***/
int tStrCSpn(const char *pS, const char *pSS)
{
const char *pStr, *pStrSet;
pStr = pS;
pStrSet = pSS;
unsigned char map[32] = {0};
while(*pStrSet)
{
map[*pStrSet >> 3] |= (1 << (*pStrSet & 7));
pStrSet++;
}
map[0] |= 1;
int count = 0;
while(!(map[*pStr >> 3] & (1 << (*pStr & 7))))
{
count++;
pStr++;
}
return count;
}
static int count_bledev_discover_service = 0;
int vtool::slo_bledev_discover_service(struct gatt_svc_rec *svc)
{
}
/**
****************************************************************************************
*
* @file hollong.cpp
*
* @brief Main functionalities
*
* Copyright (C) ViewTool 2018
*
* $Rev: 1.0$
*
* Change History:
* 12/21/18: Initial release, working on capturing BLE data, see captured data in file: 2018.12.21-14.52.34.txt
*
****************************************************************************************
*/
int vtool::slo_bledev_discover_chars(struct gatt_char_disc *char_rec)
{
}
#define BD_ADDR_FIRST_BYTE_POS 9
#define BD_ADDR_SPAN 3
/*
return retrieved command
*/
#define INPUT_DELAY_TIME 2000
void vtool::rsp_cmd_hci_process(uint8_t type, uint8_t *param, uint16_t param_len)
{
}
void vtool::rsp_cmd_process(uint8_t cmd, uint8_t *param, uint16_t param_len)
{
}
void vtool::receive_rx_raw_data(uint8_t *rxData, int rxSize)
{
}
void vtool::slo_task_done(int task_id)
{
}
void vtool::timer_start(unsigned int *timerID)
{
}
void vtool::timer_end(unsigned int *timerID)
{
}
int vtool::timer_is_up(unsigned int timerID, unsigned int time)
{
return 1;
}
void vtool::timeup()
{
}
vtool::~vtool()
{
delete ui;
}