Communicate to bluetooth devices or wifi per at-commands

Dependents:   Nucleo_bt

Revision:
4:96aa57261092
Parent:
3:cdabd56aec53
Child:
5:31306be5fde6
--- a/at.cpp	Sun Aug 19 16:58:17 2018 +0000
+++ b/at.cpp	Sun Aug 26 10:50:45 2018 +0000
@@ -10,9 +10,12 @@
 
 Serial atserial0(TX, RX); //UART1
 Serial atserial1(TX1, RX1); //UART6
+Serial terminal(USBTX, USBRX); //UART Terminal
 
 atterm at0;
 atterm at1;
+atterm pc;
+
 Timer t;
 
 void CallBack0()
@@ -49,6 +52,23 @@
     }
 }
 
+void CallBack2()
+{
+    pc.sign = terminal.getc();
+
+
+    if(pc.sign != '\r')  {  //with no linefeed and carriage return, string is written in buffer
+        pc.buffer[at1.a] = pc.sign;
+        pc.a ++;
+    } else {   //if cr and lf were received, the content of buffer is send to atcommand device
+
+        if(at1.off == 0)  {
+            terminal.printf("Read: %s\r\n", pc.buffer); // via printf formatted as string for debug use
+        }
+
+    }
+}
+
 void atterm::debug_off(bool l)
 {
     if(l) atterm::off = 1;
@@ -95,11 +115,28 @@
 
 }
 
+void atterm::pc_send(char *format, char *buf)
+{
+    terminal.printf(format, buf);
+}
+
+void atterm::device_init2(unsigned long baud, _IRQ interrupt)
+{
+    atterm::debug_off(1);
+    if(interrupt == ON)  {
+        terminal.attach(&CallBack2);
+    }
+    terminal.baud(baud);
+    pc.pc_send("*****Terminal*******\r\n", "");
+
+}
+
+
 char *atterm::getAnswer(uint32_t timeout)
 {
     int b = 0;
     uint32_t t_time = 0;
-    char sign, sign1;
+    char sign, sign1, sign2;
 
     memset(read_timed_buffer, 0, sizeof(read_timed_buffer));
 
@@ -118,6 +155,13 @@
             read_timed_buffer[b] = sign1;
             b ++;
         }
+        
+        else if(terminal.readable())  {
+            sign2 = terminal.getc();
+            read_timed_buffer[b] = sign2;
+            b ++;
+        }
+        
         if((t.read_ms() - t_time) > timeout)  {
             t.stop();
             t.reset();