QRSS Rx Network receiver. A receiver to sample a segment of RF spectrum and send this data to a server for further processing and display. NXP mbed Design Challenge entry (Honorable Mention). Published in Circuit Cellar, Feb 2012

Dependencies:   NetServices mbed DNSResolver

Committer:
claytong
Date:
Wed Jan 25 20:32:53 2012 +0000
Revision:
0:82ff15078322
1.0 (initial public release)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
claytong 0:82ff15078322 1 /*---------------------------------------------------------------------------
claytong 0:82ff15078322 2
claytong 0:82ff15078322 3 QRSS Receiver Application
claytong 0:82ff15078322 4
claytong 0:82ff15078322 5 by Clayton ZL3TKA/VK1TKA
claytong 0:82ff15078322 6 clayton@isnotcrazy.com
claytong 0:82ff15078322 7
claytong 0:82ff15078322 8 main function
claytong 0:82ff15078322 9
claytong 0:82ff15078322 10 ---------------------------------------------------------------------------*/
claytong 0:82ff15078322 11 // include files
claytong 0:82ff15078322 12
claytong 0:82ff15078322 13 #include "mbed.h"
claytong 0:82ff15078322 14 #include "global.h"
claytong 0:82ff15078322 15 #include "EthernetNetIf.h"
claytong 0:82ff15078322 16 #include "UDPSocket.h"
claytong 0:82ff15078322 17 #include "dnsresolve.h"
claytong 0:82ff15078322 18 #include "gps.h"
claytong 0:82ff15078322 19 #include "BufferSys.h"
claytong 0:82ff15078322 20 #include "I2S_Rx.h"
claytong 0:82ff15078322 21 #include "DSP.h"
claytong 0:82ff15078322 22 #include "comms.h"
claytong 0:82ff15078322 23
claytong 0:82ff15078322 24 // Definitions
claytong 0:82ff15078322 25
claytong 0:82ff15078322 26 // Macros
claytong 0:82ff15078322 27
claytong 0:82ff15078322 28 // Local Data
claytong 0:82ff15078322 29
claytong 0:82ff15078322 30 // Global Data
claytong 0:82ff15078322 31
claytong 0:82ff15078322 32 // Serial port interface to the PC
claytong 0:82ff15078322 33 Serial pc( USBTX, USBRX );
claytong 0:82ff15078322 34
claytong 0:82ff15078322 35 // LEDs
claytong 0:82ff15078322 36 DigitalOut OnLED( LED1 );
claytong 0:82ff15078322 37
claytong 0:82ff15078322 38 // IO
claytong 0:82ff15078322 39 DigitalOut TestOscillator( p21 );
claytong 0:82ff15078322 40 #define TESTOSC_ON 0
claytong 0:82ff15078322 41 #define TESTOSC_OFF 1
claytong 0:82ff15078322 42
claytong 0:82ff15078322 43 // The Buffer pool for audio data
claytong 0:82ff15078322 44 TBufferPool BufferPool;
claytong 0:82ff15078322 45
claytong 0:82ff15078322 46 // The array of buffers for the pool
claytong 0:82ff15078322 47 TBufferData BufferDataArray[NUM_OF_BUFFERS];
claytong 0:82ff15078322 48
claytong 0:82ff15078322 49 // I2S Object
claytong 0:82ff15078322 50 TI2SReceiver AudioInput( BufferPool );
claytong 0:82ff15078322 51
claytong 0:82ff15078322 52 // Communications Object
claytong 0:82ff15078322 53 TCommunications Comms;
claytong 0:82ff15078322 54
claytong 0:82ff15078322 55
claytong 0:82ff15078322 56 // Function Prototypes
claytong 0:82ff15078322 57
claytong 0:82ff15078322 58 //---------------------------------------------------------------------------
claytong 0:82ff15078322 59 // MAIN
claytong 0:82ff15078322 60 //---------------------------------------------------------------------------
claytong 0:82ff15078322 61
claytong 0:82ff15078322 62 //---------------------------------------------------------------------------
claytong 0:82ff15078322 63 //
claytong 0:82ff15078322 64 // Main start routine
claytong 0:82ff15078322 65 // Just starts everything running
claytong 0:82ff15078322 66 //
claytong 0:82ff15078322 67 int main()
claytong 0:82ff15078322 68 {
claytong 0:82ff15078322 69 TDSPProcessor ADCBuffer;
claytong 0:82ff15078322 70 uint32_t uiCurrentTestmode = 0x1234;
claytong 0:82ff15078322 71
claytong 0:82ff15078322 72 // Set up IOs
claytong 0:82ff15078322 73 OnLED = 1;
claytong 0:82ff15078322 74 TestOscillator = TESTOSC_OFF;
claytong 0:82ff15078322 75
claytong 0:82ff15078322 76 // Set up PC port
claytong 0:82ff15078322 77 pc.baud( 38400 );
claytong 0:82ff15078322 78
claytong 0:82ff15078322 79 // Report
claytong 0:82ff15078322 80 printf( "\r\n\r\nQRSS_Rx Application running\r\n" );
claytong 0:82ff15078322 81 printf( "Built " __DATE__ " " __TIME__ "\r\n" );
claytong 0:82ff15078322 82 printf( "System Core Clock = %ld\r\n", SystemCoreClock );
claytong 0:82ff15078322 83
claytong 0:82ff15078322 84 // Add array of buffers to the pool
claytong 0:82ff15078322 85 pc.printf ("Setting up buffer pool with %d buffer of %d samples ...", NUM_OF_BUFFERS, BUFFERSYS_SIZE );
claytong 0:82ff15078322 86 BufferPool.AddNewMsgsToPool( BufferDataArray, NUM_OF_BUFFERS );
claytong 0:82ff15078322 87 printf (" OK\r\n");
claytong 0:82ff15078322 88
claytong 0:82ff15078322 89 // Set up audio receiver
claytong 0:82ff15078322 90 pc.printf ("Initialise the I2S Receiver ...");
claytong 0:82ff15078322 91 AudioInput.Init();
claytong 0:82ff15078322 92 printf (" OK\r\n");
claytong 0:82ff15078322 93
claytong 0:82ff15078322 94 // Set up GPS
claytong 0:82ff15078322 95 pc.printf ("Initialise GPS ...");
claytong 0:82ff15078322 96 GPSModule.Init();
claytong 0:82ff15078322 97 printf (" OK\r\n");
claytong 0:82ff15078322 98
claytong 0:82ff15078322 99 // Set up communications
claytong 0:82ff15078322 100 pc.printf ("Initialise Communications ...");
claytong 0:82ff15078322 101 Comms.Init();
claytong 0:82ff15078322 102 Comms.SetServer( "192.168.0.15" ); // default QRSS Server Address (could be a DNS name)
claytong 0:82ff15078322 103 printf (" OK\r\n");
claytong 0:82ff15078322 104
claytong 0:82ff15078322 105 ADCBuffer.NCOFrequency( TEST_NCO_FREQ );
claytong 0:82ff15078322 106
claytong 0:82ff15078322 107 // echo GPS data out the PC port
claytong 0:82ff15078322 108 while(1)
claytong 0:82ff15078322 109 {
claytong 0:82ff15078322 110 // Poll the sub-systems
claytong 0:82ff15078322 111 Net::poll();
claytong 0:82ff15078322 112 GPSModule.Poll();
claytong 0:82ff15078322 113 Comms.Poll();
claytong 0:82ff15078322 114
claytong 0:82ff15078322 115 // Handle Comms Mode
claytong 0:82ff15078322 116 if ( Comms.Running() )
claytong 0:82ff15078322 117 { // online comms
claytong 0:82ff15078322 118 if ( !AudioInput.Running() )
claytong 0:82ff15078322 119 {
claytong 0:82ff15078322 120 printf( "Starting Processing\r\n" );
claytong 0:82ff15078322 121 ADCBuffer.NCOPhaseInc( Comms.NCOPhaseInc() );
claytong 0:82ff15078322 122 AudioInput.Start();
claytong 0:82ff15078322 123 }
claytong 0:82ff15078322 124 // process and output any received samples
claytong 0:82ff15078322 125 if ( !AudioInput.Empty() )
claytong 0:82ff15078322 126 {
claytong 0:82ff15078322 127 // ADC buffer will be automatically released
claytong 0:82ff15078322 128 AudioInput.Read( ADCBuffer );
claytong 0:82ff15078322 129 // Mix the LO
claytong 0:82ff15078322 130 ADCBuffer.MixLO();
claytong 0:82ff15078322 131 // Filter the result
claytong 0:82ff15078322 132 ADCBuffer.LPF();
claytong 0:82ff15078322 133 // Output the data to the comms module
claytong 0:82ff15078322 134 for ( int ii=0; ii<8; ii++ )
claytong 0:82ff15078322 135 Comms.SendSamples( ADCBuffer.Timestamp(), ADCBuffer.FilteredOutput(ii) );
claytong 0:82ff15078322 136 }
claytong 0:82ff15078322 137 }
claytong 0:82ff15078322 138 else
claytong 0:82ff15078322 139 { // offline comms
claytong 0:82ff15078322 140 if ( AudioInput.Running() )
claytong 0:82ff15078322 141 {
claytong 0:82ff15078322 142 AudioInput.Stop();
claytong 0:82ff15078322 143 printf( "Stopping Processing\r\n" );
claytong 0:82ff15078322 144 }
claytong 0:82ff15078322 145 if ( !AudioInput.Empty() )
claytong 0:82ff15078322 146 { // discard messages
claytong 0:82ff15078322 147 AudioInput.Read( ADCBuffer );
claytong 0:82ff15078322 148 ADCBuffer.Release();
claytong 0:82ff15078322 149 }
claytong 0:82ff15078322 150 }
claytong 0:82ff15078322 151
claytong 0:82ff15078322 152 // Handle Test Modes
claytong 0:82ff15078322 153 if ( Comms.TestMode()!=uiCurrentTestmode )
claytong 0:82ff15078322 154 {
claytong 0:82ff15078322 155 uiCurrentTestmode = Comms.TestMode();
claytong 0:82ff15078322 156 if ( uiCurrentTestmode!=0 )
claytong 0:82ff15078322 157 { // enable test Osc
claytong 0:82ff15078322 158 printf( "Turn ON Test Osc\r\n" );
claytong 0:82ff15078322 159 TestOscillator = TESTOSC_ON;
claytong 0:82ff15078322 160 }
claytong 0:82ff15078322 161 else
claytong 0:82ff15078322 162 { // disable test Osc
claytong 0:82ff15078322 163 printf( "Turn OFF Test Osc\r\n" );
claytong 0:82ff15078322 164 TestOscillator = TESTOSC_OFF;
claytong 0:82ff15078322 165 }
claytong 0:82ff15078322 166 }
claytong 0:82ff15078322 167
claytong 0:82ff15078322 168 // Process Keystrokes - debug only
claytong 0:82ff15078322 169 if( pc.readable() )
claytong 0:82ff15078322 170 {
claytong 0:82ff15078322 171 int iCharIn = pc.getc();
claytong 0:82ff15078322 172 switch ( iCharIn )
claytong 0:82ff15078322 173 {
claytong 0:82ff15078322 174 case'1':
claytong 0:82ff15078322 175 printf( "Turn on Test Osc\r\n" );
claytong 0:82ff15078322 176 TestOscillator = TESTOSC_ON;
claytong 0:82ff15078322 177 break;
claytong 0:82ff15078322 178 case '2':
claytong 0:82ff15078322 179 printf( "Turn off Test Osc\r\n" );
claytong 0:82ff15078322 180 TestOscillator = TESTOSC_OFF;
claytong 0:82ff15078322 181 break;
claytong 0:82ff15078322 182 case '7':
claytong 0:82ff15078322 183 printf( "AudioInput Start\r\n" );
claytong 0:82ff15078322 184 AudioInput.Start();
claytong 0:82ff15078322 185 break;
claytong 0:82ff15078322 186 case '8':
claytong 0:82ff15078322 187 printf( "AudioInput Stop\r\n" );
claytong 0:82ff15078322 188 AudioInput.Stop();
claytong 0:82ff15078322 189 break;
claytong 0:82ff15078322 190 case '9':
claytong 0:82ff15078322 191 AudioInput.Report();
claytong 0:82ff15078322 192 break;
claytong 0:82ff15078322 193 case 'x':
claytong 0:82ff15078322 194 ADCBuffer.NCOFrequency( 15000 );
claytong 0:82ff15078322 195 break;
claytong 0:82ff15078322 196 case 'y':
claytong 0:82ff15078322 197 ADCBuffer.NCOFrequency( -15000 );
claytong 0:82ff15078322 198 break;
claytong 0:82ff15078322 199 case 'z':
claytong 0:82ff15078322 200 ADCBuffer.NCOFrequency( 15600 );
claytong 0:82ff15078322 201 break;
claytong 0:82ff15078322 202 }
claytong 0:82ff15078322 203 }
claytong 0:82ff15078322 204 }
claytong 0:82ff15078322 205
claytong 0:82ff15078322 206 }
claytong 0:82ff15078322 207
claytong 0:82ff15078322 208 //---------------------------------------------------------------------------
claytong 0:82ff15078322 209 // END
claytong 0:82ff15078322 210 //---------------------------------------------------------------------------
claytong 0:82ff15078322 211
claytong 0:82ff15078322 212