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 
7 // frequency shift in Hz
8 #define RADIOLIB_PAGER_FREQ_SHIFT_HZ (4500)
9 
10 // supported encoding schemes
11 #define RADIOLIB_PAGER_ASCII (0)
12 #define RADIOLIB_PAGER_BCD (1)
13 
14 // preamble length in 32-bit code words
15 #define RADIOLIB_PAGER_PREAMBLE_LENGTH (18)
16 
17 // protocol-specified code words
18 #define RADIOLIB_PAGER_PREAMBLE_CODE_WORD (0xAAAAAAAA)
19 #define RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD (0x7CD215D8)
20 #define RADIOLIB_PAGER_IDLE_CODE_WORD (0x7A89C197)
21 
22 // code word type identification flags
23 #define RADIOLIB_PAGER_ADDRESS_CODE_WORD (0UL)
24 #define RADIOLIB_PAGER_MESSAGE_CODE_WORD (1UL)
25 
26 // length of code word in bits
27 #define RADIOLIB_PAGER_CODE_WORD_LEN (32)
28 
29 // number of message bits in a single code block
30 #define RADIOLIB_PAGER_ADDRESS_POS (13)
31 #define RADIOLIB_PAGER_FUNC_BITS_POS (11)
32 #define RADIOLIB_PAGER_MESSAGE_BITS_LENGTH (20)
33 #define RADIOLIB_PAGER_MESSAGE_END_POS (11)
34 
35 // number of code words in a batch
36 #define RADIOLIB_PAGER_BATCH_LEN (16)
37 
38 // mask for address bits in a single code word
39 #define RADIOLIB_PAGER_ADDRESS_BITS_MASK (0x7FFFE000UL)
40 
41 // mask for function bits in a single code word
42 #define RADIOLIB_PAGER_FUNCTION_BITS_MASK (0x00001800UL)
43 
44 // mask for BCH bits in a single code word
45 #define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL)
46 
47 // message type functional bits
48 #define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00UL << RADIOLIB_PAGER_FUNC_BITS_POS)
49 #define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01UL << RADIOLIB_PAGER_FUNC_BITS_POS)
50 #define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11UL << RADIOLIB_PAGER_FUNC_BITS_POS)
51 
52 // the maximum allowed address (2^22 - 1)
53 #define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
54 
55 // BCH(31, 21) code constants
56 #define RADIOLIB_PAGER_BCH_M (5)
57 #define RADIOLIB_PAGER_BCH_N (31)
58 #define RADIOLIB_PAGER_BCH_K (21)
59 #define RADIOLIB_PAGER_BCH_D (5)
60 
61  // BCH(31, 21) primitive polynomial x^5 + x^2 + 1
62 #define RADIOLIB_PAGER_BCH_PRIMITIVE_POLY (0x25)
63 
69 class PagerClient {
70  public:
76  explicit PagerClient(PhysicalLayer* phy);
77 
78  // basic methods
79 
93  int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
94 
102  int16_t sendTone(uint32_t addr);
103 
104  #if defined(RADIOLIB_BUILD_ARDUINO)
116  int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
117  #endif
118 
130  int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
131 
145  int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
146 
147 
148 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
160  int16_t startReceive(RADIOLIB_PIN_TYPE pin, uint32_t addr, uint32_t mask = 0xFFFFF);
161 
167  size_t available();
168 
169  #if defined(RADIOLIB_BUILD_ARDUINO)
182  int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
183  #endif
184 
198  int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
199 #endif
200 
201 #if !defined(RADIOLIB_GODMODE)
202  private:
203 #endif
204  PhysicalLayer* _phy;
205 
206  float _base;
207  float _speed;
208  uint32_t _baseRaw;
209  uint16_t _shift;
210  uint16_t _shiftHz;
211  uint16_t _bitDuration;
212  uint32_t _filterAddr;
213  uint32_t _filterMask;
214  bool inv = false;
215 
216  // BCH encoder
217  int32_t _bchAlphaTo[RADIOLIB_PAGER_BCH_N + 1];
218  int32_t _bchIndexOf[RADIOLIB_PAGER_BCH_N + 1];
219  int32_t _bchG[RADIOLIB_PAGER_BCH_N - RADIOLIB_PAGER_BCH_K + 1];
220 
221  void write(uint32_t* data, size_t len);
222  void write(uint32_t codeWord);
223 
224 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
225  uint32_t read();
226 #endif
227 
228  uint8_t encodeBCD(char c);
229  char decodeBCD(uint8_t b);
230 
231  void encoderInit();
232  uint32_t encodeBCH(uint32_t data);
233 };
234 
235 #endif
Client for Pager communication.
Definition: Pager.h:69
int16_t begin(float base, uint16_t speed, bool invert=false, uint16_t shift=RADIOLIB_PAGER_FREQ_SHIFT_HZ)
Initialization method.
Definition: Pager.cpp:27
int16_t sendTone(uint32_t addr)
Method to send a tone-only alert to a destination pager.
Definition: Pager.cpp:51
PagerClient(PhysicalLayer *phy)
Default constructor.
Definition: Pager.cpp:20
int16_t transmit(const char *str, uint32_t addr, uint8_t encoding=RADIOLIB_PAGER_BCD)
C-string transmit method.
Definition: Pager.cpp:61
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:312
int16_t startReceive(RADIOLIB_PIN_TYPE pin, uint32_t addr, uint32_t mask=0xFFFFF)
Start reception of POCSAG packets.
Definition: Pager.cpp:224
size_t available()
Get the number of POCSAG batches available in buffer. Limited by the size of direct mode buffer!
Definition: Pager.cpp:261
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14