From e3460fb4598cc1460d6c6c7e48ccebaec6b4b119 Mon Sep 17 00:00:00 2001 From: kutayboz Date: Tue, 6 Jun 2023 20:03:51 +0300 Subject: Compiler parameters correction and resulting fixes. --- CMakeLists.txt | 6 +++--- src/gpio.c | 7 +++---- src/main.c | 10 ++++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2bf1ac..141e300 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,9 @@ set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD_REQUIRED True) project(network_monitor VERSION 0.1.0) -set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -pedantic-errors") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2") +set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -pedantic-errors") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2") add_executable(network_monitor ./src/main.c) add_library(gpio STATIC ./src/gpio.c ./include/gpio.h) 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 #include +#include 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 #include #include +#include +#include #include #include @@ -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"); -- cgit v1.3