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

📄 ex3new.bak

📁 工业控制,模拟量,数字量转化,采集数据,有模拟量,有数字量
💻 BAK
📖 第 1 页 / 共 2 页
字号:
// this program is developed for deling cod and shangdong haiyang
#include "5510drv.h"
#include "adam5090.h"
#include "string.h"
#include "stdio.h"
#include "exchange.h"
#define INTR 0x0c

char cod_y,cod_m,cod_d,cod_h,cod_mi,cod_s,cod_state=0,flow_state=1,hz_cod;
int timer_cod,timer_coddelay,timer_startcod,
	timer_flow,timer_flowdelay,timer_flowadd,
	timer_outXA,timer_exa,timer_detmo,timer_sendstate;
int CanAskmo=0,CanStartcod=0;
float cod_v,flow_v;
void sendstate(unsigned char *mobil,char bsf);
void sendcoddata(char bsf,char pk,char y,char m,char d,char h,char mi,char se,
		  int what,float value,float flow,char *mobil);


void init_all(void)
{
	char firstmo[30], secondmo[30],chls;
	unsigned int inls;
	com_install(1);
	com_set_format(8,0,1);
	com_set_speed((unsigned long)9600);
	cur_record(&chls,&inls,&cod_v,&flow_v,&cod_y,&cod_m,&cod_d,&cod_h,&cod_mi,&cod_s);
	/*com_pgm_install();
	com_pgm_set_format(8,0,1);
	com_pgm_set_speed((unsigned long)9600);*/
	port_install(11);
	port_set_speed(11,9600L);
	port_set_format(11,7,1,1); //7 bit data,odd check,1 stop bit

	port_install(12);
	port_set_speed(12,9600L);
	port_set_format(12,8,0,1);
	port_install(13);
	port_set_speed(13,9600L);
	port_set_format(13,8,0,1);
	port_install(14);
	port_set_speed(14,9600L);
	port_set_format(14,8,0,1);
	LED_init();
	Timer_Init();
	timer_cod=Timer_Set(5000);
	timer_startcod=Timer_Set(60000);
	timer_flow=Timer_Set(1000);
	timer_flowadd=Timer_Set(10000);
	timer_coddelay=Timer_Set(60000);
	timer_flowdelay=Timer_Set(60000);
	timer_outXA=Timer_Set(30000);
	timer_exa=Timer_Set(3000);
	timer_detmo=Timer_Set(20000);
	timer_sendstate=Timer_Set(30000);
	flow_v=readdkflow();
	loadmobil(firstmo,0);
	loadmobil(secondmo,1);
	if (streql("",firstmo)) savemobil(" 13813815421",0);
	if (streql("",secondmo)) savemobil(" 13062547329",1);
	LED_OFF(PWR);
	WDT_enable();
}

char dlc_t_si(char *string,int posit)
{
 unsigned char returnchar;
 unsigned char midstring[10];
 string+=posit;
 midstring[0]=*string;
 string++;
 midstring[1]=*string;
 midstring[2]=0;
 sscanf(midstring,"%d\n",&returnchar);
 return returnchar;
}

float dlc_t_f(char *string,int posit)
{
long returnlong;
float returnfloat;
unsigned char midstring[10];
string+=posit;
midstring[0]=*(string+6);
midstring[1]=*(string+7);
midstring[2]=*(string+4);
midstring[3]=*(string+5);
midstring[4]=*(string+2);
midstring[5]=*(string+3);
midstring[6]=*string;
midstring[7]=*(string+1);
midstring[8]=0;
sscanf(midstring,"%ld\n",&returnlong);
returnfloat=returnlong;
return returnfloat;
}

char clearport(int portno)
{
char a;
port_select(portno);
port_enable_fifo(portno);
while (port_rx_ready(portno)) a=port_rx(portno);
return a;
}

void ask_codv(void)
{
	char portin[20],*midpoint;
	int portlen=0;
	//old data
	unsigned char pk,y,m,d,h,mi,s;unsigned int what;float value,flow;
	clearport(11);
	port_tx_string(11,"%01#RDD0152101525**"); //d01521-01525 save cod and time
	port_tx(11,13);
	ADAMdelay(50);
	while (port_rx_ready(11))
	{
	 portin[portlen++]=port_rx(11);
	}
	portin[portlen]=0;
	printf("%s",portin);
	midpoint=portin;
	midpoint+=3;
	if (((*midpoint)=='$') && (portlen==29) && (portin[28]==13))
	{
	 cod_y=dlc_t_si(portin,16);
	 cod_m=dlc_t_si(portin,14);
	 cod_d=dlc_t_si(portin,12);
	 cod_h=dlc_t_si(portin,10);
	 cod_mi=dlc_t_si(portin,8);
	 cod_s=dlc_t_si(portin,6);
	 cod_v=dlc_t_f(portin,18);
	 cur_record(&pk,&what,&value,&flow,&y,&m,&d,&h,&mi,&s);
	 if ((cod_y==y) && (cod_m==m) && (cod_d==d) && (cod_h==h) && (cod_mi==mi) && (cod_s==s)) printf("no new data\n");
	 else
	{
	flow=readkeepflow();
	writekeepflow(0);
	record_add(1,316,cod_v,flow,cod_y,cod_m,cod_d,cod_h,cod_mi,cod_s);
	}
	 Timer_Reset(timer_coddelay);
	}
}

