Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial SDFileSystem mbed wave_player
main.cpp@10:071b7cc8b0ff, 2017-05-03 (annotated)
- Committer:
- Thomas Cauwelier
- Date:
- Wed May 03 09:40:14 2017 +0200
- Revision:
- 10:071b7cc8b0ff
- Parent:
- 9:d95984ce5de9
- Child:
- 11:e462ce7a42b9
add consts to manchester methods
uart thread test force reading 2 bytes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Desertification | 1:6b839581dc9f | 1 | |
Desertification | 1:6b839581dc9f | 2 | #include "mbed.h" |
Thomas Cauwelier |
6:0e1973fdfe28 | 3 | #include "rtos.h" |
Thomas Cauwelier |
9:d95984ce5de9 | 4 | #include "Manchester.h" |
Thomas Cauwelier |
6:0e1973fdfe28 | 5 | |
Thomas Cauwelier |
9:d95984ce5de9 | 6 | Serial out(p9, p10, 3200); //p9 |
Thomas Cauwelier |
9:d95984ce5de9 | 7 | Serial in(p13, p14, 3200); //p14 |
Thomas Cauwelier |
6:0e1973fdfe28 | 8 | |
Thomas Cauwelier |
10:071b7cc8b0ff | 9 | char *read_2_bytes(Serial *serial, char out[2]) { |
Thomas Cauwelier |
10:071b7cc8b0ff | 10 | int i = 0; |
Thomas Cauwelier |
10:071b7cc8b0ff | 11 | while (true) { |
Thomas Cauwelier |
10:071b7cc8b0ff | 12 | while (!serial->readable()); |
Thomas Cauwelier |
10:071b7cc8b0ff | 13 | char c = (char) serial->getc(); |
Thomas Cauwelier |
10:071b7cc8b0ff | 14 | if (c == 0b11100011) //no data flag |
Thomas Cauwelier |
10:071b7cc8b0ff | 15 | continue; |
Thomas Cauwelier |
10:071b7cc8b0ff | 16 | else{ |
Thomas Cauwelier |
10:071b7cc8b0ff | 17 | out[i] = c; |
Thomas Cauwelier |
10:071b7cc8b0ff | 18 | i++; |
Thomas Cauwelier |
10:071b7cc8b0ff | 19 | } |
Thomas Cauwelier |
10:071b7cc8b0ff | 20 | |
Thomas Cauwelier |
10:071b7cc8b0ff | 21 | if (i == 2){ |
Thomas Cauwelier |
10:071b7cc8b0ff | 22 | break; |
Thomas Cauwelier |
10:071b7cc8b0ff | 23 | } |
Thomas Cauwelier |
10:071b7cc8b0ff | 24 | } |
Thomas Cauwelier |
10:071b7cc8b0ff | 25 | return out; |
Thomas Cauwelier |
10:071b7cc8b0ff | 26 | } |
Thomas Cauwelier |
10:071b7cc8b0ff | 27 | |
Thomas Cauwelier |
6:0e1973fdfe28 | 28 | |
Thomas Cauwelier |
6:0e1973fdfe28 | 29 | void receive_uart() { |
Thomas Cauwelier |
10:071b7cc8b0ff | 30 | while (true) { |
Thomas Cauwelier |
10:071b7cc8b0ff | 31 | if (in.readable()) { |
Thomas Cauwelier |
10:071b7cc8b0ff | 32 | char s[2]; |
Thomas Cauwelier |
10:071b7cc8b0ff | 33 | read_2_bytes(&in, s); |
Thomas Cauwelier |
10:071b7cc8b0ff | 34 | char dec[1]; |
Thomas Cauwelier |
10:071b7cc8b0ff | 35 | Manchester::decode_manchester(s, 2, dec); |
Thomas Cauwelier |
9:d95984ce5de9 | 36 | |
Thomas Cauwelier |
9:d95984ce5de9 | 37 | printf(dec); |
Thomas Cauwelier |
10:071b7cc8b0ff | 38 | } else { |
Thomas Cauwelier |
6:0e1973fdfe28 | 39 | Thread::yield(); |
Thomas Cauwelier |
6:0e1973fdfe28 | 40 | } |
Thomas Cauwelier |
6:0e1973fdfe28 | 41 | } |
Thomas Cauwelier |
6:0e1973fdfe28 | 42 | } |
Desertification | 1:6b839581dc9f | 43 | |
Desertification | 1:6b839581dc9f | 44 | int main() { |
Thomas Cauwelier |
7:2b99a26e6a43 | 45 | printf("%s\r\n", "hello, term!"); |
Thomas Cauwelier |
7:2b99a26e6a43 | 46 | |
Thomas Cauwelier |
7:2b99a26e6a43 | 47 | Thread thread; |
Thomas Cauwelier |
7:2b99a26e6a43 | 48 | thread.start(receive_uart); |
Thomas Cauwelier |
6:0e1973fdfe28 | 49 | |
Thomas Cauwelier |
10:071b7cc8b0ff | 50 | while (true) { |
Thomas Cauwelier |
8:4fcc746968b3 | 51 | while (!out.writeable()); |
Thomas Cauwelier |
9:d95984ce5de9 | 52 | |
Thomas Cauwelier |
9:d95984ce5de9 | 53 | char tosend[28]; |
Thomas Cauwelier |
10:071b7cc8b0ff | 54 | Manchester::encode_manchester("hello, term\r\n", 14, tosend); |
Thomas Cauwelier |
9:d95984ce5de9 | 55 | out.printf(tosend); |
Thomas Cauwelier |
9:d95984ce5de9 | 56 | wait(1); |
Thomas Cauwelier |
6:0e1973fdfe28 | 57 | } |
Thomas Cauwelier |
6:0e1973fdfe28 | 58 | |
thoma@THOMAS-CAUWELIER.khbo.be | 4:a07612fbf279 | 59 | } |