RadioLib Universal wireless communication library for Arduino

Pager.h
1 #if !defined(_RADIOLIB_PAGER_H) && !defined(RADIOLIB_EXCLUDE_PAGER)
2 #define _RADIOLIB_PAGER_H
3
4 #include "../../TypeDef.h"
5 #include "../PhysicalLayer/PhysicalLayer.h"
6 #include "../../utils/FEC.h"
7
8 // frequency shift in Hz
9 #define RADIOLIB_PAGER_FREQ_SHIFT_HZ (4500)
10
11 // supported encoding schemes
12 #define RADIOLIB_PAGER_ASCII (0)
13 #define RADIOLIB_PAGER_BCD (1)
14
15 // preamble length in 32-bit code words
16 #define RADIOLIB_PAGER_PREAMBLE_LENGTH (18)
17
18 // protocol-specified code words
19 #define RADIOLIB_PAGER_PREAMBLE_CODE_WORD (0xAAAAAAAA)
20 #define RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD (0x7CD215D8)
21 #define RADIOLIB_PAGER_IDLE_CODE_WORD (0x7A89C197)
22
23 // code word type identification flags
24 #define RADIOLIB_PAGER_ADDRESS_CODE_WORD (0UL)
25 #define RADIOLIB_PAGER_MESSAGE_CODE_WORD (1UL)
26
27 // length of code word in bits
28 #define RADIOLIB_PAGER_CODE_WORD_LEN (32)
29
30 // number of message bits in a single code block
31 #define RADIOLIB_PAGER_ADDRESS_POS (13)
32 #define RADIOLIB_PAGER_FUNC_BITS_POS (11)
33 #define RADIOLIB_PAGER_MESSAGE_BITS_LENGTH (20)
34 #define RADIOLIB_PAGER_MESSAGE_END_POS (11)
35
36 // number of code words in a batch
37 #define RADIOLIB_PAGER_BATCH_LEN (16)
38
39 // mask for address bits in a single code word
40 #define RADIOLIB_PAGER_ADDRESS_BITS_MASK (0x7FFFE000UL)
41
42 // mask for function bits in a single code word
43 #define RADIOLIB_PAGER_FUNCTION_BITS_MASK (0x00001800UL)
44
45 // mask for BCH bits in a single code word
46 #define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL)
47
48 // message type functional bits
49 #define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00)
50 #define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01)
51 #define RADIOLIB_PAGER_FUNC_BITS_ACTIVATION (0b10)
52 #define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11)
53 #define RADIOLIB_PAGER_FUNC_AUTO 0xFF
54
55 // the maximum allowed address (2^22 - 1)
56 #define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
57
62 class PagerClient {
63 public:
68 explicit PagerClient(PhysicalLayer* phy);
69
70 // basic methods
71
80 int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
81
87 int16_t sendTone(uint32_t addr);
88
89 #if defined(RADIOLIB_BUILD_ARDUINO)
98 int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
99 #endif
100
109 int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
110
120 int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
121
122 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
131 int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask = 0xFFFFF);
132
137 size_t available();
138
139 #if defined(RADIOLIB_BUILD_ARDUINO)
149 int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
150 #endif
151
162 int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
163 #endif
164
165 #if !defined(RADIOLIB_GODMODE)
166 private:
167 #endif
168 PhysicalLayer* phyLayer;
169
170 float baseFreq;
171 float dataRate;
172 uint32_t baseFreqRaw;
173 uint16_t shiftFreq;
174 uint16_t shiftFreqHz;
175 uint16_t bitDuration;
176 uint32_t filterAddr;
177 uint32_t filterMask;
178 bool inv = false;
179
180 void write(uint32_t* data, size_t len);
181 void write(uint32_t codeWord);
182
183 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
184 uint32_t read();
185 #endif
186
187 uint8_t encodeBCD(char c);
188 char decodeBCD(uint8_t b);
189 };
190
191 #endif
PagerClient
Client for Pager communication.
Definition: Pager.h:62
PagerClient::begin
int16_t begin(float base, uint16_t speed, bool invert=false, uint16_t shift=RADIOLIB_PAGER_FREQ_SHIFT_HZ)
Initialization method.
Definition: Pager.cpp:29
PagerClient::sendTone
int16_t sendTone(uint32_t addr)
Method to send a tone-only alert to a destination pager.
Definition: Pager.cpp:53
PagerClient::PagerClient
PagerClient(PhysicalLayer *phy)
Default constructor.
Definition: Pager.cpp:22
PagerClient::startReceive
int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask=0xFFFFF)
Start reception of POCSAG packets.
Definition: Pager.cpp:239
PagerClient::readData
int16_t readData(uint8_t *data, size_t *len, uint32_t *addr=NULL)
Reads data that was received after calling startReceive method.
Definition: Pager.cpp:327
PagerClient::transmit
int16_t transmit(const char *str, uint32_t addr, uint8_t encoding=RADIOLIB_PAGER_BCD, uint8_t function=RADIOLIB_PAGER_FUNC_AUTO)
C-string transmit method.
Definition: Pager.cpp:63
PagerClient::available
size_t available()
Get the number of POCSAG batches available in buffer. Limited by the size of direct mode buffer!
Definition: Pager.cpp:276
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:34