forked from slepp/AX25
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModem.h
54 lines (49 loc) · 1.19 KB
/
Modem.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
#ifndef MODEM_H
#define MODEM_H
#include "AFSKEncode.h"
#include "AFSKDecode.h"
#include "Packet.h"
// This is the main "modem" and handles
// all the basic routines needed for IO
extern volatile unsigned long lastTx;
extern volatile unsigned long lastTxEnd;
extern volatile unsigned long lastRx;
class Modem {
public:
void start(); // Start the timers
void timer(); // Process a timer event
inline bool read() {
return decoder.read();
}
inline bool txReady() volatile {
if(encoder.isDone() && encoder.hasPackets())
return true;
return false;
}
inline bool isDone() volatile { return encoder.isDone(); }
inline bool txStart() {
if(decoder.isReceiving()) {
encoder.setRandomWait();
return false;
}
return encoder.start();
}
inline bool putTXPacket(Packet *packet) {
bool ret = encoder.putPacket(packet);
if(!ret) // No room?
PacketBuffer::freePacket(packet);
return ret;
}
inline Packet *getRXPacket() {
return decoder.getPacket();
}
inline uint8_t rxPacketCount() volatile {
return decoder.packetCount();
}
private:
unsigned long lastTx;
unsigned long lastRx;
AFSKEncode encoder;
AFSKDecode decoder;
};
#endif