diff options
Diffstat (limited to 'src/bg96.c')
| -rw-r--r-- | src/bg96.c | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -1,6 +1,7 @@ #include "bg96.h" -#include "gpio.h" #include "serial.h" +#include "utils.h" +#include <gpiod.h> #include <inttypes.h> #include <math.h> #include <stdio.h> @@ -9,6 +10,47 @@ #include <time.h> #include <unistd.h> +int modemPowerToggle(char *pathToChip, int pinNum) { + struct gpiod_chip *chip; + struct gpiod_line *line; + + chip = gpiod_chip_open(pathToChip); + if (!chip) { + perror("Error opening GPIO chip"); + return 1; + } + + line = gpiod_chip_get_line(chip, pinNum); + if (!line) { + perror("Error getting GPIO line"); + gpiod_chip_close(chip); + return 1; + } + + if (gpiod_line_request_output(line, "cellular modem power toggle", 0) < 0) { + perror("Error setting GPIO line as output"); + gpiod_chip_close(chip); + return 1; + } + + if (gpiod_line_set_value(line, 1) < 0) { + perror("Error setting GPIO line high"); + gpiod_chip_close(chip); + return 1; + } + + sleep(1); + + if (gpiod_line_set_value(line, 0) < 0) { + perror("Error setting GPIO line low"); + gpiod_chip_close(chip); + return 1; + } + + gpiod_chip_close(chip); + return 0; +} + int initNetworkData(networkData *nD) { nD->operatorName = calloc(1, sizeof(char)); nD->networkName = calloc(1, sizeof(char)); |
