Manchester
Manchester.h@1:11292d238e50, 2017-05-17 (annotated)
- Committer:
- hudakz
- Date:
- Wed May 17 08:17:13 2017 +0000
- Revision:
- 1:11292d238e50
- Parent:
- 0:d5c75b0e5708
- Child:
- 2:de778df5892c
Updated.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:d5c75b0e5708 | 1 | /* |
hudakz | 0:d5c75b0e5708 | 2 | ****************************************************************************** |
hudakz | 0:d5c75b0e5708 | 3 | * @file Manchester.h |
hudakz | 0:d5c75b0e5708 | 4 | * @author Zoltan Hudak |
hudakz | 0:d5c75b0e5708 | 5 | * @version |
hudakz | 0:d5c75b0e5708 | 6 | * @date 16-May-2017 |
hudakz | 1:11292d238e50 | 7 | * @brief Manchester code for mbed |
hudakz | 0:d5c75b0e5708 | 8 | ****************************************************************************** |
hudakz | 0:d5c75b0e5708 | 9 | * @attention |
hudakz | 0:d5c75b0e5708 | 10 | * |
hudakz | 0:d5c75b0e5708 | 11 | * <h2><center>© COPYRIGHT(c) 2017 Zoltan Hudak <hudakz@outlook.com> |
hudakz | 0:d5c75b0e5708 | 12 | * |
hudakz | 0:d5c75b0e5708 | 13 | * All rights reserved. |
hudakz | 0:d5c75b0e5708 | 14 | |
hudakz | 0:d5c75b0e5708 | 15 | This program is free software: you can redistribute it and/or modify |
hudakz | 0:d5c75b0e5708 | 16 | it under the terms of the GNU General Public License as published by |
hudakz | 0:d5c75b0e5708 | 17 | the Free Software Foundation, either version 3 of the License, or |
hudakz | 0:d5c75b0e5708 | 18 | (at your option) any later version. |
hudakz | 0:d5c75b0e5708 | 19 | |
hudakz | 0:d5c75b0e5708 | 20 | This program is distributed in the hope that it will be useful, |
hudakz | 0:d5c75b0e5708 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hudakz | 0:d5c75b0e5708 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hudakz | 0:d5c75b0e5708 | 23 | GNU General Public License for more details. |
hudakz | 0:d5c75b0e5708 | 24 | |
hudakz | 0:d5c75b0e5708 | 25 | You should have received a copy of the GNU General Public License |
hudakz | 0:d5c75b0e5708 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
hudakz | 0:d5c75b0e5708 | 27 | */ |
hudakz | 0:d5c75b0e5708 | 28 | |
hudakz | 0:d5c75b0e5708 | 29 | #ifndef MANCHESTER_H |
hudakz | 0:d5c75b0e5708 | 30 | #define MANCHESTER_H |
hudakz | 0:d5c75b0e5708 | 31 | |
hudakz | 0:d5c75b0e5708 | 32 | #include "mbed.h" |
hudakz | 0:d5c75b0e5708 | 33 | #include "ManchesterMsg.h" |
hudakz | 0:d5c75b0e5708 | 34 | |
hudakz | 0:d5c75b0e5708 | 35 | class Manchester |
hudakz | 0:d5c75b0e5708 | 36 | { |
hudakz | 0:d5c75b0e5708 | 37 | enum State |
hudakz | 0:d5c75b0e5708 | 38 | { |
hudakz | 0:d5c75b0e5708 | 39 | IDLE, |
hudakz | 0:d5c75b0e5708 | 40 | SYNCH_START, |
hudakz | 0:d5c75b0e5708 | 41 | SYNCH_NEXT, |
hudakz | 0:d5c75b0e5708 | 42 | SYNCH_END, |
hudakz | 0:d5c75b0e5708 | 43 | SETUP, |
hudakz | 0:d5c75b0e5708 | 44 | TRANSITION, |
hudakz | 0:d5c75b0e5708 | 45 | COMPLETE, |
hudakz | 0:d5c75b0e5708 | 46 | LISTEN, |
hudakz | 0:d5c75b0e5708 | 47 | DECODE, |
hudakz | 0:d5c75b0e5708 | 48 | ERROR |
hudakz | 0:d5c75b0e5708 | 49 | }; |
hudakz | 0:d5c75b0e5708 | 50 | |
hudakz | 0:d5c75b0e5708 | 51 | public: |
hudakz | 0:d5c75b0e5708 | 52 | Manchester |
hudakz | 0:d5c75b0e5708 | 53 | ( |
hudakz | 1:11292d238e50 | 54 | PinName txPin, /* transmitter pin name */ |
hudakz | 1:11292d238e50 | 55 | PinName rxPin, /* receiver pin name */ |
hudakz | 1:11292d238e50 | 56 | uint32_t speed = 1200 /* speed in bits per second */, |
hudakz | 1:11292d238e50 | 57 | uint8_t tol = 20 /* pulse width tolerance (+/-) in % */ |
hudakz | 0:d5c75b0e5708 | 58 | ); |
hudakz | 0:d5c75b0e5708 | 59 | ~Manchester(void) { }; |
hudakz | 0:d5c75b0e5708 | 60 | void transmit(ManchesterMsg& msg); |
hudakz | 0:d5c75b0e5708 | 61 | bool receive(ManchesterMsg& msg); |
hudakz | 0:d5c75b0e5708 | 62 | |
hudakz | 0:d5c75b0e5708 | 63 | private: |
hudakz | 0:d5c75b0e5708 | 64 | DigitalOut _tx; // transmitter line |
hudakz | 0:d5c75b0e5708 | 65 | InterruptIn _rx; // receiver line |
hudakz | 0:d5c75b0e5708 | 66 | Ticker _txTicker; // transmitter ticker |
hudakz | 0:d5c75b0e5708 | 67 | Timeout _rxTimeout; // receiver timeout |
hudakz | 0:d5c75b0e5708 | 68 | uint32_t _midBitTime; // mid-bit time [us] |
hudakz | 1:11292d238e50 | 69 | uint32_t _minPulseWidth; // minimum pulse width [us] |
hudakz | 1:11292d238e50 | 70 | uint32_t _maxPulseWidth; // maximum pulse width [us] |
hudakz | 0:d5c75b0e5708 | 71 | State _state; // state |
hudakz | 0:d5c75b0e5708 | 72 | char* _data; // data array |
hudakz | 0:d5c75b0e5708 | 73 | uint8_t _len; // data length in bytes |
hudakz | 0:d5c75b0e5708 | 74 | uint8_t _maxLen; // maximum length |
hudakz | 0:d5c75b0e5708 | 75 | |
hudakz | 0:d5c75b0e5708 | 76 | void transmission(void); |
hudakz | 0:d5c75b0e5708 | 77 | void reception(void); |
hudakz | 0:d5c75b0e5708 | 78 | void rxTimeout(void); |
hudakz | 0:d5c75b0e5708 | 79 | }; |
hudakz | 0:d5c75b0e5708 | 80 | #endif // MANCHESTER_H |
hudakz | 0:d5c75b0e5708 | 81 |