Skip to content

Commit 71c39a9

Browse files
committed
Add voice class
1 parent 0f2b97e commit 71c39a9

File tree

3 files changed

+143
-4
lines changed

3 files changed

+143
-4
lines changed

src/sfe_lara_r6.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
#define SFE_LARA_R6_LIBRARY_H
33

44
#include "sfe_ublox_cellular.h"
5+
#include "sfe_ublox_cellular_voice.h"
56

67
// Base LARA-R6 class
7-
class LARA_R6: public UBX_CELL
8+
class LARA_R6: virtual public UBX_CELL
89
{
910

1011
};
1112

12-
class LARA_R6001: public LARA_R6
13+
class LARA_R6001: public LARA_R6, public UBX_CELL_VOICE
1314
{
1415

1516
};
@@ -19,7 +20,7 @@ class LARA_R6001D: public LARA_R6
1920

2021
};
2122

22-
class LARA_R6401: public LARA_R6
23+
class LARA_R6401: public LARA_R6, public UBX_CELL_VOICE
2324
{
2425

2526
};
@@ -29,7 +30,7 @@ class LARA_R6401D: public LARA_R6
2930

3031
};
3132

32-
class LARA_R6801_00B: public LARA_R6
33+
class LARA_R6801_00B: public LARA_R6, public UBX_CELL_VOICE
3334
{
3435

3536
};

src/sfe_ublox_cellular_voice.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "sfe_ublox_cellular_voice.h"
2+
3+
UBX_CELL_error_t UBX_CELL_VOICE::dial(String number)
4+
{
5+
char *command;
6+
char *numberCStr;
7+
UBX_CELL_error_t err;
8+
9+
numberCStr = ubx_cell_calloc_char(number.length() + 1);
10+
if (numberCStr == nullptr)
11+
return UBX_CELL_ERROR_OUT_OF_MEMORY;
12+
number.toCharArray(numberCStr, number.length() + 1);
13+
14+
command = ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_DIAL) + strlen(numberCStr) + 3);
15+
if (command != nullptr)
16+
{
17+
// Heads up! The dial command is one of the only commands that requires a
18+
// semicolon at the end of it!
19+
sprintf(command, "%s=%s;", UBX_CELL_COMMAND_DIAL, numberCStr);
20+
21+
err = sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK,
22+
nullptr, UBX_CELL_10_SEC_TIMEOUT);
23+
24+
free(command);
25+
}
26+
else
27+
{
28+
err = UBX_CELL_ERROR_OUT_OF_MEMORY;
29+
}
30+
31+
free(numberCStr);
32+
33+
return err;
34+
}
35+
36+
UBX_CELL_error_t UBX_CELL_VOICE::answer(void)
37+
{
38+
return sendCommandWithResponse(UBX_CELL_COMMAND_ANSWER, UBX_CELL_RESPONSE_OK_OR_ERROR,
39+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
40+
}
41+
42+
UBX_CELL_error_t UBX_CELL_VOICE::hangUp(void)
43+
{
44+
return sendCommandWithResponse(UBX_CELL_COMMAND_HANG_UP, UBX_CELL_RESPONSE_OK_OR_ERROR,
45+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
46+
}
47+
48+
UBX_CELL_error_t UBX_CELL_VOICE::playAudioResource(uint8_t audio_resource, uint8_t tone_id, uint8_t nof_repeat)
49+
{
50+
UBX_CELL_error_t err;
51+
char *command;
52+
53+
command = ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_PLAY_AUDIO) + 13);
54+
if (command == nullptr)
55+
return UBX_CELL_ERROR_OUT_OF_MEMORY;
56+
sprintf(command, "%s=%d,%d,%d", UBX_CELL_COMMAND_PLAY_AUDIO, audio_resource, tone_id, nof_repeat);
57+
58+
err = sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK_OR_ERROR,
59+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
60+
free(command);
61+
return err;
62+
}
63+
64+
UBX_CELL_error_t UBX_CELL_VOICE::stopAudioResource(uint8_t audio_resource)
65+
{
66+
UBX_CELL_error_t err;
67+
char *command;
68+
69+
command = ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_STOP_AUDIO) + 5);
70+
if (command == nullptr)
71+
return UBX_CELL_ERROR_OUT_OF_MEMORY;
72+
sprintf(command, "%s=%d", UBX_CELL_COMMAND_STOP_AUDIO, audio_resource);
73+
74+
err = sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK_OR_ERROR,
75+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
76+
free(command);
77+
return err;
78+
}
79+
80+
UBX_CELL_error_t UBX_CELL_VOICE::generateToneFreq(uint16_t frequency, uint16_t duration, uint8_t volume)
81+
{
82+
UBX_CELL_error_t err;
83+
char *command;
84+
char response[] = "\r\nOK\r\n\r\n+UUTGN: 0\r\n";
85+
86+
command = ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_GENERATE_TONE) + 15);
87+
if (command == nullptr)
88+
return UBX_CELL_ERROR_OUT_OF_MEMORY;
89+
sprintf(command, "%s=%d,%d,%d", UBX_CELL_COMMAND_GENERATE_TONE, frequency, duration, volume);
90+
91+
err = sendCommandWithResponse(command, response,
92+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
93+
free(command);
94+
return err;
95+
}
96+
97+
UBX_CELL_error_t UBX_CELL_VOICE::generateToneDTMF(char dtmf_character, uint16_t duration, uint8_t volume)
98+
{
99+
UBX_CELL_error_t err;
100+
char *command;
101+
char response[] = "\r\nOK\r\n\r\n+UUTGN: 0\r\n";
102+
103+
command = ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_GENERATE_TONE) + 14);
104+
if (command == nullptr)
105+
return UBX_CELL_ERROR_OUT_OF_MEMORY;
106+
sprintf(command, "%s=\"%c\",%d,%d", UBX_CELL_COMMAND_GENERATE_TONE, dtmf_character, duration, volume);
107+
108+
err = sendCommandWithResponse(command, response,
109+
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
110+
free(command);
111+
return err;
112+
}

