WWW serwer SKM
Dependencies: SDFileSystem mbed
Fork of SKM_SERWER_WWW by
main.cpp@1:623f51ea713b, 2015-02-23 (annotated)
- Committer:
- erigow01
- Date:
- Mon Feb 23 15:57:49 2015 +0000
- Revision:
- 1:623f51ea713b
- Parent:
- 0:f682dcf80f00
- Child:
- 2:8d5a84fcf90c
Improved!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 0:f682dcf80f00 | 1 | #include "mbed.h" |
andcor02 | 0:f682dcf80f00 | 2 | //Simple program allowing user to send messages from mbed COM out through UART to another UART COM. |
andcor02 | 0:f682dcf80f00 | 3 | //Andrea Corrado |
erigow01 | 1:623f51ea713b | 4 | //Updated 2015/02/23 Eric Gowland - Process on line termination. |
erigow01 | 1:623f51ea713b | 5 | |
erigow01 | 1:623f51ea713b | 6 | |
andcor02 | 0:f682dcf80f00 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
andcor02 | 0:f682dcf80f00 | 8 | Serial uart (PTC17, PTC16); |
andcor02 | 0:f682dcf80f00 | 9 | |
erigow01 | 1:623f51ea713b | 10 | char* PARSE_TRIGGERS = "\r\n"; |
erigow01 | 1:623f51ea713b | 11 | int PARSE_TRIGGERS_LENGTH = 2; |
erigow01 | 1:623f51ea713b | 12 | int MAX_BUFFER_SIZE = 128; |
andcor02 | 0:f682dcf80f00 | 13 | |
erigow01 | 1:623f51ea713b | 14 | bool isTriggerChar(char c); |
erigow01 | 1:623f51ea713b | 15 | |
erigow01 | 1:623f51ea713b | 16 | int main() { |
erigow01 | 1:623f51ea713b | 17 | char buffer[MAX_BUFFER_SIZE]; |
erigow01 | 1:623f51ea713b | 18 | int pos = 0; |
erigow01 | 1:623f51ea713b | 19 | char thisChar = 0; |
andcor02 | 0:f682dcf80f00 | 20 | while(1) { |
andcor02 | 0:f682dcf80f00 | 21 | if (pc.readable()) { |
erigow01 | 1:623f51ea713b | 22 | thisChar = pc.getc(); |
erigow01 | 1:623f51ea713b | 23 | //Echo |
erigow01 | 1:623f51ea713b | 24 | pc.putc(thisChar); |
erigow01 | 1:623f51ea713b | 25 | //Buffer |
erigow01 | 1:623f51ea713b | 26 | buffer[pos++] = thisChar; |
erigow01 | 1:623f51ea713b | 27 | //If trigger or buffer overflow, output and reset buffer... |
erigow01 | 1:623f51ea713b | 28 | if(pos >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) { |
erigow01 | 1:623f51ea713b | 29 | pc.printf("\r\n"); |
erigow01 | 1:623f51ea713b | 30 | uart.printf("%.*s\r\n", pos, buffer); |
erigow01 | 1:623f51ea713b | 31 | pos = 0; |
erigow01 | 1:623f51ea713b | 32 | } |
andcor02 | 0:f682dcf80f00 | 33 | } |
andcor02 | 0:f682dcf80f00 | 34 | } |
andcor02 | 0:f682dcf80f00 | 35 | } |
erigow01 | 1:623f51ea713b | 36 | |
erigow01 | 1:623f51ea713b | 37 | bool isTriggerChar(char c) { |
erigow01 | 1:623f51ea713b | 38 | for (int i = 0; i < PARSE_TRIGGERS_LENGTH; i++) { |
erigow01 | 1:623f51ea713b | 39 | if(c == PARSE_TRIGGERS[i]) { |
erigow01 | 1:623f51ea713b | 40 | return true; |
erigow01 | 1:623f51ea713b | 41 | } |
erigow01 | 1:623f51ea713b | 42 | } |
erigow01 | 1:623f51ea713b | 43 | return false; |
erigow01 | 1:623f51ea713b | 44 | } |