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_BLE_Example_Modified Hexi_BLE_Example_ModifiedPOTATO
Fork of Hexi_KW40Z by
Revision 13:84ead63f7353, committed 2018-08-09
- Comitter:
- xihan94
- Date:
- Thu Aug 09 22:45:01 2018 +0000
- Parent:
- 12:3f5ed7abc5c7
- Child:
- 14:241c491f985f
- Commit message:
- dev;
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 05:28:55 2016 +0000
+++ b/Hexi_KW40Z.cpp Thu Aug 09 22:45:01 2018 +0000
@@ -36,14 +36,14 @@
#include "Hexi_KW40Z.h"
KW40Z::KW40Z(PinName txPin,PinName rxPin) :
-#if defined (LIB_DEBUG) || defined (RAW_DEBUG)
+#if defined (LIB_DEBUG) || defined (RAW_DEBUG) || defined (RX_DEBUG)
pc(USBTX, USBRX),
#endif
device(txPin, rxPin), rxThread(osPriorityNormal,1024), mainThread(osPriorityNormal,1024)
{
-#if defined (LIB_DEBUG)
+#if defined (LIB_DEBUG) || defined (RX_DEBUG)
pc.baud(115200);
- pc.printf("Initializing\r\n");
+ printf("Initializing\r\n");
#endif
device.baud(230400);
@@ -58,6 +58,7 @@
buttonRightCb = NULL;
buttonSlideCb = NULL;
alertCb = NULL;
+ messageCb = NULL;
passkeyCb = NULL;
notificationsCb = NULL;
@@ -85,13 +86,14 @@
void KW40Z::attach_buttonRight(button_t btnFct) { buttonRightCb = btnFct; }
void KW40Z::attach_buttonSlide(button_t btnFct) { buttonSlideCb = btnFct; }
void KW40Z::attach_alert(alert_t alertFct) { alertCb = alertFct; }
+void KW40Z::attach_message(message_t msgFct) { messageCb = msgFct; }
void KW40Z::attach_passkey(passkey_t passkeyFct){ passkeyCb = passkeyFct; }
void KW40Z::attach_notifications(notifications_t notFct) { notificationsCb = notFct; }
void KW40Z::mainTask(void)
{
#if defined (LIB_DEBUG)
- pc.printf("MainTask Stared\r\n");
+ printf("MainTask Stared\r\n");
#endif
SendGetActiveTsiGroup();
@@ -113,8 +115,8 @@
void KW40Z::rxTask(void)
{
-#if defined (LIB_DEBUG)
- pc.printf("RxTask Stared\r\n");
+#if defined (LIB_DEBUG) || defined (RX_DEBUG)
+ printf("RxTask Stared\r\n");
#endif
while(1)
@@ -149,7 +151,7 @@
}
#if defined (LIB_DEBUG)
- pc.printf("SendPacket: ");
+ printf("SendPacket: ");
DebugPrintPacket(packet);
#endif
@@ -164,7 +166,7 @@
confirmReceived = false;
#if defined (LIB_DEBUG)
- pc.printf("SendInternal: ");
+ printf("SendInternal: ");
DebugPrintPacket(txPacket);
#endif
@@ -172,7 +174,7 @@
{
confirmRequested = true;
#if defined (LIB_DEBUG)
- pc.printf("Found confirmRequested\r\n");
+ printf("Found confirmRequested\r\n");
#endif
}
@@ -188,7 +190,7 @@
}
#if defined (LIB_DEBUG)
- pc.printf("TX: ");
+ printf("TX: ");
DebugPrintPacket(txPacket);
#endif
@@ -209,7 +211,7 @@
void KW40Z::ProcessBuffer()
{
#if defined (RAW_DEBUG)
- pc.printf("%02X ", rxBuff-1);
+ printf("%02X ", rxBuff-1);
#endif
/* check if header has been received */
if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize))
@@ -219,8 +221,8 @@
(gHostInterface_startByte2 != (hostInterface_rxPacket.start2 & 0xFE))||
(hostInterface_rxPacket.length > gHostInterface_dataSize))
{
-#if defined (LIB_DEBUG)
- pc.printf("Check header failed: ");
+#if defined (LIB_DEBUG) || defined (RX_DEBUG)
+ printf("Check header failed: ");
DebugPrintPacket(&hostInterface_rxPacket);
#endif
@@ -235,7 +237,7 @@
if(gHostInterface_trailerByte != hostInterface_rxPacket.data[hostInterface_rxPacket.length])
{
#if defined (LIB_DEBUG)
- pc.printf("Trailer byte failed: ");
+ printf("Trailer byte failed: ");
DebugPrintPacket(&hostInterface_rxPacket);
#endif
@@ -257,11 +259,11 @@
queue.put(rxPacket);
#if defined (LIB_DEBUG)
- pc.printf("RX: ");
+ printf("RX: ");
DebugPrintPacket(&hostInterface_rxPacket);
#endif
#if defined (RAW_DEBUG)
- pc.printf("\r\n");
+ printf("\r\n");
#endif
/* reset buffer position */
rxBuff = (uint8_t*)&hostInterface_rxPacket;
@@ -288,7 +290,7 @@
found = true;
#if defined (LIB_DEBUG)
- pc.printf("moving %d", len);
+ printf("moving %d", len);
#endif
break;
}
@@ -303,10 +305,10 @@
}
#if defined (LIB_DEBUG)
- pc.printf("Search done: \r\n");
- pc.printf("rxBuff: ");
+ printf("Search done: \r\n");
+ printf("rxBuff: ");
DebugPrintPacket((hostInterface_packet_t*)rxBuff);
- pc.printf("rxPack: ");
+ printf("rxPack: ");
DebugPrintPacket(&hostInterface_rxPacket);
#endif
}
@@ -314,7 +316,7 @@
void KW40Z::ProcessPacket(hostInterface_packet_t * packet)
{
#if defined (LIB_DEBUG)
- pc.printf("ProcessPacket: ");
+ printf("ProcessPacket: ");
DebugPrintPacket(packet);
#endif
@@ -364,6 +366,11 @@
case packetType_alertIn:
if(alertCb != NULL) alertCb(&packet->data[0], packet->length);
break;
+
+ /* Message Service */
+ case packetType_messageIn:
+ if(messageCb != NULL) messageCb(&packet->data[1], (uint8_t) packet->data[0]);
+ break;
/* Passkey for pairing received */
case packetType_passDisplay:
@@ -600,6 +607,22 @@
SendPacket(&txPacket, true);
}
+void KW40Z::SendMessage(uint8_t *pData, uint8_t length)
+{
+ hostInterface_packet_t txPacket = {0};
+
+ txPacket.start1 = gHostInterface_startByte1;
+ txPacket.start2 = gHostInterface_startByte2;
+ txPacket.type = packetType_messageOut;
+ txPacket.length = 20;
+ memcpy(&txPacket.data[1],pData,length);
+ txPacket.data[0] = length;
+ txPacket.data[20] = gHostInterface_trailerByte;
+
+ SendPacket(&txPacket, true);
+}
+
+
void KW40Z::ToggleTsiGroup(void)
{
hostInterface_packet_t txPacket = {0};
@@ -733,7 +756,7 @@
return activeTsiGroup;
}
-#if defined (LIB_DEBUG)
+#if defined (LIB_DEBUG) || defined (RX_DEBUG)
void KW40Z::DebugPrintPacket(hostInterface_packet_t * packet)
{
char * idx = (char *)packet;
@@ -746,9 +769,9 @@
for(uint8_t i = 0; i < length; i++)
{
- pc.printf("%02X ",*idx);
+ printf("%02X ",*idx);
idx++;
}
- pc.printf("\r\n");
+ printf("\r\n");
}
#endif
--- a/Hexi_KW40Z.h Mon Sep 26 05:28:55 2016 +0000
+++ b/Hexi_KW40Z.h Thu Aug 09 22:45:01 2018 +0000
@@ -41,6 +41,7 @@
//#define LIB_DEBUG 1
//#define RAW_DEBUG 1
+//#define RX_DEBUG 1
#define gHostInterface_startByte1 0x55
#define gHostInterface_startByte2 0xAA
@@ -122,6 +123,10 @@
packetType_sleepON = 34, /**< sleep ON */
packetType_sleepOFF = 35, /**< sleep OFF */
+ /* Message Service */
+ packetType_messageIn = 116, /**< incoming alerts */
+ packetType_messageOut = 117, /**< outcoming alerts */
+
packetType_OK = 255 /**< OK packet */
} hostInterface_packetType_t;
@@ -155,6 +160,7 @@
typedef void (*button_t)(void);
typedef void (*alert_t)(uint8_t *data, uint8_t length);
+typedef void (*message_t)(uint8_t *data, uint8_t length);
//typedef void (*passkey_t)(uint8_t *data);
typedef void (*passkey_t)(void);
typedef void (*notifications_t)(uint8_t eventId, uint8_t categoryId);
@@ -191,6 +197,7 @@
void attach_buttonSlide(button_t btnFct);
void attach_alert(alert_t alertFct);
+ void attach_message(message_t msgFct);
void attach_passkey(passkey_t passkeyFct);
void attach_notifications(notifications_t notFct);
@@ -206,6 +213,7 @@
void SendSteps(uint16_t steps);
void SendCalories(uint16_t calories);
void SendAlert(uint8_t *pData, uint8_t length);
+ void SendMessage(uint8_t *pData, uint8_t length);
void SendSetApplicationMode(gui_current_app_t mode);
void SendGetVersion(void);
@@ -220,7 +228,7 @@
uint32_t GetPassKey(void);
private:
-#if defined (LIB_DEBUG) || defined (RAW_DEBUG)
+#if defined (LIB_DEBUG) || defined (RAW_DEBUG) || defined (RX_DEBUG)
RawSerial pc;
#endif
@@ -238,6 +246,7 @@
button_t buttonSlideCb;
alert_t alertCb;
+ message_t messageCb;
passkey_t passkeyCb;
notifications_t notificationsCb;
@@ -267,7 +276,7 @@
void SendGetAdvertisementMode(void);
void SendGetLinkState(void);
-#if defined (LIB_DEBUG)
+#if defined (LIB_DEBUG) || defined (RX_DEBUG)
void DebugPrintPacket(hostInterface_packet_t * packet);
#endif
};
