Skip to content

Commit 7efffde

Browse files
committed
Add RING URC handler
Pending #16, this should work after that gets merged
1 parent e109e63 commit 7efffde

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/sfe_ublox_cellular_voice.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const char* const UBX_CELL_COMMAND_PLAY_AUDIO = "+UPAR"; // Play audio resour
1010
const char* const UBX_CELL_COMMAND_STOP_AUDIO = "+USAR"; // Stop audio resource
1111
const char* const UBX_CELL_COMMAND_GENERATE_TONE = "+UTGN"; // Tone generator
1212

13+
const char* const UBX_CELL_RING_URC = "RING";
14+
1315
typedef enum
1416
{
1517
UBX_CELL_AUDIO_RESOURCE_TONE = 0,
@@ -22,6 +24,15 @@ template <typename T>
2224
class UBX_CELL_VOICE
2325
{
2426
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+
2536
UBX_CELL_error_t dial(String number)
2637
{
2738
char *command;
@@ -132,6 +143,31 @@ class UBX_CELL_VOICE
132143
free(command);
133144
return err;
134145
}
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+
}
135171
};
136172

137173
class UBX_CELL_VOICE_BASE : public UBX_CELL, public UBX_CELL_VOICE<UBX_CELL_VOICE_BASE>

0 commit comments

Comments
 (0)