Communicate to bluetooth devices or wifi per at-commands

Dependents:   Nucleo_bt

Revision:
0:413f3c13a00a
Child:
1:ce7fb335aa1b
diff -r 000000000000 -r 413f3c13a00a at.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/at.cpp	Mon Aug 13 20:27:21 2018 +0000
@@ -0,0 +1,93 @@
+
+#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");
+
+
+}
\ No newline at end of file