mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Windows can now also send data to the Arduino
This commit is contained in:
parent
85af55e0aa
commit
2d4548e310
2 changed files with 53 additions and 26 deletions
71
RFCOMM.cpp
71
RFCOMM.cpp
|
@ -769,6 +769,7 @@ void RFCOMM::ACL_event_task()
|
|||
|
||||
if(rfcommChannel>>3 != 0x00)
|
||||
rfcommChannelPermanent = rfcommChannel;
|
||||
|
||||
#ifdef EXTRADEBUG
|
||||
Notify(PSTR("\r\nRFCOMM Channel: "));
|
||||
Serial.print(rfcommChannel>>3,HEX);
|
||||
|
@ -781,6 +782,14 @@ void RFCOMM::ACL_event_task()
|
|||
Notify(PSTR(" PF_BIT: "));
|
||||
Serial.print(rfcommPfBit,HEX);
|
||||
#endif
|
||||
|
||||
if (rfcommChannelType == RFCOMM_DISC) {
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nReceived Disconnect RFCOMM Command"));
|
||||
#endif
|
||||
connected = false;
|
||||
l2cap_disconnection_request(0x0A, rfcomm_dcid, rfcomm_scid);
|
||||
}
|
||||
if(connected) {
|
||||
readReport();
|
||||
#ifdef PRINTREPORT
|
||||
|
@ -807,30 +816,39 @@ void RFCOMM::ACL_event_task()
|
|||
rfcommbuf[8] = 0x00; // MaxRatransm.
|
||||
rfcommbuf[9] = 0x00; // Number of Frames
|
||||
sendRfcomm(rfcommChannel,rfcommDirection,0,RFCOMM_UIH,rfcommPfBit,rfcommbuf,0x0A);
|
||||
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nUIH Modem Status Command"));
|
||||
#endif
|
||||
rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command
|
||||
rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
|
||||
rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
|
||||
rfcommbuf[3] = 0x0D; // Can receive frames (YES), Ready to Communicate (YES), Ready to Receive (YES), Incomig Call (NO), Data is Value (NO)
|
||||
sendRfcomm(rfcommChannel,rfcommDirection,0,RFCOMM_UIH,rfcommPfBit,rfcommbuf,0x04);
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nUIH Modem Status Response"));
|
||||
#endif
|
||||
rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
|
||||
rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
|
||||
rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
|
||||
rfcommbuf[3] = 0x8D; // Can receive frames (YES), Ready to Communicate (YES), Ready to Receive (YES), Incomig Call (NO), Data is Value (YES)
|
||||
rfcommbuf[3] = l2capinbuf[14];
|
||||
sendRfcomm(rfcommChannel,rfcommDirection,0,RFCOMM_UIH,rfcommPfBit,rfcommbuf,0x04);
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit
|
||||
|
||||
delay(1);
|
||||
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nUIH Modem Status Command"));
|
||||
#endif
|
||||
rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command
|
||||
rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
|
||||
rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
|
||||
rfcommbuf[3] = 0x8D; // Can receive frames (YES), Ready to Communicate (YES), Ready to Receive (YES), Incomig Call (NO), Data is Value (YES)
|
||||
|
||||
sendRfcomm(rfcommChannel,rfcommDirection,0,RFCOMM_UIH,rfcommPfBit,rfcommbuf,0x04);
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response
|
||||
if(!creditSent) {
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nUIH Command with credit"));
|
||||
#endif
|
||||
sendRfcommCredit(rfcommChannelPermanent,rfcommDirection,0,RFCOMM_UIH,0x10,0xFF); // 255 credit
|
||||
creditSent = true;
|
||||
}
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nReceived credit"));
|
||||
#endif
|
||||
timer = millis();
|
||||
waitForLastCommand = true;
|
||||
} else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
|
||||
|
@ -852,21 +870,22 @@ void RFCOMM::ACL_event_task()
|
|||
Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"));
|
||||
#endif
|
||||
waitForLastCommand = false;
|
||||
creditSent = false;
|
||||
connected = true; // The RFCOMM channel is now established
|
||||
}
|
||||
|
||||
else if (rfcommChannelType == RFCOMM_DISC) {
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nReceived Disconnect RFCOMM Command"));
|
||||
#endif
|
||||
l2cap_disconnection_request(0x0A, rfcomm_dcid, rfcomm_scid);
|
||||
} else {
|
||||
} else if(rfcommChannelType != RFCOMM_DISC) {
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nUnsupported RFCOMM - ChannelType: "));
|
||||
PrintHex<uint8_t>(rfcommChannelType);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef EXTRADEBUG
|
||||
Notify(PSTR("\r\nUnsupported L2CAP Data: Channel ID: "));
|
||||
PrintHex<uint8_t>(l2capinbuf[7]);
|
||||
Notify(PSTR(" "));
|
||||
PrintHex<uint8_t>(l2capinbuf[6]);
|
||||
#endif
|
||||
}
|
||||
SDP_task();
|
||||
RFCOMM_task();
|
||||
|
@ -945,8 +964,9 @@ void RFCOMM::RFCOMM_task()
|
|||
if(!connected) {
|
||||
if((millis() - timer) > 100 && waitForLastCommand) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"));
|
||||
Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"));
|
||||
#endif
|
||||
creditSent = false;
|
||||
waitForLastCommand = false;
|
||||
connected = true; // The RFCOMM channel is now established
|
||||
|
||||
|
@ -1009,8 +1029,15 @@ void RFCOMM::readReport() {
|
|||
if(rfcommAvailable + length > 256)
|
||||
return; // Return if the buffer would be full
|
||||
|
||||
uint8_t offset;
|
||||
if(l2capinbuf[4] == length+4) {
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
offset = 1; // There must be credit
|
||||
|
||||
for(uint8_t i = 0; i < length; i++)
|
||||
rfcommDataBuffer[rfcommAvailable+i] = l2capinbuf[11+i];
|
||||
rfcommDataBuffer[rfcommAvailable+i] = l2capinbuf[11+i+offset];
|
||||
rfcommAvailable += length;
|
||||
#ifdef EXTRADEBUG
|
||||
Notify(PSTR("\r\nRFCOMM Data Available: "));
|
||||
|
|
2
RFCOMM.h
2
RFCOMM.h
|
@ -275,7 +275,7 @@ private:
|
|||
|
||||
unsigned long timer;
|
||||
bool waitForLastCommand;
|
||||
|
||||
bool creditSent;
|
||||
|
||||
uint8_t rfcommDataBuffer[256]; // Create a 256 sized buffer for incoming data
|
||||
uint8_t rfcommAvailable;
|
||||
|
|
Loading…
Reference in a new issue