Communicate to bluetooth devices or wifi per at-commands

Dependents:   Nucleo_bt

at.cpp

Committer:
rainerraul
Date:
2018-08-13
Revision:
0:413f3c13a00a
Child:
1:ce7fb335aa1b

File content as of revision 0:413f3c13a00a:


#include "mbed.h"
#include "at.h"

#define TX PA_9
#define RX PA_10

#define TX1 PC_6
#define RX1 PC_7

Serial atserial0(TX, RX); //UART1
Serial atserial1(TX1, RX1); //UART6

atterm at0;
atterm at1;

void CallBack0()
{
    at0.sign = atserial0.getc();


    if(at0.sign != '\r')  {  //with no linefeed and carriage return, string is written in buffer
        at0.buffer[at0.a] = at0.sign;
        at0.a ++;
    } else {   //if user typed in cr and lf, the content of buffer is send to atcommand device

        if(at0.off == 0)  {
            atserial0.printf("Read: %s\r\n", at0.buffer); // via printf formatted as string for debug use
        }

    }
}

void CallBack1()
{
    at1.sign = atserial1.getc();


    if(at1.sign != '\r')  {  //with no linefeed and carriage return, string is written in buffer
        at1.buffer[at1.a] = at1.sign;
        at1.a ++;
    } else {   //if user typed in cr and lf, the content of buffer is send to atcommand device

        if(at1.off == 0)  {
            atserial1.printf("Read: %s\r\n", at1.buffer); // via printf formatted as string for debug use
        }

    }
}

void atterm::debug_off(bool l)
{
    if(l) atterm::off = 1;
    if(!l) atterm::off = 0;
}

void atterm::at_send(char *format, char *buf)
{
    atserial0.printf(format, buf);
}

void atterm::clear()
{
    memset(atterm::buffer, 0, sizeof(atterm::buffer)); //set buffer to 0, for next clean read
    atterm::a = 0; //index pointer to zero

}

void atterm::device_init(unsigned long baud)
{
    atterm::debug_off(1);
    atserial0.attach(&CallBack0);
    atserial0.baud(baud);
    atserial0.printf("AT\r\n");

}

void atterm::at_send1(char *format, char *buf)
{
    atserial1.printf(format, buf);
}



void atterm::device_init1(unsigned long baud)
{
    atterm::debug_off(1);
    atserial1.attach(&CallBack1);
    atserial1.baud(baud);
    atserial1.printf("AT\r\n");


}