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.
Receiver.h@4:a3c4a43f94f8, 2017-10-23 (annotated)
- Committer:
- ThierryLeonard
- Date:
- Mon Oct 23 21:18:07 2017 +0000
- Revision:
- 4:a3c4a43f94f8
- Child:
- 6:ac7c0ccf9b5d
rip
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ThierryLeonard | 4:a3c4a43f94f8 | 1 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 2 | #include "mbed.h" |
| ThierryLeonard | 4:a3c4a43f94f8 | 3 | #include "rtos.h" |
| ThierryLeonard | 4:a3c4a43f94f8 | 4 | #include <vector> |
| ThierryLeonard | 4:a3c4a43f94f8 | 5 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 6 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 7 | const unsigned char preamble = 85; |
| ThierryLeonard | 4:a3c4a43f94f8 | 8 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 9 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 10 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 11 | class ReceiverData |
| ThierryLeonard | 4:a3c4a43f94f8 | 12 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 13 | public: |
| ThierryLeonard | 4:a3c4a43f94f8 | 14 | ReceiverData():lastTime(0),receiving(false),data(80),temp(0),currentBit(0),ready(false){} |
| ThierryLeonard | 4:a3c4a43f94f8 | 15 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 16 | const vector<unsigned char> & receivedData(){ return data; } |
| ThierryLeonard | 4:a3c4a43f94f8 | 17 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 18 | bool waiting(){return receiving == false;} |
| ThierryLeonard | 4:a3c4a43f94f8 | 19 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 20 | void fall(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 21 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 22 | void rise(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 23 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 24 | void setTime(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 25 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 26 | void addBit(unsigned char bit); |
| ThierryLeonard | 4:a3c4a43f94f8 | 27 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 28 | void start(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 29 | void waitData(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 30 | void clear(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 31 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 32 | void timeout(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 33 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 34 | private: |
| ThierryLeonard | 4:a3c4a43f94f8 | 35 | Timer time; |
| ThierryLeonard | 4:a3c4a43f94f8 | 36 | Ticker watchDog; |
| ThierryLeonard | 4:a3c4a43f94f8 | 37 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 38 | Semaphore dataSemaphore; |
| ThierryLeonard | 4:a3c4a43f94f8 | 39 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 40 | int lastTime; |
| ThierryLeonard | 4:a3c4a43f94f8 | 41 | bool receiving; |
| ThierryLeonard | 4:a3c4a43f94f8 | 42 | bool ready; |
| ThierryLeonard | 4:a3c4a43f94f8 | 43 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 44 | vector<unsigned char> data; |
| ThierryLeonard | 4:a3c4a43f94f8 | 45 | unsigned char temp; |
| ThierryLeonard | 4:a3c4a43f94f8 | 46 | int currentBit; |
| ThierryLeonard | 4:a3c4a43f94f8 | 47 | }; |
| ThierryLeonard | 4:a3c4a43f94f8 | 48 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 49 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 50 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 51 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 52 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 53 | /* |
| ThierryLeonard | 4:a3c4a43f94f8 | 54 | void* arg = NULL; |
| ThierryLeonard | 4:a3c4a43f94f8 | 55 | Thread receiver(arg,&receive); |
| ThierryLeonard | 4:a3c4a43f94f8 | 56 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 57 | bool bit = false; |
| ThierryLeonard | 4:a3c4a43f94f8 | 58 | MO = false; |
| ThierryLeonard | 4:a3c4a43f94f8 | 59 | for(int i = 0; i < 16 ; i++) |
| ThierryLeonard | 4:a3c4a43f94f8 | 60 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 61 | printf("MO\n"); |
| ThierryLeonard | 4:a3c4a43f94f8 | 62 | Thread::wait(us_period/2000); |
| ThierryLeonard | 4:a3c4a43f94f8 | 63 | MO = bit; |
| ThierryLeonard | 4:a3c4a43f94f8 | 64 | bit = !bit; |
| ThierryLeonard | 4:a3c4a43f94f8 | 65 | } |
| ThierryLeonard | 4:a3c4a43f94f8 | 66 | while(1) |
| ThierryLeonard | 4:a3c4a43f94f8 | 67 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 68 | Thread::wait(2); |
| ThierryLeonard | 4:a3c4a43f94f8 | 69 | } |
| ThierryLeonard | 4:a3c4a43f94f8 | 70 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 71 | void receive(void* args) |
| ThierryLeonard | 4:a3c4a43f94f8 | 72 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 73 | pc.printf("Receive Start\n"); |
| ThierryLeonard | 4:a3c4a43f94f8 | 74 | ReceiverData data; |
| ThierryLeonard | 4:a3c4a43f94f8 | 75 | while(true) |
| ThierryLeonard | 4:a3c4a43f94f8 | 76 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 77 | data.start(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 78 | data.waitData(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 79 | vector<unsigned char> vec = data.receivedData(); |
| ThierryLeonard | 4:a3c4a43f94f8 | 80 | pc.printf("print"); |
| ThierryLeonard | 4:a3c4a43f94f8 | 81 | for(int i = 0 ; i < vec.size();i++) |
| ThierryLeonard | 4:a3c4a43f94f8 | 82 | { |
| ThierryLeonard | 4:a3c4a43f94f8 | 83 | pc.printf("%c",vec[i]); |
| ThierryLeonard | 4:a3c4a43f94f8 | 84 | } |
| ThierryLeonard | 4:a3c4a43f94f8 | 85 | } |
| ThierryLeonard | 4:a3c4a43f94f8 | 86 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 87 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 88 | } |
| ThierryLeonard | 4:a3c4a43f94f8 | 89 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 90 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 91 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 92 | |
| ThierryLeonard | 4:a3c4a43f94f8 | 93 | */ |
