From addad212bbf05f6599fea747ebae945cb16e5d96 Mon Sep 17 00:00:00 2001 From: kutayboz Date: Mon, 5 Jun 2023 05:30:20 +0300 Subject: Added device power status pin functionality --- src/main.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src/main.c') 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; } -- cgit v1.3