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.
main.cpp@7:332766fb3114, 2017-10-24 (annotated)
- Committer:
- ThierryLeonard
- Date:
- Tue Oct 24 07:04:28 2017 +0000
- Revision:
- 7:332766fb3114
- Parent:
- 6:ac7c0ccf9b5d
- Child:
- 8:7c56fb1ed8c0
G.G
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evrast | 0:c67f69d9e82e | 1 | #include "mbed.h" |
| ThierryLeonard | 4:a3c4a43f94f8 | 2 | #include "rtos.h" |
| ThierryLeonard | 2:36faaaa70f8b | 3 | #include <vector> |
| evrast | 3:f7a9f0784ca6 | 4 | #include "sender.h" |
| evrast | 0:c67f69d9e82e | 5 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 6 | #include "Receiver.h" |
| ThierryLeonard | 6:ac7c0ccf9b5d | 7 | #include "defines.h" |
| ThierryLeonard | 4:a3c4a43f94f8 | 8 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 9 | #include "CRC.h" |
| ThierryLeonard | 4:a3c4a43f94f8 | 10 | |
| evrast | 0:c67f69d9e82e | 11 | DigitalOut myled(LED1); |
| evrast | 0:c67f69d9e82e | 12 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 13 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 14 | DigitalOut MO(p22); |
| evrast | 3:f7a9f0784ca6 | 15 | Serial pc(USBTX, USBRX); |
| ThierryLeonard | 2:36faaaa70f8b | 16 | |
| ThierryLeonard | 7:332766fb3114 | 17 | const int us_period = 15; |
| ThierryLeonard | 7:332766fb3114 | 18 | const int us_timeout = us_period * 5/4; |
| ThierryLeonard | 7:332766fb3114 | 19 | const int us_prepare = us_period *3/4; |
| ThierryLeonard | 7:332766fb3114 | 20 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 21 | const unsigned char preamble_byte = 85; |
| ThierryLeonard | 2:36faaaa70f8b | 22 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 23 | const unsigned char STARTBYTE = 126; |
| ThierryLeonard | 6:ac7c0ccf9b5d | 24 | const unsigned char ENDBYTE = 126; |
| ThierryLeonard | 6:ac7c0ccf9b5d | 25 | |
| ThierryLeonard | 7:332766fb3114 | 26 | |
| ThierryLeonard | 7:332766fb3114 | 27 | #include "string" |
| ThierryLeonard | 4:a3c4a43f94f8 | 28 | |
| ThierryLeonard | 7:332766fb3114 | 29 | Sender s; |
| ThierryLeonard | 7:332766fb3114 | 30 | void sendConstantData() |
| ThierryLeonard | 7:332766fb3114 | 31 | { |
| ThierryLeonard | 6:ac7c0ccf9b5d | 32 | |
| ThierryLeonard | 7:332766fb3114 | 33 | vector<unsigned char> message; |
| ThierryLeonard | 7:332766fb3114 | 34 | for(int i = 'A'; i < 'z'; i++) |
| ThierryLeonard | 7:332766fb3114 | 35 | { |
| ThierryLeonard | 7:332766fb3114 | 36 | message.push_back(i); |
| ThierryLeonard | 7:332766fb3114 | 37 | } |
| ThierryLeonard | 7:332766fb3114 | 38 | vector<unsigned char> trame = createFrame(message); |
| ThierryLeonard | 7:332766fb3114 | 39 | |
| ThierryLeonard | 7:332766fb3114 | 40 | while(true) |
| ThierryLeonard | 7:332766fb3114 | 41 | { |
| ThierryLeonard | 7:332766fb3114 | 42 | s.sendMessage(trame); |
| ThierryLeonard | 7:332766fb3114 | 43 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 44 | |
| ThierryLeonard | 7:332766fb3114 | 45 | } |
| ThierryLeonard | 7:332766fb3114 | 46 | void sendMessage() |
| ThierryLeonard | 7:332766fb3114 | 47 | { |
| ThierryLeonard | 7:332766fb3114 | 48 | unsigned char c = 0; |
| ThierryLeonard | 7:332766fb3114 | 49 | vector<unsigned char> message; |
| ThierryLeonard | 7:332766fb3114 | 50 | while ( c != '\n') |
| ThierryLeonard | 7:332766fb3114 | 51 | { |
| ThierryLeonard | 7:332766fb3114 | 52 | while(!pc.readable()) |
| ThierryLeonard | 7:332766fb3114 | 53 | { |
| ThierryLeonard | 7:332766fb3114 | 54 | Thread::wait(1); |
| ThierryLeonard | 7:332766fb3114 | 55 | } |
| ThierryLeonard | 7:332766fb3114 | 56 | c = pc.getc(); |
| ThierryLeonard | 7:332766fb3114 | 57 | pc.printf("%c",c); |
| ThierryLeonard | 7:332766fb3114 | 58 | message.push_back(c); |
| ThierryLeonard | 7:332766fb3114 | 59 | } |
| ThierryLeonard | 7:332766fb3114 | 60 | vector<unsigned char> trame = createFrame(message); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 61 | |
| ThierryLeonard | 7:332766fb3114 | 62 | s.sendMessage(trame); |
| ThierryLeonard | 7:332766fb3114 | 63 | |
| ThierryLeonard | 7:332766fb3114 | 64 | } |
| ThierryLeonard | 7:332766fb3114 | 65 | |
| ThierryLeonard | 7:332766fb3114 | 66 | int main() { |
| ThierryLeonard | 7:332766fb3114 | 67 | ManchesterReceiver r; |
| ThierryLeonard | 7:332766fb3114 | 68 | |
| ThierryLeonard | 7:332766fb3114 | 69 | |
| ThierryLeonard | 7:332766fb3114 | 70 | |
| ThierryLeonard | 7:332766fb3114 | 71 | Callback<void()> cb(&r, &ManchesterReceiver::getMessages); |
| ThierryLeonard | 7:332766fb3114 | 72 | Thread receiving(cb,osPriorityHigh); |
| ThierryLeonard | 7:332766fb3114 | 73 | |
| ThierryLeonard | 7:332766fb3114 | 74 | pc.printf("\n******************\nStarting to listen\n"); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 75 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 76 | while(1) |
| ThierryLeonard | 6:ac7c0ccf9b5d | 77 | { |
| ThierryLeonard | 7:332766fb3114 | 78 | sendMessage(); |
| ThierryLeonard | 7:332766fb3114 | 79 | Thread::wait(1000); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 80 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 81 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 82 | /* |
| ThierryLeonard | 6:ac7c0ccf9b5d | 83 | for(int i = 0; i < 16; i++) |
| ThierryLeonard | 6:ac7c0ccf9b5d | 84 | { |
| ThierryLeonard | 6:ac7c0ccf9b5d | 85 | pc.printf("M"); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 86 | Thread::wait(50 + 10*i); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 87 | MO = !MO; |
| ThierryLeonard | 6:ac7c0ccf9b5d | 88 | pc.printf("O\n"); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 89 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 90 | |
| ThierryLeonard | 6:ac7c0ccf9b5d | 91 | pc.printf("%i",r.endData); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 92 | while(true) |
| ThierryLeonard | 6:ac7c0ccf9b5d | 93 | { |
| ThierryLeonard | 6:ac7c0ccf9b5d | 94 | EdgeData data = r.getNext(); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 95 | pc.printf("val %i, timeStamp %i\n",data.value,data.us_timeStamp); |
| ThierryLeonard | 6:ac7c0ccf9b5d | 96 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 97 | |
| evrast | 3:f7a9f0784ca6 | 98 | while(1){} |
| evrast | 0:c67f69d9e82e | 99 | } |
| ThierryLeonard | 6:ac7c0ccf9b5d | 100 | */ |
