Skip to content

Commit

Permalink
Updating the demodulator library.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashgti committed Mar 28, 2011
1 parent 871df66 commit f038e44
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 22 deletions.
73 changes: 73 additions & 0 deletions Arduino Xbee Modem/AudioDemodulator/AudioDemodulator.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#define SOFT_MODEM_DEBUG 1
#include <SoftModem.h> // include the library
#include <ctype.h>

SoftModem modem; // create an instance of Softmodem

void setup()
{
Serial.begin(9600);
modem.begin(); // Setup () call to begin at
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(1, OUTPUT);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}

unsigned long time = 0;

void loop()
{
if (time < millis()) {
Serial.print("ints: ");
Serial.print(modem.ints);
Serial.print(":");
Serial.println(modem._ints);
Serial.print("errs: ");
Serial.print(modem.errs, DEC);
Serial.print(":");
Serial.println(modem._errs, DEC);
time = millis() + 10000;
}
while (modem.available()) { // Make sure iPhone is receiving data from
int c = modem.read(); // Read 1byte
if (isprint(c)) {
Serial.print("received: ");
Serial.println((char) c); // send to PC
}
else {
Serial.print("("); // Hex printable characters are displayed in
Serial.print(c, HEX );
Serial.println(")");
}
}
while (Serial.available()) { // Make sure that the PC receives data from
char c = Serial.read(); // Read 1byte
Serial.print("r: ");
Serial.println(c);
if (c == 'c') {
modem.begin();
delay(100);
modem.write(c);
}
#ifdef SOFT_MODEM_DEBUG
else if (c == 'a') {
Serial.print("ints: ");
Serial.print(modem.ints);
Serial.print(":");
Serial.println(modem._ints);
Serial.print("errs: ");
Serial.print(modem.errs, DEC);
Serial.print(":");
Serial.println(modem._errs, DEC);
}
else if (c == 'v') {
modem.demodulateTest();
}
#endif
else
modem.write(c); // send to iPhone
}
}
26 changes: 26 additions & 0 deletions Arduino Xbee Modem/AudioDemodulator/data/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#######################################
# Syntax Coloring Map For SoftModem
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################
SoftModem KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
end KEYWORD2
available KEYWORD2
read KEYWORD2
write KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################
16 changes: 2 additions & 14 deletions Arduino Xbee Modem/SoftModem/SoftModem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ ISR(TIMER2_COMPA_vect)
#endif
}

int SoftModem::available()
uint8_t SoftModem::available(void)
{
return (_recvBufferTail + SOFT_MODEM_MAX_RX_BUFF - _recvBufferHead) & (SOFT_MODEM_MAX_RX_BUFF - 1);
}

int SoftModem::read()
int SoftModem::read(void)
{
if(_recvBufferHead == _recvBufferTail)
return -1;
Expand All @@ -262,18 +262,6 @@ int SoftModem::read()
return d;
}

int SoftModem::peek()
{
if(_recvBufferHead == _recvBufferTail)
return -1;
return _recvBuffer[_recvBufferHead];
}

void SoftModem::flush()
{
_recvBufferHead = _recvBufferTail = 0;
}

void SoftModem::modulate(uint8_t b)
{
uint8_t cnt,tcnt,tcnt2,adj;
Expand Down
14 changes: 6 additions & 8 deletions Arduino Xbee Modem/SoftModem/SoftModem.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SoftModem_h
#define SoftModem_h

#include <Stream.h>
#include <Print.h>
#include <inttypes.h>

//#define SOFT_MODEM_BAUD_RATE (126)
Expand Down Expand Up @@ -45,9 +45,9 @@
// 1 stop bit (HIGH)
// 1 push bit (HIGH)

#define SOFT_MODEM_DEBUG (0)
#define SOFT_MODEM_DEBUG (1)

class SoftModem : public Stream
class SoftModem : public Print
{
private:
volatile uint8_t *_txPortReg;
Expand All @@ -67,11 +67,9 @@ class SoftModem : public Stream
~SoftModem();
void begin(void);
void end(void);
virtual int available();
virtual int read();
virtual void flush();
virtual int peek();
virtual void write(uint8_t data);
uint8_t available(void);
int read(void);
void write(uint8_t data);
void demodulate(void);
void recv(void);
static SoftModem *activeObject;
Expand Down

0 comments on commit f038e44

Please sign in to comment.