如何在检测程序中添加一个触发发短信功能的子程序(没思路)
已实现的功能为:程序检测到温度,异常则报错,累计n次异常会有一次警告;现在想实现的时:在累计n次异常后触发一个短信功能,能通过GSM MODEM发送短信到手机。
这段短信功能的程序应该怎么写进检测程序,并且结构原理是怎么样的?应该用怎么样的语句来触发远程计算机上的GSM MODEM的串口程序,然后发送短信?
GSM MODEM与计算机的串口程序已经是完整的了,不过只能在LINUX机下编译运行,不知道应该怎么使这个LINUX下的程序也能在windows下的vc中正常编译运行?
我知道我解释的够不够清楚。
附两段程序,待解决:
检测程序:
#include <stdio.h>
#include <string.h>
#include <windows.h>
FILE *f;
char ln[80];
int n,L;
float t,v;
int i=0;
void main()
{
// printf("Input 警戒值:");//特定数据
// fflush(stdout);
//if (1!=scanf("%f",&t)) return;
t=31.0f;
f=fopen("C:\\HidTEMPerHUM\\HidTEMPerHUM_2011Y7M5D10h59m30s.csv","r");
if (NULL==f) return;
while (1)
{
fseek(f,-60 ,SEEK_END);
fgets(ln,80,f);
fgets(ln,80,f);
if (1==sscanf(ln,"%*d, %*d/%*d/%*d %*d:%*d:%*d, %fC, %*f, %*f",&v))
{
if (v>t)
{ i++;
printf("[%s] The temperature is too HIGH!\n",ln);//大于这个特定数据,则打印错误
}
else {printf("[%s] The temperature is OK!\n",ln);}
printf("i=%d\n",i);
if(i==6)
{printf("The temperature is unusual for %d times,I will send you a warnmessage!!!\n\n",i);
i=0;
}
}
Sleep(300*1000);
}
fclose(f);
}
串口程序(LINUX),能否修改成windows下的:
由于篇幅有限,我截取一些片段:
// compile: g++ -D_LINUX tricom.cpp -o tricom
#include <sys/file.h>
#include <termios.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <string.h>
#include <strings.h>
#include <unistd.h> //getdtablesize
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <iostream>
using namespace std;
#define BUFSIZE 1000 /* read buffer size */
#ifdef _LINUX
#define TERM_PATH_COM1 "/dev/ttyS0" /* termio path first name */
#define TERM_PATH_COM2 "/dev/ttyS1" /* termio path first name */
#else
#define TERM_PATH_COM1 "/dev/term/a" /* termio path first name */
#define TERM_PATH_COM2 "/dev/term/b" /* termio path first name */
#endif
#define TERM_SPEED B115200 /* termio speed, out = in */
#define TERM_SPEED_D 115200
static int ZG_TERM_SPEED;
#define DEBUG_SWITCH 0
#define COUT if(DEBUG_SWITCH)cout
#ifdef _LINUX
#define CBAUDEXT EXTB
#endif
extern int errno;
#define ESCAPE_CHAR 0x1b // CTRL('@')
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#undef SEARCH_TIMES
#define SEARCH_TIMES 5
#undef QLEN
#define QLEN 5 /* maximum connection queue length */
#define DBPrintIN
#define DBPrintOUT
#define DBPrint fprintf
#define DBPS0 stderr
这是一些开头的头文件,以及定义什么的。
求指教。