src/sfe_ublox_cellular_voice.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef SPARKFUN_UBX_CELL_VOICE_ARDUINO_LIBRARY_H
2+
#define SPARKFUN_UBX_CELL_VOICE_ARDUINO_LIBRARY_H
3+
4+
#include "sfe_ublox_cellular.h"
5+
6+
const char UBX_CELL_COMMAND_DIAL[] = "D"; // Dial command
7+
const char UBX_CELL_COMMAND_ANSWER[] = "A"; // Answer call
8+
const char UBX_CELL_COMMAND_HANG_UP[] = "+CHUP"; // Hang up call
9+
const char UBX_CELL_COMMAND_PLAY_AUDIO[] = "+UPAR"; // Play audio resource
10+
const char UBX_CELL_COMMAND_STOP_AUDIO[] = "+USAR"; // Stop audio resource
11+
const char UBX_CELL_COMMAND_GENERATE_TONE[] = "+UTGN"; // Tone generator
12+
13+
// Base class for any modules supporting voice calls
14+
class UBX_CELL_VOICE: virtual public UBX_CELL
15+
{
16+
public:
17+
UBX_CELL_error_t dial(String number);
18+
UBX_CELL_error_t answer(void);
19+
UBX_CELL_error_t hangUp(void);
20+
UBX_CELL_error_t playAudioResource(uint8_t audio_resource, uint8_t tone_id, uint8_t nof_repeat);
21+
UBX_CELL_error_t stopAudioResource(uint8_t audio_resource);
22+
UBX_CELL_error_t generateToneFreq(uint16_t frequency, uint16_t duration, uint8_t volume);
23+
UBX_CELL_error_t generateToneDTMF(char dtmf_character, uint16_t duration, uint8_t volume);
24+
};
25+
26+
#endif

0 commit comments

Comments
 (0)