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 导出数据
MySQL中你可以使用SELECT...INTO OUTFILE语句来简单的导出数据到文本文件上. 使用 SELECT ... INTO OUTFILE 语句导出数据 以下实例中我们将数据表 cnbl ...
- 使用Flask设计带认证token的RESTful API接口[翻译]
上一篇文章, 使用python的Flask实现一个RESTful API服务器端 简单地演示了Flask实的现的api服务器,里面提到了因为无状态的原则,没有session cookies,如果访问 ...
- MySql.Data.Entity 在EF中解析uint的枚举时有BUG
当枚举继承uint类型时无法获取值.
- apache httpd服务器403 forbidden的问题
一.问题描述 在apache2的httpd配置中,很多情况都会出现403. 刚安装好httpd服务,当然是不会有403的问题了.主要是修改了一些配置后出现,问题描述如下: 修改了DocumentRoo ...
- MyBatis源码分析-MyBatis初始化流程
MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简 ...
- 第9章 Shell基础(4)_Bash的运算符及环境变量配置文件
5. Bash的运算符 5.1 数值运算与运算符 5.1.1 declare 声明变量类型:#declare [+/-] [选项] 变量名 选项 说明 - 给变量设定类型属性 + 取消变量的类型属性 ...
- AC日记——地鼠游戏 codevs 1052
1052 地鼠游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 王钢是一名学习成绩优异的学生,在平 ...
- 【repost】js 常见错误类型
1)SyntaxError SyntaxError是解析代码时发生的语法错误 // 变量名错误 var 1a; // 缺少括号 console.log 'hello'); (2)Referenc ...
- November 3rd Week 45th Thursday 2016
Shared joy is a double joy, the same as your gift and idea. 与人分享,欢乐.灵感加倍. As a coder, I must work wi ...
- Linux ——————用Secure传文件时直接拖了文件用的是AssIC导致linux那边直乱码
如下: 解决办法: 直接删除.