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 
115  int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
116 
128  int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
129 
143  int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
144 
156  int16_t startReceive(RADIOLIB_PIN_TYPE pin, uint32_t addr, uint32_t mask = 0xFFFFF);
157 
163  size_t available();
164 
177  int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
178 
192  int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
193 
194 #if !defined(RADIOLIB_GODMODE)
195  private:
196 #endif
197  PhysicalLayer* _phy;
198 
199  float _base;
200  float _speed;
201  uint32_t _baseRaw;
202  uint16_t _shift;
203  uint16_t _shiftHz;
204  uint16_t _bitDuration;
205  uint32_t _readBatchPos;
206  uint32_t _filterAddr;
207  uint32_t _filterMask;
208  bool inv = false;
209 
210  // BCH encoder
211  int32_t _bchAlphaTo[RADIOLIB_PAGER_BCH_N + 1];
212  int32_t _bchIndexOf[RADIOLIB_PAGER_BCH_N + 1];
213  int32_t _bchG[RADIOLIB_PAGER_BCH_N - RADIOLIB_PAGER_BCH_K + 1];
214 
215  void write(uint32_t* data, size_t len);
216  void write(uint32_t codeWord);
217  uint32_t read();
218 
219  uint8_t encodeBCD(char c);
220  char decodeBCD(uint8_t b);
221 
222  void encoderInit();
223  uint32_t encodeBCH(uint32_t data);
224 };
225 
226 #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:23
int16_t transmit(String &str, uint32_t addr, uint8_t encoding=RADIOLIB_PAGER_BCD)
Arduino String transmit method.
Definition: Pager.cpp:51
int16_t sendTone(uint32_t addr)
Method to send a tone-only alert to a destination pager.
Definition: Pager.cpp:47
PagerClient(PhysicalLayer *phy)
Default constructor.
Definition: Pager.cpp:18
int16_t readData(String &str, size_t len=0, uint32_t *addr=NULL)
Reads data that was received after calling startReceive method.
Definition: Pager.cpp:249
int16_t startReceive(RADIOLIB_PIN_TYPE pin, uint32_t addr, uint32_t mask=0xFFFFF)
Start reception of POCSAG packets.
Definition: Pager.cpp:217
size_t available()
Get the number of POCSAG batches available in buffer. Limited by the size of direct mode buffer!
Definition: Pager.cpp:245
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14