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@12:a070de571ea1, 2017-05-09 (annotated)
- Committer:
- Thomas Cauwelier
- Date:
- Tue May 09 21:39:59 2017 +0200
- Revision:
- 12:a070de571ea1
- Parent:
- 11:e462ce7a42b9
- Child:
- 13:c111ea1c5990
test softserial
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 |
12:a070de571ea1 | 5 | #include "SoftSerial.h" |
Thomas Cauwelier |
6:0e1973fdfe28 | 6 | |
Thomas Cauwelier |
12:a070de571ea1 | 7 | //Serial out(p9, p10, 3200); //p9 |
Thomas Cauwelier |
12:a070de571ea1 | 8 | //Serial in(p13, p14, 3200); //p14 |
Thomas Cauwelier |
12:a070de571ea1 | 9 | //Serial usb(USBTX,USBRX); |
Thomas Cauwelier |
12:a070de571ea1 | 10 | // |
Thomas Cauwelier |
12:a070de571ea1 | 11 | //char *read_2_bytes(Serial *serial, char out[2]) { |
Thomas Cauwelier |
12:a070de571ea1 | 12 | // int i = 0; |
Thomas Cauwelier |
12:a070de571ea1 | 13 | // while (true) { |
Thomas Cauwelier |
12:a070de571ea1 | 14 | // while (!serial->readable()); |
Thomas Cauwelier |
12:a070de571ea1 | 15 | // char c = (char) serial->getc(); |
Thomas Cauwelier |
12:a070de571ea1 | 16 | // if (c == 0b11100011) //no data flag |
Thomas Cauwelier |
12:a070de571ea1 | 17 | // continue; |
Thomas Cauwelier |
12:a070de571ea1 | 18 | // else { |
Thomas Cauwelier |
12:a070de571ea1 | 19 | // out[i] = c; |
Thomas Cauwelier |
12:a070de571ea1 | 20 | // i++; |
Thomas Cauwelier |
12:a070de571ea1 | 21 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 22 | // |
Thomas Cauwelier |
12:a070de571ea1 | 23 | // if (i == 2) { |
Thomas Cauwelier |
12:a070de571ea1 | 24 | // break; |
Thomas Cauwelier |
12:a070de571ea1 | 25 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 26 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 27 | // return out; |
Thomas Cauwelier |
12:a070de571ea1 | 28 | //} |
Thomas Cauwelier |
12:a070de571ea1 | 29 | // |
Thomas Cauwelier |
12:a070de571ea1 | 30 | // |
Thomas Cauwelier |
12:a070de571ea1 | 31 | //void receive_uart() { |
Thomas Cauwelier |
12:a070de571ea1 | 32 | // while (true) { |
Thomas Cauwelier |
12:a070de571ea1 | 33 | // if (in.readable()) { |
Thomas Cauwelier |
12:a070de571ea1 | 34 | // char s[2]; |
Thomas Cauwelier |
12:a070de571ea1 | 35 | // read_2_bytes(&in, s); |
Thomas Cauwelier |
12:a070de571ea1 | 36 | // char dec[1]; |
Thomas Cauwelier |
12:a070de571ea1 | 37 | // bool success = Manchester::decode_manchester(s, 2, dec); |
Thomas Cauwelier |
12:a070de571ea1 | 38 | // printf(dec); |
Thomas Cauwelier |
12:a070de571ea1 | 39 | // if (!success) { |
Thomas Cauwelier |
12:a070de571ea1 | 40 | // printf("#"); |
Thomas Cauwelier |
12:a070de571ea1 | 41 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 42 | // } else { |
Thomas Cauwelier |
12:a070de571ea1 | 43 | // Thread::yield(); |
Thomas Cauwelier |
12:a070de571ea1 | 44 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 45 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 46 | //} |
Thomas Cauwelier |
12:a070de571ea1 | 47 | // |
Thomas Cauwelier |
12:a070de571ea1 | 48 | //void send_uart(Serial *serial, const char *s, int size) { |
Thomas Cauwelier |
12:a070de571ea1 | 49 | // int size_m = size * 2; |
Thomas Cauwelier |
12:a070de571ea1 | 50 | // char encoded[size_m]; |
Thomas Cauwelier |
12:a070de571ea1 | 51 | // Manchester::encode_manchester(s, size, encoded); |
Thomas Cauwelier |
12:a070de571ea1 | 52 | // |
Thomas Cauwelier |
12:a070de571ea1 | 53 | // for (int i = 0; i < size_m; ++i) { |
Thomas Cauwelier |
12:a070de571ea1 | 54 | // while (!serial->writeable()); |
Thomas Cauwelier |
12:a070de571ea1 | 55 | // serial->putc(encoded[i]); |
Thomas Cauwelier |
12:a070de571ea1 | 56 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 57 | //} |
Thomas Cauwelier |
12:a070de571ea1 | 58 | // |
Thomas Cauwelier |
12:a070de571ea1 | 59 | //void hardware_uart_test(){ |
Thomas Cauwelier |
12:a070de571ea1 | 60 | // |
Thomas Cauwelier |
12:a070de571ea1 | 61 | // |
Thomas Cauwelier |
12:a070de571ea1 | 62 | // printf("%s\r\n", "hello, term!"); |
Thomas Cauwelier |
12:a070de571ea1 | 63 | // |
Thomas Cauwelier |
12:a070de571ea1 | 64 | // Thread thread; |
Thomas Cauwelier |
12:a070de571ea1 | 65 | // thread.start(receive_uart); |
Thomas Cauwelier |
12:a070de571ea1 | 66 | // |
Thomas Cauwelier |
12:a070de571ea1 | 67 | // while (true) { |
Thomas Cauwelier |
12:a070de571ea1 | 68 | // char tosend[28]; |
Thomas Cauwelier |
12:a070de571ea1 | 69 | // Manchester::encode_manchester("hello, term\r\n", 14, tosend); |
Thomas Cauwelier |
12:a070de571ea1 | 70 | // send_uart(&out, tosend, 28); |
Thomas Cauwelier |
12:a070de571ea1 | 71 | // //wait(1); |
Thomas Cauwelier |
12:a070de571ea1 | 72 | // } |
Thomas Cauwelier |
12:a070de571ea1 | 73 | //} |
Desertification | 1:6b839581dc9f | 74 | |
Thomas Cauwelier |
12:a070de571ea1 | 75 | #define RELAY 1 |
Thomas Cauwelier |
11:e462ce7a42b9 | 76 | |
Desertification | 1:6b839581dc9f | 77 | int main() { |
Thomas Cauwelier |
12:a070de571ea1 | 78 | SoftSerial s(LED1,NC); |
Thomas Cauwelier |
12:a070de571ea1 | 79 | s.baud(1); |
Thomas Cauwelier |
6:0e1973fdfe28 | 80 | |
Thomas Cauwelier |
12:a070de571ea1 | 81 | if (RELAY){ |
Thomas Cauwelier |
12:a070de571ea1 | 82 | s.putc(0b00110101); |
Thomas Cauwelier |
12:a070de571ea1 | 83 | } else { |
Thomas Cauwelier |
12:a070de571ea1 | 84 | |
Thomas Cauwelier |
6:0e1973fdfe28 | 85 | } |
thoma@THOMAS-CAUWELIER.khbo.be | 4:a07612fbf279 | 86 | } |