blob: c9031815eb958d3839e75f39fe715c7f3d78639b (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gpio.h>
#include <serial.h>
int main() {
char *commandList[] = {"AT", "ATI", "AT+COPS?"/* ,
"AT+COPS=?" */},
serialFilePath[] = "/dev/serial0", *output = malloc(1);
int serialPort;
unsigned long idx;
serialPort = openSerialPort(serialFilePath);
if (serialPort < 0) {
printf("Error openSerialPort()\n");
free(output);
return 1;
}
/* if (0 != querySerialPort(&output, serialPort, "AT")) {
printf("Error querySerialPort()\n");
close(serialPort);
free(output);
return 1;
}
if (NULL == strstr(output, "OK\r\n")) {
if (0 != modemPowerToggle(17)) {
printf("Error toggling modem power\n");
free(output);
return 1;
}
} */
for (idx = 0; idx < sizeof(commandList) / sizeof(*commandList); idx++) {
if (0 != querySerialPort(&output, serialPort, commandList[idx])) {
printf("Error querySerialPort()\n");
close(serialPort);
free(output);
return 1;
}
printf("%s\n", output);
}
close(serialPort);
/* if (0 != modemPowerToggle(17)) {
printf("Error toggling modem power\n");
free(output);
return 1;
} */
free(output);
return 0;
}
|