-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
call.c
74 lines (73 loc) · 2.18 KB
/
call.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "gsm.h"
#if (_GSM_CALL == 1)
//###############################################################################################################
bool gsm_call_answer(void)
{
if (gsm_lock(10000) == false)
{
gsm_printf("[GSM] call_answer() failed!\r\n");
return false;
}
if (gsm_command("ATA\r\n", 1000, NULL, 0, 2, "\r\nOK\r\n", "\r\nERROR\r\n") != 1)
{
gsm_printf("[GSM] call_answer() failed!\r\n");
gsm_unlock();
return false;
}
memset(gsm.call.dtmfBuffer, 0, sizeof(gsm.call.dtmfBuffer));
gsm.call.dtmfCount = 0;
gsm.call.dtmfUpdate = 0;
gsm_printf("[GSM] call_answer() done\r\n");
gsm_unlock();
return true;
}
//###############################################################################################################
bool gsm_call_dial(const char *number, uint8_t waitSecond)
{
gsm_printf("[GSM] call_dial() begin\r\n");
char str[32];
if (gsm_lock(10000) == false)
{
gsm_printf("[GSM] call_dial() failed!\r\n");
return false;
}
memset(gsm.call.dtmfBuffer, 0, sizeof(gsm.call.dtmfBuffer));
gsm.call.dtmfCount = 0;
gsm.call.dtmfUpdate = 0;
sprintf(str, "ATD%s;\r\n", number);
uint8_t ans = gsm_command(str, waitSecond * 1000, NULL, 0, 5, "\r\nNO DIALTONE\r\n", "\r\nBUSY\r\n",
"\r\nNO CARRIER\r\n", "\r\nNO ANSWER\r\n", "\r\nOK\r\n");
if (ans == 5)
{
gsm_printf("[GSM] call_dial() done\r\n");
gsm_unlock();
return true;
}
else
{
gsm_printf("[GSM] call_dial() failed!\r\n");
gsm_unlock();
gsm_call_end();
return false;
}
}
//###############################################################################################################
bool gsm_call_end(void)
{
if (gsm_lock(10000) == false)
{
gsm_printf("[GSM] call_end() failed!\r\n");
return false;
}
if (gsm_command("ATH\r\n", 20000 , NULL, 0, 2, "\r\nOK\r\n", "\r\nERROR\r\n") != 1)
{
gsm_printf("[GSM] call_end() failed!\r\n");
gsm_unlock();
return false;
}
gsm_printf("[GSM] call_end() done\r\n");
gsm_unlock();
return true;
}
//#############################################################################################
#endif