/* ======================================================= ECE 320 Final Project: Digital Modem (Transmitter Part) by Matthew J Perry, Andi Susanto ------------------------------------------------------- Modulation scheme : BPSK Carrier Frequency : 8800Hz */ #include "dsp.h" #define SymLen 32 #define ByteLen 8 #define HEADER 0xC3 #define INBYTE 1 #define BLOCK_LEN 2 #define COSINE_LEN 5 #define HWRAP(i) ((i) & 7) #define HINCR(i) i = HWRAP(i + 1) #define HDECR(i) i = HWRAP(i - 1) short cosine[] = // cos with freq 2*pi/5 { 32767, 10126, -26510, -26510, 10126, }; short data[] = { HEADER, // header -1, // char to be sent (undefined for now) }; main() { used_recv_chans = 0; used_xmit_chans = 1; xmit_append = 1; xmit_prefix = "../receiver/in"; short *Rcvptr, *Xmitptr; short i, j; short symbol; short ttlBack = 0; short noData = 1; short writeDone = 1; short phase = 0; short curbyte = 0; short numSend = 1; char *greeting = "\n\r" "ECE320 Transmitter\n\r" "------------------\n\r" "> "; unsigned char curbit = 1<<7; for (i = 0; greeting[i]; i++) SerialTX(greeting[i]); while ( 1 ) { WaitAudio(&Rcvptr, &Xmitptr); i = 0; while (i < BlockLen) { if (writeDone) { // We transmitted all the bits of the previous data. // Get a new one and start at the front. data[INBYTE] = SerialRX(); if (data[INBYTE] == -1) noData = 1; // nothing typed, send NULL else { // echo what they typed back to the serial port // and start writing data/header to the output chan. if (data[INBYTE] == 0x08) { // Backspace => delete character if (ttlBack>0) { SerialTX(0x08); SerialTX(0x20); SerialTX(0x08); ttlBack--; } } else if (data[INBYTE] == 0x13) { // Enter Key SerialTX('\n'); SerialTX('\r'); SerialTX('>'); SerialTX(' '); ttlBack = 0; data[INBYTE] = '\n'; } else { SerialTX(data[INBYTE]); ttlBack++; } curbit = 1 << 7; curbyte = 0; writeDone = 0; noData = 0; } } // BPSK: -1 or +1 volts // Convert bit 0 as -32767 and bit 1 as 32767 if (noData) symbol = (i < SymLen) ? -32767 : 32767; else if ((data[curbyte] & curbit) == 0) symbol = -32767; else symbol = 32767; // SymLen samples/symbol, modulated with a cosine for (j = 0; j < SymLen; i++, j++) { Xmitptr[6*i] = _smpy(symbol, cosine[phase]); Xmitptr[6*i+1] = Xmitptr[6*i]; if (++phase >= COSINE_LEN) phase = 0; } // Go to next bit in the sequence if (!noData) { numSend--; if (numSend == 0) { curbit >>= 1; if (curbyte == INBYTE) numSend = 3; else numSend = 1; } if (curbit == 0) { // finished all this byte's bits, go to next byte curbit = 1 << 7; curbyte++; if (curbyte == INBYTE) numSend = 3; else { numSend = 1; if (curbyte >= BLOCK_LEN) { // yay, we're done with this sequence writeDone = 1; curbyte = 0; } } } } } } }