Library set up as dummy module on mbed to mimic Nordic.
Diff: main.cpp
- Revision:
- 2:9ab591cf81b8
- Parent:
- 1:d6b18299a715
--- a/main.cpp Mon Dec 12 23:19:30 2016 +0000
+++ b/main.cpp Tue Dec 13 00:20:29 2016 +0000
@@ -8,7 +8,14 @@
#include "uart1.h"
#include "BTpacket.h"
-#define FX 0x02
+extern const unsigned char DEVADDRESS = 0xF0;
+#define NORDIC_ADDRESS DEVADDRESS
+#define BTMODULE_A_ADDRESS 0x20 // #CC not sure if this has been defined by CEPD
+#define BTMODULE_B_ADDRESS 0x22 // #CC not sure if this has been defined by CEPD
+
+enum Commands { FX1 = 0x10 , FX1_ACK = 0x90 , // #CC list the commands needed for the NORDIC Module
+ FX2 = 0x12 , FX2_ACK = 0x92
+ };
/*===========================================
* These functions need to be completed
@@ -16,9 +23,11 @@
*/
int Bluetooth_ReceivePacket( Packet * );
int Bluetooth_SendChar( unsigned char );
+int Bluetooth_SerialHandler( void );
/*==========================================*/
-void Fx( unsigned char * );
+void Fx1( unsigned char * );
+void Fx2( unsigned char * );
/*===========================================
@@ -39,11 +48,13 @@
}
void Test( void );
+void PrintPacket( Packet *_packet );
/*==========================================*/
int main() {
- RegisterCommand( FX , &Fx );
+ RegisterCommand( FX1 , &Fx1 );
+ RegisterCommand( FX2 , &Fx2 );
initComms();
pc.printf( "\n\rStarted...\n\r" );
@@ -60,10 +71,29 @@
}
+//================ Custom Functions =============================================
+/* These functions local functions to the Nordic chip that are exposed to the
+* system. They must follow this prototype (same return values and parameter)
+* and must be registered with a command using RegisterCommand() from RS485
+* library.
+*/
+void Fx1( unsigned char *_receivedData ){
+
+ pc.printf( "In FX1!\n\r" );
+
+ Packet packet;
+ packet.sourceID = 0xF0;
+ packet.deviceID = 0xFE;
+ packet.command = 0x90;
+ packet.packetData[0] = 0x22;
+ packet.packetLength = 0x01;
+
+ SetResponsePacket( &packet );
+}
-void Fx( unsigned char *_receivedData ){
+void Fx2( unsigned char *_receivedData ){
- pc.printf( "In FX!\n\r" );
+ pc.printf( "In FX2!\n\r" );
Packet packet;
packet.sourceID = 0xF0;
@@ -72,44 +102,82 @@
packet.packetData[0] = 0x22;
packet.packetLength = 0x01;
- SetResponse( &packet );
+ SetResponsePacket( &packet );
}
+//================ End Custom Functions =========================================
-int Bluetooth_SerialGetChar( unsigned char *_c ){
- if( bus.readable() ){
- char c = bus.getc();
- pc.printf( "%x" , c );
- _c = (unsigned char*)c;
- return 1;
- }
+//#CC This needs to handle the uart port and pass received bytes on
+/******************************************************************************
+ * Bluetooth_SerialHandler
+ *
+ * The UART port needs to be handled and when a byte is received it is passed on
+ * to SerialHandler() form the rs485 library.
+ *
+ * PreCondition: None
+ *
+ * Input: '_packet' - packet received from the bus.
+ *
+ *
+ * Output: None
+ *
+ * Side Effects: None
+ *
+ *****************************************************************************/
+int Bluetooth_SerialHandler( void ){
+// if( ByteAvailableOnSerial ){
+// SerialHandler( GetByte() );
+// }
return 0;
}
+//#CC This needs to be modified as commented below
+/******************************************************************************
+ * Bluetooth_ReceivePacket
+ *
+ * This gets automatically called by the bus library when a complete packet is
+ * received. It checks the address the packet is going to and redirects the
+ * message appropriately (ie: if message is for the Nordic chip it calls a
+ * function or it sends it off to a BT device).
+ *
+ * PreCondition: None
+ *
+ * Input: '_packet' - packet received from the bus.
+ *
+ *
+ * Output: None
+ *
+ * Side Effects: None
+ *
+ *****************************************************************************/
int Bluetooth_ReceivePacket( Packet *_packet ){
#ifdef DEBUG
PrintPacket( _packet );
#endif // DEBUG
- switch ( _packet->command ){
+ switch ( _packet->command ){ // makes decision based off where packet is addressed to go
- case 0x01:
- CheckFunction( _packet );
+ case NORDIC_ADDRESS: // if the message is for the Nordic chip...
+ if( !CheckFunction( _packet ) ){ // this will call the appropriate function if one is registered
+ //#CC // code goes here if the function is not registered
+ }
break;
- case 0x02:
-
+ case BTMODULE_A_ADDRESS: // if message is for Bluetooth Module A
+ //#CC
+ /*
+ Need to bring in packet and modify to send out over BT
+ */
break;
- case 0x03:
+ case BTMODULE_B_ADDRESS:
break;
default:
break;
- }
-
+ }
return 0;
}