FTDI Simulator
Dependencies: mbed
Fork of Wifly_configure by
main.cpp@2:8b5ff73de8f0, 2017-01-25 (annotated)
- Committer:
- defrost
- Date:
- Wed Jan 25 22:25:06 2017 +0000
- Revision:
- 2:8b5ff73de8f0
- Parent:
- 1:20eea0789016
- Child:
- 3:cb83f5431e08
- tried to save incoming data whilst the user is typing, doesn't work great
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:a63053b8abc0 | 1 | #include "mbed.h" |
samux | 0:a63053b8abc0 | 2 | |
defrost | 2:8b5ff73de8f0 | 3 | #define MAXINCOMINGBUFF 4096 |
defrost | 2:8b5ff73de8f0 | 4 | |
samux | 0:a63053b8abc0 | 5 | Serial pc(USBTX, USBRX); |
defrost | 2:8b5ff73de8f0 | 6 | Serial wifi(D8, D2); |
samux | 0:a63053b8abc0 | 7 | |
samux | 0:a63053b8abc0 | 8 | |
samux | 0:a63053b8abc0 | 9 | int main() { |
defrost | 2:8b5ff73de8f0 | 10 | int br = 9600; |
defrost | 2:8b5ff73de8f0 | 11 | int bufflen = 0; |
defrost | 2:8b5ff73de8f0 | 12 | char buff[256]; |
defrost | 2:8b5ff73de8f0 | 13 | char incomingBuff[4096]; |
defrost | 2:8b5ff73de8f0 | 14 | int incomingbufflen = 0; |
defrost | 2:8b5ff73de8f0 | 15 | int ii,jj; |
defrost | 2:8b5ff73de8f0 | 16 | pc.printf("\n\n\rTest Wifly!\r\n"); |
defrost | 2:8b5ff73de8f0 | 17 | pc.printf("External Baud Rate: %d\n\n\r", br); |
defrost | 2:8b5ff73de8f0 | 18 | wifi.baud(br); |
defrost | 2:8b5ff73de8f0 | 19 | //wait(1); |
samux | 0:a63053b8abc0 | 20 | |
defrost | 2:8b5ff73de8f0 | 21 | char c; |
samux | 0:a63053b8abc0 | 22 | while (1) |
samux | 0:a63053b8abc0 | 23 | { |
defrost | 2:8b5ff73de8f0 | 24 | while(pc.readable()){ |
defrost | 2:8b5ff73de8f0 | 25 | c = pc.getc(); |
defrost | 2:8b5ff73de8f0 | 26 | buff[bufflen] = c; |
defrost | 2:8b5ff73de8f0 | 27 | bufflen++; |
defrost | 2:8b5ff73de8f0 | 28 | |
defrost | 2:8b5ff73de8f0 | 29 | pc.printf("%c", c); |
defrost | 2:8b5ff73de8f0 | 30 | |
defrost | 2:8b5ff73de8f0 | 31 | if(c == 13){ |
defrost | 2:8b5ff73de8f0 | 32 | // Send a whole string: |
defrost | 2:8b5ff73de8f0 | 33 | for(ii=0;ii<bufflen;ii++){ |
defrost | 2:8b5ff73de8f0 | 34 | wifi.putc(buff[ii]); |
defrost | 2:8b5ff73de8f0 | 35 | } |
defrost | 2:8b5ff73de8f0 | 36 | bufflen = 0; |
defrost | 2:8b5ff73de8f0 | 37 | pc.printf("\r"); |
defrost | 2:8b5ff73de8f0 | 38 | } |
defrost | 2:8b5ff73de8f0 | 39 | |
defrost | 2:8b5ff73de8f0 | 40 | /*pc.printf("%c",c); |
defrost | 2:8b5ff73de8f0 | 41 | if(c == '\r'){ |
defrost | 2:8b5ff73de8f0 | 42 | pc.printf("\n"); |
defrost | 2:8b5ff73de8f0 | 43 | }*/ |
defrost | 2:8b5ff73de8f0 | 44 | } |
defrost | 2:8b5ff73de8f0 | 45 | while(wifi.readable()){ |
defrost | 2:8b5ff73de8f0 | 46 | if(bufflen == 0){ |
defrost | 2:8b5ff73de8f0 | 47 | if(incomingbufflen == 0){ |
defrost | 2:8b5ff73de8f0 | 48 | pc.putc(wifi.getc()); |
defrost | 2:8b5ff73de8f0 | 49 | }else{ |
defrost | 2:8b5ff73de8f0 | 50 | for(jj=0;jj<incomingbufflen;jj++){ |
defrost | 2:8b5ff73de8f0 | 51 | pc.putc(incomingBuff[jj]); |
defrost | 2:8b5ff73de8f0 | 52 | } |
defrost | 2:8b5ff73de8f0 | 53 | incomingbufflen = 0; |
defrost | 2:8b5ff73de8f0 | 54 | pc.putc(wifi.getc()); |
defrost | 2:8b5ff73de8f0 | 55 | } |
defrost | 2:8b5ff73de8f0 | 56 | }else{ |
defrost | 2:8b5ff73de8f0 | 57 | if(incomingbufflen < MAXINCOMINGBUFF){ |
defrost | 2:8b5ff73de8f0 | 58 | incomingBuff[incomingbufflen] = wifi.getc(); |
defrost | 2:8b5ff73de8f0 | 59 | incomingbufflen++; |
defrost | 2:8b5ff73de8f0 | 60 | } |
defrost | 2:8b5ff73de8f0 | 61 | // data is lost |
defrost | 2:8b5ff73de8f0 | 62 | wifi.getc(); |
defrost | 2:8b5ff73de8f0 | 63 | } |
defrost | 2:8b5ff73de8f0 | 64 | } |
samux | 0:a63053b8abc0 | 65 | } |
samux | 0:a63053b8abc0 | 66 | } |