FTDI Simulator

Dependencies:   mbed

Fork of Wifly_configure by Samuel Mokrani

main.cpp

Committer:
defrost
Date:
2017-01-25
Revision:
2:8b5ff73de8f0
Parent:
1:20eea0789016
Child:
3:cb83f5431e08

File content as of revision 2:8b5ff73de8f0:

#include "mbed.h"

#define MAXINCOMINGBUFF 4096

Serial pc(USBTX, USBRX);
Serial wifi(D8, D2);


int main() {
    int br = 9600;
    int bufflen = 0;
    char buff[256];
    char incomingBuff[4096];
    int incomingbufflen = 0;
    int ii,jj;
    pc.printf("\n\n\rTest Wifly!\r\n");
    pc.printf("External Baud Rate: %d\n\n\r", br);
    wifi.baud(br);
    //wait(1);
    
    char c;
    while (1) 
    {
        while(pc.readable()){
            c = pc.getc();
            buff[bufflen] = c;
            bufflen++;
            
            pc.printf("%c", c);
            
            if(c == 13){
                // Send a whole string:
                for(ii=0;ii<bufflen;ii++){
                    wifi.putc(buff[ii]);
                }
                bufflen = 0;
                pc.printf("\r");
            }
            
            /*pc.printf("%c",c);
            if(c == '\r'){
                pc.printf("\n");
            }*/
        }
        while(wifi.readable()){
            if(bufflen == 0){
                if(incomingbufflen == 0){
                    pc.putc(wifi.getc());
                }else{
                    for(jj=0;jj<incomingbufflen;jj++){
                        pc.putc(incomingBuff[jj]);
                    }
                    incomingbufflen = 0;
                    pc.putc(wifi.getc());
                }
            }else{
                if(incomingbufflen < MAXINCOMINGBUFF){
                    incomingBuff[incomingbufflen] = wifi.getc();
                    incomingbufflen++;
                }
                // data is lost
                wifi.getc();
            }
        }
    }
}