Library set up as dummy module on mbed to mimic Nordic.
Revision 1:d6b18299a715, committed 2016-12-12
- Comitter:
- Stephen_NewVistas
- Date:
- Mon Dec 12 23:19:30 2016 +0000
- Parent:
- 0:226550611f0d
- Child:
- 2:9ab591cf81b8
- Commit message:
- about to branch and make generic and not cpp
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BTpacket.h Mon Dec 12 23:19:30 2016 +0000
@@ -0,0 +1,7 @@
+#pragma pack(1)
+typedef struct{
+ unsigned char command;
+ unsigned char packetLength;
+ unsigned char packetData[18];
+} BTpacket_t;
+#pragma pack(0)
\ No newline at end of file
--- a/main.cpp Mon Dec 12 23:06:58 2016 +0000
+++ b/main.cpp Mon Dec 12 23:19:30 2016 +0000
@@ -6,6 +6,7 @@
#include "comms.h"
#include "rs485.h"
#include "uart1.h"
+#include "BTpacket.h"
#define FX 0x02
@@ -86,21 +87,29 @@
int Bluetooth_ReceivePacket( Packet *_packet ){
- #ifdef DEBUG
- pc.printf( "Process Packet\n\r" );
-
- pc.printf( "\t%x - Device ID\n\r" , _packet->deviceID );
- pc.printf( "\t%x - Source ID\n\r" , _packet->sourceID );
- pc.printf( "\t%x - Command\n\r" , _packet->command );
- pc.printf( "\t%x - Length\n\r" , _packet->packetLength );
- unsigned char *ptr = (unsigned char *)&_packet->packetData;
- for( int i = 0 ; i < _packet->packetLength ; i++ ){
- pc.printf( "\t%x - Data[%d]\n\r" , *ptr++ , i );
- }
+ #ifdef DEBUG
+ PrintPacket( _packet );
+ #endif // DEBUG
+
+ switch ( _packet->command ){
+
+ case 0x01:
+ CheckFunction( _packet );
+ break;
- #endif // DEBUG
+ case 0x02:
+
+ break;
+
+ case 0x03:
+
+ break;
+
+ default:
+ break;
+
+ }
- CheckFunction( _packet );
return 0;
}
@@ -110,6 +119,19 @@
return 0;
}
+void PrintPacket( Packet *_packet ){
+ pc.printf( "Process Packet\n\r" );
+
+ pc.printf( "\t%x - Device ID\n\r" , _packet->deviceID );
+ pc.printf( "\t%x - Source ID\n\r" , _packet->sourceID );
+ pc.printf( "\t%x - Command\n\r" , _packet->command );
+ pc.printf( "\t%x - Length\n\r" , _packet->packetLength );
+ unsigned char *ptr = (unsigned char *)&_packet->packetData;
+ for( int i = 0 ; i < _packet->packetLength ; i++ ){
+ pc.printf( "\t%x - Data[%d]\n\r" , *ptr++ , i );
+ }
+}
+
void Test( void ){
Packet commandPacket;
@@ -155,7 +177,9 @@
}
// create message
- SetResponse( 0xF0 , 0x10 , 0x01 );
+ Bluetooth_SendChar( 0xF0 );
+ Bluetooth_SendChar( 0x01 );
+ Bluetooth_SendChar( 0x10 );
// poll with message
ptr = buf1;
--- a/packetformatter.cpp Mon Dec 12 23:06:58 2016 +0000
+++ b/packetformatter.cpp Mon Dec 12 23:19:30 2016 +0000
@@ -2,8 +2,6 @@
#include <string.h>
#include "packetformatter.h"
#include "charactercode.h"
-//#include "command.h"
-
//#define DEBUG
static unsigned int checkSum;
@@ -30,7 +28,7 @@
memset( _packet , '\0' , sizeof( Packet ) );
_packet->deviceID = (int)_buffer[1] ;
- _packet->sourceID = (int)_buffer[2] ;
+ _packet->sourceID = (int)_buffer[2] ;
_packet->command = _buffer[3];
_packet->packetLength = _buffer[4];
_packet->packetLength = _packet->packetLength << 8;
--- a/rs485.cpp Mon Dec 12 23:06:58 2016 +0000
+++ b/rs485.cpp Mon Dec 12 23:19:30 2016 +0000
@@ -119,7 +119,7 @@
*
*****************************************************************************/
void SetResponse( Packet *_packet ){
- packetBufferSize = getFormattedPacket(&_packet, packetBuffer);
+ packetBufferSize = getFormattedPacket(_packet, packetBuffer);
message = 1;
}