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
urcHandler.h File Reference
#include "sfe_platform.h"
#include "sfe_ip_address.h"
#include "sfe_debug.h"
#include "Iridium_9604_typedefs.h"
#include <string.h>
#include <vector>
Include dependency graph for urcHandler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SparkFun_Iridium_9604::urcHandlerInterface
 urcHandlerInterface: the services DevIridium9604 provides to the URC handlers. DevIridium9604 inherits (implements) this interface. More...
 
class  SparkFun_Iridium_9604::urcHandler
 The base class for the URC handlers. See the file description for how to add a new URC. More...
 
class  SparkFun_Iridium_9604::urcHandlerRegistry
 The registry of URC handler classes - mirrors the GNSS v4 message registries. More...
 
class  SparkFun_Iridium_9604::urcHandlerBuilder< HandlerType >
 Declared (by urcRegisterHandler) at the bottom of each URC handler header. Registers the handler class with the urcHandlerRegistry. More...
 

Namespaces

namespace  SparkFun_Iridium_9604
 

Macros

#define urcRegisterHandler(kHandler)   static urcHandlerBuilder<kHandler> global_##kHandler##Builder;
 Declare a file-scope static builder that self-registers a URC handler class. More...
 

Typedefs

typedef void(* SparkFun_Iridium_9604::urcCallback_t) (void)
 The generic URC callback type. Cast your callback to this for setURCCallback(). More...
 

Variables

const uint8_t SparkFun_Iridium_9604::URC_MAX_CALLBACKS = 3
 The maximum number of user callbacks per URC. More...
 

Detailed Description

Date
2026

SPDX-License-Identifier: MIT

Please see LICENSE.md for more details

https://github.com/sparkfun/SparkFun_Iridium_9604_Library

Support for Unsolicited Result Codes (URCs): the urcHandler base class, the urcHandlerInterface (the parts of DevIridium9604 a handler is allowed to use) and the self-registration machinery.

In the original SARA-R5 library, every URC was decoded by one large function: processURCEvent(). Adding a URC meant editing processURCEvent() and pruneBacklog(). Here, each URC has its own class, in its own header file in src/urcHandlers/. Each class:

  • knows its URC prefix (e.g. "+UUSORD:")
  • parses the URC parameters in process()
  • calls the user's callback (if one has been registered), or calls back into DevIridium9604 via urcHandlerInterface where the URC needs more AT commands (e.g. reading socket data)
  • self-registers, exactly like the GNSS v4 NMEA and UBX message classes do, using urcRegisterHandler() at the bottom of its header

DevIridium9604 owns a urcHandlerVector (see urcHandlerVector.h) which builds one instance of every registered handler. bufferedPoll() / poll() pass each event to urcHandlerVector::processEvent(); pruneBacklog() asks urcHandlerVector::isURC() which events to keep.

User callbacks are registered with DevIridium9604::setURCCallback(urcPrefix, callback, index) - or with the typed helpers which call it (setSocketReadCallback(), setPingCallback(), etc.). The callback pointer is stored in the handler as a generic function pointer (urcCallback_t) and cast back to the handler's own typed signature when it is called. (Converting a function pointer to another function pointer type and back again is well defined in C++.) This means DevIridium9604 does not need to know the handler class - so a handler header can be commented out of urcHandlerVector.h to save memory without breaking the build.

Adding a new URC:

  1. Copy one of the handlers in src/urcHandlers/ (e.g. urcUUSOCL.h)
  2. Change the class name, the URC prefix, process() and the callback signature
  3. Add the header to the list in urcHandlerVector.h - or include it in your own code before the DevIridium9604 object is defined
  4. Register your callback with setURCCallback()

Macro Definition Documentation

◆ urcRegisterHandler

#define urcRegisterHandler (   kHandler)    static urcHandlerBuilder<kHandler> global_##kHandler##Builder;

Declare a file-scope static builder that self-registers a URC handler class.

Placed at the bottom of each per-URC header (e.g. urcUUSORD.h), inside namespace SparkFun_Iridium_9604.