summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c
index c903181..408fcb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,33 +7,43 @@
int main() {
- char *commandList[] = {"AT", "ATI", "AT+COPS?"/* ,
- "AT+COPS=?" */},
+ char *commandList[] = {"AT", "ATI", "AT+COPS?", "AT+COPS=?"},
serialFilePath[] = "/dev/serial0", *output = malloc(1);
- int serialPort;
+ int serialPort, moduleStatus;
unsigned long idx;
+ time_t pwrKeyTime;
- serialPort = openSerialPort(serialFilePath);
- if (serialPort < 0) {
- printf("Error openSerialPort()\n");
- free(output);
- return 1;
- }
-
- /* if (0 != querySerialPort(&output, serialPort, "AT")) {
- printf("Error querySerialPort()\n");
+ moduleStatus = checkPinVal(27);
+ if (0 > moduleStatus) {
+ printf("Error checkPinVal()\n");
close(serialPort);
free(output);
return 1;
- }
- if (NULL == strstr(output, "OK\r\n")) {
+ } else if (moduleStatus == 0) {
+ printf("Module is off\nPowering on\n");
if (0 != modemPowerToggle(17)) {
printf("Error toggling modem power\n");
free(output);
return 1;
}
- } */
+ pwrKeyTime = time(NULL);
+ while (!checkPinVal(27)) {
+ sleep(1);
+ if (time(NULL) - pwrKeyTime > 10) {
+ printf("Modem power on takes longer than 10s\nAborting\n");
+ free(output);
+ return 1;
+ }
+ }
+ }
+
+ serialPort = openSerialPort(serialFilePath);
+ if (serialPort < 0) {
+ printf("Error openSerialPort()\n");
+ free(output);
+ return 1;
+ }
for (idx = 0; idx < sizeof(commandList) / sizeof(*commandList); idx++) {
if (0 != querySerialPort(&output, serialPort, commandList[idx])) {
@@ -47,12 +57,6 @@ int main() {
close(serialPort);
- /* if (0 != modemPowerToggle(17)) {
- printf("Error toggling modem power\n");
- free(output);
- return 1;
- } */
-
free(output);
return 0;
}