Radio Structures in OOP

Dependencies:   mbed mbed-rtos

main.cpp

Committer:
jjones646
Date:
2014-12-28
Revision:
2:7d523bdd2f50
Parent:
1:c935902c73ef
Child:
3:dc7e9c6bc26c

File content as of revision 2:7d523bdd2f50:

#include "robot.h"

// Create a file system if needed for writing startup information to the boot log
#if RJ_BOOT_LOG
LocalFileSystem local("local");     // Create the local filesystem object
#endif

// Dummy function
void callback(void const *arg)
{
    while(1) {
        // do nothing - function declared for compile testing purposes
    }
}

// Sets the mbed's baudrate for debugging purposes
void baud(int baudrate)
{
    Serial s(USBTX, USBRX);
    s.baud(baudrate);
}

// Main program operations =======================
int main()
{
    // 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
// 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
#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;

    // Create a Communication Module Object
    CommModule comm;
    
    // Let the Communication Module Object know of the physical hardware link
    comm.setLink(link);

    // 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);

    // Create an example RTP packet
    RTP_t packet;
    packet.port = 2;
    packet.subclass = 1;
    packet.data[0] = 2;

    // 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);

    // Enable watchdog timer
    Watchdog watchdog;
    watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
    
    // Variable for the first thread's status after each delay period
    osStatus status;

    while(1) {
        // Renew the watchdog timer through every itteration
        watchdog.renew();
        
        // Cycle the LED state
        temp_led = !temp_led;
        
        // Delay 1 second
        status = osDelay(1000);
    }
}