'SmOuse' / Mbed 2 deprecated SerialPassthroughcjsESP8266

Dependencies:   mbed

Fork of SerialPassthroughcjsESP8266 by chris stevens

Files at this revision

API Documentation at this revision

Comitter:
cstevens
Date:
Tue Jun 07 19:37:59 2016 +0000
Parent:
6:dc4c165f6b53
Child:
8:34cc66421054
Commit message:
added comments and changed name to reflect newer specialist role of the code on the CWM for testing the ESP units.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jun 07 16:19:17 2016 +0000
+++ b/main.cpp	Tue Jun 07 19:37:59 2016 +0000
@@ -1,11 +1,18 @@
+/* Simpler prog based on the serial passthrough code to enable a command line driven test of esp8266
+* wifi modules.
+* NB this uses the mbed sleep() command to form a low power system but on some MCUs this is a problem
+* this works fine on an lpc1768 but not as yet on the KL25Z
+*/
 #include "mbed.h"
 
-RawSerial  pc(USBTX, USBRX);
-RawSerial  dev(p28,p27);
-DigitalOut led1(LED1);
-DigitalOut led4(LED4);
+RawSerial  pc(USBTX, USBRX); // serial terminal for the pc connection
+RawSerial  dev(p28,p27); // serial uart for connecting to the esp8266 tx,rx NB mbed tx must connect ot esp rx and vice versa
+DigitalOut led1(LED1); // twp leds  
+DigitalOut led4(LED4); // to allow visual check of bidirectional comms
 DigitalOut rst(p26);
 
+// subroutine to run anytime a serial interrupt arrives from the device
+// this basically passes everything thatthe device produces on to the pc terminal screen
 void dev_recv()
 {
     led1 = !led1;
@@ -13,7 +20,10 @@
         pc.putc(dev.getc());
     }
 }
-
+// subroutine to service the serial interrupt on the pc connection
+// this is a bit more complex - it takes what the use sends on the pc and copies it on to the device 
+// the esp should echo these straight back to the the pc if all is well
+// this also detects the end of command character which is ascii 13 (0x0d) adn adds a linefeed after it =asscii 10 (0x0a)
 void pc_recv()
 {
     char c;
@@ -22,7 +32,7 @@
         c=pc.getc();
         dev.putc(c);
         //pc.putc(c); // echo back
-        if(c==13) {dev.putc(10);
+        if(c==13) {dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc
         pc.putc(10);
             }
     }