summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gpio.c7
-rw-r--r--src/main.c10
2 files changed, 7 insertions, 10 deletions
diff --git a/src/gpio.c b/src/gpio.c
index 9c00805..74d37ef 100644
--- a/src/gpio.c
+++ b/src/gpio.c
@@ -1,5 +1,6 @@
#include <gpiod.h>
#include <stdio.h>
+#include <unistd.h>
int modemPowerToggle(int pinNum) {
struct gpiod_chip *chip;
@@ -11,8 +12,7 @@ int modemPowerToggle(int pinNum) {
return 1;
}
- line = gpiod_chip_get_line(
- chip, pinNum); // Replace with the desired GPIO pin number
+ line = gpiod_chip_get_line(chip, pinNum);
if (!line) {
perror("Error getting GPIO line");
gpiod_chip_close(chip);
@@ -54,8 +54,7 @@ int checkPinVal(int pinNum) {
return -1;
}
- line = gpiod_chip_get_line(
- chip, pinNum); // Replace with the desired GPIO pin number
+ line = gpiod_chip_get_line(chip, pinNum);
if (!line) {
perror("Error getting GPIO line");
gpiod_chip_close(chip);
diff --git a/src/main.c b/src/main.c
index 408fcb6..df33ffb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
+#include <unistd.h>
#include <gpio.h>
#include <serial.h>
@@ -8,7 +10,7 @@
int main() {
char *commandList[] = {"AT", "ATI", "AT+COPS?", "AT+COPS=?"},
- serialFilePath[] = "/dev/serial0", *output = malloc(1);
+ serialFilePath[] = "/dev/serial0", *output;
int serialPort, moduleStatus;
unsigned long idx;
@@ -17,14 +19,11 @@ int main() {
moduleStatus = checkPinVal(27);
if (0 > moduleStatus) {
printf("Error checkPinVal()\n");
- close(serialPort);
- free(output);
return 1;
} 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);
@@ -32,7 +31,6 @@ int main() {
sleep(1);
if (time(NULL) - pwrKeyTime > 10) {
printf("Modem power on takes longer than 10s\nAborting\n");
- free(output);
return 1;
}
}
@@ -41,10 +39,10 @@ int main() {
serialPort = openSerialPort(serialFilePath);
if (serialPort < 0) {
printf("Error openSerialPort()\n");
- free(output);
return 1;
}
+ output = malloc(1);
for (idx = 0; idx < sizeof(commandList) / sizeof(*commandList); idx++) {
if (0 != querySerialPort(&output, serialPort, commandList[idx])) {
printf("Error querySerialPort()\n");