@@ -11,16 +11,120 @@ const char UBX_CELL_COMMAND_STOP_AUDIO[] = "+USAR"; // Stop audio resource
11
11
const char UBX_CELL_COMMAND_GENERATE_TONE[] = " +UTGN" ; // Tone generator
12
12
13
13
// Base class for any modules supporting voice calls
14
- class UBX_CELL_VOICE : virtual public UBX_CELL
14
+ template <typename T>
15
+ class UBX_CELL_VOICE
15
16
{
16
17
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);
18
+ UBX_CELL_error_t dial (String number)
19
+ {
20
+ char *command;
21
+ char *numberCStr;
22
+ UBX_CELL_error_t err;
23
+
24
+ numberCStr = static_cast <T*>(this )->ubx_cell_calloc_char (number.length () + 1 );
25
+ if (numberCStr == nullptr )
26
+ return UBX_CELL_ERROR_OUT_OF_MEMORY;
27
+ number.toCharArray (numberCStr, number.length () + 1 );
28
+
29
+ command = static_cast <T*>(this )->ubx_cell_calloc_char (strlen (UBX_CELL_COMMAND_DIAL) + strlen (numberCStr) + 3 );
30
+ if (command != nullptr )
31
+ {
32
+ // Heads up! The dial command is one of the only commands that requires a
33
+ // semicolon at the end of it!
34
+ sprintf (command, " %s=%s;" , UBX_CELL_COMMAND_DIAL, numberCStr);
35
+
36
+ err = static_cast <T*>(this )->sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK,
37
+ nullptr , UBX_CELL_10_SEC_TIMEOUT);
38
+
39
+ free (command);
40
+ }
41
+ else
42
+ {
43
+ err = UBX_CELL_ERROR_OUT_OF_MEMORY;
44
+ }
45
+
46
+ free (numberCStr);
47
+
48
+ return err;
49
+ }
50
+
51
+ UBX_CELL_error_t answer (void )
52
+ {
53
+ return static_cast <T*>(this )->sendCommandWithResponse (UBX_CELL_COMMAND_ANSWER, UBX_CELL_RESPONSE_OK_OR_ERROR,
54
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
55
+ }
56
+
57
+ UBX_CELL_error_t hangUp (void )
58
+ {
59
+ return static_cast <T*>(this )->sendCommandWithResponse (UBX_CELL_COMMAND_HANG_UP, UBX_CELL_RESPONSE_OK_OR_ERROR,
60
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
61
+ }
62
+
63
+ UBX_CELL_error_t playAudioResource (uint8_t audio_resource, uint8_t tone_id, uint8_t nof_repeat)
64
+ {
65
+ UBX_CELL_error_t err;
66
+ char *command;
67
+
68
+ command = static_cast <T*>(this )->ubx_cell_calloc_char (strlen (UBX_CELL_COMMAND_PLAY_AUDIO) + 13 );
69
+ if (command == nullptr )
70
+ return UBX_CELL_ERROR_OUT_OF_MEMORY;
71
+ sprintf (command, " %s=%d,%d,%d" , UBX_CELL_COMMAND_PLAY_AUDIO, audio_resource, tone_id, nof_repeat);
72
+
73
+ err = static_cast <T*>(this )->sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR,
74
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
75
+ free (command);
76
+ return err;
77
+ }
78
+
79
+ UBX_CELL_error_t stopAudioResource (uint8_t audio_resource)
80
+ {
81
+ UBX_CELL_error_t err;
82
+ char *command;
83
+
84
+ command = static_cast <T*>(this )->ubx_cell_calloc_char (strlen (UBX_CELL_COMMAND_STOP_AUDIO) + 5 );
85
+ if (command == nullptr )
86
+ return UBX_CELL_ERROR_OUT_OF_MEMORY;
87
+ sprintf (command, " %s=%d" , UBX_CELL_COMMAND_STOP_AUDIO, audio_resource);
88
+
89
+ err = static_cast <T*>(this )->sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR,
90
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
91
+ free (command);
92
+ return err;
93
+ }
94
+
95
+ UBX_CELL_error_t generateToneFreq (uint16_t frequency, uint16_t duration, uint8_t volume)
96
+ {
97
+ UBX_CELL_error_t err;
98
+ char *command;
99
+ char response[] = " \r\n OK\r\n\r\n +UUTGN: 0\r\n " ;
100
+
101
+ command = static_cast <T*>(this )->ubx_cell_calloc_char (strlen (UBX_CELL_COMMAND_GENERATE_TONE) + 15 );
102
+ if (command == nullptr )
103
+ return UBX_CELL_ERROR_OUT_OF_MEMORY;
104
+ sprintf (command, " %s=%d,%d,%d" , UBX_CELL_COMMAND_GENERATE_TONE, frequency, duration, volume);
105
+
106
+ err = static_cast <T*>(this )->sendCommandWithResponse (command, response,
107
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
108
+ free (command);
109
+ return err;
110
+ }
111
+
112
+ UBX_CELL_error_t generateToneDTMF (char dtmf_character, uint16_t duration, uint8_t volume)
113
+ {
114
+ UBX_CELL_error_t err;
115
+ char *command;
116
+ char response[] = " \r\n OK\r\n\r\n +UUTGN: 0\r\n " ;
117
+
118
+ command = static_cast <T*>(this )->ubx_cell_calloc_char (strlen (UBX_CELL_COMMAND_GENERATE_TONE) + 14 );
119
+ if (command == nullptr )
120
+ return UBX_CELL_ERROR_OUT_OF_MEMORY;
121
+ sprintf (command, " %s=\" %c\" ,%d,%d" , UBX_CELL_COMMAND_GENERATE_TONE, dtmf_character, duration, volume);
122
+
123
+ err = static_cast <T*>(this )->sendCommandWithResponse (command, response,
124
+ nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
125
+ free (command);
126
+ return err;
127
+ }
24
128
};
25
129
26
130
#endif
0 commit comments