SparkFun Iridium 9604  v1.0.0
Library for the Iridium 9604 Hybrid LTE-M Cellular + Iridium Satellite (SBD) + GNSS IoT module
Loading...
Searching...
No Matches
urcHandlerVector.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <vector>
20#include <string.h>
21
22#include "urcHandler.h"
23
24// ===========================
25
26// Support for individual URCs is contained in these files.
27// Individual files can be commented out to save both program memory and RAM. (If a URC is commented
28// out, it is no longer kept in the backlog or decoded. Registering a callback for it fails - returns false.)
29// The URCs are tried in this order.
30
31// Sockets
36// Positioning
40// SIM
42// Internet services
47// Network registration
48#include "urcHandlers/urcCREG.h"
50// Satellite
51#include "urcHandlers/urcCIEV.h"
52#include "urcHandlers/urcAREG.h"
53
54// ===========================
55
57{
58
61 {
62 public:
63 std::vector<urcHandler *> urcHandlerVectors;
64
67 {
69 }
70
73 {
74 for (auto handler : urcHandlerVectors)
75 delete handler;
76 }
77
84 urcHandler *find(const char *urcPrefix)
85 {
86 for (auto handler : urcHandlerVectors)
87 {
88 if (handler->amI(urcPrefix))
89 return handler;
90 }
91 return nullptr;
92 }
93
102 bool setCallback(const char *urcPrefix, urcCallback_t callback, uint8_t index = 0)
103 {
104 urcHandler *handler = find(urcPrefix);
105 if (handler == nullptr)
106 return false;
107 return handler->setCallback(callback, index);
108 }
109
113 bool isURC(const char *event)
114 {
115 for (auto handler : urcHandlerVectors)
116 {
117 if (handler->_keepInBacklog && (handler->match(event) != nullptr))
118 return true;
119 }
120 return false;
121 }
122
130 bool processEvent(urcHandlerInterface &device, const char *event)
131 {
132 for (auto handler : urcHandlerVectors)
133 {
134 const char *params = handler->match(event);
135 if (params != nullptr)
136 {
137 if (handler->process(device, params))
138 return true;
139 }
140 }
141 return false;
142 }
143 };
144
145} // namespace SparkFun_Iridium_9604
Debug printing: replaces the SARA-R5 library _debugPort prints. A base class of DevIridium9604 and th...
Definition: sfe_debug.h:38
The base class for the URC handlers. See the file description for how to add a new URC.
Definition: urcHandler.h:92
bool setCallback(urcCallback_t callback, uint8_t index=0)
Set (or clear, with nullptr) callback 'index' for this URC.
Definition: urcHandler.h:152
urcHandlerInterface: the services DevIridium9604 provides to the URC handlers. DevIridium9604 inherit...
Definition: urcHandler.h:70
static urcHandlerRegistry & get(void)
Get the single, lazily-constructed urcHandlerRegistry instance.
Definition: urcHandler.h:182
void buildAll(std::vector< urcHandler * > &handlers) const
Construct one instance of every currently-registered URC handler class.
Definition: urcHandler.h:204
The collection of registered URC handlers. Replaces the SARA-R5 processURCEvent().
Definition: urcHandlerVector.h:61
bool processEvent(urcHandlerInterface &device, const char *event)
Pass an event to the handlers. The first handler which matches and decodes it, wins.
Definition: urcHandlerVector.h:130
urcHandlerVector(void)
Construct the vector and populate it with one instance of every registered URC handler.
Definition: urcHandlerVector.h:66
bool setCallback(const char *urcPrefix, urcCallback_t callback, uint8_t index=0)
Register (or clear) a user callback for a URC.
Definition: urcHandlerVector.h:102
~urcHandlerVector(void)
Destroy the vector, deleting every handler object it owns.
Definition: urcHandlerVector.h:72
urcHandler * find(const char *urcPrefix)
Find the registered handler for a URC prefix.
Definition: urcHandlerVector.h:84
std::vector< urcHandler * > urcHandlerVectors
The URC handler objects.
Definition: urcHandlerVector.h:63
bool isURC(const char *event)
Does this event contain a URC we want to keep in the backlog? Used by pruneBacklog().
Definition: urcHandlerVector.h:113
Definition: nmeaMessage.h:30
void(* urcCallback_t)(void)
The generic URC callback type. Cast your callback to this for setURCCallback().
Definition: urcHandler.h:59