Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Diff: TransferService.cpp
- Revision:
- 1:d623a5792ce5
- Parent:
- 0:4eaf82806f06
- Child:
- 2:4ca946e0ebdc
--- a/TransferService.cpp Mon Aug 18 16:03:22 2014 +0000
+++ b/TransferService.cpp Thu Aug 21 14:09:18 2014 +0000
@@ -67,7 +67,6 @@
return transferServiceUUID;
}
-void requestBlock(uint16_t); // prototype declaration
void sendFileInfo();
void refuseFile();
void sendFileDownloadedSuccessfully();
@@ -91,14 +90,15 @@
return;
}
- DEBUG("Offered file len=%d, crc=0x%04x, acceptFile=%d, downloadInProgress=%d\r\n", fileInfo.length, fileInfo.crc16, acceptFile, downloadInProgress);
+ DEBUG("Offered file len=%u, crc=0x%04x, acceptFile=%u, downloadInProgress=%u\r\n",
+ fileInfo.length, fileInfo.crc16, acceptFile, downloadInProgress);
// Now we must decide whether to accept it or not
if (acceptFile && !downloadInProgress) {
downloadTimer.reset();
downloadTimer.start();
downloadInProgress = true;
- requestBlock(0);
+ expectingBlock = 0;
} else {
refuseFile();
}
@@ -106,51 +106,21 @@
uint16_t len = sizeof(fileBlock);
ble->readCharacteristicValue(handle, (uint8_t *) &fileBlock, &len);
- // DEBUG("received blk %u (total %u): ", fileBlock.blockNumber, fileInfo.length / Config::blockSize);
- // uint8_t byte;
- // for (int i = 2; i < len; i++) {
- // byte = *(((uint8_t*) &fileBlock) + i);
- // DEBUG("%02x ", byte);
- // }
- // DEBUG("\r\n");
-
if (fileBlock.blockNumber != expectingBlock) {
- DEBUG("Expected blk %d, not %d!\r\n", expectingBlock, fileBlock.blockNumber);
- requestBlock(expectingBlock);
- return;
+ DEBUG("Expected blk %u, not %u!\r\n", expectingBlock, fileBlock.blockNumber);
+ } else if (fileBlock.blockNumber <= (fileInfo.length / Config::blockSize)) {
+ expectingBlock = fileBlock.blockNumber + 1;
+ if (fileBlock.blockNumber == ((fileInfo.length / Config::blockSize) - 1)) {
+ sendFileDownloadedSuccessfully();
+ }
} else {
- // DEBUG("."); // one dot = one successfully received packet
- }
-
- if (fileBlock.blockNumber > (fileInfo.length / Config::blockSize)) {
- DEBUG("Error: block %d is out of range\r\n", fileBlock.blockNumber);
- return;
- }
-
- // "processing" step disabled
- //uint16_t offset = fileBlock.blockNumber * Config::blockSize;
- //memcpy(downloadLocation, fileBlock[0].data, Config::blockSize);
-
- // request next block if needed
- uint16_t nextBlock = fileBlock.blockNumber + 1;
- if (nextBlock <= fileInfo.length / Config::blockSize) {
- requestBlock(nextBlock);
- } else {
- sendFileDownloadedSuccessfully();
+ DEBUG("Error: block %u is out of range\r\n", fileBlock.blockNumber);
}
} else {
DEBUG("Got data on unexpected characteristic handle %u!\r\n", handle);
}
}
-void requestBlock(uint16_t blockNumber)
-{
- // Requesting a block by sending notification is disabled for speed
- //ble->updateCharacteristicValue(transferFileBlocks[0].getHandle(), (uint8_t*) &blockNumber, sizeof(blockNumber), false);
- //DEBUG("BlockReq %d --> PHONE\r\n", blockNumber);
- expectingBlock = blockNumber;
-}
-
void sendFileInfo(uint32_t value)
{
// refusal is indicated by sending a fileInfo with all zeros