Radio Structures in OOP

Dependencies:   mbed mbed-rtos

Committer:
jjones646
Date:
Sun Dec 28 06:05:17 2014 +0000
Revision:
2:7d523bdd2f50
Parent:
1:c935902c73ef
Child:
3:dc7e9c6bc26c
outlining communication implementations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jjones646 1:c935902c73ef 1 #include "robot.h"
jjones646 1:c935902c73ef 2
jjones646 2:7d523bdd2f50 3 // Create a file system if needed for writing startup information to the boot log
jjones646 2:7d523bdd2f50 4 #if RJ_BOOT_LOG
jjones646 2:7d523bdd2f50 5 LocalFileSystem local("local"); // Create the local filesystem object
jjones646 2:7d523bdd2f50 6 #endif
jjones646 2:7d523bdd2f50 7
jjones646 2:7d523bdd2f50 8 // Dummy function
jjones646 2:7d523bdd2f50 9 void callback(void const *arg)
jjones646 1:c935902c73ef 10 {
jjones646 2:7d523bdd2f50 11 while(1) {
jjones646 2:7d523bdd2f50 12 // do nothing - function declared for compile testing purposes
jjones646 2:7d523bdd2f50 13 }
jjones646 2:7d523bdd2f50 14 }
jjones646 1:c935902c73ef 15
jjones646 2:7d523bdd2f50 16 // Sets the mbed's baudrate for debugging purposes
jjones646 2:7d523bdd2f50 17 void baud(int baudrate)
jjones646 2:7d523bdd2f50 18 {
jjones646 2:7d523bdd2f50 19 Serial s(USBTX, USBRX);
jjones646 2:7d523bdd2f50 20 s.baud(baudrate);
jjones646 2:7d523bdd2f50 21 }
jjones646 2:7d523bdd2f50 22
jjones646 2:7d523bdd2f50 23 // Main program operations =======================
jjones646 2:7d523bdd2f50 24 int main()
jjones646 2:7d523bdd2f50 25 {
jjones646 2:7d523bdd2f50 26 // Set the baud rate
jjones646 2:7d523bdd2f50 27 baud(57600);
jjones646 2:7d523bdd2f50 28
jjones646 2:7d523bdd2f50 29 /* Old implementation of CC1101 constructor
jjones646 2:7d523bdd2f50 30 CC1101 radio_900(
jjones646 1:c935902c73ef 31 RJ_SPI_BUS,
jjones646 1:c935902c73ef 32 RJ_PRIMARY_RADIO_CS,
jjones646 1:c935902c73ef 33 RJ_TX_LED, RJ_RX_LED,
jjones646 1:c935902c73ef 34 RJ_PRIMARY_RADIO_INT
jjones646 1:c935902c73ef 35 );
jjones646 2:7d523bdd2f50 36 */
jjones646 2:7d523bdd2f50 37
jjones646 2:7d523bdd2f50 38 // Check the mbed's firmware if enabled
jjones646 2:7d523bdd2f50 39 #if RJ_CHECK_FIRMWARE
jjones646 2:7d523bdd2f50 40 // Write any errors to a log file if enabled
jjones646 2:7d523bdd2f50 41 #if RJ_BOOT_LOG
jjones646 2:7d523bdd2f50 42 FILE *fp = fopen("/local/log.txt", "w"); // Open text file for tracking boot sequence results
jjones646 2:7d523bdd2f50 43 if (fp == NULL) {
jjones646 2:7d523bdd2f50 44 error("Could not get pointer to log file\r\n");
jjones646 2:7d523bdd2f50 45 }
jjones646 2:7d523bdd2f50 46 std::string firmware = firmware_version(); // this is from FirmwareHelper.h
jjones646 2:7d523bdd2f50 47 fprintf(fp, "Start Logging...\r\nFirmware Version: %s\r\n", firmware.c_str());
jjones646 2:7d523bdd2f50 48 fclose(fp); // close the file pointer
jjones646 2:7d523bdd2f50 49 #endif
jjones646 2:7d523bdd2f50 50 #endif
jjones646 2:7d523bdd2f50 51
jjones646 2:7d523bdd2f50 52 // Create an LED to signal mbed activity
jjones646 2:7d523bdd2f50 53 DigitalOut temp_led(RJ_MISC_LED);
jjones646 2:7d523bdd2f50 54 temp_led = 1; // initialize to an ON state
jjones646 2:7d523bdd2f50 55
jjones646 2:7d523bdd2f50 56 // Create a new physical hardware communication link
jjones646 2:7d523bdd2f50 57 CC1101 radio;
jjones646 2:7d523bdd2f50 58
jjones646 2:7d523bdd2f50 59 // Get a pointer to the neqly created communiication link
jjones646 2:7d523bdd2f50 60 CommLink *link;
jjones646 2:7d523bdd2f50 61 link = &radio;
jjones646 2:7d523bdd2f50 62
jjones646 2:7d523bdd2f50 63 // Create a Communication Module Object
jjones646 2:7d523bdd2f50 64 CommModule comm;
jjones646 2:7d523bdd2f50 65
jjones646 2:7d523bdd2f50 66 // Let the Communication Module Object know of the physical hardware link
jjones646 2:7d523bdd2f50 67 comm.setLink(link);
jjones646 2:7d523bdd2f50 68
jjones646 2:7d523bdd2f50 69 // 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
jjones646 2:7d523bdd2f50 70 comm.openSocket(8, &callback);
jjones646 2:7d523bdd2f50 71
jjones646 2:7d523bdd2f50 72 // Create an example RTP packet
jjones646 2:7d523bdd2f50 73 RTP_t packet;
jjones646 2:7d523bdd2f50 74 packet.port = 2;
jjones646 2:7d523bdd2f50 75 packet.subclass = 1;
jjones646 2:7d523bdd2f50 76 packet.data[0] = 2;
jjones646 2:7d523bdd2f50 77
jjones646 2:7d523bdd2f50 78 // Send the packet (without explicitly having to state which interface the communication will be implemented on - if multiple CommLink objects were present)
jjones646 2:7d523bdd2f50 79 comm.send(packet);
jjones646 2:7d523bdd2f50 80
jjones646 2:7d523bdd2f50 81 // Enable watchdog timer
jjones646 2:7d523bdd2f50 82 Watchdog watchdog;
jjones646 2:7d523bdd2f50 83 watchdog.set(RJ_WATCHDOG_TIMER_VALUE);
jjones646 2:7d523bdd2f50 84
jjones646 2:7d523bdd2f50 85 // Variable for the first thread's status after each delay period
jjones646 2:7d523bdd2f50 86 osStatus status;
jjones646 1:c935902c73ef 87
jjones646 1:c935902c73ef 88 while(1) {
jjones646 2:7d523bdd2f50 89 // Renew the watchdog timer through every itteration
jjones646 2:7d523bdd2f50 90 watchdog.renew();
jjones646 2:7d523bdd2f50 91
jjones646 2:7d523bdd2f50 92 // Cycle the LED state
jjones646 2:7d523bdd2f50 93 temp_led = !temp_led;
jjones646 2:7d523bdd2f50 94
jjones646 2:7d523bdd2f50 95 // Delay 1 second
jjones646 2:7d523bdd2f50 96 status = osDelay(1000);
jjones646 1:c935902c73ef 97 }
jjones646 1:c935902c73ef 98 }