📄 predictor.c
字号:
/****************************************************************
** *
** FILE : Predictor.c *
** *
** By : Cyb 2007.01.05 *
****************************************************************/
#include "includes.h"
#include "errcode.h"
#include "errtask.h"
#include "message.h"
#include "tools.h"
#include "public.h"
#include "timetask.h"
#include "sensor.h"
#include "almtask.h"
#include "alarmer.h"
#include "GpsTool.h"
#include "flash.h"
#include "VtPos.h"
#include "debug.h"
#include "PredicTools.h"
#include "Predictor.h"
#include "systime.h"
#include "SysTask.h"
#include "StaName.h"
#include "DisplayTask.h"
#include "vtcalculate.h"
#include "PortDrv.h"
#define AOPEN_ 0x55
#define ACLOSE_ 0xaa
#define UPSTREAM 1
#define DOWMSTREAM 2
#define LEDPARA_GPSVALID PORT_LEDGREEN,10,10
#define LEDPARA_WORK PORT_LEDRED, 20, 20
#define MainSearchPeriod SECOND,1
#define AssiSearchPeriod SECOND,1
static LINE_STR CurLine; //当前线路
static STATION_STR Station_Searched; //搜寻到的站点
static STATION_STR Station_Last; //上一次被搜寻到的站点
static INT16S StationID_Cur; //当前的站点ID
static INT16S StationID_Last; //上一个站点ID
static INT16S StationID_Next; //下一个站点ID
static INT16S MemIndex;
static ADOBJECT_STR AdObj; //广告点
static INT32U Status;
static OBJECT_STR Object_Searched; //搜寻到的目标点
static INT16U Index_Line; //线路数据的索引
static DATUM_STRUCT Gpsdata;
static DATUM_STRUCT Gpsdatum;
static TMR_TSK *MainSearchTmr;
static TMR_TSK *AssiSearchTmr;
static INT8U Count_Station_Search;
static INT32U Space[2];
//static INT16U CurStaNum;
static BOOLEAN AutoValid;
static INT8S LineDirection;
// 获取该条线路数据的存储索引
static INT16U GetLineIndex_Memory(void)
{
if (!PubParaValid(LINENUM_))
{
return 0xffff;
}
else
{
return LineNumPara.index;
}
}
static BOOLEAN IsDepartStation(STATION_STR *station_searched)
{
if(!(Status & IS_BEGIN_DEPART))
{
if(CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,station_searched->pos.latitude, station_searched->pos.longitude) <ALARM_LEN_DEPART)
{
Status |= IS_BEGIN_DEPART;
}
}
else
{
if(CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,station_searched->pos.latitude, station_searched->pos.longitude) >= ALARM_LEN_DEPART)
{
Status &= ~IS_BEGIN_DEPART;
Status |= IS_DEPART_STATION;
return TRUE;
}
}
return FALSE;
}
// 搜寻站点
static BOOLEAN SearchBusStation(STATION_STR *station_searched)
{
INT16U i;
INT16S direction;
INT32U space;
STATION_STR station_searching;
#if DEBUG_UARTNo_BUSSTATION <=1
if(!(Status & IS_FOUND_STATION))
{
PrintFromUART(DEBUG_UARTNo_BUSSTATION, "\n搜寻站点.....\n");
}
#endif
for( i=0;i<CurLine.nums;i++)
{
if(Status & IS_FOUND_STATION)
{
break;
}
if(Status & IS_DEPART_STATION)
{
if( i == StationID_Last)
{
continue;
}
}
ReadRecFromFlash(POSITI_STA, CurLine.cell[i].cur,sizeof(STATION_STR), (INT8U*)&station_searching);
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,station_searching.pos.latitude, station_searching.pos.longitude);
if(space < ALARM_LEN_STAFOUND)
{
direction = (Gpsdata.direction-1)*3;
if((direction >= (station_searching.direction -15)) && (direction <=(station_searching.direction +15)))
{
if(!(Status & IS_FOUND_STATION))
{
if(Count_Station_Search <=1)
{
Space[Count_Station_Search] = space;
}
else
{
if(Space[1] < Space[0])
{
Status |= IS_FOUND_STATION;
// StationID_Last = i;
// StationID_Cur = i;
// StationID_Next = i+2;
MemIndex = i;
memcpy((INT8U*)station_searched,(INT8U*)&station_searching,sizeof(STATION_STR));
#if DEBUG_UARTNo_BUSSTATION <=1
PrintFromUART(DEBUG_UARTNo_BUSSTATION , "\n当前站点ID:");
SendFromUART_HEX(DEBUG_UARTNo_BUSSTATION ,CurLine.cell[i].cur);
#endif
if(!AutoValid)
{
AutoValid = TRUE;
}
if(!(Status & IS_NOTAT_START))
{
Status |= IS_NOTAT_START;
}
}
Count_Station_Search = 0;
}
if(Status & IS_FOUND_STATION)
{
return TRUE;
}
Count_Station_Search++;
break;
}
}
}
}
if(Status & IS_FOUND_STATION)
{
if(IsDepartStation(station_searched))
{
Status &= ~IS_FOUND_STATION;
memcpy((INT8U*)&Station_Last,(INT8U*)station_searched,sizeof(STATION_STR));
}
else if (!(Status & IS_BEGIN_DEPART))
{
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,station_searched->pos.latitude, station_searched->pos.longitude);
if(space >= ALARM_LEN_STAFOUND)
{
Status &= ~IS_FOUND_STATION;
}
}
}
if(Status & IS_DEPART_STATION)
{
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude, Station_Last.pos.latitude, Station_Last.pos.longitude);
if(space >= ALARM_LEN_STAFOUND)
{
Status &= ~IS_DEPART_STATION;
}
}
if(Status & IS_FOUND_STATION)
{
return TRUE;
}
else
{
return FALSE;
}
}
//是否进站
static BOOLEAN IsStationArrived(void)
{
INT16U direction;
INT32U space;
#if DEBUG_UARTNo_BUSSTATION <=1
PrintFromUART(DEBUG_UARTNo_BUSSTATION , "\n等待进站.....");
#endif
if(!(Status &IS_ARRIVED_STATION))
{
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,Station_Searched.pos.latitude, Station_Searched.pos.longitude);
if(space <= ALARM_LEN_ARRIVE)
{
direction = (Gpsdata.direction - 1)*3;
if((direction >= (Station_Searched.direction -15)) && (direction <=(Station_Searched.direction +15)))
{
Status |= IS_ARRIVED_STATION;
return TRUE;
}
}
if(space <= ALARM_LEN_ARRIVEMAX)
{
direction = (Gpsdata.direction - 1)*3;
if((direction >= (Station_Searched.direction -15)) && (direction <=(Station_Searched.direction +15)))
{
if(VechicleIsStopNow())
{
Status |= IS_ARRIVED_STATION;
return TRUE;
}
}
}
}
else
{
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,Station_Searched.pos.latitude, Station_Searched.pos.longitude);
if(space > ALARM_LEN_ARRIVEMAX)
{
Status &= ~IS_ARRIVED_STATION;
}
}
return FALSE;
}
//开始出站
static BOOLEAN IsStationBeginDepart(void)
{
INT16U direction;
INT32U space;
#if DEBUG_UARTNo_BUSSTATION <=1
PrintFromUART(DEBUG_UARTNo_BUSSTATION, "\n等待出站.....");
#endif
if(!(Status & IS_LEFT_STATION))
{
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,Station_Searched.pos.latitude, Station_Searched.pos.longitude);
if(space < ALARM_LEN_LEAVE)
{
direction = (Gpsdata.direction - 1)*3;
if((direction >= (Station_Searched.direction -15)) && (direction <=(Station_Searched.direction +15)))
{
Status |= IS_LEFT_STATION;
return TRUE;
}
}
}
else
{
if(CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,Station_Searched.pos.latitude, Station_Searched.pos.longitude)>=ALARM_LEN_LEAVE)
{
Status &= ~IS_LEFT_STATION;
}
}
return FALSE;
}
//搜寻特定道路状态(拐弯、上坡、下坡)
static BOOLEAN SearchRoadObjects(OBJECT_STR *object_searched)
{
INT8U i;
INT16U objindex;
INT32U space;
OFFSET2_STR offset;
OBJECT_STR object_searching;
ReadRecFromFlash(OFFSET_OBJ,Index_Line,sizeof(OFFSET2_STR), (INT8U*)&offset);
for (i=0;i<offset.nums;i++)
{
if(Status & IS_FOUND_OBJECT)
{
break;
}
ReadRecFromFlash(NUMBER_OBJ, offset.pos++,2, (INT8U*)&objindex);
ReadRecFromFlash(POSITI_OBJ, objindex,sizeof(OBJECT_STR), (INT8U*)&object_searching);
space = CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,object_searching.pos.latitude,object_searching.pos.longitude);
if(space < ALARM_LEN_OBJFOUND)
{
if(!(Status & IS_FOUND_OBJECT))
{
Status |= IS_FOUND_OBJECT;
memcpy((INT8U*)object_searched,(INT8U*)&object_searching,sizeof(OBJECT_STR));
return TRUE;
}
}
}
if(Status & IS_FOUND_OBJECT)
{
if(CalculateGpsSpace(Gpsdata.latitude, Gpsdata.longitude,object_searched->pos.latitude,object_searched->pos.longitude)>ALARM_LEN_OBJFOUND)
{
Status &=~IS_FOUND_OBJECT;
}
}
return FALSE;
}
//起步提醒
static void DeclareOnStartRun(void)
{
if(VechicleIsStopNow())
{
if(!(Status & IS_VECHICLE_STOP))
{
Status |= IS_VECHICLE_STOP;
}
}
else
{
if(Status & IS_VECHICLE_STOP)
{
Status &=~IS_VECHICLE_STOP;
OSQPost(AlmTaskMsgQue, MSG_BUSSWORDS_BUSSTART, 0 ,0);
}
}
}
//整点报时
static void DeclareOnExactTime(void)
{
TIME_STRUCT curtime;
GetCurTime_Time(&curtime);
if((curtime.hour > 5) && (curtime.hour <24))
{
if(curtime.minute == 0)
{
if(!(Status & IS_TIME_PROMPT))
{
if(!(Status & IS_TIME_EXACT))
{
Status |= IS_TIME_EXACT;
}
}
}
else
{
Status &= ~IS_TIME_PROMPT;
}
}
if(Status & IS_TIME_EXACT)
{
Status &= ~IS_TIME_EXACT;
Status |= IS_TIME_PROMPT;
OSQPost(AlmTaskMsgQue, MSG_TIME_PROMPT, curtime.hour ,0);
}
}
//行驶特定道路状态提醒(拐弯、上坡、下坡)
static void DeclareOnObjectsFound(void)
{
if(SearchRoadObjects(&Object_Searched))
{
switch(Object_Searched.type)
{
case GUAIWAN_TYPE:
OSQPost(AlmTaskMsgQue, MSG_OBJECT_WANDAOFD, 0 ,0);
break;
case SHANGPO_TYPE:
OSQPost(AlmTaskMsgQue, MSG_OBJECT_SHANGPOFD,0,0);
break;
case XIAPO_TYPE:
OSQPost(AlmTaskMsgQue, MSG_OBJECT_XIAPOFD,0,0);
break;
default:
break;
}
}
}
static void MainSearchProc(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -