Generates RTTY from a GPS receiver
Dependencies: mbed-dsp mbed-rtos mbed
Revision 3:33d80761aa06, committed 2014-01-11
- Comitter:
- adwiens
- Date:
- Sat Jan 11 18:48:08 2014 +0000
- Parent:
- 2:1f19f8e52c75
- Child:
- 4:ed77fd381cc5
- Commit message:
- added ham callsign
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jan 11 05:55:54 2014 +0000
+++ b/main.cpp Sat Jan 11 18:48:08 2014 +0000
@@ -10,15 +10,18 @@
#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 (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 */
-#define RTTY_BAUD (45.45) /* rtty bit rate in bps */
-#define MARK_FREQ (2295) /* mark frequency (1) in hz */
-#define SPACE_FREQ (2125) /* space frequency (0) in hz */
-#define AUDIO_VOL (0.25) /* range 0-1 */
-#define RTTY_NUM_ZEROS (3) /* number of empty characters to append before each rtty message */
+#define RADIO_TX_WAIT (1000) /* time between radio transmissions in ms */
+#define PRINT_NMEA_WAIT (2000) /* time between console debug messages in ms */
+#define CALLSIGN_WAIT (600) /* time between sending amateur radio callsign in s */
+#define AUDIO_FS (8000) /* audio sample rate in hz */
+#define RTTY_BAUD (110) /* rtty bit rate in bps */
+#define MARK_FREQ (2850) /* mark frequency (1) in hz */
+#define SPACE_FREQ (2000) /* space frequency (0) in hz */
+#define AUDIO_VOL (1) /* range 0-1 */
+#define RTTY_NUM_ZEROS_BEFORE (25) /* number of empty characters to append before each rtty message. helps receivers sync. */
+#define RTTY_NUM_ZEROS_AFTER (8) /* number of empty characters to append after each rtty message. */
+#define CALLSIGN "KC0WYS" /* my amateur radio callsign */
+#define CALLSIGN_TAG "HAMID" /* 5-character tag used in the fake nmea sentence */
using namespace std;
@@ -99,7 +102,7 @@
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;
+ rtty_led = !rtty_led;
} else {
dac = 0;
ptt = 1;
@@ -128,17 +131,7 @@
}
}
-// 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.
+// Adds NMEA sentences periodically to a buffer for the other RTTY functions to process.
void rtty_tx_thread(void const *argument)
{
while(1) {
@@ -148,18 +141,37 @@
for (map<string,string>::iterator iter = nmea_data.begin(); iter != nmea_data.end(); ++iter) {
txbuf << (iter->second); // fill the packet with the most recent nmea sentences
}
+ nmea_data.clear(); // empty the map
nmea_data_mutex.unlock();
- rtty_add_padding(); // pad message with empty characters
+ for(int i = 0; i < RTTY_NUM_ZEROS_BEFORE; ++i) { // add empty characters
+ 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 character
+ }
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;
}
- rtty_add_padding();
+ for(int i = 0; i < RTTY_NUM_ZEROS_AFTER; ++i) { // add empty characters
+ 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 character
+ }
while(!txen) Thread::wait(100); // wait for transmission to start
while( txen) Thread::wait(100); // wait for transmission to end
}
}
+// Periodically inserts HAM radio callsign into NMEA sentence map.
+// Required by FCC to send callsign at least every 30 minutes.
+void insert_callsign_thread(void const *argument)
+{
+ while(1) {
+ nmea_data_mutex.lock();
+ nmea_data[CALLSIGN_TAG] = "$" CALLSIGN_TAG "," CALLSIGN "," CALLSIGN "," CALLSIGN ",*00\r\n"; // dummy nmea sentence
+ nmea_data_mutex.unlock();
+ for(int i = 0; i < CALLSIGN_WAIT; ++i) Thread::wait(1000); // wait for CALLSIGN_WAIT seconds
+ }
+}
+
// Writes debug messages periodically to the console. Useful for debug.
void print_nmea_thread(void const *argument)
{
@@ -180,6 +192,7 @@
Thread gps_thread(gps_rx_thread); // gps receive thread
Thread rtty_thread(rtty_tx_thread); // rtty transmit thread
Thread print_thread(print_nmea_thread); // debug print thread
+ Thread callsign_thread(insert_callsign_thread); // amateur callsign thread
gps.baud(GPS_BAUD); // set gps bit rate
gps.attach(&gps_rx_isr); // set up gps receive interrupt service routine
sample_tick.attach_us(&rtty_sample_tick,1000000/AUDIO_FS); // begin generating audio