| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093 |
- #include "Bluetooth.h"
- #include "AutoConnect.h"
- #include "RunnableThread.h"
- #include "Multimedia.h"
- #include "UserInterfaceUtility.h"
- #include "carlink.h"
- #include "Audio.h"
- #include "Setting.h"
- #include <QList>
- #include <QString>
- #include <QChar>
- #include <QMap>
- #include <unistd.h>
- #include <stdio.h>
- #include <QTime>
- #include <QTimer>
- #include <QFile>
- #include <iostream>
- #include <sstream>
- #include <iomanip>
- #include <fstream>
- #include <QTextCodec>
- #include "BusinessLogic/Setting.h"
- #include "BusinessLogic/configUtils.h"
- static const QString BTconfig("/data/Blutooth.ini");
- #if 0
- static bool IsNotChinese(QString str)
- {
- QByteArray ba = str.toLatin1();
- const char *ch = ba.data();
- while (*ch) {
- if((*ch >= 'A' && *ch <= 'Z')||(*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9')){
- }else {
- return false;
- }
- ch++;
- }
- return true;
- }
- #endif
- static bool IsChinese(QString str)
- {
- int count = str.count();
- for(int i = 0; i < count; i++){
- QChar ch = str.at(i);
- ushort us = ch.unicode();
- if(us >= 0x4E00 && us <= 0x9FA5){
- }else {
- return false;
- }
- }
- return true;
- }
- bool In(wchar_t start, wchar_t end, wchar_t code)
- {
- if (code >= start && code <= end)
- {
- return true;
- }
- return false;
- }
- char convert(int n)
- {
- if (In(0xB0A1,0xB0C4,n)) return 'a';
- if (In(0XB0C5,0XB2C0,n)) return 'b';
- if (In(0xB2C1,0xB4ED,n)) return 'c';
- if (In(0xB4EE,0xB6E9,n)) return 'd';
- if (In(0xB6EA,0xB7A1,n)) return 'e';
- if (In(0xB7A2,0xB8c0,n)) return 'f';
- if (In(0xB8C1,0xB9FD,n)) return 'g';
- if (In(0xB9FE,0xBBF6,n)) return 'h';
- if (In(0xBBF7,0xBFA5,n)) return 'j';
- if (In(0xBFA6,0xC0AB,n)) return 'k';
- if (In(0xC0AC,0xC2E7,n)) return 'l';
- if (In(0xC2E8,0xC4C2,n)) return 'm';
- if (In(0xC4C3,0xC5B5,n)) return 'n';
- if (In(0xC5B6,0xC5BD,n)) return 'o';
- if (In(0xC5BE,0xC6D9,n)) return 'p';
- if (In(0xC6DA,0xC8BA,n)) return 'q';
- if (In(0xC8BB,0xC8F5,n)) return 'r';
- if (In(0xC8F6,0xCBF0,n)) return 's';
- if (In(0xCBFA,0xCDD9,n)) return 't';
- if (In(0xCDDA,0xCEF3,n)) return 'w';
- if (In(0xCEF4,0xD188,n)) return 'x';
- if (In(0xD1B9,0xD4D0,n)) return 'y';
- if (In(0xD4D1,0xD7F9,n)) return 'z';
- return '\0';
- }
- class BluetoothPrivate
- {
- public:
- explicit BluetoothPrivate(Bluetooth* parent);
- ~BluetoothPrivate();
- void connectAllSlots();
- void cancelSync();
- void syncPhoneBook();
- void syncAllCallLog();
- void syncInComingCallLog();
- void syncOutComingCallLog();
- void syncMissedCallLog();
- void initializeAutoCancelTimer();
- void getBwSerialData(std::string data);
- void getAddrMac();
- QString getBtManufacturer();
- QString getChineseSpell(QString src);
- public:
- std::ifstream readStream;
- private:
- Bluetooth* const q_ptr;
- Q_DECLARE_PUBLIC(Bluetooth)
- QString m_Pincode;
- QString m_LocalDeviceName;
- QString m_RemoteDeviceName;
- QString m_RemoteBtAddress;
- QString m_LocalAddress;
- int m_BluetoothConnectStatus;
- int m_LastBluetoothConnectStatus;
- QTimer* m_AutoCancelTimer;
- BluetoothVoiceMode m_BluetoothVoiceMode;
- BluetoothPairedMode m_BluetoothPairedMode;
- int m_BluetoothPowerStatus;
- int m_BluetoothAutoConnect;
- int m_BluetoothAutoAnswer;
- QString m_LastNumber;
- QList<struct PhoneBookInfo> m_PhoneBookList;
- QList<struct CallLogInfo> m_AllCallList;
- QList<struct RemoteDeviceInfo>m_RemoteDeviceInfoList;
- QMap<QString, QString> m_PairedMap;
- int m_SyncType;
- int m_index;
- int m_HFPCFGBit;
- int m_A2DPStatus;
- int m_BluetoothPlayerStatus;
- int m_BtMicMuteStatus;
- int m_BtFirstEnterStatus;
- int m_LastBtStatus;
- int m_MusicType;
- QString m_BtMusicTitle;
- QString m_BtMusicArtist;
- QString m_BtMusicAlbum;
- QString m_HicarBackLinkMac;
- QString m_HicarBackLinkCmd;
- QString m_LastOnCallingNum;
- };
- Bluetooth::Bluetooth(QObject *parent)
- : QObject(parent)
- , d_ptr(new BluetoothPrivate(this))
- {
- }
- Bluetooth::~Bluetooth()
- {
- if (NULL != d_ptr) {
- delete d_ptr;
- }
- }
- QString Bluetooth::pinCode()
- {
- Q_D(Bluetooth);
- QFile BTcfgFile(BTconfig);
- if(BTcfgFile.exists()){
- QSettings * BTcfgSetFile = new QSettings(BTconfig,QSettings::IniFormat);
- d->m_Pincode = BTcfgSetFile->value("General/PinCode").toString();
- delete BTcfgSetFile;
- qDebug() << __PRETTY_FUNCTION__ << d->m_Pincode;
- }
- return d->m_Pincode;
- }
- QString Bluetooth::localDeviceName()
- {
- Q_D(Bluetooth);
- QSettings * BTcfgSetFile = new QSettings(BTconfig,QSettings::IniFormat);
- d->m_LocalDeviceName = BTcfgSetFile->value("General/DeviceName").toString();
- delete BTcfgSetFile;
- qDebug() << __PRETTY_FUNCTION__ << d->m_LocalDeviceName;
- return d->m_LocalDeviceName;
- }
- QString Bluetooth::remoteDeviceName()
- {
- Q_D(Bluetooth);
- return d->m_RemoteDeviceName;
- }
- int Bluetooth::connectStatus()
- {
- Q_D(Bluetooth);
- return d->m_BluetoothConnectStatus;
- }
- const QList<PhoneBookInfo> &Bluetooth::getRecordList()
- {
- Q_D(Bluetooth);
- return d->m_PhoneBookList;
- }
- QList<struct CallLogInfo>& Bluetooth::getCallLogInfo(){
- Q_D(Bluetooth);
- return d->m_AllCallList;
- }
- const QMap<QString, QString> &Bluetooth::getPairedList()
- {
- Q_D(Bluetooth);
- return d->m_PairedMap;
- }
- void Bluetooth::musicToggle()
- {
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- Q_D(Bluetooth);
- QString type;
- qDebug()<<__PRETTY_FUNCTION__ <<"LINE:"<<__LINE__ <<"m_BluetoothPlayerStatus ="<<d->m_BluetoothPlayerStatus;
- if (Bluetooth::BtMusic_Playing == d->m_BluetoothPlayerStatus) {
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- type = QString("MA");// ABT_MusicPause;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- type = QString("PAUSE");// ABT_MusicPause;
- }
- } else{
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- type = QString("MA");// ABT_MusicPlay;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- type = QString("PLAY");// ABT_MusicPlay;
- }
- }
- QString CMD = type;
- Send_AT_CMD(CMD);
- }
- void Bluetooth::musicPause()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- if(Bluetooth::BtMusic_Playing == d->m_BluetoothPlayerStatus)
- CMD = QString("MA");// ABT_MusicPause;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CMD = QString("PAUSE");// ABT_MusicPause;
- }
- Send_AT_CMD(CMD);
- }
- void Bluetooth::musicStop()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CMD = QString("MC");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CMD = QString("STOP");
- }
- Send_AT_CMD(CMD);
- }
- void Bluetooth::musicPlay()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CMD = QString("MA");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CMD = QString("PLAY");
- }
- Send_AT_CMD(CMD);
- }
- void Bluetooth::musicPrevious()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CMD = QString("ME");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CMD = QString("FORWARD");
- }
- Send_AT_CMD(CMD);
- }
- void Bluetooth::musicNext()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CMD = QString("MD");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CMD = QString("BACKWARD");
- }
- Send_AT_CMD(CMD);
- }
- void Bluetooth::disconnectRemoteDevice()
- {
- Q_D(Bluetooth);
- if (BPS_PowerOn != getPowerStatus()) {
- return;
- }
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("CD");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("DSCA");
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::deleteRemoteDevice(const unsigned short index)
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("CV") + QString::number(index);
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("PLIST=") + QString::number(index);
- }
- Send_AT_CMD(AT_CMD);
- }
- int Bluetooth::getSynchronizeType()
- {
- Q_D(Bluetooth);
- return d->m_SyncType;
- }
- void Bluetooth::cancelSynchronize(BluetoothRecordType type)
- {
- Q_D(Bluetooth);
- if (d->m_SyncType == type) {
- d->cancelSync();
- }
- }
- void Bluetooth::synchronizePhoneBook()
- {
- // g_Radio->setRadioIdle();
- Q_D(Bluetooth);
- d->cancelSync();
- d->m_PhoneBookList.clear();
- d->syncPhoneBook();
- d->initializeAutoCancelTimer();
- d->m_AutoCancelTimer->start();
- }
- void Bluetooth::synchronizeAllCallLog(){
- Q_D(Bluetooth);
- d->cancelSync();
- d->m_AllCallList.clear();
- d->syncInComingCallLog();
- d->initializeAutoCancelTimer();
- d->m_AutoCancelTimer->start();
- }
- void Bluetooth::setPincode(const QString &pincode)
- {
- Q_D(Bluetooth);
- QString PINCODE;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- PINCODE = QString("MN") + pincode;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- PINCODE = QString("PIN=") + pincode;
- }
- Send_AT_CMD(PINCODE);
- d->m_Pincode = pincode;
- emit onPinCodeChange(pincode);
- QFile BTcfgFile(BTconfig);
- if(!BTcfgFile.exists()){
- QSettings *BTcfgSetFile = new QSettings(BTconfig,QSettings::IniFormat);
- BTcfgSetFile->beginGroup("General");
- BTcfgSetFile->setValue("PinCode", pincode);
- BTcfgSetFile->endGroup();
- BTcfgSetFile->sync();
- CHECK_SYSTEM("sync");
- delete BTcfgSetFile;
- }
- }
- void Bluetooth::setLocalDeviceName(const QString &devicename)
- {
- Q_D(Bluetooth);
- QString DEVNAME;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- DEVNAME = QString("MM") + devicename;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- DEVNAME = QString("NAME=") + devicename;
- }
- Send_AT_CMD(DEVNAME);
- d->m_LocalDeviceName = devicename;
- emit onLocalDeviceNameChange(devicename);
- QSettings *BTcfgFile = new QSettings(BTconfig,QSettings::IniFormat);
- BTcfgFile->beginGroup("General");
- BTcfgFile->setValue("DeviceName", devicename);
- BTcfgFile->endGroup();
- BTcfgFile->sync();
- CHECK_SYSTEM("sync");
- delete BTcfgFile;
- }
- void Bluetooth::dialPhone(const QString &phone)
- {
- Q_D(Bluetooth);
- QString CALLPHONE;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CALLPHONE = QString("CW") + phone;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CALLPHONE = QString("HFPDIAL=") + phone;
- }
- Send_AT_CMD(CALLPHONE);
- }
- void Bluetooth::dialNumber(const QString &number)
- {
- Q_D(Bluetooth);
- QString CALLNUMBER;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- CALLNUMBER = QString("CX") + number;
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- CALLNUMBER = QString("HFPDTMF=") + number;
- }
- Send_AT_CMD(CALLNUMBER);
- }
- BluetoothVoiceMode Bluetooth::getVoiceMode()
- {
- Q_D(Bluetooth);
- return d->m_BluetoothVoiceMode;
- }
- void Bluetooth::voiceToggleSwitch()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->m_BluetoothVoiceMode == BVM_VoicePhone){
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- qDebug()<<"++++++++AT_CMD_CN_CP+++++++++++++";
- AT_CMD= QString("CP");//CP切换到车机蓝牙
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD= QString("HFPADTS=2");//CP切换到车机蓝牙
- }
- d->m_BluetoothVoiceMode = BVM_VoiceBluetooth;
- }else {
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- qDebug()<<"++++++++AT_CMD_CN+++++++++++++";
- AT_CMD= QString("CN");//CN音频切换到手机
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD= QString("HFPADTS=1");//音频切换到手机
- }
- d->m_BluetoothVoiceMode = BVM_VoicePhone;
- }
- Send_AT_CMD(AT_CMD);
- onVoiceChange(d->m_BluetoothVoiceMode);
- }
- void Bluetooth::redialLastPhone()//重播电话
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("CH");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("HFPDIAL");
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::pickupPhone()//接听
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("CE");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("HFPANSW");
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::hanupPhone()//挂断
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- qDebug()<<"+++++++hanupPhone_CG+++++++";
- AT_CMD = QString("CG");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("HFPCHUP");
- }
- Send_AT_CMD(AT_CMD);
- g_Audio->releaseAudioSource(AS_BluetoothPhone);
- emit onHangUpPhone();
- }
- void Bluetooth::asynchronousQueryStatus()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("CY");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("HFPSTAT");
- }
- Send_AT_CMD(AT_CMD);
- }
- int Bluetooth::getPowerStatus()//蓝牙开关状态
- {
- Q_D(Bluetooth);
- return d->m_BluetoothPowerStatus;//蓝牙开关状态
- }
- void Bluetooth::powerOn()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("P1");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("BTEN=1");
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::powerOff()
- {
- Q_D(Bluetooth);
- d->cancelSync();
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("P0");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- AT_CMD = QString("BTEN=0");
- }
- Send_AT_CMD(AT_CMD);
- }
- int Bluetooth::getAutoConnectStatus()
- {
- Q_D(Bluetooth);
- return d->m_BluetoothAutoConnect;
- }
- void Bluetooth::autoConnectOn()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("MG");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- d-> m_HFPCFGBit = d->m_HFPCFGBit | 0x01;
- qDebug()<<"+++++[autoConnectOn:d->m_HFPCFGBit]+++++"<< d->m_HFPCFGBit;
- AT_CMD = "HFPCFG=" + QString("%1").arg(d->m_HFPCFGBit);
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::autoConnectOff()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("MH");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- d->m_HFPCFGBit = d->m_HFPCFGBit & 0x0E;
- qDebug()<<"+++++[autoConnectOff:d->m_HFPCFGBit]+++++"<<d->m_HFPCFGBit;
- AT_CMD = "HFPCFG=" + QString("%1").arg(d->m_HFPCFGBit);
- }
- Send_AT_CMD(AT_CMD);
- }
- int Bluetooth::getAutoAnswer()
- {
- Q_D(Bluetooth);
- return d->m_BluetoothAutoAnswer;
- }
- void Bluetooth::autoAnswerOn()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- AT_CMD = QString("MP");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- d->m_HFPCFGBit = d->m_HFPCFGBit | 0x02;
- qDebug()<<"+++++[autoAnswerOn:d->m_HFPCFGBit]+++++"<<d->m_HFPCFGBit;
- AT_CMD = "HFPCFG=" + QString("%1").arg(d->m_HFPCFGBit);
- }
- Send_AT_CMD(AT_CMD);
- }
- void Bluetooth::autoAnswerOff()
- {
- Q_D(Bluetooth);
- QString AT_CMD;
- if(d->getBtManufacturer() == "s")//速鼎蓝牙
- {
- qDebug()<<"++++++++autoAnswerOff_S+++++++++++";
- AT_CMD = QString("MQ");
- }
- else//飞易通蓝牙和顾凯蓝牙
- {
- qDebug()<<"++++++++autoAnswerOff_NS+++++++++++";
- d->m_HFPCFGBit = d->m_HFPCFGBit & 0x0D;
- qDebug()<<"+++++[autoAnswerOff:d->m_HFPCFGBit]+++++"<<d->m_HFPCFGBit;
- AT_CMD = "HFPCFG=" + QString("%1").arg(d->m_HFPCFGBit);
- }
- Send_AT_CMD(AT_CMD);
- }
- int Bluetooth::getBTMusicStatus()
- {
- Q_D(Bluetooth);
- return d->m_BluetoothPlayerStatus;
- }
- static void* RevBtCmdTask(void *parent)
- {
- BluetoothPrivate *pThis = (BluetoothPrivate *)parent;
- std::string readData;
- printf("[Bluetooth] RevBtCmdTask Create\n");
- while (1)
- {
- readData.clear();
- if(std::getline(pThis->readStream, readData))
- {
- if(readData.size() <= 0)
- {
- usleep(50*1000);
- }
- else
- {
- pThis->getBwSerialData(readData);
- }
- }
- }
- return NULL;
- }
- int Bluetooth::Blutooth_startThread()
- {
- Q_D(Bluetooth);
- pthread_t mThread;
- int ret = -1;
- QString btManufacturer = d->getBtManufacturer();
- std::string filename;
- if(btManufacturer == "s")
- {
- filename = string("/dev/goc_serial");
- }
- else{
- filename = string("/dev/bw_serial");
- }
- if (access(filename.data(), F_OK) == 0)
- {
- d->readStream.open(filename);
- printf("[Bluetooth] open %s success.\n", filename.c_str());
- }
- ret = pthread_create(&mThread, NULL, RevBtCmdTask, d);
- if(ret != 0)
- {
- printf("[Bluetooth] pthread_create failed.\n");
- ret = -1;
- }
- return ret;
- }
- void Bluetooth::Send_AT_CMD(QString AT_STR)
- {
- qDebug()<<__PRETTY_FUNCTION__ <<"LINE :"<<__LINE__;
- Q_D(Bluetooth);
- QString AT_CMD;
- QString btManufacturer = d->getBtManufacturer();
- QFile gocsdk_dev;
- if(btManufacturer == "s")
- {
- AT_CMD = QString("AT#") + AT_STR;
- AT_CMD.append("\r\n");
- gocsdk_dev.setFileName(QString("/dev/goc_serial"));
- }
- else{
- AT_CMD = QString("AT+") + AT_STR;
- AT_CMD.append("\r\n");
- gocsdk_dev.setFileName(QString("/dev/bw_serial"));
- //gocsdk_dev.setFileName(QString("/dev/goc_serial"));
- }
- qDebug()<<__PRETTY_FUNCTION__ <<__LINE__ <<"ATCMD:"<<AT_CMD.toLocal8Bit();
- if(gocsdk_dev.exists()){
- if(gocsdk_dev.open(QIODevice::ReadWrite)){
- gocsdk_dev.write(AT_CMD.toLocal8Bit());
- gocsdk_dev.close();
- }else {
- qDebug("/dev/bt_serial is open failed");
- }
- }else {
- qDebug("/dev/bt_serial is not exists");
- }
- qDebug()<<__PRETTY_FUNCTION__ <<"LINE :"<<__LINE__;
- }
- void Bluetooth::connectRemoteDevice(const unsigned short index)
- {
- Q_D(Bluetooth);
- qDebug()<<"+++++++++connectRemoteDevice+++++++++++="<<d->m_RemoteDeviceInfoList.size();
- if(d->m_RemoteDeviceInfoList.size() > index)
- {
- if(d->m_RemoteDeviceInfoList.at(index).macAddress != d->m_RemoteBtAddress){
- if(d->m_BluetoothConnectStatus >=3)
- {
- disconnectRemoteDevice();
- }
- if(d->getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("CC") + d->m_RemoteDeviceInfoList.at(index).macAddress;
- Send_AT_CMD(AT_CMD);
- }
- else{
- QString AT_CMD = QString("HFPCONN=") + d->m_RemoteDeviceInfoList.at(index).macAddress;
- Send_AT_CMD(AT_CMD);
- }
- }
- }
- qDebug()<<"+++++++++>m_PairedMap.size()+++++++++++="<<d->m_PairedMap.size();
- if(d->m_PairedMap.size()>0)
- {
- QMap<QString, QString>::iterator itor = d->m_PairedMap.begin();
- bool _CanPaired(true);
- int count = 0;
- QString _RemoteAddr;
- while(itor != d->m_PairedMap.end())
- {
- if(count == index)
- {
- _RemoteAddr = itor.key();
- }
- if(itor.key() == d->m_RemoteBtAddress)
- {
- _CanPaired = false;
- break;
- }
- count++;
- itor++;
- }
- qDebug()<<"+++++++count++++++++"<<count;
- if(_CanPaired == true)
- {
- if(d->m_BluetoothConnectStatus >=3)
- {
- disconnectRemoteDevice();
- }
- if(d->getBtManufacturer() =="s")
- {
- QString AT_CMD = QString("CC") + _RemoteAddr;
- Send_AT_CMD(AT_CMD);
- }
- else{
- QString AT_CMD = QString("HFPCONN=") + _RemoteAddr;
- Send_AT_CMD(AT_CMD);
- }
- }
- }
- }
- void Bluetooth::onHolderChange(const AudioSource oldHolder, const AudioSource newHolder)
- {
- switch (newHolder) {
- case AS_Aux: {
- if (AS_BluetoothMusic == oldHolder) {
- musicPause();
- }
- break;
- }
- case AS_BluetoothMusic: {
- qDebug() << __PRETTY_FUNCTION__ << __LINE__;
- break;
- }
- default:
- break;
- }
- }
- void Bluetooth::onTimeout()
- {
- qDebug() << __PRETTY_FUNCTION__ << __LINE__;
- QTimer* ptr = static_cast<QTimer*>(sender());
- Q_D(Bluetooth);
- if (ptr == d->m_AutoCancelTimer) {
- d->cancelSync();
- qDebug() << __PRETTY_FUNCTION__ << __LINE__;
- }
- }
- /**********************************************************
- * source_str: 源字符串
- * n: 默认为2,每间隔两个字符串添加ch
- * ch:默认为空格
- * eg:Get_MAC_addr(out_str, 2 , ":");得到MAC地址
- **********************************************************/
- QString Get_MAC_addr(QString source_str, int n=2,const QString &ch=" ")
- {
- int size= source_str.size();
- int lenth = size/n;
- QString target_str = source_str;
- int str_lenth = ch.size();
- int i = 0;
- for(i = 0; i < lenth ; i++){
- target_str = target_str.insert((i + 1) * n + (i * str_lenth), ch);
- }
- return target_str.left(target_str.size() -1);
- }
- void Bluetooth::readHFPCFGValue()
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() != "s")
- {
- QString CMD = "HFPCFG";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "MF";
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::ScanNearByRemoteDevice(){
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "SD";
- Send_AT_CMD(CMD);
- d->m_RemoteDeviceInfoList.clear();
- }
- else{
- QString CMD = "SCAN=1";
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::StopScanNearByRemoteDevice(){
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "ST";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "SCAN=0";
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::QueryPairedList()
- {
- qDebug()<<"+++[Bluetooth::QueryPairedList]+++";
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "MX";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "PLIST";
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::BtMusicPlyaStatus(int status)
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "VI";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "PLAYSTAT=" + QString("%1").arg(status);
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::BtMusicInfo(int param)
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "MK";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "AVRCPCFG=" + QString("%1").arg(param);
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::BtMicMuteChanged(int mute){
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- qDebug()<<"++++++++BtMicMuteChanged_CM++++++++++";
- QString CMD = "CM";//打开关闭麦克风
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "MICMUTE=" + QString("%1").arg(mute);
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::disableBtMusic()
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "VA";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "A2DPDISC";
- Send_AT_CMD(CMD);
- }
- }
- void Bluetooth::connectBtMusic()
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "VB";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "A2DPCONN";
- Send_AT_CMD(CMD);
- }
- }
- int Bluetooth::getBtMicMuteStatus()
- {
- Q_D(Bluetooth);
- return d->m_BtMicMuteStatus;
- }
- void Bluetooth::reConnectLastDevice()
- {
- Q_D(Bluetooth);
- if(d->getBtManufacturer() == "s")
- {
- QString CMD = "MI";
- Send_AT_CMD(CMD);
- }
- else{
- QString CMD = "HFPCONN";
- Send_AT_CMD(CMD);
- }
- }
- QString Bluetooth::getRemoteBtAddress(){
- Q_D(Bluetooth);
- return d->m_RemoteBtAddress;
- }
- void Bluetooth::setMusicType(int musicType)
- {
- Q_D(Bluetooth);
- d->m_MusicType = musicType;
- }
- char convertCharToHex(char ch)
- {
- if((ch >= '0') && (ch <= '9'))
- return ch-0x30;
- else if((ch >= 'A') && (ch <= 'F'))
- return ch-'A'+10;
- else if((ch >= 'a') && (ch <= 'f'))
- return ch-'a'+10;
- else return (-1);
- }
- BluetoothPrivate::BluetoothPrivate(Bluetooth *parent)
- : q_ptr(parent)
- {
- m_BluetoothConnectStatus = 0;
- m_LastBluetoothConnectStatus = 0;
- m_BluetoothPlayerStatus = -1;
- m_AutoCancelTimer = NULL;
- m_BluetoothVoiceMode = BVM_VoiceBluetooth;
- m_BluetoothPairedMode = BPM_Undefine;
- m_BluetoothPowerStatus = undefined;
- m_BluetoothAutoConnect = BAC_Undefine;
- m_BluetoothAutoAnswer = BAA_Undefine;
- m_SyncType = BRT_Undefine;
- m_index = 0;
- m_HFPCFGBit = 0;
- m_BtMicMuteStatus = 0;
- m_BtMusicTitle = "";
- m_BtMusicArtist= "";
- m_BtMusicAlbum = "";
- m_BtFirstEnterStatus = true;
- m_LastBtStatus = 0;
- m_MusicType = 0;
- connectAllSlots();
- }
- BluetoothPrivate::~BluetoothPrivate()
- {
- }
- void BluetoothPrivate::connectAllSlots()
- {
- Q_Q(Bluetooth);
- connectSignalAndSlotByNamesake(g_Audio, q, ARKRECEIVER(onHolderChange(const int, const int)));
- }
- void BluetoothPrivate::cancelSync()
- {
- qDebug() << __PRETTY_FUNCTION__ << __LINE__;
- if (BRT_Undefine != m_SyncType) {
- Q_Q(Bluetooth);
- if(getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("PS");//停止下载
- q->Send_AT_CMD(AT_CMD);
- }
- else{
- QString AT_CMD = QString("PBABORT");//停止下载
- q->Send_AT_CMD(AT_CMD);
- }
- if(m_SyncType == BRT_PhoneBook)
- {
- emit q->onSyncPhoneBook();
- }
- else if(m_SyncType != BRT_PhoneBook && m_SyncType != BRT_Undefine){
- emit q->onSyncAllCallLog();
- }
- m_SyncType = BRT_Undefine;
- if (NULL != m_AutoCancelTimer) {
- m_AutoCancelTimer->stop();
- }
- }
- }
- void BluetoothPrivate::getAddrMac()
- {
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- if(getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("DF");
- q->Send_AT_CMD(AT_CMD);
- }
- else
- {
- QString AT_CMD = QString("ADDR");
- q->Send_AT_CMD(AT_CMD);
- }
- }
- void BluetoothPrivate::syncPhoneBook()
- {
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- m_SyncType = BRT_PhoneBook;
- if(getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("PB");//同步电话本
- q->Send_AT_CMD(AT_CMD);
- }
- else
- {
- QString AT_CMD = QString("PBDOWN=1");//同步电话本
- q->Send_AT_CMD(AT_CMD);
- }
- }
- void BluetoothPrivate::syncAllCallLog(){
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- m_SyncType = BRT_AllCall;
- if(getBtManufacturer() != "s")
- {
- QString AT_CMD = QString("PBDOWN=5");//同步电话本
- q->Send_AT_CMD(AT_CMD);
- }
- }
- void BluetoothPrivate::syncInComingCallLog(){
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- m_SyncType = BRT_Incoming;
- if(getBtManufacturer() == "s")
- {
- qDebug()<<"+++++++syncInComingCallLog_PI+++++++++";
- QString AT_CMD = QString("PI");//已接电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- else
- {
- QString AT_CMD = QString("PBDOWN=2");//已接电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- }
- void BluetoothPrivate::syncOutComingCallLog(){
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- cancelSync();
- m_SyncType = BRT_Outgoing;
- if(getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("PH");//已拨电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- else
- {
- QString AT_CMD = QString("PBDOWN=3");//已拨电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- initializeAutoCancelTimer();
- m_AutoCancelTimer->start();
- }
- void BluetoothPrivate::syncMissedCallLog(){
- qDebug() << __PRETTY_FUNCTION__;
- Q_Q(Bluetooth);
- cancelSync();
- m_SyncType = BRT_Missed;
- if(getBtManufacturer() == "s")
- {
- QString AT_CMD = QString("PJ");//未接电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- else
- {
- QString AT_CMD = QString("PBDOWN=4");//未接电话同步
- q->Send_AT_CMD(AT_CMD);
- }
- initializeAutoCancelTimer();
- m_AutoCancelTimer->start();
- }
- void BluetoothPrivate::initializeAutoCancelTimer()
- {
- if (NULL == m_AutoCancelTimer) {
- Q_Q(Bluetooth);
- m_AutoCancelTimer = new QTimer(q);
- m_AutoCancelTimer->setInterval(10 * 1000);
- m_AutoCancelTimer->setSingleShot(true);
- QObject::connect(m_AutoCancelTimer, ARKSENDER(timeout()),
- q, ARKRECEIVER(onTimeout()));
- }
- }
- void BluetoothPrivate::getBwSerialData(std::string data)
- {
- Q_Q(Bluetooth);
- if(getBtManufacturer() == "s")
- {
- q->SudingBlutoothHandle(QString::fromStdString(data));
- }
- else{
- q->BlutoothHandle(QString::fromStdString(data));
- }
- }
- QString BluetoothPrivate::getChineseSpell(QString src)
- {
- QTextCodec *codec4gbk = QTextCodec::codecForName("GBK"); //获取qt提供的gbk的解码器
- QByteArray buf = codec4gbk->fromUnicode(src); //qt用的unicode,转成gbk
- int size = buf.size();
- quint16 *array = new quint16[size+1];
- QString alphbats;
- for( int i = 0, j = 0; i < buf.size(); i++, j++ )
- {
- if( (quint8)buf[i] < 0x80 ) //gbk的第一个字节都大于0x81,所以小于0x80的都是符号,字母,数字etc
- continue;
- array[j] = (((quint8)buf[i]) << 8) + (quint8)buf[i+1]; //计算gbk编码
- i++;
- alphbats.append( convert( array[j] ) ); //相当于查表,用gbk编码得到首拼音字母
- }
- delete [] array;
- return alphbats;
- }
- QList<struct RemoteDeviceInfo> Bluetooth::getRemoteDeviceInfoList(){
- Q_D(Bluetooth);
- return d->m_RemoteDeviceInfoList;
- }
- void Bluetooth::sendHicarDataToblueware(QString atCmd,QString Data)
- {
- Q_D(Bluetooth);
- qDebug()<<__PRETTY_FUNCTION__ <<"LINE :"<<__LINE__;
- QString btManufacturer = d->getBtManufacturer();
- QFile gocsdk_dev;
- QString AT_CMD;
- if(btManufacturer == "s")
- {
- AT_CMD = QString("AT#") + atCmd + Data;
- AT_CMD.append("\r\n");
- gocsdk_dev.setFileName(QString("/dev/goc_serial"));
- }
- else{
- AT_CMD = QString("AT#") + atCmd + QString("=")+Data;
- AT_CMD.append("\r\n");
- qDebug()<<"++++++AT_CMD++++++"<<AT_CMD;
- gocsdk_dev.setFileName(QString("/dev/bw_serial"));
- }
- qDebug()<<__PRETTY_FUNCTION__ <<__LINE__ <<"ATCMD:"<<AT_CMD.toLocal8Bit();
- if(gocsdk_dev.exists()){
- if(gocsdk_dev.open(QIODevice::ReadWrite)){
- gocsdk_dev.write(AT_CMD.toLocal8Bit());
- gocsdk_dev.close();
- }else {
- qDebug("/dev/bt_serial is open failed");
- }
- }else {
- qDebug("/dev/bt_serial is not exists");
- }
- qDebug()<<__PRETTY_FUNCTION__ <<"LINE :"<<__LINE__;
- }
- QString Bluetooth::getLocalMacAddress(){
- Q_D(Bluetooth);
- return d->m_LocalAddress;
- }
- QString Bluetooth::getHicarBackLinkMac(){
- Q_D(Bluetooth);
- return d->m_HicarBackLinkMac;
- }
- QString Bluetooth::getHicarBackLinkCmd(){
- Q_D(Bluetooth);
- return d->m_HicarBackLinkCmd;
- }
- void Bluetooth::BlutoothHandle(QString data)
- {
- Q_D(Bluetooth);
- //qDebug()<<__PRETTY_FUNCTION__<<__LINE__<<"readData:"<<data;
- //蓝牙开关状态
- if(data.contains("DEVSTAT"))
- {
- int ofIndex = data.indexOf('=');
- QString powerStatusStr = data.mid(ofIndex+1);
- powerStatusStr = powerStatusStr.left(powerStatusStr.size()-1);
- d->m_BluetoothPowerStatus = powerStatusStr.toInt() & 0x01;
- emit onPowerChange(d->m_BluetoothPowerStatus);
- if(d->m_BluetoothPowerStatus > 0){
- d->getAddrMac();
- setPincode(QString("0000"));
- }
- qDebug()<<"===[Bluetooth::BlutoothHandle:m_BluetoothPowerStatus000]====="<<d->m_BluetoothPowerStatus;
- }
- //自动连接和自动接听状态
- else if(data.contains("HFPCFG"))
- {
- int ofIndex = data.indexOf('=');
- QString HFPCFGStr = data.mid(ofIndex+1);
- HFPCFGStr = HFPCFGStr.left(HFPCFGStr.size()-1);
- d->m_HFPCFGBit = HFPCFGStr.toInt();
- d->m_BluetoothAutoConnect = HFPCFGStr.toInt() & 0x01;
- qDebug()<<"++++++d->m_BluetoothAutoConnect++++++"<<d->m_BluetoothAutoConnect;
- emit onAutoConnectChange(d->m_BluetoothAutoConnect);
- if((HFPCFGStr.toInt() & 0x02) == 0x02)
- {
- d->m_BluetoothAutoAnswer = 0x01;
- }
- else
- {
- d->m_BluetoothAutoAnswer = 0;
- }
- qDebug()<<"++++++d->m_BluetoothAutoAnswer++++++"<<d->m_BluetoothAutoAnswer;
- emit onAutoAnswerChange(d->m_BluetoothAutoAnswer);
- }
- //扫描远程设别的信息
- else if(data.contains("SCAN"))
- {
- int ofIndex = data.indexOf('=');
- QString scanStr = data.mid(ofIndex+1);
- //E\r
- QStringList scanStrList;
- scanStrList.clear();
- RemoteDeviceInfo _RemoteDeviceInfo;
- if(scanStr.left(2)!="E\r")
- {
- scanStrList = scanStr.split("�");
- if(QString(scanStrList.at(0)).toInt() == 1)
- {
- d->m_RemoteDeviceInfoList.clear();
- }
- for(int i= 0;i< scanStrList.size();i++)
- {
- switch (i) {
- case 0:
- _RemoteDeviceInfo.index = QString(scanStrList.at(0)).toInt();
- break;
- case 1:
- _RemoteDeviceInfo.rssi = QString(scanStrList.at(1)).toInt();
- break;
- case 2:
- _RemoteDeviceInfo.deviceType = QString(scanStrList.at(2)).toInt();
- break;
- case 3:
- _RemoteDeviceInfo.macAddress = QString(scanStrList.at(3));
- break;
- case 4:
- _RemoteDeviceInfo.name = QString(scanStrList.at(4));
- break;
- case 5:
- _RemoteDeviceInfo.deviceClass = QString(scanStrList.at(5)).left(QString(scanStrList.at(5)).size()-1);
- break;
- default:
- break;
- }
- }
- d->m_RemoteDeviceInfoList.append(_RemoteDeviceInfo);
- }
- else{
- d->m_PairedMap.clear();
- d->m_BtFirstEnterStatus = false;
- emit onScanFinish();
- }
- }
- //配对状态
- else if(data.contains("HFPSTAT")){
- int ofIndex = data.indexOf('=');
- QString btConnectStatusStr = data.mid(ofIndex+1);
- d->m_BluetoothConnectStatus= btConnectStatusStr.left(1).toInt();
- QString _onCallingNumber;
- if(d->m_BluetoothConnectStatus == 6)
- {
- QStringList _onCallingList = btConnectStatusStr.split(",");
- if(_onCallingList.size() > 1)
- {
- _onCallingNumber = QString(_onCallingList.at(1)).left(QString(_onCallingList.at(1)).size()-1);
- d->m_LastOnCallingNum = _onCallingNumber;
- }
- }
- qDebug()<<"++++++++++++d->m_BluetoothConnectStatus++++++++++++"<<d->m_BluetoothConnectStatus;
- qDebug()<<"++++++++++++_onCallingNumber++++++++++++"<<_onCallingNumber;
- qDebug()<<"++++++++++++d->m_LastBluetoothConnectStatus++++++++++++"<<d->m_LastBluetoothConnectStatus;
- qDebug()<<"++++++++++++d->m_LastOnCallingNum++++++++++++"<<d->m_LastOnCallingNum;
- qDebug()<<"++++++++++++d->m_LastOnCallingNum.size++++++++++++"<<d->m_LastOnCallingNum.size();
- if(d->m_BluetoothConnectStatus != d->m_LastBluetoothConnectStatus)
- {
- if(_onCallingNumber.size() == 0 || ( _onCallingNumber.size() != 0 && _onCallingNumber != QString("000000")))
- {
- emit onConnectStatusChange(d->m_BluetoothConnectStatus);
- }
- if(d->m_LastBluetoothConnectStatus >= 4 && d->m_BluetoothConnectStatus < 4)
- {
- if(d->m_LastBluetoothConnectStatus != Bluetooth::BCS_Talking || d->m_LastOnCallingNum != QString("000000"))
- {
- qDebug()<<"++++++0000####xxx++++++";
- g_Audio->releaseAudioSource(AS_BluetoothPhone);
- }
- }
- }
- d->m_LastBluetoothConnectStatus = d->m_BluetoothConnectStatus;
- if(d->m_LastBluetoothConnectStatus != Bluetooth::BCS_Talking)
- {
- d->m_LastOnCallingNum.clear();
- }
- if(d->m_BluetoothConnectStatus < 3){
- if(d->m_LastBtStatus >= 3)
- d->m_BtFirstEnterStatus = true;
- d->m_RemoteBtAddress.clear();
- d->m_RemoteDeviceName.clear();
- }
- d->m_LastBtStatus = d->m_BluetoothConnectStatus;
- qDebug()<<"+++[Bluetooth::BlutoothHandle:BluetoothConnectStatus]+++"<<d->m_BluetoothConnectStatus;
- //电话接入
- if(d->m_BluetoothConnectStatus == Bluetooth::BCS_Incoming){
- // if(g_Link->getLinkConnectStatus() != 0 && g_Link->getLinkType() == Carlife && g_Setting->getCarlifeTelephoneStatus() == 0)
- // {
- // g_Link->requestKey(KEY_MUSIC_PAUSE);
- // g_Link->requestLink(g_Link->getLinkType(), g_Link->getLinkMode(), DBUS_REQUEST_BACKGROUND);
- // }
- // QStringList _IncomingList = btConnectStatusStr.split(",");
- // QString IncomingNumber;
- // if(_IncomingList.size() > 1)
- // {
- // IncomingNumber = QString(_IncomingList.at(1)).left(QString(_IncomingList.at(1)).size()-1);
- // }
- // emit onDialInfo(d->m_BluetoothConnectStatus,IncomingNumber);
- // g_Audio->requestAudioSource(AS_BluetoothPhone);
- }//正在接听中
- else if(d->m_BluetoothConnectStatus == Bluetooth::BCS_Talking && _onCallingNumber != "000000"){
- qDebug()<<"------_onCallingNumber-----"<<_onCallingNumber;
- emit onDialInfo(d->m_BluetoothConnectStatus,_onCallingNumber);
- g_Audio->requestAudioSource(AS_BluetoothPhone);
- }//电话拨出
- else if(d->m_BluetoothConnectStatus == Bluetooth::BCS_Outgoing){
- QStringList _OutComingList = btConnectStatusStr.split(",");
- QString _OutComingNumber;
- if(_OutComingList.size() > 1)
- {
- _OutComingNumber = QString(_OutComingList.at(1)).left(QString(_OutComingList.at(1)).size()-1);
- }
- g_Audio->requestAudioSource(AS_BluetoothPhone);
- emit onDialInfo(d->m_BluetoothConnectStatus,_OutComingNumber);
- }
- }
- //配对过的链表
- else if(data.contains("PLIST")){
- if(!d->m_BtFirstEnterStatus){
- return;
- }
- int ofIndex = data.indexOf('=');
- QString pairedListStr = data.mid(ofIndex+1);
- QStringList pairedList;
- if(pairedListStr.left(2)!="E\r"){
- pairedList = pairedListStr.split("�");
- QString pairedAddr = QString(pairedList.at(2));
- QString pairedName = QString(pairedList.at(3)).left(QString(pairedList.at(3)).size()-1);
- d->m_PairedMap.insert(pairedAddr,pairedName);
- }
- else
- {
- qDebug()<<"=======onGetPairedListFinish======";
- emit onGetPairedListFinish();
- }
- }
- //配对成功的远程设备MAC地址和名称
- else if(data.contains("HFPDEV")){
- int ofIndex = data.indexOf('=');
- QString pairedConnectStr = data.mid(ofIndex+1);
- QStringList pairedConnectList;
- pairedConnectList = pairedConnectStr.split("�");
- d->m_RemoteBtAddress = QString(pairedConnectList.at(0));
- d->m_RemoteDeviceName = QString(pairedConnectList.at(1)).left(QString(pairedConnectList.at(1)).size()-1);
- qDebug()<<"+++[Bluetooth::BlutoothHandle:m_RemoteBtAddress]+++"<<__LINE__ <<d->m_RemoteBtAddress;
- qDebug()<<"+++[Bluetooth::BlutoothHandle:m_RemoteDeviceName]+++"<<__LINE__ <<d->m_RemoteDeviceName;
- onRemoteDeviceNameChange(d->m_RemoteDeviceName);
- }
- //蓝牙音乐Play状态
- else if(data.contains("PLAYSTAT")){
- int ofIndex = data.indexOf('=');
- int btMusicPlayStatus = QString(data.mid(ofIndex+1)).left(QString(data.mid(ofIndex+1)).size()-1).toInt();
- qDebug()<<"++++++++Bluetooth::BtMusic_Playing+++++++++" << btMusicPlayStatus;
- if(btMusicPlayStatus == Bluetooth::BtMusic_Playing)
- {
- qDebug()<<"++++++++Bluetooth::BtMusic_Playing0000+++++++++";
- g_Audio->requestAudioSource(AS_BluetoothMusic);
- int param = 35;
- BtMusicInfo(param);
- }
- else
- {
- if(d->m_BluetoothPlayerStatus == Bluetooth::BtMusic_Playing)
- {
- if(d->m_MusicType == 1 && btMusicPlayStatus == BtMusic_Stopped)
- {
- qDebug()<<"+++++++++++holderChange+++++++++++";
- g_Audio->requestAudioSource(AS_Music);
- }
- }
- }
- d->m_BluetoothPlayerStatus = btMusicPlayStatus;
- emit onMusicStatusChange(d->m_BtMusicTitle,d->m_BluetoothPlayerStatus);
- }
- else if(data.contains("TRACKINFO")){
- int ofIndex = data.indexOf('=');
- QString btMusicID3InfoStr = data.mid(ofIndex+1);
- QStringList btMusicID3InfoList;
- btMusicID3InfoList = btMusicID3InfoStr.split("�");
- qDebug()<<"++++++++btMusicID3InfoList000++++++"<<btMusicID3InfoList.size();
- if(btMusicID3InfoList.size() < 3){
- return;
- }
- QString _Title_Artist = QString(btMusicID3InfoList.at(1));
- QStringList _Title_ArtistList = _Title_Artist.split("-");
- qDebug()<<"++++++++_Title_Artist000++++++"<<_Title_Artist;
- qDebug()<<"++++++++_Title_ArtistList.size()0000++++++"<<_Title_ArtistList.size();
- if(_Title_ArtistList.size() == 1)
- {
- _Title_ArtistList = _Title_Artist.split(" — ");
- }
- if(_Title_ArtistList.size() >= 2)
- {
- QString _TitleStr = QString(_Title_ArtistList.at(1));
- QString _ArtistStr = QString(_Title_ArtistList.at(0));
- QString _AlbumStr = QString(btMusicID3InfoList.at(2)).left(QString(btMusicID3InfoList.at(2)).size()-1);
- d->m_BtMusicTitle = _TitleStr;
- d->m_BtMusicArtist= _ArtistStr;
- d->m_BtMusicAlbum = _AlbumStr;
- qDebug()<<"++++++++_TitleStr111++++++"<<_TitleStr;
- qDebug()<<"++++++++_ArtistStr111++++++"<<_ArtistStr;
- qDebug()<<"++++++++_AlbumStr+++++"<<_AlbumStr;
- emit onBtMusicID3InfoChange(_TitleStr,_ArtistStr,_AlbumStr);
- }
- else
- {
- if(btMusicID3InfoList.size() >= 2)
- {
- QString _TitleStr = QString(btMusicID3InfoList.at(0));
- QString _ArtistStr = QString(btMusicID3InfoList.at(1));
- QString _AlbumStr ="";
- qDebug()<<"++++++++_TitleStr222++++++"<<_TitleStr;
- qDebug()<<"++++++++_ArtistStr22++++++"<<_ArtistStr;
- emit onBtMusicID3InfoChange(_TitleStr,_ArtistStr,_AlbumStr);
- }
- }
- qDebug()<<"--------TRACKINFO----END-------";
- }
- else if(data.contains("TRACKSTAT")){
- int ofIndex = data.indexOf('=');
- QString btMusicTimeInfoStr = data.mid(ofIndex+1);
- QStringList btMusicTimeInfoList;
- btMusicTimeInfoList = btMusicTimeInfoStr.split(",");
- int _ElapsedTime = QString(btMusicTimeInfoList.at(1)).toInt();
- int _EndTime = QString(btMusicTimeInfoList.at(2)).toInt();
- // qDebug()<<"+++++++++++TRACKSTAT++++++++++";
- onBtMusicElapsedInfo(_ElapsedTime,_EndTime);
- }
- else if(data.contains("PBDATA")){
- int ofIndex = data.indexOf('=');
- QString _RecordStr = data.mid(ofIndex+1);
- if(_RecordStr.left(1) != "E")
- {
- if(_RecordStr.left(1) == "1")
- {
- QStringList _PhoneBookList = _RecordStr.split("�");
- if(_PhoneBookList.size() < 3){
- return;
- }
- struct PhoneBookInfo _PhoneBookStr;
- _PhoneBookStr.name = QString(_PhoneBookList.at(1));
- _PhoneBookStr.phone = QString(_PhoneBookList.at(2)).left(QString(_PhoneBookList.at(2)).size()-1);
- if(QString(_PhoneBookStr.name) <= 0)
- {
- _PhoneBookStr.name = _PhoneBookStr.phone;
- }
- QString character;
- if(IsChinese(_PhoneBookStr.name.left(1))){
- character = d->getChineseSpell(QString(_PhoneBookStr.name.left(1)));
- }
- else{
- character = _PhoneBookStr.name.left(1);
- }
- if(character.size() >= 1)
- _PhoneBookStr.head = character.left(1);
- d->m_PhoneBookList.append(_PhoneBookStr);
- }
- else{
- QStringList _AllCallList = _RecordStr.split("�");
- if(_AllCallList.size() < 4){
- return;
- }
- struct CallLogInfo _AllCallStr;
- _AllCallStr.callType = QString(_AllCallList.at(0)).toInt();
- _AllCallStr.name = QString(_AllCallList.at(1));
- _AllCallStr.phoneNumber = QString(_AllCallList.at(2));
- if(_AllCallStr.name.size()==0)
- {
- _AllCallStr.name = _AllCallStr.phoneNumber;
- }
- QStringList _DataTimeList = QString(_AllCallList.at(3)).split("T");
- _AllCallStr.data = QString(_DataTimeList.at(0));
- _AllCallStr.time = QString(_DataTimeList.at(1));
- d->m_AllCallList.append(_AllCallStr);
- }
- }
- else{
- if(d->m_AutoCancelTimer->isActive())
- {
- d->m_AutoCancelTimer->stop();
- }
- if(d->m_SyncType == BRT_PhoneBook){
- emit onSyncPhoneBook();
- }
- else if(d->m_SyncType == BRT_Incoming){
- d->syncOutComingCallLog();
- }
- else if(d->m_SyncType == BRT_Outgoing){
- d->syncMissedCallLog();
- }
- else if(d->m_SyncType == BRT_Missed){
- emit onSyncAllCallLog();
- }
- }
- }
- else if(data.contains("MICMUTED")){
- int ofIndex = data.indexOf('=');
- QString _BtMicMuteStatusStr = data.mid(ofIndex+1);
- d->m_BtMicMuteStatus = _BtMicMuteStatusStr.left(1).toInt();
- }
- //Hicar无线连接
- else if(data.contains("ADDR=")){
- int ofIndex = data.indexOf('=');
- QString _AddrStr = data.mid(ofIndex+1);
- _AddrStr = _AddrStr.left(_AddrStr.size()-1);
- d->m_LocalAddress = _AddrStr;
- QFile addressfile(QString("/data/bluetoothaddress"));
- if(!addressfile.exists())
- {
- QString _BtAddress = _AddrStr;
- if(_BtAddress.size() == 12)
- {
- _BtAddress = d->m_LocalAddress.mid(0,2) +(QString(":")) + d->m_LocalAddress.mid(2,2) +(QString(":"))+
- d->m_LocalAddress.mid(4,2) +(QString(":")) + d->m_LocalAddress.mid(6,2) +(QString(":"))+
- d->m_LocalAddress.mid(8,2) +(QString(":")) + d->m_LocalAddress.mid(10,2);
- }
- if (addressfile.open(QFile::WriteOnly)) {
- QString localAddress = _BtAddress;
- addressfile.write(localAddress.toLocal8Bit().data(), localAddress.length());
- addressfile.flush();
- addressfile.close();
- }
- }
- qDebug()<<"=====_AddrStr=========="<<_AddrStr;
- }
- else if(data.left(2)== QString("SR")){
- qDebug()<<"========Hicar无线连接SR======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SI")){
- qDebug()<<"========Hicar无线连接SI======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SV")){
- qDebug()<<"========Hicar无线连接SV======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SS")){
- qDebug()<<"========Hicar无线连接SS======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(3)== QString("MX0")){
- qDebug()<<"========Hicar无线连接MX0======="<<data.left(data.size()-1);
- d->m_HicarBackLinkMac = data.left(15).right(12);
- d->m_HicarBackLinkCmd = data.left(data.size()-1);
- if(g_Link->getHicarInitDoneStatu()){
- }
- g_Link->requestBluetoothCmd(g_Bluetooth->getHicarBackLinkCmd().left(15).toStdString());
- }
- else if(data.left(4)== QString("MZ12")){
- qDebug()<<"========Hicar无线连接MZ12======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- }
- void Bluetooth::SudingBlutoothHandle(QString data)
- {
- Q_D(Bluetooth);
- qDebug()<<__PRETTY_FUNCTION__<<__LINE__<<"readData:"<<data;
- //蓝牙开关状态:ST0 关闭, ST1 开启 undefined、BPS_PowerOff、BPS_PowerOn
- // if(data.contains("ST1"))
- // {
- // d->m_BluetoothPowerStatus = BPS_PowerOn;
- // emit onPowerChange(d->m_BluetoothPowerStatus);
- // d->getAddrMac();
- // setPincode(QString("0000"));
- // }
- // else if(data.contains("ST0")){
- // d->m_BluetoothPowerStatus = BPS_PowerOff;
- // emit onPowerChange(d->m_BluetoothPowerStatus);
- // }
- if (data.startsWith("IS")){
- int power = data.mid(2,1).toInt();
- qDebug()<<__PRETTY_FUNCTION__<<__LINE__<<"111=== blutooth power status"<<power;
- if (power == 1) {
- Send_AT_CMD(QString("DF"));
- d->m_BluetoothPowerStatus = BPS_PowerOn;
- } else {
- d->m_BluetoothPowerStatus = BPS_PowerOff;
- }
- emit onPowerChange(d->m_BluetoothPowerStatus);
- }
- //自动连接和自动接听状态MF[auto_reconnect:1][ auto_pickup:1]\r\n1 为 TRUE,0 为 FALSE
- else if(data.contains("MF") && data.size() >=4)
- {
- d->m_BluetoothAutoConnect = data.right(3).left(1).toInt();
- if(d->m_BluetoothAutoConnect > 0)
- {
- d->m_BluetoothAutoConnect = 1;
- }
- emit onAutoConnectChange(d->m_BluetoothAutoConnect);
- d->m_BluetoothAutoAnswer = data.right(2).left(1).toInt();
- if(d->m_BluetoothAutoAnswer > 0)
- {
- d->m_BluetoothAutoAnswer = 1;
- }
- emit onAutoAnswerChange(d->m_BluetoothAutoAnswer);
- }
- //扫描远程设别的信息
- else if(data.contains("SF"))
- {
- RemoteDeviceInfo _RemoteDeviceInfo;
- _RemoteDeviceInfo.index= d->m_RemoteDeviceInfoList.size();
- _RemoteDeviceInfo.rssi = 0;
- _RemoteDeviceInfo.deviceType = data.left(3).right(1).toInt();
- _RemoteDeviceInfo.macAddress = data.left(15).right(12);
- _RemoteDeviceInfo.name = data.right(data.size()-15).left(data.right(data.size()-15).size()-1);
- _RemoteDeviceInfo.deviceClass = QString("0");
- d->m_RemoteDeviceInfoList.append(_RemoteDeviceInfo);
- qDebug()<<__FUNCTION__<<__LINE__<<_RemoteDeviceInfo.macAddress<<" "<<_RemoteDeviceInfo.name;
- }
- //结束扫描
- else if(data.contains("SH")){
- d->m_PairedMap.clear();
- d->m_BtFirstEnterStatus = false;
- emit onScanFinish();
- }
- //当前HFP和a2dp状态MG[status]1:未连接 3:已连接 4:电话拨出 5:电话打入 6:通话中
- // enum BluetoothConnectStatus {
- // BCS_Undefine = -1,
- // BCS_Unsupported,
- // BCS_Idle,
- // BCS_Connecting,
- // BCS_Connected,
- // BCS_Outgoing,
- // BCS_Incoming,
- // BCS_Talking,
- // BCS_ActiveHeld,
- // };
- else if(data.contains("MG")){
- d->m_BluetoothConnectStatus = data.left(3).right(1).toInt();
- if(d->m_BluetoothConnectStatus != d->m_LastBluetoothConnectStatus)
- {
- emit onConnectStatusChange(d->m_BluetoothConnectStatus);
- }
- d->m_LastBluetoothConnectStatus = d->m_BluetoothConnectStatus;
- if(d->m_BluetoothConnectStatus < 3){
- if(d->m_LastBtStatus >= 3)
- d->m_BtFirstEnterStatus = true;
- d->m_RemoteBtAddress.clear();
- d->m_RemoteDeviceName.clear();
- }
- d->m_LastBtStatus = d->m_BluetoothConnectStatus;
- }
- //来电电话号码
- else if(data.left(2).contains("ID"))
- {
- // //电话接入
- // if(g_Link->getLinkConnectStatus() != 0 && g_Link->getLinkType() == Carlife && g_Setting->getCarlifeTelephoneStatus() == 0)
- // {
- // g_Link->requestKey(KEY_MUSIC_PAUSE);
- // g_Link->requestLink(g_Link->getLinkType(), g_Link->getLinkMode(), DBUS_REQUEST_BACKGROUND);
- // }
- // QString IncomingNumber = data.left(data.size()-1).right(data.left(data.size()-1).size()-2);
- // d->m_BluetoothConnectStatus = BCS_Incoming;
- // emit onDialInfo(d->m_BluetoothConnectStatus,IncomingNumber);
- // g_Audio->requestAudioSource(AS_BluetoothPhone);
- }
- //去电电话号码
- else if(data.left(2).contains("IC"))
- {
- //电话拨出
- QString _OutComingNumber = data.left(data.size()-1).right(data.left(data.size()-1).size()-2);
- g_Audio->requestAudioSource(AS_BluetoothPhone);
- d->m_BluetoothConnectStatus = BCS_Outgoing;
- emit onDialInfo(d->m_BluetoothConnectStatus,_OutComingNumber);
- }
- //通话中电话号码...
- else if(data.left(2).contains("IG"))
- {
- //通话中...
- QString _onCallingNumber = data.left(data.size()-1).right(data.left(data.size()-1).size()-2);
- g_Audio->requestAudioSource(AS_BluetoothPhone);
- d->m_BluetoothConnectStatus = BCS_Talking;
- emit onDialInfo(d->m_BluetoothConnectStatus,_onCallingNumber);
- g_Audio->requestAudioSource(AS_BluetoothPhone);
- }
- //挂断电话
- else if(data.left(2).contains("IF")){
- g_Audio->releaseAudioSource(AS_BluetoothPhone);
- }
- //配对记录
- else if(data.contains("MX") && data.left(3) != "MX0")
- {
- if(!d->m_BtFirstEnterStatus){
- return;
- }
- QString pairedAddr = data.left(15).right(12);
- QString pairedName = data.right(data.size()-15).left(data.right(data.size()-15).size()-1);
- d->m_PairedMap.insert(pairedAddr,pairedName);
- emit onGetPairedListFinish();
- }
- //当前连接设备名称
- else if(data.contains("SA"))
- {
- d->m_RemoteDeviceName = data.left(data.size()-1).right(data.left(data.size()-1).size()-2);
- onRemoteDeviceNameChange(d->m_RemoteDeviceName);
- qDebug()<<"+++[Bluetooth::BlutoothHandle:m_RemoteDeviceName]+++"<<__LINE__ <<d->m_RemoteDeviceName;
- }
- //当前连接设备地址:::JH[addr:12]
- else if(data.contains("JH"))
- {
- d->m_RemoteBtAddress = data.left(data.size()-1).right(data.left(data.size()-1).size()-2);
- onRemoteDeviceNameChange(d->m_RemoteBtAddress);
- qDebug()<<"+++[Bluetooth::BlutoothHandle:m_RemoteBtAddress]+++"<<__LINE__ <<d->m_RemoteBtAddress;
- }
- //蓝牙音乐状态
- else if(data.contains("MB"))
- {
- d->m_BluetoothPlayerStatus = Bluetooth::BtMusic_Playing;
- g_Audio->requestAudioSource(AS_BluetoothMusic);
- BtMusicInfo(0);//获取歌曲信息
- }
- //音乐停止
- else if(data.contains("MA"))
- {
- d->m_BluetoothPlayerStatus = Bluetooth::BtMusic_Paused;
- emit onMusicStatusChange(d->m_BtMusicTitle,d->m_BluetoothPlayerStatus);
- }
- //音乐信息
- else if(data.contains("MI"))
- {
- QStringList _MusicInfoList = data.split("�");
- if(_MusicInfoList.size() >=3)
- {
- QString _MusicName = QString(_MusicInfoList.at(0)).right(QString(_MusicInfoList.at(0)).size()-2);
- QString _MusicArtist = _MusicInfoList.at(1);
- QString _MusicAlbum = _MusicInfoList.at(2);
- d->m_BtMusicTitle = _MusicName;
- d->m_BtMusicArtist= _MusicArtist;
- d->m_BtMusicAlbum = _MusicAlbum;
- emit onBtMusicID3InfoChange(_MusicName,_MusicArtist,_MusicAlbum);
- emit onMusicStatusChange(d->m_BtMusicTitle,d->m_BluetoothPlayerStatus);
- }
- }
- //蓝牙音乐进度信息
- else if(data.contains("MP"))
- {
- if(data.size() >=22)
- {
- int _ElapsedTime = data.left(12).right(10).toInt();
- int _EndTime = data.right(11).right(data.right(11).size()-1).toInt();
- onBtMusicElapsedInfo((_ElapsedTime/1000),(_EndTime/1000));
- }
- }
- //电话本信息
- else if(data.contains("PB"))
- {
- struct PhoneBookInfo _PhoneBookStr;
- //int _PhoneNameLen = data.left(4).right(2).toInt();
- int _PhoneNumberLen = data.left(6).right(2).toInt();
- _PhoneBookStr.name = data.left(data.size()-_PhoneNumberLen-1).right(data.left(data.size()-_PhoneNumberLen-1).size()-6);
- _PhoneBookStr.phone = data.left(data.size()-1).right(_PhoneNumberLen);
- if(QString(_PhoneBookStr.name) <= 0)
- {
- _PhoneBookStr.name = _PhoneBookStr.phone;
- }
- QString character;
- if(IsChinese(_PhoneBookStr.name.left(1))){
- character = d->getChineseSpell(QString(_PhoneBookStr.name.left(1)));
- }
- else{
- character = _PhoneBookStr.name.left(1);
- }
- if(character.size() >= 1)
- _PhoneBookStr.head = character.left(1);
- d->m_PhoneBookList.append(_PhoneBookStr);
- }
- //下载电话本结束
- else if(data.left(2)== QString("PC"))
- {
- d->initializeAutoCancelTimer();
- if(d->m_AutoCancelTimer->isActive())
- {
- d->m_AutoCancelTimer->stop();
- }
- if(d->m_SyncType == BRT_PhoneBook){
- emit onSyncPhoneBook();
- }
- }
- //下载通话记录
- else if(data.contains("PD"))
- {
- QStringList _AllCallList = data.split("�");
- if(_AllCallList.size() < 3){
- return;
- }
- struct CallLogInfo _AllCallStr;
- _AllCallStr.callType = QString(_AllCallList.at(0)).left(3).right(1).toInt();
- _AllCallStr.name = QString(_AllCallList.at(0)).right(QString(_AllCallList.at(0)).size()-3);
- _AllCallStr.phoneNumber = QString(_AllCallList.at(1));
- if(_AllCallStr.name.size()==0)
- {
- _AllCallStr.name = _AllCallStr.phoneNumber;
- }
- QStringList _DataTimeList = QString(_AllCallList.at(2)).left(QString(_AllCallList.at(2)).size()-1).split("T");
- if(_DataTimeList.size()>= 2)
- {
- _AllCallStr.data = QString(_DataTimeList.at(0));
- _AllCallStr.time = QString(_DataTimeList.at(1));
- }
- else{
- _AllCallStr.data = QString(_AllCallList.at(2)).left(QString(_AllCallList.at(2)).size()-1);
- }
- d->m_AllCallList.append(_AllCallStr);
- }
- //下载通话记录结束
- else if(data.left(2)== QString("PE"))
- {
- d->initializeAutoCancelTimer();
- if(d->m_AutoCancelTimer->isActive())
- {
- d->m_AutoCancelTimer->stop();
- }
- if(d->m_SyncType == BRT_Incoming){
- d->syncOutComingCallLog();
- }
- else if(d->m_SyncType == BRT_Outgoing){
- d->syncMissedCallLog();
- }
- else if(d->m_SyncType == BRT_Missed){
- emit onSyncAllCallLog();
- }
- }
- else if(data.contains("IO"))
- {
- d->m_BtMicMuteStatus = data.right(3).right(1).toInt();
- }
- //Hicar无线连接
- else if(data.contains("DB")){
- d->m_LocalAddress = data.left(data.size()-1).right(12);
- QFile addressfile(QString("/data/bluetoothaddress"));
- if(!addressfile.exists())
- {
- QString _BtAddress = d->m_LocalAddress;
- if(_BtAddress.size() == 12)
- {
- _BtAddress = d->m_LocalAddress.mid(0,2) +(QString(":")) + d->m_LocalAddress.mid(2,2) +(QString(":"))+
- d->m_LocalAddress.mid(4,2) +(QString(":")) + d->m_LocalAddress.mid(6,2) +(QString(":"))+
- d->m_LocalAddress.mid(8,2) +(QString(":")) + d->m_LocalAddress.mid(10,2);
- }
- if (addressfile.open(QFile::WriteOnly)) {
- QString localAddress = _BtAddress;
- addressfile.write(localAddress.toLocal8Bit().data(), localAddress.length());
- addressfile.flush();
- addressfile.close();
- }
- }
- qDebug()<<"=====_AddrStr=========="<<d->m_LocalAddress;
- }
- else if(data.left(2)== QString("SR")){
- qDebug()<<"========Hicar无线连接SR======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SI")){
- qDebug()<<"========Hicar无线连接SI======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SV")){
- qDebug()<<"========Hicar无线连接SV======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(2)== QString("SS")){
- qDebug()<<"========Hicar无线连接SS======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- else if(data.left(3)== QString("MX0")){
- qDebug()<<"========Hicar无线连接MX0======="<<data.left(data.size()-1);
- d->m_HicarBackLinkMac = data.left(15).right(12);
- d->m_HicarBackLinkCmd = data.left(data.size()-1);
- d->m_RemoteBtAddress = data.mid(3).left(12);
- qDebug() << "============ m_RemoteBtAddress" << d->m_RemoteBtAddress;
- onRemoteDeviceNameChange(d->m_RemoteBtAddress);
- //d->m_ProcessedRemoteBtAddr = Get_MAC_addr(d->m_RemoteBtAddress,2,QString(":"));
- }
- else if(data.left(4)== QString("MZ12")){
- qDebug()<<"========Hicar无线连接MZ12======="<<data.left(data.size()-1);
- g_Link->requestBluetoothCmd(data.left(data.size()-1).toStdString());
- }
- }
- QString BluetoothPrivate::getBtManufacturer()
- {
- string value;
- string fileName("/data/bluetoothType");
- LoadConfigString(value, fileName);
- QString btManufacturer = QString::fromStdString(value);
- return btManufacturer;
- }
- QString Bluetooth::getBtType()
- {
- Q_D(Bluetooth);
- QString _BtType = d->getBtManufacturer();
- return _BtType;
- }
|