Commit e5745067 authored by danzu's avatar danzu

first push

parents
#include "bluetooth_queue.h"
BulueQueueSTRUCT BLQ;
void BulueQueue_in_data(BulueQueueSTRUCT *in,unsigned char data)
{
in->DATA[in->in_index++] = data;
}
unsigned char BulueQueue_out_data(BulueQueueSTRUCT *in)
{
if(in->out_index == in->in_index)
{
return 0xFF;
}
else
{
return in->DATA[in->out_index++];
}
}
bool BulueQueueIsEmty(BulueQueueSTRUCT *in)
{
if(in->out_index == in->in_index)
{
return true;
}
else
{
return false;
}
}
bool BulueQueueIsBusy(BulueQueueSTRUCT *in)
{
if((in->in_index+1) == in->out_index)
{
return true;
}
else
{
return false;
}
}
void BulueQueueClear(BulueQueueSTRUCT *in)
{
in->in_index = 0;
in->out_index = 0;
}
#ifndef BLUETOOTH_QUEUE_H
#define BLUETOOTH_QUEUE_H
typedef struct{
unsigned char DATA[65536];
unsigned short in_index;
unsigned short out_index;
}BulueQueueSTRUCT;
void BulueQueue_in_data(BulueQueueSTRUCT *in,unsigned char data);
unsigned char BulueQueue_out_data(BulueQueueSTRUCT *in);
bool BulueQueueIsBusy(BulueQueueSTRUCT *in);
bool BulueQueueIsEmty(BulueQueueSTRUCT *in);
void BulueQueueClear(BulueQueueSTRUCT *in);
extern BulueQueueSTRUCT BLQ;
#endif // BLUETOOTH_QUEUE_H
#include "bluetoothonlinedevice.h"
QMap <QString,BluetoothOnlineDevice* > BluetoothOnlineMan; //通过QString可以查找与之关联的BluetooothOnlineDevice的值
BluetoothOnlineDevice *BON;
bool BluetoothScanDataDeal(QByteArray tem_MAC,QByteArray tem_Name,QString TemNameStatus)
{
bool return_value;
if(BluetoothOnlineMan.contains(tem_MAC.toHex()))
{
//Uupdata the signal value
return_value = false;
}
else
{
BON = new BluetoothOnlineDevice();
BON->MAC = tem_MAC;
BON->Name = tem_Name;
BON->NameStatus =TemNameStatus;
BON->QListIndexLoc = 255;
BluetoothOnlineMan.insert(tem_MAC.toHex(),BON);
return_value =true;
}
return return_value;
}
bool BluetoothSignalUpdata(QByteArray tem_MAC,QByteArray tem_Signal)
{
bool return_value;
if(BluetoothOnlineMan.contains(tem_MAC.toHex()))
{
//Uupdata the signal value
BluetoothOnlineMan[tem_MAC.toHex()]->Singal = tem_Signal;
return_value = true;
}
else
{
return_value = false;
}
return return_value;
}
bool BluetoothBoradNameIsChanged(QByteArray tem_MAC,QByteArray temName)
{
if(BluetoothOnlineMan.contains(tem_MAC.toHex()))
{
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
if(tem.value()->MAC == tem_MAC)
{
if(tem.value()->Name != temName)
{
tem.value()->Name = temName;
return true;
}
else
{
return false;
}
}
}
}
else
{
return false;
}
return false;
}
bool BluetoothIsExist(QByteArray tem_MAC)
{
bool return_value;
if(BluetoothOnlineMan.contains(tem_MAC.toHex()))
{
return_value = true;
}
else
{
return_value = false;
}
return return_value;
}
void BluetoothAddTheQListIndex(QByteArray tem_MAC,int QListIndex)
{
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
if(tem.value()->MAC == tem_MAC)
{
tem.value()->QListIndexLoc = QListIndex;
return;
}
}
}
int BluetoothGetTheQListIndex(QByteArray tem_MAC)
{
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
if(tem.value()->MAC == tem_MAC)
{
return tem.value()->QListIndexLoc;
}
}
return 255;
}
QString BluetoothGetShowString(QByteArray tem_MAC)
{
QString returnstring;
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
if(tem.value()->MAC == tem_MAC)
{
returnstring = tem.value()->NameStatus+tem.value()->Name+" 信号强度:";
if(tem.value()->Singal.toInt(NULL,16) == 0)
{
returnstring += "Unkown";
}
else
{
returnstring +=QString::number(tem.value()->Singal.toInt(NULL,16),10) ;
}
returnstring +=" dbm";
return returnstring;
}
}
return NULL;
}
void BluetoothBoradDataDeal(QByteArray tem_MAC,QByteArray tem_Signal,QByteArray tem_boarddata)
{
if(!BluetoothOnlineMan.contains(tem_MAC.toHex()))
{//
return;
}
else
{
BluetoothOnlineMan[tem_MAC.toHex()]->Singal = tem_Signal;
}
}
QStringList GetBluetoothList()
{
QStringList Strlist;
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
Strlist << BluetoothGetShowString(tem.value()->MAC);
}
return Strlist;
}
void ClearTheBuletoothOnlineDeciveQmap()
{
BluetoothOnlineMan.clear();
}
QByteArray GetBluetoothMAC(int QListIndex)
{
QByteArray returnvalue;
QMap <QString,BluetoothOnlineDevice* >::iterator tem;
for(tem = BluetoothOnlineMan.begin();tem!= BluetoothOnlineMan.end();++tem)
{
if(tem.value()->QListIndexLoc==QListIndex)
{
returnvalue = tem.value()->MAC;
break;
}
}
return returnvalue;
}
#ifndef BLUETOOTHONLINEDEVICE_H
#define BLUETOOTHONLINEDEVICE_H
#include <QByteArray>
#include <QStringList>
#include <QMap>
#include <qDebug>
class BluetoothOnlineDevice
{
public:
QByteArray MAC;
QByteArray Singal;
int SingalInt()
{
bool ok;
Singal.toInt(&ok);
if(ok)
{
return Singal.toInt(&ok);
}
else
{
return 0;
}
}
QByteArray Name;
QString NameStr()
{
return QString(Name);
}
QString NameStatus;
int UUIDNum;
QStringList UUID;
QString BOARDDATA;
int QListIndexLoc;
};
extern QMap <QString,BluetoothOnlineDevice* > BluetoothOnlineMan;
bool BluetoothScanDataDeal(QByteArray tem_MAC,QByteArray tem_Name,QString TemNameStatus);
QString BluetoothGetShowString(QByteArray tem_MAC);
bool BluetoothBoradNameIsChanged(QByteArray tem_MAC,QByteArray temName);
bool BluetoothSignalUpdata(QByteArray tem_MAC,QByteArray tem_Signal);
bool BluetoothIsExist(QByteArray tem_MAC);
void BluetoothBoradDataDeal(QByteArray tem_MAC,QByteArray tem_Signal,QByteArray tem_Name);
void BluetoothAddTheQListIndex(QByteArray tem_MAC,int QListIndex);
QStringList GetBluetoothList();
QByteArray GetBluetoothMAC(int QListIndex);
void ClearTheBuletoothOnlineDeciveQmap();
int BluetoothGetTheQListIndex(QByteArray tem_MAC);
#endif // BLUETOOTHONLINEDEVICE_H
This diff is collapsed.
#ifndef COM_1_H
#define COM_1_H
#include <QMainWindow>
#include "QDebug"
#include "QtSerialPort/QSerialPort"
#include "QtSerialPort/QSerialPortInfo"
#include "QMessageBox"
#include "QTimer"
#include "QByteArray"
#include "bluetooth_queue.h"
#include "bluetoothonlinedevice.h"
#include "QDateTime"
#include "QTimerEvent"
#include "QByteArray"
QT_BEGIN_NAMESPACE
namespace Ui { class com_1; }
QT_END_NAMESPACE
class com_1 : public QMainWindow
{
Q_OBJECT
public:
com_1(QWidget *parent = nullptr);
~com_1();
QSerialPort com_BT;
QSerialPort com_VT;
QTimer BT_port_read_timer;
void SerOpen(int data);
void BT_port_read();
void VT_port_read();
void BluetoothReceiveDataDeal(QByteArray data);
void AtAnslysis(QByteArray str);
QByteArray GetSendAtCommand(QString str);
void BT_port_open_work();
void timerEvent(QTimerEvent *event);
void VT_port_open_work();
private:
Ui::com_1 *ui;
int bluetoothinfoupdata = 0;
private slots:
void SerRefresh();
void on_port_open_clicked();
void on_BuletoothOnlineList_doubleClicked(const QModelIndex &index);
void on_port_refresh_VT_clicked();
void on_port_open_VT_clicked();
};
#endif // COM_1_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>com_1</class>
<widget class="QMainWindow" name="com_1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>733</width>
<height>578</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="windowTitle">
<string>com_1</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>蓝牙串口</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="port_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="port_refresh">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>刷新串口</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="port_open">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>打开串口</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="port_state">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>串口未连接</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="BT_state">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>蓝牙未连接</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>虚拟串口</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>186</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QComboBox" name="port_list_VT">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QPushButton" name="port_refresh_VT">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>刷新串口</string>
</property>
</widget>
<widget class="QPushButton" name="port_open_VT">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>打开串口</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="port_state_VT">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>串口未连接</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>186</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>733</width>
<height>36</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
#include "com_1.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
com_1 w;
w.show();
return a.exec();
}
QT += core gui
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
bluetooth_queue.cpp \
bluetoothonlinedevice.cpp \
main.cpp \
com_1.cpp
HEADERS += \
bluetooth_queue.h \
bluetoothonlinedevice.h \
com_1.h
FORMS += \
com_1.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment