nasrullah nasrullah / Mbed 2 deprecated Nucleo_printf

Dependencies:   mbed

Revision:
2:01696b00d551
Parent:
1:e9d1c42a73ae
--- a/main.cpp	Fri Feb 28 06:52:34 2014 +0000
+++ b/main.cpp	Sun Dec 27 18:36:29 2015 +0000
@@ -1,21 +1,84 @@
 #include "mbed.h"
+#include <string>
 
-//------------------------------------
-// Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
+Serial pc(USBTX, USBRX);
+Serial esp(PA_9,PA_10);
 
-Serial pc(SERIAL_TX, SERIAL_RX);
- 
-DigitalOut myled(LED1);
+
+Timer t;
  
-int main() {
-  int i = 1;
-  pc.printf("Hello World !\n");
-  while(1) { 
-      wait(1);
-      pc.printf("This program runs since %d seconds.\n", i++);
-      myled = !myled;
-  }
+int  count,ended,timeout;
+char buf[1024];
+char snd[255];
+
+void getreply(),SendCMD();
+
+int main()
+{
+
+//int a=34;
+//int cm=1;
+//int mode=1;
+//int port=333;
+
+//char ssid[10]="reborn",psd[15]="sempakkoyak";
+esp.baud(115200);
+pc.baud(115200);
+//pc.puts("Hi! this uses type anytihing\r\n");
+//esp.printf("%s\r\n");
+//esp.printf("AT+RST\r\n");
+//wait(10);
+//esp.printf("AT\r\n");
+//wait(2);
+//esp.printf("AT+CWMODE=3\r\n");
+//wait(2);
+//esp.printf("AT+CWJAP=%c%s%c,%c%s%c\r\n",a,ssid,a,a,psd,a);
+//wait(10);
+//esp.printf("AT+CIPMUX=%i\r\n",cm);
+//wait(5);
+//esp.printf("AT+CIPSERVER=%i,%i\r\n",mode,port);
+//wait(10);
+        strcpy(snd,"AT+CWLAP\r\n");
+        SendCMD();
+      
+        //wait(5);
+        //strcpy(snd,"AT+CWLAP\r\n");
+       // SendCMD();
+        //timeout=3;
+        //wait(10);
+       // getreply();  
+       // pc.printf(buf);
+while(1) 
+{       
+        
+        
+        timeout=3;
+        getreply();  
+        pc.printf(buf);
+      
 }
- 
\ No newline at end of file
+ 
+}
+
+void SendCMD()
+{    
+    esp.printf("%s", snd);    
+} 
+
+void getreply()
+{    
+    memset(buf, '\0', sizeof(buf));
+    t.start();
+    ended=0;count=0;
+    while(!ended) {
+        if(esp.readable()) {
+            buf[count] = esp.getc();count++;
+            }
+        if(t.read() > timeout) {
+                ended = 1;t.stop();t.reset();
+            }
+        }   
+}              
+ 
+ 
+