GPRS通信问题!!!!!

xiatiancc1 2009-03-06 07:36:35
我最近在做实验,用的是博创ARM9的2410的板子,
在做到GPRS实验时,发现运行不下去了!
我找了很长时间的错误,但是还是没有找出来。我发现好像是GPRS模块与串口不通信,我写的AT命令好像不能通过串口写回GPRS模块里。

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>

//#include <sys/signal.h>
#include <pthread.h>
#include "tty.h"
#include "gprs.h"

/*--------------------------------------------------------*/
#define ENDMINITERM 27 /* ESC to quit miniterm */
#define FALSE 0
#define TRUE 1
/*--------------------------------------------------------*/
volatile int STOP=FALSE;
int GET_GPRS_OK=FALSE;
int baud=B115200;
int get_baudrate(int argc,char** argv);

char * cmd[20]={
"at",
"ate1",
"at+chfa=1", //设置通话通道为1,AT+CHFA 命令切换主副音频通道
"at+clvl=100", //设置受话器音量最大, AT+CLVL 命令可以调节输出音频信号增益
"at+cmic=1,10" //设置通道1的话筒增益

};


void * keyshell() ;
/*--------------------------------------------------------*/


void* gprs_read(void * data)
{
int i=0;
char c;
char buf[1024];
printf("\nread modem\n");

while (STOP==FALSE) {

tty_read(&c,1);
printf("%c",c);
}
printf("exit from reading modem\n");
return NULL;
}

/*--------------------------------------------------------*/
int main(int argc,char** argv)
{
int ok;
pthread_t th_a, th_b, th_show;
void * retval;


if(argc < 2) {
printf (" Default baudrate is 115200 bps. If not, please enter the baudrate as a parameter\n");
}
else
baud=get_baudrate(argc, argv);
tty_init();

pthread_create(&th_a, NULL, keyshell, 0);
pthread_create(&th_b, NULL, gprs_read, 0);

while(!STOP){
usleep(100000);
}
tty_end();
exit(0);
}

///////////////////////////////////////////////////////////////////////////////////////////////////

#define BAUDRATE B115200
#define COM1 "/dev/tts/1"
#define COM2 "/dev/tts/2"

static int fd;////volatile int fd
static struct termios oldtio,newtio;

//==============================================================
int tty_end()
{
tcsetattr(fd,TCSANOW,&oldtio); /* restore old modem setings */
// tcsetattr(0,TCSANOW,&oldstdtio); /* restore old tty setings */

}
//==============================================================
/*static void do_exit()
{
tty_end();
exit(1);
}*/
//==============================================================
int tty_read(char *buf,int nbytes)
{
return read(fd,buf,nbytes);
}
//==============================================================
int tty_write(char *buf,int nbytes)
{
int i;
for(i=0; i<nbytes; i++) {
write(fd,&buf[i],1);
usleep(100);
}
return tcdrain(fd);
}

//==============================================================
int tty_writecmd(char *buf,int nbytes)
{
int i;
for(i=0; i<nbytes; i++) {
write(fd,&buf[i],1);
usleep(100);
}
write(fd,"\r",1);
usleep(300000);
return tcdrain(fd);
//extern int tcdrain (int fildes);

}

//==============================================================

