Radio Structures in OOP

Dependencies:   mbed mbed-rtos

Revision:
3:dc7e9c6bc26c
Parent:
2:7d523bdd2f50
Child:
4:989d51f3e6ef
--- a/main.cpp	Sun Dec 28 06:05:17 2014 +0000
+++ b/main.cpp	Sat Jan 03 04:35:32 2015 +0000
@@ -5,12 +5,21 @@
 LocalFileSystem local("local");     // Create the local filesystem object
 #endif
 
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
 // Dummy function
-void callback(void const *arg)
+void primary_radio_rx_handle(void const *arg)
 {
-    while(1) {
-        // do nothing - function declared for compile testing purposes
-    }
+    led3 != led3;
+}
+
+// Dummy function
+void primary_radio_tx_handle(RTP_t* p)
+{
+    led4 = 1;
 }
 
 // Sets the mbed's baudrate for debugging purposes
@@ -23,76 +32,94 @@
 // Main program operations =======================
 int main()
 {
+    led1 = 1;
+    led4 = 0;
     // Set the baud rate
     baud(57600);
 
-    /*  Old implementation of CC1101 constructor
-    CC1101 radio_900(
-        RJ_SPI_BUS,
-        RJ_PRIMARY_RADIO_CS,
-        RJ_TX_LED, RJ_RX_LED,
-        RJ_PRIMARY_RADIO_INT
-    );
-    */
-
 // Check the mbed's firmware if enabled
 #if RJ_CHECK_FIRMWARE
+    std::string firmware;
+    firmware_version(firmware);  // this is from FirmwareHelper.h
+    LOG("Firmware Version: %s\r\n", firmware.c_str());
+
 // Write any errors to a log file if enabled
 #if RJ_BOOT_LOG
-    FILE *fp = fopen("/local/log.txt", "w");  // Open text file for tracking boot sequence results
-    if (fp == NULL) {
-        error("Could not get pointer to log file\r\n");
-    }
-    std::string firmware = firmware_version();  // this is from FirmwareHelper.h
-    fprintf(fp, "Start Logging...\r\nFirmware Version: %s\r\n", firmware.c_str());
-    fclose(fp); // close the file pointer
+    LOG("Begin logging\r\n");
 #endif
+
 #endif
 
-    // Create an LED to signal mbed activity
-    DigitalOut temp_led(RJ_MISC_LED);
-    temp_led = 1;   // initialize to an ON state
-    
     // Create a new physical hardware communication link
-    CC1101 radio;
-
-    // Get a pointer to the neqly created communiication link
-    CommLink *link;
-    link = &radio;
+    CC1101 radio_900(
+        RJ_SPI_BUS,
+        RJ_PRIMARY_RADIO_CS,
+        RJ_PRIMARY_RADIO_INT
+    );
 
     // Create a Communication Module Object
     CommModule comm;
-    
-    // Let the Communication Module Object know of the physical hardware link
-    comm.setLink(link);
+
+    //comm.TxHandler((CommLink*)&radio_900, &CommLink::sendPacket, 8);
+    comm.TxHandler(primary_radio_tx_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
-    comm.openSocket(8, &callback);
+    comm.openSocket((CommLink*)&radio_900, 8, primary_radio_rx_handle);
+    led3 = 1;
+
+    // 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;
 
-    // Create an example RTP packet
-    RTP_t packet;
-    packet.port = 2;
-    packet.subclass = 1;
-    packet.data[0] = 2;
+    // Send the packet
+    comm.send(dummy_packet);
 
-    // Send the packet (without explicitly having to state which interface the communication will be implemented on - if multiple CommLink objects were present)
-    comm.send(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((CommLink*)&radio_900, 7, primary_radio_rx_handle);
 
     // Enable watchdog timer
-    Watchdog watchdog;
-    watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
-    
-    // Variable for the first thread's status after each delay period
-    osStatus status;
+    //Watchdog watchdog;
+    //watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
+
+    led2 = 0;
+
+
+    for (int i=1; i<=10000000; i*=10) {
+        std::printf("Itterations: %u\r\n", i);
+        Timer t;
+        t.start();
+        
+        led2 = 1;
+        
+        for(int j=0; j<i; j++) {
+            comm.send(dummy_packet);
+            //osDelay(2);
+        }
+        
+        led2 = 0;
+
+        t.stop();
+        std::printf("Timer Reading: %uus\r\n", t.read_us());
+    }
+
+    std::printf("Done\r\n");
 
     while(1) {
         // Renew the watchdog timer through every itteration
-        watchdog.renew();
-        
-        // Cycle the LED state
-        temp_led = !temp_led;
-        
+        //watchdog.renew();
+        led2 = !led2;
+
         // Delay 1 second
-        status = osDelay(1000);
+        osDelay(1000);
+        led3 != led3;
+        osDelay(300);
     }
 }
\ No newline at end of file