just to test TO BE DELETED
Dependencies: mbed
main.cpp@0:67f12256c9d4, 2018-12-06 (annotated)
- Committer:
- eboily1
- Date:
- Thu Dec 06 21:04:26 2018 +0000
- Revision:
- 0:67f12256c9d4
temp for test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eboily1 | 0:67f12256c9d4 | 1 | #include "mbed.h" |
eboily1 | 0:67f12256c9d4 | 2 | |
eboily1 | 0:67f12256c9d4 | 3 | RawSerial pc(D1, D0, 115200); |
eboily1 | 0:67f12256c9d4 | 4 | #define OK 0 |
eboily1 | 0:67f12256c9d4 | 5 | #define TOO_LONG 1 |
eboily1 | 0:67f12256c9d4 | 6 | #define TIMEOUT 2 |
eboily1 | 0:67f12256c9d4 | 7 | |
eboily1 | 0:67f12256c9d4 | 8 | int readLine(RawSerial serialport, char * bufferin, int maxlenght, int Timeout) |
eboily1 | 0:67f12256c9d4 | 9 | { |
eboily1 | 0:67f12256c9d4 | 10 | Timer timer; |
eboily1 | 0:67f12256c9d4 | 11 | timer.start(); |
eboily1 | 0:67f12256c9d4 | 12 | int bytesReaded = 0; |
eboily1 | 0:67f12256c9d4 | 13 | |
eboily1 | 0:67f12256c9d4 | 14 | while (timer.read_ms() < Timeout) |
eboily1 | 0:67f12256c9d4 | 15 | { |
eboily1 | 0:67f12256c9d4 | 16 | if (serialport.readable()) |
eboily1 | 0:67f12256c9d4 | 17 | { |
eboily1 | 0:67f12256c9d4 | 18 | bufferin[bytesReaded] = serialport.getc(); |
eboily1 | 0:67f12256c9d4 | 19 | if (bufferin[bytesReaded] == '\n') |
eboily1 | 0:67f12256c9d4 | 20 | { |
eboily1 | 0:67f12256c9d4 | 21 | if (bytesReaded < maxlenght-1) |
eboily1 | 0:67f12256c9d4 | 22 | bufferin[bytesReaded++] = 0; |
eboily1 | 0:67f12256c9d4 | 23 | return OK; |
eboily1 | 0:67f12256c9d4 | 24 | } |
eboily1 | 0:67f12256c9d4 | 25 | bytesReaded++; |
eboily1 | 0:67f12256c9d4 | 26 | if (bytesReaded >= maxlenght) |
eboily1 | 0:67f12256c9d4 | 27 | return TOO_LONG; |
eboily1 | 0:67f12256c9d4 | 28 | } |
eboily1 | 0:67f12256c9d4 | 29 | } |
eboily1 | 0:67f12256c9d4 | 30 | return TIMEOUT; |
eboily1 | 0:67f12256c9d4 | 31 | } |
eboily1 | 0:67f12256c9d4 | 32 | |
eboily1 | 0:67f12256c9d4 | 33 | |
eboily1 | 0:67f12256c9d4 | 34 | int main() |
eboily1 | 0:67f12256c9d4 | 35 | { |
eboily1 | 0:67f12256c9d4 | 36 | char buffer[128]; |
eboily1 | 0:67f12256c9d4 | 37 | pc.printf("start\r"); |
eboily1 | 0:67f12256c9d4 | 38 | while(true) |
eboily1 | 0:67f12256c9d4 | 39 | { |
eboily1 | 0:67f12256c9d4 | 40 | if(pc.readable()) |
eboily1 | 0:67f12256c9d4 | 41 | { |
eboily1 | 0:67f12256c9d4 | 42 | readLine(pc, buffer, 128, 600); |
eboily1 | 0:67f12256c9d4 | 43 | //pc.scanf("%s", buffer); |
eboily1 | 0:67f12256c9d4 | 44 | pc.printf(buffer); |
eboily1 | 0:67f12256c9d4 | 45 | } |
eboily1 | 0:67f12256c9d4 | 46 | } |
eboily1 | 0:67f12256c9d4 | 47 | |
eboily1 | 0:67f12256c9d4 | 48 | } |