-
Notifications
You must be signed in to change notification settings - Fork 94
Added various features for WH-1000XM4 #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aybruh00
wants to merge
15
commits into
Plutoberth:master
Choose a base branch
from
aybruh00:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
416ae88
Optimizer for XM4 added
aybruh00 88877fb
XM4 Speak To Chat Added
aybruh00 7614b25
Added some structure for Listener (incoming packet handler)
aybruh00 f26b215
Listener code added, some message handling added
aybruh00 c0be286
Listener object registered
aybruh00 9974848
Fixed cyclic dependency issues
aybruh00 8639d9e
fixed timing issues; listener working (but barely)
aybruh00 b9ebbe8
Listener completed
aybruh00 333b269
Multi-point options added
aybruh00 9ef2969
multi-point and device state query added
aybruh00 8ee7e46
fixed issue where queries causing app to hang
aybruh00 2f6245a
converted CRLF to LF
aybruh00 af23393
fixed seqNumber logic and device state query
aybruh00 5ef5e4e
Added device capabilities querying
aybruh00 e330d98
Update CommandSerializer.cpp
aybruh00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,17 +22,25 @@ BluetoothWrapper& BluetoothWrapper::operator=(BluetoothWrapper&& other) noexcept | |||||||||||
return *this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
int BluetoothWrapper::sendCommand(const std::vector<char>& bytes) | ||||||||||||
int BluetoothWrapper::sendCommand(const std::vector<char>& bytes, DATA_TYPE dtype) | ||||||||||||
{ | ||||||||||||
int bytesSent; | ||||||||||||
std::lock_guard guard(this->_connectorMtx); | ||||||||||||
auto data = CommandSerializer::packageDataForBt(bytes, DATA_TYPE::DATA_MDR, this->_seqNumber++); | ||||||||||||
auto bytesSent = this->_connector->send(data.data(), data.size()); | ||||||||||||
auto data = CommandSerializer::packageDataForBt(bytes, dtype, this->_seqNumber); | ||||||||||||
bytesSent = this->_connector->send(data.data(), data.size()); | ||||||||||||
|
||||||||||||
this->_waitForAck(); | ||||||||||||
if (dtype != DATA_TYPE::ACK) | ||||||||||||
this->_waitForAck(); | ||||||||||||
|
||||||||||||
return bytesSent; | ||||||||||||
} | ||||||||||||
|
||||||||||||
void BluetoothWrapper::sendAck(unsigned int seqNumber) | ||||||||||||
{ | ||||||||||||
auto data = CommandSerializer::packageDataForBt({}, DATA_TYPE::ACK, seqNumber ^ 0x01); | ||||||||||||
this->_connector->send(data.data(), data.size()); | ||||||||||||
} | ||||||||||||
|
||||||||||||
bool BluetoothWrapper::isConnected() noexcept | ||||||||||||
{ | ||||||||||||
return this->_connector->isConnected(); | ||||||||||||
|
@@ -51,13 +59,29 @@ void BluetoothWrapper::disconnect() noexcept | |||||||||||
this->_connector->disconnect(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
||||||||||||
std::vector<BluetoothDevice> BluetoothWrapper::getConnectedDevices() | ||||||||||||
{ | ||||||||||||
return this->_connector->getConnectedDevices(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void BluetoothWrapper::_waitForAck() | ||||||||||||
{ | ||||||||||||
std::unique_lock<std::mutex> guard(this->_dataMtx); | ||||||||||||
|
||||||||||||
while (!(this->_ackBuffer > 0)){ | ||||||||||||
this->_ack.wait(guard); | ||||||||||||
} | ||||||||||||
|
||||||||||||
this->_ackBuffer--; | ||||||||||||
} | ||||||||||||
|
||||||||||||
void BluetoothWrapper::postAck() | ||||||||||||
{ | ||||||||||||
std::lock_guard guard(this->_dataMtx); | ||||||||||||
this->_ackBuffer++; | ||||||||||||
} | ||||||||||||
|
||||||||||||
Buffer BluetoothWrapper::readReplies() | ||||||||||||
{ | ||||||||||||
bool ongoingMessage = false; | ||||||||||||
bool messageFinished = false; | ||||||||||||
|
@@ -66,11 +90,25 @@ void BluetoothWrapper::_waitForAck() | |||||||||||
|
||||||||||||
do | ||||||||||||
{ | ||||||||||||
auto numRecvd = this->_connector->recv(buf, sizeof(buf)); | ||||||||||||
int i = 0; | ||||||||||||
while(!messageFinished) | ||||||||||||
{ | ||||||||||||
this->_connector->recv(buf+i, 1); | ||||||||||||
i++; | ||||||||||||
if (buf[i-1] == 0x3c) | ||||||||||||
messageFinished = true; | ||||||||||||
// break; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
auto numRecvd = i; | ||||||||||||
size_t messageStart = 0; | ||||||||||||
size_t messageEnd = numRecvd; | ||||||||||||
// for (int i = 0; i < numRecvd; i++) | ||||||||||||
// { | ||||||||||||
// std::cout << std::hex << (0xff & (unsigned int)buf[i]) << " "; | ||||||||||||
// } | ||||||||||||
// std::cout << std::endl; | ||||||||||||
Comment on lines
+105
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
for (size_t i = 0; i < numRecvd; i++) | ||||||||||||
for (int i = 0; i < numRecvd; i++) | ||||||||||||
{ | ||||||||||||
if (buf[i] == START_MARKER) | ||||||||||||
{ | ||||||||||||
|
@@ -92,7 +130,14 @@ void BluetoothWrapper::_waitForAck() | |||||||||||
msgBytes.insert(msgBytes.end(), buf + messageStart, buf + messageEnd); | ||||||||||||
} while (!messageFinished); | ||||||||||||
|
||||||||||||
return msgBytes; | ||||||||||||
|
||||||||||||
auto msg = CommandSerializer::unpackBtMessage(msgBytes); | ||||||||||||
this->_seqNumber = msg.seqNumber; | ||||||||||||
Comment on lines
+134
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
|
||||||||||||
void BluetoothWrapper::setSeqNumber(unsigned char seqNumber) | ||||||||||||
{ | ||||||||||||
std::lock_guard guard(this->_dataMtx); | ||||||||||||
this->_seqNumber = seqNumber; | ||||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole change here is unclear - now two different pieces of logic are parsing the messages. Delete one of them and use the constants for both END and START markers.