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.
Fork of IEEE_14_Freescale by
Diff: droidBT.cpp
- Revision:
- 23:53cafcd67828
- Parent:
- 22:ac1f69a841ce
- Child:
- 24:46eeab7cebc6
--- a/droidBT.cpp Wed Mar 12 22:34:37 2014 +0000
+++ b/droidBT.cpp Thu Mar 13 04:30:24 2014 +0000
@@ -59,19 +59,23 @@
int i=BTStart;
int startChunk=i;
int seen=0;
+ int cheapHash=0;
while (i!=BTEnd) {
if(i==startChunk){ //first bit in the chunk
if((BTBuffer[i]&0xF0)==0x60){//data returned
- i++;
+ cheapHash=BTBuffer[i];
DBGPRINT("gettin data\r\n",1);
- } else if((BTBuffer[i]&0xF0)==0xC0){//ack
i++;
- DBGPRINT("gettin ack\r\n",1);
+ } else if((BTBuffer[i]&0xF0)==0xF0){//ack
+ cheapHash=BTBuffer[i];
+ DBGPRINT("gettin ack %x\r\n",BTBuffer[i]);
+ BTBuffer[i]=0xF1;
+ i++;
} else {//dunno what this data is, toss
BTStart++;
+ startChunk=i;
+ DBGPRINT("throwing away %x\r\n",BTBuffer[i]);
i++;
- startChunk=i;
- DBGPRINT("throwing away\r\n",1);
}
} else {
DBGPRINT("not first\r\n",1);
@@ -82,11 +86,23 @@
for(j=0;j<(BTBuffer[startChunk]&0xF);j++){
DBGPRINT("copying %d, %d\r\n",BTBuffer[i+j], j);
DataChunk[DCEnd][j+1]=BTBuffer[i+j];
+ if(j<((BTBuffer[startChunk]&0xF)-1)){
+ cheapHash^=BTBuffer[i+j];
+ }
}
- if(DCEnd>=DCHUNKSIZE)
- DCEnd=0;
+ //check and store if the hash matched
+ if(cheapHash == BTBuffer[i+(BTBuffer[startChunk]&0xF)-1]){
+ DBGPRINT("Hash Matches\r\n",1);
+ DataChunk[DCEnd][(BTBuffer[startChunk]&0xF)]=1;
+ if(DCEnd>=DCHUNKSIZE)
+ DCEnd=0;
+ DCEnd++;
+ }else{
+ DBGPRINT("Hash Does Not Match\r\n",1);
+ DataChunk[DCEnd][(BTBuffer[startChunk]&0xF)]=0;
+ }
DBGPRINT("Got Data of size %d [%x %d %d]\n", BTBuffer[startChunk]&0xF, DataChunk[DCEnd][1], DataChunk[DCEnd][2], DataChunk[DCEnd][3]);
- DCEnd++;
+
BTStart=i+j;
startChunk=i=BTStart;
} else {
@@ -130,7 +146,7 @@
droid.putc(info[i]);
cheapHash^=info[i];
}
- return 0xF000|((len+1)<<2)|cheapHash;
+ return 0xF000|((len+1)<<8)|(cheapHash&0xFF);
}
int droidBT::getAck(int hashetc){
