Manchester
Diff: Manchester.h
- Revision:
- 0:d5c75b0e5708
- Child:
- 1:11292d238e50
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Manchester.h Wed May 17 07:52:15 2017 +0000 @@ -0,0 +1,81 @@ +/* + ****************************************************************************** + * @file Manchester.h + * @author Zoltan Hudak + * @version + * @date 16-May-2017 + * @brief Manchester code for ARMmbed + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2017 Zoltan Hudak <hudakz@outlook.com> + * + * All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MANCHESTER_H +#define MANCHESTER_H + +#include "mbed.h" +#include "ManchesterMsg.h" + +class Manchester +{ + enum State + { + IDLE, + SYNCH_START, + SYNCH_NEXT, + SYNCH_END, + SETUP, + TRANSITION, + COMPLETE, + LISTEN, + DECODE, + ERROR + }; + +public: + Manchester + ( + PinName txPin, /* transmitter pin name */ + PinName rxPin, /* receiver pin name */ + uint32_t speed = 1500 /* speed in bits per second */, + uint8_t tol = 20 /* pulse width tolerance (+/-) in % */ + ); + ~Manchester(void) { }; + void transmit(ManchesterMsg& msg); + bool receive(ManchesterMsg& msg); + +private: + DigitalOut _tx; // transmitter line + InterruptIn _rx; // receiver line + Ticker _txTicker; // transmitter ticker + Timeout _rxTimeout; // receiver timeout + uint32_t _midBitTime; // mid-bit time [us] + uint32_t _minPulseWidth; // minimum pulse width + uint32_t _maxPulseWidth; // maximum pulse width + State _state; // state + char* _data; // data array + uint8_t _len; // data length in bytes + uint8_t _maxLen; // maximum length + + void transmission(void); + void reception(void); + void rxTimeout(void); +}; +#endif // MANCHESTER_H +