int tty_init()
{
fd = open(COM2, O_RDWR ); //| O_NONBLOCK);//
if (fd <0) {
perror(COM2);
exit(-1);
}


tcgetattr(fd,&oldtio); /* save current modem settings */

bzero(&newtio, sizeof(newtio)); /// 功能:置字节字符串s的前n个字节为零。


newtio.c_cflag = BAUDRATE | CRTSCTS |CS8 CLOCAL | CREAD ;//
newtio.c_iflag = IGNPAR | ICRNL;

newtio.c_oflag = 0;
newtio.c_lflag = ICANON;



newtio.c_cc[VTIME] = 0; /* 不使用分割字元组的计时器 */ // c_cc[VTIME] = TIME (\0),\0, 定时器值(参见后面说明)。
newtio.c_cc[VMIN] = 1; /* 在读取到 1 个字元前先停止 */// c_cc[VMIN] = MIN (\1),\1, 定时器值

tcflush(fd, TCIFLUSH);//刷清未决输入和/或输出 TCIFLUSH 0 // 清接收到的数据但不读。
tcsetattr(fd,TCSANOW,&newtio);/*set attrib *///// TCSANOW 0 // 改变立即发生
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void gprs_init()
{
int i;
for(i=0; i<5; i++) {
tty_writecmd(cmd[i], strlen(cmd[i]));
}


}

void gprs_hold()
{
tty_writecmd("at", strlen("at"));
tty_writecmd("ath", strlen("ath"));//拒绝或者挂断电话ATH
}

void gprs_ans()
{
tty_writecmd("at", strlen("at"));
tty_writecmd("ata", strlen("ata"));//接听电话ATA
}

//打电话
void gprs_call(char *number, int num)
{

tty_write("atd", strlen("atd")); //拨打号码ATD
tty_write(number, num);
tty_write(";\r", strlen(";\r"));
usleep(200000);
}


void gprs_msg(char *number, int num)
{
char ctl[]={26,0};
char text[]="Welcome to use up-tech embedded platform!";

tty_writecmd("at", strlen("at"));
tty_writecmd("at+cmgf=1", strlen("at+cmgf=1"));


tty_write("at+cmgs=", strlen("at+cmgs="));


tty_write("\"", strlen("\""));
tty_write(number, strlen(number));
tty_write("\"", strlen("\""));
tty_write(";\r", strlen(";\r"));


tty_write(text, strlen(text));
tty_write(ctl, 1);
usleep(300000);
}

void gprs_baud(char *baud,int num)
{
tty_write("at+ipr=", strlen("at+ipr="));

tty_writecmd(baud, strlen(baud) );
usleep(200000);
}

//////////////////////////////////////
请问下高人是哪里出了问题啊???
...全文
401 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wen287877566 2009-06-19
  • 打赏
  • 举报
回复
没有接触过,但感觉这个比较有意思
帮忙顶
tengulre 2009-04-23
  • 打赏
  • 举报
回复
看看mgetty的代码,我想会给你一些帮助
!
子晞 2009-04-22
  • 打赏
  • 举报
回复
代码看来一下,没有问题,你调试了没有?
eyun221 2009-04-22
  • 打赏
  • 举报
回复
up............
超龄编码人 2009-04-14
  • 打赏
  • 举报
回复
先用minicom打开串口手动发送at命令看是否返回 然后根据minicom的通讯参数 波特率,校验位,数据位等信息写代码
morris88 2009-04-14
  • 打赏
  • 举报
回复
貌似 AT 命令写错了,结束时应该是 Z...
cceczjxy 2009-03-31
  • 打赏
  • 举报
回复
没有用过这种板子,但做过gprs。
对于有的gprs模块,如果你确定模块已经启动,但没有返回数,一般是模块的波特率的问题。模块和机器通讯,它要设置一个波特率,你也要设置个波特率,如果两个设置不匹配,当然是不能通讯;
interfish520 2009-03-31
  • 打赏
  • 举报
回复
没用过板子,友情帮顶.
Bestrem_9 2009-03-30
  • 打赏
  • 举报
回复
弄过那款开发板,但是没有做过那个实验,以后有机会做下
  • 打赏
  • 举报
回复
不懂 ~~来学习的~
  • 打赏
  • 举报
回复
没做过GPRS,帮顶下
xhy_851221 2009-03-29
  • 打赏
  • 举报
回复
没做过
up
独孤过儿 2009-03-28
  • 打赏
  • 举报
回复
就看了個頭,有點疑問,不往下看了...

void* gprs_read(void * data) // 這個data的參數在哪裡用啊?要是不用,傳進來幹嘛?
{
int i=0;
char c;
char buf[1024]; // 這個buffer根本不用,那還聲明幹嗎?
printf("\nread modem\n");

while (STOP==FALSE) {

tty_read(&c,1);
printf("%c",c);
}
printf("exit from reading modem\n");
return NULL;
}

menghai1226 2009-03-28
  • 打赏
  • 举报
回复
你出现了什么问题呢 能不能具体点呢?

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