Xiaofei Qiu / Xbee

Xbee.cpp

Committer:
Xiaofei
Date:
2015-11-28
Revision:
26:282047f761ea
Parent:
25:78fdcbf803c9
Child:
27:6bd26aff87e6

File content as of revision 26:282047f761ea:

#pragma once
#include "Xbee.h"

Serial pc(USBTX, USBRX);

Xbee::Xbee(PinName tx, PinName rx , PinName rst):_xbee(tx,rx),_rst(rst)
{
    _xbee.baud(9600);
}

void Xbee::Reset()
{
    _rst = 0;
    wait(0.01);
    _rst = 1;
    wait(0.01);
    
}

void Xbee::Send(const char& buffer)
{
    while(1)
    {
        if(_xbee.writeable())
        {
            _xbee.putc(buffer);
            if(_xbee.getc() == '.')
            {
                break;
            }
        }
    }
}

void Xbee::Recv(char& buffer)
{
    while(1)
    {
        if(_xbee.readable())
        {
            buffer = _xbee.getc();
            break;
        }
        else
        {
            _xbee.putc('.');
        }
    }
    
}