@@ -10,6 +10,8 @@ const char* const UBX_CELL_COMMAND_PLAY_AUDIO = "+UPAR"; // Play audio resour
10
10
const char * const UBX_CELL_COMMAND_STOP_AUDIO = " +USAR" ; // Stop audio resource
11
11
const char * const UBX_CELL_COMMAND_GENERATE_TONE = " +UTGN" ; // Tone generator
12
12
13
+ const char * const UBX_CELL_RING_URC = " RING" ;
14
+
13
15
typedef enum
14
16
{
15
17
UBX_CELL_AUDIO_RESOURCE_TONE = 0 ,
@@ -22,6 +24,15 @@ template <typename T>
22
24
class UBX_CELL_VOICE
23
25
{
24
26
public:
27
+ UBX_CELL_VOICE (void )
28
+ {
29
+ // Set ring URC callback to nullptr
30
+ _ringCallback = nullptr ;
31
+
32
+ // Add handler for ring URC
33
+ static_cast <T*>(this )->addURCHandler (UBX_CELL_RING_URC, [this ](const char * event){return this ->urcCheckRing (event);});
34
+ }
35
+
25
36
UBX_CELL_error_t dial (String number)
26
37
{
27
38
char *command;
@@ -132,6 +143,31 @@ class UBX_CELL_VOICE
132
143
free (command);
133
144
return err;
134
145
}
146
+
147
+ void setRingCallback (void (*callback)(void ))
148
+ {
149
+ _ringCallback = callback;
150
+ }
151
+
152
+ protected:
153
+ // Callback for incoming calls
154
+ void (*_ringCallback)(void );
155
+
156
+ bool urcCheckRing (const char *event)
157
+ {
158
+ int socket, length;
159
+ char *searchPtr = strstr (event, UBX_CELL_RING_URC);
160
+ if (searchPtr != nullptr )
161
+ {
162
+ if (_ringCallback != nullptr )
163
+ {
164
+ _ringCallback ();
165
+ }
166
+ return true ;
167
+ }
168
+
169
+ return false ;
170
+ }
135
171
};
136
172
137
173
class UBX_CELL_VOICE_BASE : public UBX_CELL , public UBX_CELL_VOICE <UBX_CELL_VOICE_BASE>
0 commit comments