Radio Structures in OOP

Dependencies:   mbed mbed-rtos

Revision:
5:146523a0d1f4
Parent:
4:989d51f3e6ef
Child:
6:4a3dbfbc30f1
--- a/main.cpp	Sat Jan 03 11:04:31 2015 +0000
+++ b/main.cpp	Wed Jan 14 17:46:44 2015 +0000
@@ -4,23 +4,27 @@
 #if RJ_BOOT_LOG
 LocalFileSystem local("local");     // Create the local filesystem object
 #endif
-
+DigitalOut ll(p5, 1);   // trigger for logic analyzer
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
+Serial pc(USBTX, USBRX);
+
 // Dummy function
 void primary_radio_rx_handle(void)
 {
     led3 != led3;
 }
-
+/*
 // Dummy function
 void primary_radio_tx_handle(RTP_t* p)
 {
-    led4 = 1;
+    led4 = !led4;
 }
+*/
+
 
 // Sets the mbed's baudrate for debugging purposes
 void baud(int baudrate)
@@ -32,9 +36,9 @@
 // Main program operations =======================
 int main()
 {
-    led1 = 1;
+
     led4 = 0;
-    // Set the baud rate
+// Set the baud rate
     baud(57600);
 
 // Check the mbed's firmware if enabled
@@ -50,76 +54,48 @@
 
 #endif
 
-    // Create a new physical hardware communication link
+DigitalOut temppp(RJ_PRIMARY_RADIO_INT, 1);
+temppp = 0;
+temppp = 1;
+
+// Create a new physical hardware communication link
     CC1101 radio_900(
         RJ_SPI_BUS,
         RJ_PRIMARY_RADIO_CS,
         RJ_PRIMARY_RADIO_INT
     );
+    
+    radio_900.selfTest();
+    
+    radio_900.status(CCXXX1_MARCSTATE);
 
-    // Create a Communication Module Object
+// Create a Communication Module Object
     CommModule comm;
-
+    radio_900.setCommModule(comm);
     comm.TxHandler((CommLink*)&radio_900, &CommLink::sendPacket, 8);
-    comm.RxHandler(primary_radio_rx_handle, 8);
+    //comm.RxHandler((CommLink*)&radio_900, &CommLink::ISR, 8);
     comm.openSocket(8);
 
-    // Open a socket for the Communication Module. Give it a port number and a function to call when a packet of that port number is received
-    //comm.openSocket((CommLink*)&radio_900, primary_radio_rx_handle, 8);
+// Open a socket for the Communication Module. Give it a port number and a function to call when a packet of that port number is received
     led3 = 1;
 
-    // Create a dummy packet that is set to send out from socket connection 8
+// Create a dummy packet that is set to send out from socket connection 8
     RTP_t dummy_packet;
     dummy_packet.port = 8;
     dummy_packet.subclass = 1;
     for (int i=0; i<20; i++)
         dummy_packet.data[0] = i;
 
-    // Send the packet
-    comm.send(dummy_packet);
-
-    // Test sending a packet on a port that has not been setup yet
-    dummy_packet.port = 7;
-    comm.send(dummy_packet);
-    //comm.TxHandler(primary_radio_tx_handle, 7);
-    //comm.openSocket(&radio_900, primary_radio_rx_handle, 7);
-
-    // Enable watchdog timer
-    //Watchdog watchdog;
-    //watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
-    
-    radio_900.triggerReceive();
-
-    led2 = 0;
+// Enable watchdog timer
+//Watchdog watchdog;
+//watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
 
-    if(false) {
-        for (int i=1; i<=1000000; i*=10) {
-            std::printf("Itterations: %u\r\n", i);
-            Timer t;
-            t.start();
-
-            for(int j=0; j<i; j++) {
-                comm.send(dummy_packet);
-                osDelay(1);
-            }
-
-            t.stop();
-            std::printf("Timer Reading: %uus (%.5fs)\r\n\r\n", t.read_us(), t.read());
-        }
-    }
-
-    led2 = 1;
-
-    std::printf("Done\r\n");
+    led1 = 0;
 
     while(1) {
-        // Renew the watchdog timer through every itteration
-        //watchdog.renew();
-        led2 = !led2;
+        led1 = !led1;
+        //comm.send(dummy_packet);
+        osDelay(500);
 
-        // Delay 1 second
-        osDelay(1000);
-        led3 != led3;
-        osDelay(300);
     }
 }
\ No newline at end of file