Manchester
Diff: Manchester.h
- Revision:
- 8:c1b5893191fe
- Parent:
- 6:7454ad91f714
- Child:
- 9:7a23184aa9ef
--- a/Manchester.h Sun Sep 03 09:04:18 2017 +0000
+++ b/Manchester.h Sun Oct 14 09:38:33 2018 +0000
@@ -25,7 +25,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
/*
This library implements Manchester code according to both IEEE 802.3
and G.E. Thomas' conventions.
@@ -40,15 +39,14 @@
Select a convention to be used by commenting or uncommenting
the line "#define G_E_THOMAS 1" below.
*/
-
#ifndef MANCHESTER_H
#define MANCHESTER_H
#include "mbed.h"
#include "ManchesterMsg.h"
+//Uncomment the following line to use G.E.Thomas' convention
-//Uncomment the following line to use G.E.Thomas' convention
//#define G_E_THOMAS 1
class Manchester
@@ -63,40 +61,46 @@
TRANSITION,
COMPLETE,
LISTEN,
+ DECODE_START,
DECODE,
+ STOP,
ERROR
};
-
public:
Manchester
(
PinName txPin, /* transmitter pin name */
PinName rxPin, /* receiver pin name */
uint32_t speed = 1200, /* speed in bits per second */
- uint8_t tol = 25 /* pulse width tolerance (+/-) in % */
+ uint8_t tol = 25, /* pulse width tolerance (+/-) in % */
+ float rxTimeout = 5 /* receive timeout */
);
- ~Manchester(void) { }
+ ~ Manchester(void) { }
void transmit(ManchesterMsg& msg);
bool receive(ManchesterMsg& msg);
-
+ void setPreamble(uint8_t preamble) { _preamble = preamble; }
+ void setRxTimeout(float seconds) { _rxTimeout = seconds; }
+ char* lastError() { return _error; }
private:
- DigitalOut _tx; // transmitter line
- InterruptIn _rx; // receiver line
- Ticker _txTicker; // transmitter ticker
- Timeout _timeout; // timeout (watchdog)
- uint32_t _midBitTime; // mid-bit time [us]
- uint32_t _minPulseWidth; // minimum pulse width [us]
- uint32_t _maxPulseWidth; // maximum pulse width [us]
- State _state; // state
- char* _data; // data array
- size_t _len; // data length in bytes
- size_t _maxLen; // maximum length
-
+ DigitalOut _tx; // transmitter line
+ InterruptIn _rx; // receiver line
+ Ticker _txTicker; // transmitter ticker
+ Timeout _timeout; // timeout (watchdog)
+ Timer _timer;
+ uint32_t _midBitTime; // mid-bit time [us]
+ uint32_t _minPulseWidth; // minimum pulse width [us]
+ uint32_t _maxPulseWidth; // maximum pulse width [us]
+ uint32_t _tol;
+ float _rxTimeout; // reception timeout [s]
+ State _state; // state
+ char* _data; // data array
+ size_t _len; // data length in bytes
+ size_t _maxLen; // maximum length
+ size_t _preamble; // number of start patterns
+ char* _error;
void transmission(void);
void reception(void);
- void txTimeout(void);
- void rxTimeout(void);
+ void onTxTimeout(void);
+ void onRxTimeout(void);
};
#endif // MANCHESTER_H
-
-