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 
68 class PagerClient {
69  public:
74  explicit PagerClient(PhysicalLayer* phy);
75 
76  // basic methods
77 
86  int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
87 
93  int16_t sendTone(uint32_t addr);
94 
95  #if defined(RADIOLIB_BUILD_ARDUINO)
103  int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
104  #endif
105 
113  int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
114 
123  int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
124 
125  #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
134  int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask = 0xFFFFF);
135 
140  size_t available();
141 
142  #if defined(RADIOLIB_BUILD_ARDUINO)
152  int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
153  #endif
154 
165  int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
166 #endif
167 
168 #if !defined(RADIOLIB_GODMODE)
169  private:
170 #endif
171  PhysicalLayer* phyLayer;
172 
173  float baseFreq;
174  float dataRate;
175  uint32_t baseFreqRaw;
176  uint16_t shiftFreq;
177  uint16_t shiftFreqHz;
178  uint16_t bitDuration;
179  uint32_t filterAddr;
180  uint32_t filterMask;
181  bool inv = false;
182 
183  // BCH encoder
184  int32_t bchAlphaTo[RADIOLIB_PAGER_BCH_N + 1];
185  int32_t bchIndexOf[RADIOLIB_PAGER_BCH_N + 1];
186  int32_t bchG[RADIOLIB_PAGER_BCH_N - RADIOLIB_PAGER_BCH_K + 1];
187 
188  void write(uint32_t* data, size_t len);
189  void write(uint32_t codeWord);
190 
191 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
192  uint32_t read();
193 #endif
194 
195  uint8_t encodeBCD(char c);
196  char decodeBCD(uint8_t b);
197 
198  void encoderInit();
199  uint32_t encodeBCH(uint32_t data);
200 };
201 
202 #endif
Client for Pager communication.
Definition: Pager.h:68
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
int16_t sendTone(uint32_t addr)
Method to send a tone-only alert to a destination pager.
Definition: Pager.cpp:53
PagerClient(PhysicalLayer *phy)
Default constructor.
Definition: Pager.cpp:22
int16_t transmit(const char *str, uint32_t addr, uint8_t encoding=RADIOLIB_PAGER_BCD)
C-string transmit method.
Definition: Pager.cpp:63
int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask=0xFFFFF)
Start reception of POCSAG packets.
Definition: Pager.cpp:226
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:314
size_t available()
Get the number of POCSAG batches available in buffer. Limited by the size of direct mode buffer!
Definition: Pager.cpp:263
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:15