forked from xeonqq/SoftModem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoftModem.h
66 lines (57 loc) · 1.68 KB
/
SoftModem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef SoftModem_h
#define SoftModem_h
#include <Arduino.h>
//#define SOFT_MODEM_BAUD_RATE (126)
//#define SOFT_MODEM_LOW_FREQ (882)
//#define SOFT_MODEM_HIGH_FREQ (1764)
//#define SOFT_MODEM_RX_BUF_SIZE (4)
//#define SOFT_MODEM_BAUD_RATE (315)
//#define SOFT_MODEM_LOW_FREQ (1575)
//#define SOFT_MODEM_HIGH_FREQ (3150)
//#define SOFT_MODEM_RX_BUF_SIZE (8)
//#define SOFT_MODEM_BAUD_RATE (630)
//#define SOFT_MODEM_LOW_FREQ (3150)
//#define SOFT_MODEM_HIGH_FREQ (6300)
//#define SOFT_MODEM_RX_BUF_SIZE (16)
#define SOFT_MODEM_BAUD_RATE (1225)
#define SOFT_MODEM_LOW_FREQ (4900)
#define SOFT_MODEM_HIGH_FREQ (7350)
#define SOFT_MODEM_RX_BUF_SIZE (32)
//#define SOFT_MODEM_BAUD_RATE (2450)
//#define SOFT_MODEM_LOW_FREQ (4900)
//#define SOFT_MODEM_HIGH_FREQ (7350)
//#define SOFT_MODEM_RX_BUF_SIZE (32)
#define SOFT_MODEM_DEBUG_ENABLE (0)
#define SOFT_MODEM_MOVING_AVERAGE_ENABLE (0)
class SoftModem : public Stream
{
private:
volatile uint8_t *_txPortReg;
uint8_t _txPortMask;
uint8_t _lastTCNT;
uint8_t _lastDiff;
uint8_t _recvStat;
uint8_t _recvBits;
uint8_t _recvBufferHead;
uint8_t _recvBufferTail;
uint8_t _recvBuffer[SOFT_MODEM_RX_BUF_SIZE];
uint8_t _lowCount;
uint8_t _highCount;
unsigned long _lastWriteTime;
void modulate(uint8_t b);
public:
SoftModem();
~SoftModem();
void begin(void);
void end(void);
virtual int available();
virtual int read();
virtual void flush();
virtual int peek();
virtual size_t write(const uint8_t *buffer, size_t size);
virtual size_t write(uint8_t data);
void demodulate(void);
void recv(void);
static SoftModem *activeObject;
};
#endif