/* * File Name: test_gprs.c * Workflow: init serial port, write to GPRS module * Return Value: 0 always */ /* Header files */ #include #include #include #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; }