⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 status.c

📁 串口程序在linux下的。通过测试!下载后请评价!
💻 C
字号:
#include <stdio.h>#include <unistd.h>#include <string.h>#include <stdlib.h>#include "seril.h"int	GetPowerStatus(char *);static    cbyte[2] = { 0x01 , 0x10 };int main(){   int	i,file_fd,fd,num,j = 100,k=0;   char  Temp_Buf[TEMPBUFFSIZE] = {};   int	POWERSTATUS = 2;   char	mimeType[] = "text/html",*p,power_onoff[STRBUFFSIZE] = {},submit[STRBUFFSIZE] = {},*tmp;   char	*content = "";   content = getenv("QUERY_STRING");   fprintf(stdout,"Content-type: %s%c%c",mimeType,10,10);   fprintf(stdout,"<HTML><HEAD>\n");   fprintf(stdout,"<TITLE>Welcome~~!</title></head>\n");   p = content;      if((tmp = strchr(content,'&')) != NULL)   {  		p = ++tmp;		for(i = 0;(i < STRBUFFSIZE)&&(p != NULL);i++)   		{			power_onoff[i] = *p++;   		}		   		POWERSTATUS =GetPowerStatus(power_onoff);          if((fd = open_port(fd,2)) < 0)   	    {             perror("open port error");             return;        }        if((i = set_opt(fd,9600,8,'N',1)) < 0)        {              	perror("set opt error");              	return;       	}   		if(POWERSTATUS == TRUE)     		{    	    printf("<p>Your application is power on!\n");			for(i = 0;i < 15; i++)			{                if(write(fd,&cbyte[0],1) != 1)                {                      	printf("write '0x01 error.\n");                }				for(j = 0;j < 1000;j++)				{					for(k = 0;k < 1000;k++);				}				}			close(fd);   		}   		else     		{            printf("<p>Your application has been shut down\n");			for(i = 0;i < 15;i++)			{                if(write(fd,&cbyte[1],1) != 1) 		        {                      	printf("write '0x01 error.\n");         		}				for(j = 0;j < 1000;j++)				{					for(k = 0;k < 1000;k++);				}						}			close(fd);	   		}    }   if((file_fd = open(SaveTempFile,O_RDONLY)) < 0)               perror("open");   if(lseek(file_fd,-TEMPBUFFSIZE,SEEK_END) == -1) //here the length is undecided;               printf("can't seek\n");   if((num = read(file_fd,Temp_Buf,TEMPBUFFSIZE)) > 0)               fprintf(stdout,"<p>Now the temprature is %s",Temp_Buf);   else               printf("read error");   fprintf(stdout,"</body></html>\n");   return 0;}int	GetPowerStatus(char *power_onoff){    char	*tmp;   if((tmp = strchr(power_onoff,'=')) != NULL)   {	   ++tmp;   }   if(tmp == NULL)   	  return FALSE;   if(strcmp(tmp,"on_button") == 0)	  return TRUE;   else	return FALSE;  } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -