aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_gprs.c
blob: fa0bf3b4962479e4c703bd2ce50445580e8f0374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * File Name:       test_gprs.c
 * Workflow:        init serial port, write to GPRS module
 * Return Value:    0 always
 */

/* Header files */
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "uart_api.h"

int main() {

  int gprs_fd;

  gprs_fd = open_port("/dev/ttyUSB0");

  set_comfig(gprs_fd, 9600);

  char temp[32] = {0};

  memset(temp, '\0', 32);
  strcpy(temp, "AT\n");
  write(gprs_fd, temp, strlen(temp));
  read(gprs_fd, temp, 32);

  if (strncmp(temp, "OK", 2)) {
    printf("[SUCCESS]Connection fine!\n");
  } else {
    printf("[ERROR]Connection invalid!\n");
  }

  sleep(1);

  printf("Testing module function......\n");
  memset(temp, '\0', 32);

  sprintf(temp, "ATD%s;", "YOUR PHONE NUMBER");

  strcat(temp, "\n");

  write(gprs_fd, temp, strlen(temp));

  return 0;
}