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
urcUUPING.h
Go to the documentation of this file.
1
20#pragma once
21
22#include "../urcHandler.h"
23
25{
26
28 class urcUUPING : public urcHandler
29 {
30 public:
31 typedef void (*callback_t)(int, int, sfe_string_t, sfe_ip_address_t, int, long);
32
34
35 bool process(urcHandlerInterface &device, const char *params)
36 {
37 int retry = 0;
38 int p_size = 0;
39 int ttl = 0;
40 sfe_string_t remote_host = "";
41 sfe_ip_address_t remoteIP = {0, 0, 0, 0};
42 long rtt = 0;
43
44 // Try to extract the UUPING retries and payload size
45 int scanNum = sscanf(params, "%d,%d,", &retry, &p_size);
46 if (scanNum != 2)
47 return false;
48
49 device.urcDebug().debugPrintln("processURCEvent: ping");
50
51 const char *searchPtr = strchr(params, '\"'); // Search to the first quote
52 if (searchPtr != nullptr)
53 {
54 // Extract the remote host name, stop at the next quote
55 while ((*(++searchPtr) != '\"') && (*searchPtr != '\0'))
56 {
57 remote_host += *(searchPtr);
58 }
59
60 if (*searchPtr != '\0') // Make sure we found a quote
61 {
62 int remoteIPstore[4];
63 scanNum = sscanf(searchPtr, "\",\"%d.%d.%d.%d\",%d,%ld",
64 &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3], &ttl, &rtt);
65 if (scanNum == 6) // Make sure we extracted enough data
66 {
67 for (int i = 0; i <= 3; i++)
68 remoteIP[i] = (uint8_t)remoteIPstore[i];
69
70 if (_callbackPtr[0] != nullptr)
71 ((callback_t)_callbackPtr[0])(retry, p_size, remote_host, remoteIP, ttl, rtt);
72 }
73 }
74 }
75 return true;
76 }
77 };
78
80
81} // namespace SparkFun_Iridium_9604
const char IRIDIUM_9604_PING_COMMAND_URC[]
The +UUPING: URC.
Definition: Iridium_9604_AT_commands.h:154
void debugPrintln(const char *message, bool important=false)
Print a debug message followed by a newline, if debugging is enabled.
Definition: sfe_debug.cpp:76
The base class for the URC handlers. See the file description for how to add a new URC.
Definition: urcHandler.h:92
urcCallback_t _callbackPtr[URC_MAX_CALLBACKS]
The user's callbacks, stored generically.
Definition: urcHandler.h:168
void addURC(const char *urcPrefix, bool keepInBacklog=true)
Register this handler's identity. Called once, from the subclass's own constructor.
Definition: urcHandler.h:108
urcHandlerInterface: the services DevIridium9604 provides to the URC handlers. DevIridium9604 inherit...
Definition: urcHandler.h:70
virtual SfeDebugPrint & urcDebug(void)=0
The debug printer.
The URC handler for +UUPING: - Ping Result. See the file description for the callback(s).
Definition: urcUUPING.h:29
urcUUPING(void)
Definition: urcUUPING.h:33
bool process(urcHandlerInterface &device, const char *params)
Parse the URC parameters and act on them.
Definition: urcUUPING.h:35
void(* callback_t)(int, int, sfe_string_t, sfe_ip_address_t, int, long)
The callback signature. See the file description.
Definition: urcUUPING.h:31
Definition: nmeaMessage.h:30
#define urcRegisterHandler(kHandler)
Declare a file-scope static builder that self-registers a URC handler class.
Definition: urcHandler.h:238