vtpos.c

来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 158 行

C
158
字号
/***************************
*      VTPos.c      ZTL    *
***************************/
#define  VTPOS_GLOBALS
#include "includes.h"
#include "bsp.h"
#include "Timetask.h"
#include "Public.h"
#include "Gpsrecer.h"
#include "VtPos.h"
#include "tools.h"
#include "zprint.h"
#include "almtask.h"
#include "message.h"
#include "debug.h"

#define  VTPOS_DEBUG  0

static TMR_TSK *VTCheckTmrID;
static TMR_TSK *VTDelayTmr;
static INT8U OverSpeedCount;
static INT8U DelayPeriod[4] = {1,1,2,2};
static INT8U COUNT;
#define VTCheckPeriod	SECOND,1
#define MAX_OVERSPEED_COUNT 5

static INT8U VTStatus;
#define OVERSPEED   0xAA

static INT8U Vector;

static void VTDelayProc(void)
{
     if (Vector > VTPosPara.LimitVector)
     {
          OverSpeedCount = 0;
    	  VTStatus=!OVERSPEED;
     }
     else
     {
         COUNT = 0;
         StopTmr(VTDelayTmr); 
     }
}
static void VTCheckTmr(void)
{
     StartTmr(VTCheckTmrID,VTCheckPeriod);
    
     if(VTPosPara.Status!=OPEN) return;

     #if VTPOS_DEBUG > 0
	  PrintFromUART(0x01,"\nVTCheckTmr");
     #endif

     Vector =GetVector();

     if(Vector>VTPosPara.LimitVector)
     {
	      OverSpeedCount++;
      
          if((VTStatus==(!OVERSPEED))&&(OverSpeedCount >= MAX_OVERSPEED_COUNT))
	      {
		   #if VTPOS_DEBUG > 0
		   PrintFromUART(0x01,"\n超速报警");
		   #endif
		 	OverSpeedCount = 0;
	 		VTStatus=OVERSPEED;
	 		
	 		if (COUNT<4)
	 		{
	 		    StartTmr(VTDelayTmr,MINUTE,DelayPeriod[COUNT++]);
	 		}
	 		else
	 		{
	 		    COUNT = 0; 
	 		}
	 		OSQPost(AlmTaskMsgQue, MSG_ALARM_OVERSPEED, VTPosPara.LimitVector, 0);
	 		
	      }
    }
    else
    {
    	 OverSpeedCount = 0;
    	 VTStatus=!OVERSPEED;
    }
}


BOOLEAN CheckVector(INT8U Node)
{
     Node=Node;
     if(!GpsDataValid()) return FALSE;
     if(GetVector()>VTPosPara.LimitVector){
     		return TRUE;
	}
     else return FALSE;

}
void VTPosInit(void)
{
   #if VTPOS_DEBUG > 0
	PrintFromUART(0x01,"\nVTPosInit");
	#endif
   VTStatus=!OVERSPEED;
   COUNT = 0;
   
   VTCheckTmrID=CreateTimer(VTCheckTmr,0);
   VTDelayTmr = CreateTimer(VTDelayProc,0);

   if(((VTPosPara.Status!=OPEN)&&(VTPosPara.Status!=CLOSE))||(!PubParaValid(VTPARA_)))
   {
      VTPosParaClear();
   }

   if(VTPosPara.Status==OPEN)
   {
       StartTmr(VTCheckTmrID,VTCheckPeriod);
   }
}

INT8U VTPosParaSet(INT8U *ParaSetPtr)
{
	#if VTPOS_DEBUG > 0
	PrintFromUART(0x01,"\nVTPosParaSet");
	#endif
   VTPosPara.LimitVector=*ParaSetPtr;
   VirStorePubPara(VTPARA_);
   return 1;
}

void VTPosParaClear(void)
{

   ClearPubPara(VTPARA_);
   VTPosPara.LimitVector=0xFF;

}

void VTPosStart(void)
{
	#if VTPOS_DEBUG > 0
	PrintFromUART(0x01,"\nVTPosStart");
	#endif
    VTStatus=!OVERSPEED;
    VTPosPara.Status=OPEN;
    OverSpeedCount = 0;
    StorePubPara(VTPARA_);
    StartTmr(VTCheckTmrID,VTCheckPeriod);
}

void VTPosStop(void)
{
   VTStatus=!OVERSPEED;
   VTPosPara.Status=CLOSE;
   StorePubPara(VTPARA_);
   StopTmr(VTCheckTmrID);
}

⌨️ 快捷键说明

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