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

📄 ch_frame.c

📁 单片机C源程序souce
💻 C
字号:
/**************************************
File          :  CH_FRAME.C
Project       :  BDTRV20_MCU_V07
Description   :  分解DSP输出的各帧,提取并存储参数
Created       :  2006.11.7
Last updata   :  
Author        :  Sunzehui   sunzehui@zzvcom.com
Compile Tool  :  Keil uVision2
Target Device :  SST89V564RD
Circuit Board :  BD7700
************************************
Modification History
************************************
 Version      : v2.0
 Date         : MM/DD/YYYY
 Modifier     :
 Description  :

 **********************************
 -- Copyright (c)
*************************************/

#include <string.h>

#include "ext_temp.h"
//extern unsigned long asc_to_long(unsigned char *p,bit m);
extern unsigned char asc_to_char(unsigned char a1,unsigned char a2,bit m);
extern unsigned char fromasc(unsigned m);
extern unsigned long tosec(unsigned char hour, unsigned char min, unsigned char sec, unsigned char date, unsigned char mon, unsigned int year);
extern unsigned char *sectodata(unsigned long tod);
extern send_lp_dsp(void);
extern SendDSP(void);
extern send_lla(void); 
extern send_ofs(void);
extern wdt(void);

extern ch_frame(void)
	{
	unsigned char temp,i;//,tmp,b[8];
	unsigned char *point;
	unsigned long  xdata p,tmp,lp_sec_tmp; 
	 
    wdt();
	if (sdata[3]=='Z'&&sdata[4]=='D'&&sdata[5]=='A') //$BDZDA帧
		{
		//temp=(sdata[7]-0x30)*10;
		//hour=temp+(sdata[8]-0x30);//提取小时
		hour=asc_to_char(sdata[7],sdata[8],0);

		//temp=(sdata[9]-0x30)*10;
		//min=temp+(sdata[10]-0x30);//提取分钟
		min=asc_to_char(sdata[9],sdata[10],0);

		//temp=(sdata[11]-0x30)*10;
		//sec=temp+(sdata[12]-0x30);//提取秒
		sec=asc_to_char(sdata[11],sdata[12],0);

		//temp=(sdata[17]-0x30)*10;
		//day=temp+(sdata[18]-0x30);//提取天
		day=asc_to_char(sdata[17],sdata[18],0);


		//temp=(sdata[20]-0x30)*10;
		//month=temp+(sdata[21]-0x30);//提取月
		month=asc_to_char(sdata[20],sdata[21],0);

		year=(sdata[23]-0x30)*1000+(sdata[24]-0x30)*100+(sdata[25]-0x30)*10+(sdata[26]-0x30);//提取年
		//year=year+100;//only for test 2000
		
		/******************得到秒值************************************************/
		if (channel_sta_2&0x40==0x40)
			{	
			p = tosec(hour,min,sec,day,month,year);	//BD时间秒值
			
			/*if (UTC_mode_fg==1)//UTC模式
	            {
			     if ((cur_lp_sec==0&&fur_lp_sec==0)||(cur_lp_sec!=0&&(fur_lp_sec-cur_lp_sec==1)))//有正闰秒或无闰秒
				      cur_time_sec=p+UTC_sec;
				 else
				     cur_time_sec=p-UTC_sec;
	             }
			else //GPS模式
			   {*/
			   tmp=gmth*3600+gmtm*60;
				if ((cur_lp_sec==0&&fur_lp_sec==0)||(cur_lp_sec!=0&&(fur_lp_sec-cur_lp_sec==1))) //有正闰秒或无闰秒
				   {
				   if (gmts==0x00)//GMT符号为正
				     cur_time_sec=p+tmp;// //cur_time = (gps0+gmt=bds-13-pp-8*3600)+gmt = bds-pp+gmt-28813
				   else if(gmts==0xff)//GMT符号为负
				     cur_time_sec=p-tmp;//
				   cur_time_sec-= 28800;
                  // cur_time_sec = cur_time_sec + UTC_sec;
				   if (UTC_mode_fg==0) //GPS模式
				      {
					  cur_time_sec = cur_time_sec + UTC_sec - 13;
					  }
				   }
				else if(cur_lp_sec !=0&&(fur_lp_sec-cur_lp_sec==-1))//有负闰秒
				   {
				   if (gmts==0x00)
				     cur_time_sec=p+tmp;//-UTC_sec;  //cur_time = (gps0+gmt=bds-13-pp-8*3600)+gmt = bds-pp+gmt-28813
				   else if(gmts==0xff)
				     cur_time_sec=p-tmp;//-UTC_sec;
				   cur_time_sec -= 28800;
				   //cur_time_sec = cur_time_sec - UTC_sec;
				   if (UTC_mode_fg==0) //GPS模式
				      {
					  cur_time_sec=cur_time_sec - UTC_sec - 13;
					  }
				   }
			   
		/******************************************************************/
		//重新得到年月日时分秒
		/*******************************************************************/
			point=sectodata(cur_time_sec);
			hour =*point++; //时
			min =*point++;  //分
			sec =*point++;  //秒
			year=0;
			year=*point++;
			year=year<<8;
			year|=*point++; //年
			month=*point++; //月
			day=*point;     //日
			}
	}


/****$ B D L P S , 2 0 2 F A 0 A 2 4 C 8 ,235958,30,06,2015*7C
     0 1 2 3 4 5 6 7 8 9
*/

	else if(sdata[3]=='L'&&sdata[4]=='P'&&sdata[5]=='S')//$BDLPS帧
		{
		//lps_cnt++;
		if (sdata[7]=='0'||sdata[7]=='1'||sdata[7]=='2') //提取BD与UTC的差值
		   {
		   UTC_sec = asc_to_char(sdata[8],sdata[9],1);//BD1与UTC相差秒值、当前闰秒值整数部分
		   for(i=10;i<17;i=i+2)
		      {
			  UTC_ns=UTC_ns<<8;
			  temp=fromasc(sdata[i])<<4;
			  temp|=fromasc(sdata[i+1]);
 			  UTC_ns|=temp;///////////////...
			  //UTC_ns=temp|fromasc(sdata[i+1]);			  
			  }		    
		   }
	  if (sdata[7]=='0')//无闰秒
		   {
		   fur_lp_sec =0;
		   cur_lp_sec =0;
		   lp_hour=0;  lp_min=0;
		   lp_sec=0;   lp_day=0;
		   lp_month=0; lp_year=0;
		   }
	  else if (sdata[7]=='1'||sdata[7]=='2')//有闰秒状态
		   {
		    //提取未来闰秒值
		   if (sdata[7]=='1')
		      {
			  cur_lp_sec=UTC_sec;  //当前闰秒
			  fur_lp_sec=UTC_sec +1;//未来闰秒
			  }
		   else if(sdata[7]=='2')
		      {
			  cur_lp_sec=UTC_sec;
			  fur_lp_sec=UTC_sec -1;
			  }
		   //闰秒发生时
		   lp_hour =asc_to_char(sdata[19],sdata[20],0);//(sdata[19]-0x30)*10+(sdata[20]-0x300);
		   //闰秒发生分
		   lp_min =asc_to_char(sdata[21],sdata[22],0);//(sdata[21]-0x30)*10+(sdata[22]-0x300);
		   //闰秒发生秒
		   lp_sec =asc_to_char(sdata[23],sdata[24],0);//(sdata[23]-0x30)*10+(sdata[24]-0x300);
		   //闰秒发生日
		   lp_day=asc_to_char(sdata[26],sdata[27],0);
		   //闰秒发生月
		   lp_month=asc_to_char(sdata[29],sdata[30],0);
		   //闰秒发生年
		   lp_year =(sdata[32]-0x30)*1000+(sdata[33]-0x30)*100+(sdata[34]-0x30)*10+sdata[35]-0x30;

		  if (channel_sta_2&0x40==0x40)
			{	
			p = tosec(lp_hour,lp_min,lp_sec,lp_day,lp_month,lp_year);	//BD时间秒值
			
		/*	if (UTC_mode_fg==1)//UTC模式
	            {
			     if ((cur_lp_sec==0&&fur_lp_sec==0)||(fur_lp_sec-cur_lp_sec==1))//有正闰秒或无闰秒
				      cur_time_sec=p+UTC_sec;
				 else
				     cur_time_sec=p-UTC_sec;
	             }
			else //GPS模式
			   {*/
			    tmp=gmth*3600+gmtm*60;

				if ((cur_lp_sec==0&&fur_lp_sec==0)||(fur_lp_sec-cur_lp_sec==1)) //有正闰秒或无闰秒
				   {
				   if (gmts==0x00)//GMT符号为正
				     lp_sec_tmp=p+tmp;  //cur_time = (gps0+gmt=bds-13-pp-8*3600)+gmt = bds-pp+gmt-28813
				   else if(gmts==0xff)//GMT符号为负
				     lp_sec_tmp=p-tmp;
				   lp_sec_tmp -=28800;
				   if (UTC_mode_fg==0)//GPS
				     {
					 lp_sec_tmp = lp_sec_tmp + UTC_sec -13;
					 }
				   }
				else if(cur_lp_sec !=0&&(fur_lp_sec-cur_lp_sec==-1))//有负闰秒
				   {
				   if (gmts==0x00)
				     lp_sec_tmp=p+tmp;  //cur_time = (gps0+gmt=bds-13-pp-8*3600)+gmt = bds-pp+gmt-28813
				   else if(gmts==0xff)
				     lp_sec_tmp=p-tmp;
				   lp_sec_tmp -=28800;
				   if (UTC_mode_fg==0)
				      {
				       cur_time_sec = cur_time_sec - UTC_sec -13;//28813
				      }
				   }

			//	}
		/******************************************************************/
		//重新得到年月日时分秒
		/*******************************************************************/
			point=sectodata(lp_sec_tmp);
			lp_hour =*point++; //时
			lp_min =*point++;  //分
			lp_sec =*point++;  //秒
			lp_year=0;
			lp_year=*point++;
			lp_year=lp_year<<8;
			lp_year|=*point++; //年
			lp_month=*point++; //月
			lp_day=*point;     //日			 
			}
		  }
		}

   /*$ B D L L A , 3 4 4 4 . 2 6 7 8 8 , N, 11337.35114, E, 119.53*64

   */
	 else if (sdata[3]=='L'&&sdata[4]=='L'&&sdata[5]=='A')//$BDLLA帧
	 	 {
		  //lla_cnt++;
		  if (sdata[7]==lat_asc[0]&&sdata[8]==lat_asc[1]&&sdata[9]==lat_asc[2]&&sdata[10]==lat_asc[3]&&//判断纬度是否相等
		      sdata[21]==long_asc[0]&&sdata[22]==long_asc[1]&&sdata[23]==long_asc[2]&&sdata[24]==long_asc[3]);//判断经度
          else //读出来的数与输入数不等
		      send_lla();//重新发送数据
	 		 }



    /*$ B D S T A , 0 0 0 3  ,  1 1 1 D  7 9 0 0  , 0  1 2 2 7 8 0 0 * 3 E<0d><0a>
      0 1 2 3 4 5 6 7 8 9 10 11 12    15       19   21             28
	*/
	 else if(sdata[3]=='S'&&sdata[4]=='T'&&sdata[5]=='A')//$BDSTA帧
	 	 {
		 if (sdata[7]=='0'&&sdata[8]=='0'&&sdata[9]=='0'&&sdata[10]=='0')
		 	channel_pps_en =0x00;//两通道都不正常,PPS不可用
		 else if(sdata[7]=='0'&&sdata[8]=='0'&&sdata[9]=='0'&&sdata[10]=='1')
		 	channel_pps_en =0x01;//1通道正常,PPS可用
		 else if(sdata[7]=='0'&&sdata[8]=='0'&&sdata[9]=='0'&&sdata[10]=='2')
		 	channel_pps_en =0x02;//2通道正常,PPS可用
		 else if (sdata[7]=='0'&&sdata[8]=='0'&&sdata[9]=='0'&&sdata[10]=='3')
		 	channel_pps_en =0x03;//两通道都正常,PPS可用

         //通道接收波束
		 channel_beam_1 = sdata[12]-0x30;
		 channel_beam_2 = sdata[21]-0x30;
		 //通道接收功率
		 channel_power_1 = fromasc(sdata[13]);
		 channel_power_1 =channel_power_1<<8;
		 channel_power_1 |=asc_to_char(sdata[14],sdata[15],1);

		 channel_power_2 = fromasc(sdata[22]);
		 channel_power_2 =channel_power_2<<8;
		 channel_power_2 |=asc_to_char(sdata[23],sdata[24],1);
		 //通道接收状态
		 channel_sta_1 =asc_to_char(sdata[16],sdata[17],1);
		 channel_sta_2 =asc_to_char(sdata[25],sdata[26],1);

		 //通道误码数
		 channel_err_1 =asc_to_char(sdata[18],sdata[19],1);
		 channel_err_2 =asc_to_char(sdata[27],sdata[28],1);
		 }

/* $ B D O F S , F F B 9 F 5 5 2 , 00000000*77
   0 1 2 3 4 5 6 7 8 9 10     14
*/

	 else if (sdata[3]=='O'&&sdata[4]=='F'&&sdata[5]=='S')//$BDOFS帧
			{
			// ofs_cnt++;
			// if (sdata[9]==pps_asc[0]&&sdata[10]==pps_asc[1]&&sdata[11]==pps_asc[2]&&sdata[12]==pps_asc[3]);
			// else//输出数与输入数不等(说明没有写入DSP,需重写)
			//     send_ofs();//重组BDOFS帧

			 send_lp_dsp();//发送$BDLPS到DSP		    
			}


	}

⌨️ 快捷键说明

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