Generates RTTY from a GPS receiver

Dependencies:   mbed-dsp mbed-rtos mbed

Revision:
2:1f19f8e52c75
Parent:
1:07d7070e9252
Child:
3:33d80761aa06
--- a/main.cpp	Sat Jan 11 05:46:49 2014 +0000
+++ b/main.cpp	Sat Jan 11 05:55:54 2014 +0000
@@ -10,7 +10,7 @@
 #define GPS_CB_SIZE (16) /* size of gps circular buffer in characters */
 #define RTTY_CB_SIZE (2048) /* characters in rtty buffer */
 #define GPS_BAUD (9600) /* gps serial port speed in bps */
-#define RADIO_TX_WAIT (20000) /* time between radio transmissions in ms */
+#define RADIO_TX_WAIT (5000) /* time between radio transmissions in ms */
 #define RADIO_KEYUP_DELAY (1000) /* time to wait for radio transmitter to turn on */
 #define PRINT_NMEA_WAIT (2000) /* time between console debug messages */
 #define AUDIO_FS (22050) /* audio sample rate in hz */
@@ -98,8 +98,12 @@
         angle += 2 * PI * ifreq / AUDIO_FS;
         if(angle > 2 * PI) angle -= 2*PI;
         dac = (arm_sin_f32(angle) + 1.0) / 2.0 * AUDIO_VOL; // write sample to dac
+        ptt = 0;
+        rtty_led = 1;
     } else {
         dac = 0;
+        ptt = 1;
+        rtty_led = 0;
     }
 }
 
@@ -124,6 +128,15 @@
     }
 }
 
+// Adds empty characters to RTTY buffer.
+void rtty_add_padding()
+{
+    for(int i = 0; i < RTTY_NUM_ZEROS; ++i) {
+        if(++r_cb_thr_i >= RTTY_CB_SIZE) r_cb_thr_i = 0; // incr/loop circular buffer index
+        r_cb[r_cb_thr_i] = 0; // append a zero
+    }
+}
+
 // Adds NMEA sentences periodically to a buffer for the other RTTY
 // functions to process.
 void rtty_tx_thread(void const *argument)
@@ -136,18 +149,14 @@
             txbuf << (iter->second); // fill the packet with the most recent nmea sentences
         }
         nmea_data_mutex.unlock();
-        for(int i = 0; i < RTTY_NUM_ZEROS; ++i) {
-            if(++r_cb_thr_i >= RTTY_CB_SIZE) r_cb_thr_i = 0; // incr/loop circular buffer index
-            r_cb[r_cb_thr_i] = 0; // append a zero
-        }
+        rtty_add_padding(); // pad message with empty characters
         for(const char* it = txbuf.str().c_str(); *it; ++it) { // add all characters to buffer
             if(++r_cb_thr_i >= RTTY_CB_SIZE) r_cb_thr_i = 0; // incr/loop circular buffer index
             r_cb[r_cb_thr_i] = *it;
         }
-        for(int i = 0; i < RTTY_NUM_ZEROS; ++i) {
-            if(++r_cb_thr_i >= RTTY_CB_SIZE) r_cb_thr_i = 0; // incr/loop circular buffer index
-            r_cb[r_cb_thr_i] = 0; // append a zero
-        }
+        rtty_add_padding();
+        while(!txen) Thread::wait(100); // wait for transmission to start
+        while( txen) Thread::wait(100); // wait for transmission to end
     }
 }