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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ******************************************************************************** *
* *
*
嵌入式资源免费下载专区
: http://www.2beanet.com *
* *
* *
* ******************************************************************************** */
// this is a test about GPRS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h> // open() close()
#include <unistd.h> // read() write()
#include <termios.h> // set baud rate
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#define FUNC_RUN 0
#define FUNC_NOT_RUN 1
#define SIMPLE_TEST 1
#define READ_SIM_CARD_ID 2
#define MAKE_A_CALL 3
#define WAIT_A_CALL 4
#define SHORT_MESSAGE 5
#define FUNC_QUIT 6
#define SEND_SHORT_MESSAGE 1
#define READ_SHORT_MESSAGE 2
#define CONFIG_SHORT_MESSAGE_ENV 3
#define QUIT_SHORT_MESSAGE 4
#define DEVICE_TTYS "/dev/ttyS0"
#define MAX_LEN_OF_SHORT_MESSAGE 140
#define RECEIVE_BUF_WAIT_1S 1
#define RECEIVE_BUF_WAIT_2S 2
#define RECEIVE_BUF_WAIT_3S 3
#define RECEIVE_BUF_WAIT_4S 4
#define RECEIVE_BUF_WAIT_5S 5
//------------------------------------- read datas from GSM/GPRS ---------------------------
// succese return 1
// error return 0
int read_GSM_GPRS_datas(int fd, char *rcv_buf,int rcv_wait)
{
int retval;
fd_set rfds;
struct timeval tv;
int ret,pos;
tv.tv_sec = rcv_wait; // wait 2.5s
tv.tv_usec = 0;
pos = 0; // point to rceeive buf
while (1)
{
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
retval = select(fd+1 , &rfds, NULL, NULL, &tv);
if (retval == -1)
{
perror("select()");
break;
}
Linux
下通过串口收发短信源码
.c 2010-3-26 20:53
Page 1 of 6