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 (0b00UL << RADIOLIB_PAGER_FUNC_BITS_POS)
50 #define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01UL << RADIOLIB_PAGER_FUNC_BITS_POS)
51 #define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11UL << RADIOLIB_PAGER_FUNC_BITS_POS)
52 
53 // the maximum allowed address (2^22 - 1)
54 #define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
55 
60 class PagerClient {
61  public:
66  explicit PagerClient(PhysicalLayer* phy);
67 
68  // basic methods
69 
78  int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
79 
85  int16_t sendTone(uint32_t addr);
86 
87  #if defined(RADIOLIB_BUILD_ARDUINO)
95  int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
96  #endif
97 
105  int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
106 
115  int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD);
116 
117  #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
126  int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask = 0xFFFFF);
127 
132  size_t available();
133 
134  #if defined(RADIOLIB_BUILD_ARDUINO)
144  int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
145  #endif
146 
157  int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
158 #endif
159 
160 #if !defined(RADIOLIB_GODMODE)
161  private:
162 #endif
163  PhysicalLayer* phyLayer;
164 
165  float baseFreq;
166  float dataRate;
167  uint32_t baseFreqRaw;
168  uint16_t shiftFreq;
169  uint16_t shiftFreqHz;
170  uint16_t bitDuration;
171  uint32_t filterAddr;
172  uint32_t filterMask;
173  bool inv = false;
174 
175  void write(uint32_t* data, size_t len);
176  void write(uint32_t codeWord);
177 
178 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
179  uint32_t read();
180 #endif
181 
182  uint8_t encodeBCD(char c);
183  char decodeBCD(uint8_t b);
184 };
185 
186 #endif
Client for Pager communication.
Definition: Pager.h:60
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