void ask_codstate(void)
{
	char portin[20];
	int portlen=0;
	clearport(11);
	port_tx_string(11,"%01#RDD0016000160**");port_tx(11,13);
	ADAMdelay(50);
	while (port_rx_ready(11))
	{
	 portin[portlen++]=port_rx(11);
	}
	portin[portlen]=0;
	printf("%s",portin);
	if ((portin[3]=='$') && (portlen==12) && (portin[11]==13))
	{
	 cod_state=dlc_t_si(portin,8);
	 Timer_Reset(timer_coddelay);
	}
	if ((CanStartcod) && (cod_state!=0)) CanStartcod=0;
}

void ask_codtime(void)
{
	char portin[20];
	char midbytechar[10];
	int portlen=0;
	clearport(11);
	port_tx_string(11,"%01#9005490056**");port_tx(11,13);
	ADAMdelay(50);
	while (port_rx_ready(11)) portin[portlen++]=port_rx(11);
	portin[portlen]=0;
	printf("%s",portin);
	if ((portin[3]=='$') && (portlen==21) && (portin[20]==13))
	{
	 Timer_Reset(timer_coddelay);
	 if ((GetRTCtime(RTC_year)==dlc_t_si(portin,16)) &&
		   (GetRTCtime(RTC_month)==dlc_t_si(portin,14)) &&
		   (GetRTCtime(RTC_day)==dlc_t_si(portin,12)) &&
		   (GetRTCtime(RTC_hour)==dlc_t_si(portin,10)) &&
		   (GetRTCtime(RTC_min)==dlc_t_si(portin,8)) &&
		   (GetRTCtime(RTC_sec)==dlc_t_si(portin,6)));
	 else
	 {
		port_tx_string(11,"%01#WDD9005490056");
		if (GetRTCtime(RTC_sec)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_sec));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_sec));
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_min)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_min));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_min));
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_hour)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_hour));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_hour));
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_day)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_day));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_day));
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_month)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_month));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_month));
		port_tx_string(11,midbytechar);
		if (GetRTCtime(RTC_year)<16)  sprintf(midbytechar,"0%x",GetRTCtime(RTC_year));
		else sprintf(midbytechar,"%x",GetRTCtime(RTC_year));
		port_tx_string(11,midbytechar);
		port_tx(11,13);
	 }
	}
}

void ask_flow(void)
{
   char ch[500];
   int len=0;
   /*while(!com_pgm_rx_empty()) ch[len++]=com_pgm_rx();*/
   while(!com_rx_empty()) ch[len++]=com_rx();
   if ((len==5) && (sumcheck(ch,4)))
   {
	flow_v=c_t_f(ch);
	writedkflow(flow_v);
	flow_state=1;
	LED_ON(COMM);
	Timer_Reset(timer_flowdelay);
   }
   else LED_OFF(COMM);
}

void get_msg(void)
{
   char data[100],mobil[20],firstmo[20],secondmo[20];
   char com1in[360],checkchar[360];
   unsigned char pk,y,m,d,h,mi,s;
   float value,flow;
   unsigned int what;
   int i=0,len;
   static char msgno=0;
   char *charread,*charjll,*charok,*getchar;
   char firsts[10],seconds[10],msgnochar[10];
   if (!CanAskmo) return;
   port_select(13);
   port_enable_fifo(13);
   msgno=(msgno+1)%30;
   strcpy(com1in,"");
   len=0;
   WDT_clear();
   strcpy(com1in,"");
   len=0;
   ADAMdelay(100);
   clearport(13);
   port_tx_string(13,"at+cmgr=");
   sprintf(msgnochar,"%d",msgno);
   port_tx_string(13,msgnochar);
   port_tx_string(13,"\x0d");
   ask_flow();
   do
	 {
	if (port_rx_ready(13))
		{
		   com1in[len++]=port_rx(13);
		   com1in[len]=0;
		}
	if (strstr(com1in,"ERROR"))
	{
	   printf("*");
	   return;
	}
	charok=strstr(com1in,"OK");
	 }
   while (!charok);
   ask_flow();
   printf(".");
   WDT_clear();
   ADAMdelay(100);
   if (port_rx_ready(13))
	   {
	  com1in[len++]=port_rx(13);
	  com1in[len]=0;
	   }
   strcpy(checkchar,com1in);
   strstr_rem(checkchar,"UN");
   strcpy(com1in,"");
   len=0;
   clearport(13);
   port_tx_string(13,"at+cmgr=");
   sprintf(msgnochar,"%d",msgno);
   port_tx_string(13,msgnochar);
   port_tx_string(13,"\x0d");
   ask_flow();
   do
	 {
	if (port_rx_ready(13))
		{
		   com1in[len++]=port_rx(13);
		   com1in[len]=0;
		}
	if (strstr(com1in,"ERROR")) return;
	charok=strstr(com1in,"OK");
	 }
   while (!charok);
   ask_flow();
   ADAMdelay(50);
   if (port_rx_ready(13))
	   {
	  com1in[len++]=port_rx(13);
	  com1in[len]=0;
	   }

⌨️ 快捷键说明

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