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.
Dependents: Hexi_Buttons_Example Hexi_Click_Relay-v2_Example Hexi_Click_Relay-v3_Example Hexi_Catch-the-dot_Game ... more
Revision 11:a9a838035b87, committed 2016-09-26
- Comitter:
- cotigac
- Date:
- Mon Sep 26 04:56:27 2016 +0000
- Parent:
- 10:1bed2b28ee18
- Child:
- 12:3f5ed7abc5c7
- Commit message:
- Fixed Search Byte algorithm which was buggy
Changed in this revision
| Hexi_KW40Z.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Hexi_KW40Z.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Hexi_KW40Z.cpp Mon Sep 26 02:36:12 2016 +0000
+++ b/Hexi_KW40Z.cpp Mon Sep 26 04:56:27 2016 +0000
@@ -36,7 +36,7 @@
#include "Hexi_KW40Z.h"
KW40Z::KW40Z(PinName txPin,PinName rxPin) :
-#if defined (LIB_DEBUG)
+#if defined (LIB_DEBUG) || defined (RAW_DEBUG)
pc(USBTX, USBRX),
#endif
device(txPin, rxPin), rxThread(osPriorityNormal,1024), mainThread(osPriorityNormal,1024)
@@ -207,7 +207,10 @@
}
void KW40Z::ProcessBuffer()
-{
+{
+#if defined (RAW_DEBUG)
+ pc.printf("%02X ", rxBuff-1);
+#endif
/* check if header has been received */
if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize))
{
@@ -256,7 +259,10 @@
#if defined (LIB_DEBUG)
pc.printf("RX: ");
DebugPrintPacket(&hostInterface_rxPacket);
-#endif
+#endif
+#if defined (RAW_DEBUG)
+ pc.printf("\r\n");
+#endif
/* reset buffer position */
rxBuff = (uint8_t*)&hostInterface_rxPacket;
}
@@ -268,20 +274,21 @@
void KW40Z::SearchStartByte()
{
bool found = false;
- uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket + 1;
-
+ uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket;
+ rdIdx++;
+
while(rdIdx < rxBuff)
{
if(*rdIdx == gHostInterface_startByte1)
{
- uint32_t len = rxBuff - rdIdx;
+ uint32_t len = rxBuff - rdIdx + 1;
memcpy(&hostInterface_rxPacket,rdIdx,len);
- rxBuff -= len;
+ rxBuff = (uint8_t*)&hostInterface_rxPacket + len;
found = true;
#if defined (LIB_DEBUG)
- pc.printf("moving ");
+ pc.printf("moving %d", len);
#endif
break;
}
@@ -292,10 +299,14 @@
{
/* reset buffer position */
rxBuff = (uint8_t*)&hostInterface_rxPacket;
+ memset(rxBuff, 0, sizeof(hostInterface_packet_t));
}
#if defined (LIB_DEBUG)
- pc.printf("Search done: ");
+ pc.printf("Search done: \r\n");
+ pc.printf("rxBuff: ");
+ DebugPrintPacket((hostInterface_packet_t*)rxBuff);
+ pc.printf("rxPack: ");
DebugPrintPacket(&hostInterface_rxPacket);
#endif
}
@@ -728,9 +739,9 @@
char * idx = (char *)packet;
uint8_t length = packet->length + gHostInterface_headerSize + 1;
- if(length > (gHostInterface_dataSize + gHostInterface_headerSize + 1))
+ if(length > sizeof(hostInterface_packet_t))
{
- length = gHostInterface_dataSize + gHostInterface_headerSize + 1;
+ length = sizeof(hostInterface_packet_t);
}
for(uint8_t i = 0; i < length; i++)
--- a/Hexi_KW40Z.h Mon Sep 26 02:36:12 2016 +0000
+++ b/Hexi_KW40Z.h Mon Sep 26 04:56:27 2016 +0000
@@ -39,7 +39,8 @@
#include "mbed.h"
#include "rtos.h"
-#define LIB_DEBUG 1
+//#define LIB_DEBUG 1
+//#define RAW_DEBUG 1
#define gHostInterface_startByte1 0x55
#define gHostInterface_startByte2 0xAA
@@ -219,7 +220,7 @@
uint32_t GetPassKey(void);
private:
-#if defined (LIB_DEBUG)
+#if defined (LIB_DEBUG) || defined (RAW_DEBUG)
RawSerial pc;
#endif