gprs/gsm 在linux下的应用
之前有篇随笔整理了一种在裸机下用状态机+超时的机制来操作gprs/gsm,linux下就不需要了,本身有完善的调度机制,在等待的流程中直接sleep就行了。
下面是飞凌OK6410下的 demo, 其他基于linux的硬件平台都是一样操作,与前面那篇裸机状态下的处理作个对比。
main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#ifndef __TTY_H__
#define __TTY_H__
int tty_init();
int tty_end();
int tty_write(char *buf,int nbytes);
int tty_writecmd(char *buf,int nbytes);
int tty_read(char *buf,int nbytes);
#endif
#ifndef __GPRS_H__
#define __GPRS_H__
void gprs_init();
void gprs_msg();
void gprs_read();
#endif
#define BAUDRATE B9600
#define COM0 "/dev/ttySAC0"
#define COM1 "/dev/ttySAC1"
#define COM2 "/dev/ttySAC2"
static int fd;
static struct termios oldtio,newtio;
#define ENDMINITERM 27
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
int GET_GPRS_OK=FALSE;
int baud=B9600;
int tty_end()
{
tcsetattr(fd,TCSANOW,&oldtio);
close(fd);
}
int tty_read(char *buf,int nbytes)
{
return read(fd,buf,nbytes);
}
int tty_write(char *buf,int nbytes)
{
int i;
; i<nbytes; i++) {
write(fd,&buf[i],);
usleep();
}
return tcdrain(fd);
}
int tty_writecmd(char *buf,int nbytes)
{
int i;
; i<nbytes; i++) {
write(fd,&buf[i],);
usleep();
}
write(fd,);
sleep();
return tcdrain(fd);
}
int tty_init()
{
fd = open(COM1, O_RDWR ); //| O_NONBLOCK);//
) {
perror(COM1);
exit(-);
}
tcgetattr(fd,&oldtio); /* save current modem settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = baud | /*CRTSCTS |*/ CS8 /*| CLOCAL | CREAD */;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = ;
newtio.c_lflag = ICANON;
newtio.c_cc[VINTR] = ; /* Ctrl-c */
newtio.c_cc[VQUIT] = ; /* Ctrl-\ */
newtio.c_cc[VERASE] = ; /* del */
newtio.c_cc[VKILL] = ; /* @ */
newtio.c_cc[VEOF] = ; /* Ctrl-d */
newtio.c_cc[VTIME] = ;
newtio.c_cc[VMIN] = ;
newtio.c_cc[VSWTC] = ; /* '\0' */
newtio.c_cc[VSTART] = ; /* Ctrl-q */
newtio.c_cc[VSTOP] = ; /* Ctrl-s */
newtio.c_cc[VSUSP] = ; /* Ctrl-z */
newtio.c_cc[VEOL] = ; /* '\0' */
newtio.c_cc[VREPRINT] = ; /* Ctrl-r */
newtio.c_cc[VDISCARD] = ; /* Ctrl-u */
newtio.c_cc[VWERASE] = ; /* Ctrl-w */
newtio.c_cc[VLNEXT] = ; /* Ctrl-v */
newtio.c_cc[VEOL2] = ; /* '\0' */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);/*set attrib */
;
}
void gprs_msg()
{
char a;
};
char text[]="Hello!Witech!";
tty_write("at", strlen("at"));
sleep();
write(fd,);
sleep();
tty_write("at+cmgf=1", strlen("at+cmgf=1"));
sleep();
write(fd,);
sleep();
tty_write("at+cmgs=13730191959", strlen("at+cmgs=13730191959"));
sleep();
write(fd,);
sleep();
tty_write("Hello!Witech!", strlen("Hello!Witech!"));
sleep();
tty_write(ctl, );
sleep();
printf("sending is end!!\n");
}
int main(void)
{
void * retval;
tty_init();
printf("wait for sending a message!\n");
fflush(stdout);
printf("sending......\n");
gprs_msg();
printf("Bye-Bye!\n");
tty_end();
exit(); }
很久以前收集的几个demo,附件打包下载http://files.cnblogs.com/files/dong1/Linux_gprs.rar
end
gprs/gsm 在linux下的应用的更多相关文章
- linux下GPRS模块的应用程序
---------------------------------------------------------------------------------------------------- ...
- Linux下的编程实战【转】
一篇比较不错的文章, 降到了 makefile make , gcc编译器,GDB调试器, Linux文件系统,Linux文件API,.C语言库函数(C库函数的文件操作实际上是独立于具体的操作系统平台 ...
- 在Linux下用C语言实现短信收发
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lyserver/archive/2008/10/01/3007090.aspx 首先,我根据功能需要创建了几个头文件 ...
- linux下编程epoll实现将GPS定位信息上报到服务器
操作系统:CentOS 开发板:fl2440 开发模块:A7(GPS/GPRS),RT3070(无线网卡) ********************************************** ...
- UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically
UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically by Elias from Mintaka This page i ...
- NodeJs在Linux下使用的各种问题
环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...
- Linux下服务器端开发流程及相关工具介绍(C++)
去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...
- Linux下Nodejs安装(完整详细)
之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录. 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码, ...
- (转载)linux下各个文件夹的作用
linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...
随机推荐
- MySQL主从复制(Master-Slave)实践
MySQL数据库自身提供的主从复制功能可以方便的实现数据的多处自动备份,实现数据库的拓展.多个数据备份不仅可以加强数据的安全性,通过实现读写分离还能进一步提升数据库的负载性能. 下图就描述了一个多个数 ...
- Oracle 哈希连接原理
<基于Oracle的sql优化>里关于哈希连接的原理介绍如下: 哈希连接(HASH JOIN)是一种两个表在做表连接时主要依靠哈希运算来得到连接结果集的表连接方法. 在Oracle 7.3 ...
- js 常用的正则表达式
以下收录一些我经常用到的正则表达式,因为工作场景中用到正则的地方几乎都跟validate插件的验证有关系, 所以以下正则也是$.validator.addMethod() 的拓展: validate: ...
- python编码最佳实践之总结
相信用python的同学不少,本人也一直对python情有独钟,毫无疑问python作为一门解释性动态语言没有那些编译型语言高效,但是python简洁.易读以及可扩展性等特性使得它大受青睐. 工作中很 ...
- [No0000A2]“原始印欧语”(PIE)听起来是什么样子?
"Faux Amis"节目中经常提到"原始印欧语"(PIE)——"Proto-Indo-European". 我们说过,英语,法语中的&qu ...
- js form 表达关于onpress 的一个问题
<form id="search-form" method="get" action="/search"> <fields ...
- TestNG 入门教程
原文出处:http://www.cnblogs.com/TankXiao/p/3888070.html 阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装T ...
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- 一个简单的ASP.NET MVC异常处理模块
一.前言 异常处理是每个系统必不可少的一个重要部分,它可以让我们的程序在发生错误时友好地提示.记录错误信息,更重要的是不破坏正常的数据和影响系统运行.异常处理应该是一个横切点,所谓横切点就是各个部分都 ...
- 3d图片切换(css3帧动画)
效果带抖动翻转隐藏,使用帧动画 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...