Summary of the invention
Purpose of the present invention just is to overcome above-mentioned shortcoming and defect, provide a kind of Digital Television EPG information of complete, simple, easy care automatic cleaning, increase record and search acquisition methods.It has automatic maintenance function, can prevent that data from overflowing, and it is very stable to work.Simultaneously, its information storage and retrieval speed is fast, and calling interface is simple.And have good portability, except that digital television set, also extend in other receiving equipments.
In order to achieve the above object, the present invention includes automatic cleaning, increase EPG information record, increase EPG current/next information record and search and obtain four parts, wherein cleaning may further comprise the steps automatically:
A1, determine shared EPG recording of information space and the dominant record bar number of all programs in the internal memory, time difference with all information in the maintenance EPG information is no more than the time that keeps EPG information in the internal memory, sets the time that keeps EPG information, overflows when preventing to work long hours;
A2 is when EPG record sum〉0 the time, retrieve the time of current state-of-the-art record:
A3 calculates the thresholding time, that is the time of state-of-the-art record subtracts the time (defaulting to 7 days) that EPG information keeps;
A4, deletion is early than the record of thresholding time;
A5 upgrades EPG information record sum and organize your messages record again.
All channels of the present invention are shared an internal memory, as the information storage area of electronic program guides.But can there be different divisions the electronic program guide information memory block of this internal memory, so its dominant record quantity is adjustable.
Increase EPG information recording part branch and comprise following steps:
B1 adjusts record start time time zone;
B2 obtains EPG information record insertion point, comprises step by step following:
B1 detects EPG information record sum, when it=0 the time, promptly enter the B3 step;
B2, whether when it is not equal to 0, it is full to detect the EPG memory block, when expire the EPG memory block, promptly enters the B3 step;
B3 when the EPG memory block is discontented, retrieves according to service-id and event-id, if retrieve existing this record, promptly enters the B3 step;
B4, if retrieve existing this record, then with move behind the record after the insertion point, with the record zero clearing of insertion point, EPG information record sum is added 1;
B3 judges the numerical value of record insertion point index, when record insertion point index<0, does not increase new EPG information record;
B4 when record insertion point index 〉=0, copies current record in the EPG information array to.
Increase EPG current/next information recording part branch comprises following steps:
C1 obtains current/next information record insertion point, comprises step by step following:
C1 detects current/next information record sum, when it=0 the time, promptly enter the C2 step:
C2, whether when it is not equal to 0, it is full to detect current/next memory block, when expire the EPG memory block, promptly enters the C2 step:
C3 when current/next memory block is discontented, retrieves according to service-id and event-id, if retrieve existing this record, promptly enters the C2 step;
C4, if retrieve existing this record, then with move behind the record after the insertion point, with the record zero clearing of insertion point, current/next information record sum is added 1;
C2 judges the numerical value of record insertion point index, when record insertion point index<0, does not increase new current/next information record;
C3 when record insertion point index 〉=0, copies current record in current/next information array to.
Search the acquisition unit branch and comprise following steps:
D1 judges whether input parameter is effective, and when input parameter was invalid, nothing was obtained;
D2, when input parameter is effective, the record quantity of searching first matching E PG information record and mating altogether;
D3, the record quantity of recording indexes more to be checked and coupling does not have when the record quantity of recording indexes to be checked 〉=coupling and obtains, and when the record quantity of recording indexes to be checked<coupling, obtains an EPG information.
The present invention searches and obtains an EPG information or store an EPG information and directly adopt binary search.Location and seek rate are fast.It has only 4 key interface functions, wherein two be used for data inject, two be used for data and obtain.
Task of the present invention comes to this and finishes.
The invention provides a kind of Digital Television EPG information of complete, simple, easy care automatic cleaning, increase record and search acquisition methods.It has automatic maintenance function, but the set information retention time, but carry out garbage-cleaning every day one time, overflow to prevent data, can guarantee to stablize altogether for a long time.Simultaneously, its information storage and retrieval speed is fast, and calling interface is simple.It also has good portability, except that digital television set, also extends in other receiving equipments.
Embodiment
Embodiment 1.A kind of automatic cleaning of Digital Television EPG information, increase record and search acquisition methods, comprise automatic cleaning, increase EPG information record, increase EPG current/next information record and search and obtain four parts.As shown in Figure 1, wherein automatic cleaning may further comprise the steps:
1. determine shared EPG recording of information space and the dominant record bar number of all programs in the internal memory, be no more than the time that keeps EPG information in the internal memory with the time difference that keeps all information in the EPG information, set the time that keeps EPG information, overflow when preventing to work long hours;
2. when EPG record sum〉0 the time, retrieve the time of current state-of-the-art record;
3. calculate the thresholding time, that is the time of state-of-the-art record subtracts the time that keeps EPG information;
4. deletion exceeds the record of thresholding time;
5. upgrade EPG information record sum and organize your messages record again.
Its source code is:
// keep all the information time differences in the EPG information to be no more than DaysToKeep, overflow when preventing to work long hours
BOOL?EPG::EPGList_GabageRemove(void)
{
int?i=0,j=0;
int?temp_Year;
UCHAR8temp_Month,temp_Day;
long?LatestTime,FirstTime,TempTime;
int?GabageCount=0;
if(Weekly_EPG_Info_Number<= 0)
return?TRUE;
temp_Year =Weekly_EPG_Info[0].start_time,Year;
temp_Month =Weekly_EPG_Info[0].start_time.Month;
temp_Day =Weekly_EPG_Info[0].start_time.Day;
LatestTime=(temp_Year<<16)|(temp_Month<<8)|temp_Day;
FirstTime=LatestTime;
// find out the nearest time
for(i=0;i<Weekly_EPG_Info_Number;i++)
{
temp_Year =Weekly_EPG_Info[i].start_time.Year;
temp_Month =Weekly_EPG_Info[i].start_time.Month;
temp_Day =Weekly_EPG_Info[i].start_time.Day;
TempTime=(temp_Year<<16)|(temp_Month<<8)|temp_Day;
if(LatestTime<TempTime)
{
LatestTime=TempTime;
}
}
temp_Day =LatestTime?&?0x000000ff;
temp_Month?=(LatestTime?&?0x0000ff00)>>8;
temp_Year=(LatestTime?&?0xffff0000)>>16;
// calculate the thresholding time, exceed with DaysToKeep
if(temp_Day>DaysToKeep)
temp_Day=temp_Day-DaysToKeep;
else?if( (temp_Month==2)||(temp_Month==4)‖(temp_Month==6)
‖(temp_Month==8)‖(temp_Month==9)||(temp_Month==11)
‖(temp_Month==1))
{
if(temp_Month-1==0)
{
temp_Month=12;
temp_Year?--;
}
else
temp_Month?--;
temp_Day=31+temp_Day-DaysToKeep;
}
else?if((temp_Month==5)‖(temp_Month==7)‖(temp_Month==10)||(temp_Month==12))
{
temp_Month?--;
temp_Day=30+temp_D?ay-DaysToKeep;
}
else?if(temp_Month==3)
{
if(((temp_Year%400)==0)||(((temp_Year%4)==0)&&((temp_Year%100)!=0)))
{
temp_Month--;
temp_Day=29+temp_Day-DaysToKeep;
}
else
{
temp_Month--;
temp_Day=28+temp_Day-DaysToKeep;
}
}
printf("Gate?Time?is?%d,%d,%d\n",temp_Year,temp_Month,temp_Day);
// deletion exceeds the information of time restriction
FirstTime=(temp_Year<<16)|(temp_Month<<8)|temp_Day;
for(i=0;i<Weekly_EPG_Info_Number;i++)
{
temp_Year=Weekly_EPG_Info[i].start_time.Year;
temp_Month=Weekly_EPG_Info[i].start_time.Month;
temp_Day=Weekly_EPG_Info[i].start_time.Day;
TempTime=(temp_Year<<16)|(temp_Month<<8)|temp_Day;
if(FirstTime>TempTime)
{
memset((void*)&?Weekly_EPG_Info[i],0,sizeof(Weekly_EPG_INFO_STRUCT));
GabageCount++;
}
}
if(GabageCount==0)
return?TRUE;
// rearrangement EPG information record
int?HoleIndex=0,DefragmentIndex;
int?k=Weekly_EPG_Info_Number;
while(k)
{
for(i=HoleIndex;i<Weekly_EPG_Info_Number;i++)
{
if(Weekly_EPG_Info[i].service_id==0)
{
HoleIndex=i;
break;
}
}
for(j=HoleIndex;j<Weekly_EPG_Info_Number;j++)
{
if(Weekly_EPG_Info[j].service_id!=0)
{
DefragmentIndex=j;
break;
}
}
memcpy((void*)&?Weekly_EPG_Info[HoleIndex],
(void*)&?Weekly_EPG_Info[DefragmentIndex],
sizeof(Weekly_EPG_INFO_STRUCT));
memset((void*)&?Weekly_EPG_Info[DefragmentIndex],0,sizeof(Weekly_EPG_INFO_STRUCT));
HoleIndex?++;
k--;
if(HoleIndex>=DefragmentIndex)
break;
}
Weekly_EPG_Info_Number=Weekly_EPG_Info_Number-GabageCount;
return?TRUE;
}
As Fig. 3~shown in Figure 4, increase EPG information recording part branch and comprise following steps:
1. adjust record start time time zone;
2. obtain EPG information record insertion point, comprise step by step following:
(1) detect EPG information record sum, when it=0 the time, promptly enter next step;
(2) whether when it is not equal to 0, it is full to detect the EPG memory block, when expire the EPG memory block, promptly enters next step;
3. when the EPG memory block is discontented, retrieve according to service-id and evemt-id:
(1) if retrieve existing this record, promptly enters next step;
(2) if do not retrieve existing this record, then with move behind the record after the insertion point, with the record zero clearing of insertion point, EPG information record sum is added 1;
4. judge the numerical value of record insertion point index, when record insertion point index<0, do not increase new EPG information record;
5. when record insertion point index 〉=0, current record is copied in the EPG information array.
Its source code is:
New EPG information of // increase
BOOL?EPG::AddEP?GList(tagDVBEIT_EVENT_ENTRY_STRUCT?*?pEPG)
{
int?IndexofNewInfo;
//----------------------------the time zone adjustment---------------------------------------------------
if((*pEPG).start_time.Hour<16)
{
(*pEPG).start_time.Hour=(*pEPG).start_time.Hour+China_TimeZone;
}
else
{
(*pEPG).start_time.Hour=(*pEPG).start_time.Hour+China_TimeZone-24;
(*pEPG).start_time.Day=(*pEPG).start_time.Day+1;
if((*pEPG).start_time.Month==1||(*pEPG).start_time.Month==3||(*pEPG).start_time.Month==5
||(*pEPG).start_time.Month==7||(*pEPG).start_time.Month==8||(*pEPG).start_time.Month==10
||(*pEPG).start_time.Month==12)
{
if((*pEPG).start_time.Day>31)
{
(*pEPG).start_time.Day=1;
(*pEPG).start_time.Month=(*pEPG).start_time.Month+1;
if((*pEPG).start_time.Month==13)
{
(*pEPG).start_time.Month=1;
(*pEPG).start_time.Year=(*pEPG).start_time.Year+1;
}
}
}
else?if((*pEPG).start_time.Month==4||(*pEPG).start_time.Month==6
||(*pEPG).start_time.Month==9||(*pEPG).start_time.Month==11)
{
if((*pEPG).start_time.Day>30)
{
(*pEPG).start_time.Day=1;
(*pEPG).start_time.Month=(*pEPG).start_time.Month+1;
if((*pEPG).start_time.Month==13)
{
(*pEPG).start_time.Month=1;
(*pEPG).start_time.Year=(*pEPG).start_time.Year+1;
}
}
}
else
{
int?OddMonth=0;
if(((*pEPG).start_time.Year?%?400)==0‖
(((*pEPG).start_time.Year%4)==0?&?&((*pEPG).start_time.Year?%?100)!=0))
OddMonth=1;
if((*pEPG).start_time.Day>28+OddMonth)
{
(*pEPG).start_time.Day=1;
(*pEPG).start_time.Month=(*pEPG).start_time.Month+1;
if((*pEPG).start_time.Month==13)
{
(*pEPG).start_time.Month=1;
(*pEPG).start_time.Year=(*pEPG).start_time.Year+1;
}
}
}
}
//------------------------------------obtain the insertion point-----------------------------------------
IndexofNewInfo=Get_EPG_ServiceID_Index((*pEPG).service_id,(*pEPG).event_id);
if(IndexofNewInfo==-1)
{ ∥ does not have available insertion point
return?FALSE;
}
else
{ // with new EPG information record copies is in the EPG information bank
Weekly_EPG_Info[IndexofNewInfo].service_id =(*pEPG).service_id;
Weekly_EPG_Info[IndexofNewInfo].duration =(*pEPG).duration;
Weekly_EPG_Info[IndexofNewInfo].event_id =(*pEPG).event_id;
Weekly_EPG_Info[IndexofNewInfo].start_time.Year =(*pEPG).start_time.Year;
Weekly_EPG_Info[IndexofNewInfo].start_time.Month =(*pEPG).start_time.Month;
Weekly_EPG_Info[IndexofNewInfo].start_time.Day =(*pEPG).start_time.Day;
Weekly_EPG_Info[IndexofNewInfo].start_time.Hour =(*pEPG).start_time.Hour;
Weekly_EPG_Info[IndexofNewInfo].start_time.Minute =(*pEPG).start_time.Minute;
Weekly_EPG_Info[IndexofNewInfo].start_time.Second=(*pEPG).start_time.Second;
Weekly_EPG_Info[IndexofNewInfo].end_time.Year =(*pEPG).end_time.Year;
Weekly_EPG_Info[IndexofNewInfo].end_time.Month?=(*pEPG).end_time.Month;
Weekly_EPG_Info[IndexofNewInfo].end_time.Day =(*pEPG).end_time.Day;
Weekly_EPG_Info[IndexofNewInfo].end_time.Hour =(*pEPG).end_time.Hour;
Weekly_EPG_Info[IndexofNewInfo].end_time.Minute =(*pEPG).end_time.Minute;
Weekly_EPG_Info[IndexofNewInfo].end_time.Second =(*pEPG).end_time.Second;
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_length =
(*pEPG).short_event_desc.event_name_length;
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_length=
(*pEPG).short_event_desc.text_length;
if(Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_length>=30)
{
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_length=30;
memcpy((char*)Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_str,(char
*)(*pEPG).short_event_desc.event_name_str,30);
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_str[29]=′\0′;
}
else
strcpy((char *)Weekly_EPG_Info[IndexofNewInfo].short_event_desc.event_name_str, (char
*)(*pEPG).short_event_desc.event_name_str);
if(Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_length>=30)
{
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_length=30;
memcpy((char *)Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_str, (char
*)(*pEPG).short_event_desc.text_str,30);
Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_str[29]=′\0′;
}
else
strcpy((char *)Weekly_EPG_Info[IndexofNewInfo].short_event_desc.text_str, (char
*)(*pEPG).short_event_desc.text_str);
}
return?TRUE;
}
// search the array index of specifying serviceID and eventID, if do not find, just distribute one
//serviceID and eventID arrange according to ascending order
int?EPG::Get_EPG_ServiceID_Index(UINT16?serviceID,UINT16?eventID)
{
int?i;
BOOL?foundIt;
int?IndexFound;
if(Weekly_EPG_Info_Number==0)
{
Weekly_EPG_Info_Number++;
return?0;
}
if(Weekly_EPG_Info_Number>=Max_Weekly_EPG_Info_Number)
{
printf("Now?EPG?storage?full!\n");
return-1;
}
// check whether have this serviceID and eventID, if exist, directly return index
foundIt=QuickFind(serviceID,eventID,TRUE,&IndexFound);
// printf("Index?is?%d,Found?result?is?%d\n",IndexFound,foundIt);
if(foundIt)
return?IndexFound;
else
// if there is no eventID, distribute one new
{
for(i=Weekly_EPG_Info_Number-1;i>=IndexFound;i--)
memcpy((void*)&?Weekly_EPG_Info[i+1],(void*)&?Weekly_EPG_Info[i],
sizeof(Weekly_EPG_INFO_STRUCT));
i++;
memset((void*)&?Weekly_EPG_Info[i],0,sizeof(Weekly_EPG_INFO_STRUCT));
Weekly_EPG_Info_Number++;
return?IndexFound;
}
retum?IndexFound;
}
As Fig. 5~shown in Figure 6, increase current/next information recording part branch and comprise following steps:
1. obtain current/next information record insertion point, comprise step by step following:
(1) detect current/next information record sum, when it=0 the time, return 0;
(2) whether when it is not equal to 0, it is full to detect current/next memory block, when expire the EPG memory block, returns-1;
(3) when current/next memory block is discontented, retrieve,, promptly return the index of this record if retrieve existing this record according to service-id and evemt-id;
(4) if do not retrieve existing this record, then with move behind the record after the insertion point, with the record zero clearing of insertion point, current/next information record sum is added 1, returns the index of this record;
2. judge the numerical value of record insertion point index:
(1) when record insertion point index<0, do not increase new current/next information record;
(2) when record insertion point index 〉=0, current record is copied in current/next information array.
Increase EPG information record, increase EPG current/source code that next information recording part divides is as follows:
New current/next event information of // increase
BOOL?EPG::AddNowNextInfo(tagDVBEIT_EVENT_ENTRY_STRUCT?*?pShortEvent)
{
int?IndexofNewInfo;
//----------------obtain the insertion point--------------------------------------------------------------------------
IndexofNewInfo=Get_NowNext_ServiceID_Index((*pShortEvent).service_id,(*pShortEvent).NextFlag);
if(IndexofNewInfo==-1)
{
printf("EPG?Storage?Full,Error\n");
return?FALSE;
}
else
{ Now_Next_Info[IndexofNewInfo].NextFlag =(*pShortEvent).NextFlag;
Now_Next_Info[IndexofNewInfo].service_id =(*pShortEvent).service_id;
Now_Next_Info[IndexofNewInfo].duration =(*pShortEvent).duration;
Now_Next_Info[IndexofNewInfo].event_id =(*pShortEvent),event_id;
Now_Next_Info[IndexofNewInfo].start_time.Year =(*pShortEvent).start_time.Year;
Now_Next_Info[IndexofNewInfo].start_time.Month =(*pShortEvent).start_time.Month;
Now_Next_Info[IndexofNewInfo].start_time.Day =(*pShortEvent).start_time.Day;
Now_Next_Info[IndexofNewInfo].start_time.Hour =(*pShortEvent).start_time.Hour;
Now_Next_Info[IndexofNewInfo].start_time.Minute?=(*pShortEvent).start_time.Minute;
Now_Next_Info[IndexofNewInfo].start_time.Second?=(*pShortEvent).start_time.Second;
Now_Next_Info[IndexofNewInfo].end_time.Year =(*pShortEvent).end_time.Year;
Now_Next_Info[IndexofNewInfo].end_time.Month =(*pShortEvent).end_time.Month;
Now_Next_Info[IndexofNewInfo].end_time.Day =(*pShortEvent).end_time.Day;
Now_Next_Info[IndexofNewInfo].end_time.Hour =(*pShortEvent).end_time.Hour;
Now_Next_Info[IndexofNewInfo].end_time.Minute =(*pShortEvent).end_time.Minute;
Now_Next_Info[IndexofNewInfo].end_time.Second =(*pShortEvent).end_time.Second;
Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_length =
(*pShortEvent).short_event_desc.event_name_length;
Now_Next_Info[IndexofNewInfo].short_event_desc.text_length =
(*pShortEvent).short_event_desc.text_length;
if(Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_length>=30)
{
Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_length=30;
memcpy((char*)Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_str, (char
*)(*pShortEvent).short_event_desc.event_name_str,30);
Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_str[29]=′\0′;
}
else
strcpy((char *)Now_Next_Info[IndexofNewInfo].short_event_desc.event_name_str, (char
*)(*pShortEvent).short_event_desc.event_name_str);
}
return?TRUE;
}
// search the array index of specifying serviceID, if do not find, just distribute one
//serviceID arranges according to ascending order
int?EPG::Get_NowNext_ServiceID_Index(UINT16?serviceID,BOOL?NextFlag)
{
inti;
BOOL?foundIt;
int?IndexFound;
if(Now_Next_Info_Number==0)
{
Now_Next_Info_Number++;
return?0;
}
if(Now_Next_Info_Number>=Max_Now_Next_Info_Number)
{
printf("Now?EPG?storage?full!\n");
return-1;
}
// check whether have this serviceID and eventID, if exist, directly return index
foundIt=QuickFind(serviceID,(int)NextFlag,FALSE,&IndexFound);
if(foundIt)
return?IndexFound;
else
// if there is no eventID, distribute one new
{
for(i=Now_Next_Info_Number-1;i>=IndexFound;i--)
memcpy((void *) & Now_Next_Info[i+1], (void *) & Now_Next_Info[i],
sizeof(Now_Next_INFO_STRUCT));
i++;
memset((void*)&?Now_Next_Info[i],0,sizeof(Now_Next_INFO_STRUCT));
Now_Next_Info_Number++;
return?IndexFound;
}
return?IndexFound;
}
As shown in Figure 7, EPG information recording searching acquisition unit branch comprises following steps:
1. judge whether input parameter is effective, and when input parameter was invalid, nothing was obtained;
2. when input parameter is effective, search first matching E PG information record and the record quantity of mating altogether;
The record quantity of recording indexes 3. more to be checked and coupling does not have when the record quantity of recording indexes to be checked 〉=coupling and obtains, and when the record quantity of recording indexes to be checked<coupling, obtains an EPG information.
Its source code is as follows:
// input serviceID and the date and the same day which bar EPG, return the pointer that points to this EPG record, then be sky
// notice that the IndexOfRecords value is since 0
Weekly_EPG_INFO_STRUCT * EPG::Get_EPG_Info_InOneDay(UINT16 serviceID,UCHAR8 Date,?int
IndexOfRecords)
{
int?RecordsFound=0;
int?firstIndex;
if(Date>31||Date<=0||IndexOfRecords<0)
return?NULL;
firstIndex=QuickLocateMultiEPG(serviceID,Date,&?RecordsFound);
if(IndexOfRecords>=RecordsFound)
{
printf("No?More?EPG?Records?for?This?Day!\n");
return?NULL;
}
else
{
return?&(Weekly_EPG_Info[firstIndex+IndexOfRecords]);
}
}
// notice that when supposing the EPG information issuing herein, the program EVENT_ID of appointment is continuous, though discontinuous,
// middle the eventID that also can not insert other programs.If this hypothesis is false, then should revise this function
int?EPG::QuickLocateMultiEPG(UINT16?ServiceID,UCHAR8?Date,int*MatchedNumber)
{
int?left=0;
int?right=0;
int?mid;
long?tempID;
tempID=(ServiceID<<16)|Date;
int?firstIndex=0,lastIndex=0;
right=Weekly_EPG_Info_Number-1;
if(right<0)
{
*MatchedNumber=0;
return?0;
}
mid=(right+left)/2;
First coupling record of // location
while(left<=right)
{
mid=(right+left)/2;
if(tempID<=((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].start_time.Day))
right=mid-1;
else
left=mid+1;
}
if(tempID==((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].start_time.Day))
{
firstIndex=mid;
}
else?if(tempID==((Weekly_EPG_Info[mid+1].service_id<<16)|Weekly_EPG_Info[mid+1].start_time.Day))
{
firstIndex=mid+1;
}
else
{
*?MatchedNumber=0;
return?0;
}
Last the coupling record of // location
left=0;
right=Weekly_EPG_Info_Number-1;
mid=(right+left)/2;
while(left<=right)
{
mid=(right+left)/2;
if(tempID<((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].start_time.Day))
right=mid-1;
else
left=mid+1;
}
if(tempID==((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].start_time.Day))
{
lastIndex=mid;
}
elseif(tempID==((Weekly_EPG_Info[mid-1].service_id<<16)|Weekly_EPG_Info[mid-1].start_time.Day))
{
lastIndex=mid-1;
}
*?MatchedNumber=lastIndex-firstIndex+1;
return?firstIndex;
}
Search and obtain a current/next information and directly adopt binary search.Search obtain and the source code of binary search as follows:
// obtain the pointer of a current or next event information
// input service ID, the Current state.
// NextFlag=FALSE, the current program information of this serviceID is obtained in expression
// NextFlag=TRUE, the next programme information of this serviceID is obtained in expression
Now_Next_INFO_STRUCT?*?EPG::GetNowNextInfo(UINT16?serviceID,BOOL?NextFlag)
{
int?left=0,right=0,mid=0;
long?tempID=(serviceID<<16)|(int)NextFlag;
right=Now_Next_Info_Number-1;
if(right<0)
{
return?NULL;
}
mid=(right+left)/2;
while(left<=right)
{
mid=(right+left)/2;
if(tempID<(Now_Next_Info[mid].service_id<<16|(int)(Now_Next_Info[mid].NextFlag)))
{
right=mid-1;
}
else?if(tempID>(Now_Next_Info[mid].service_id<<16|(int)(Now_Next_Info[mid].NextFlag)))
{
left=mid+1;
}
else?if(tempID==(Now_Next_Info[mid].service_id<<16|(int)(Now_Next_Info[mid].NextFlag)))
{
return?&Now_Next_Info[mid];
}
}
if(tempID==(Now_Next_Info[mid].service_id<<16|(int)(Now_Next_Info[mid].NextFlag)))
{
return?&Now_Next_Info[mid];
}
return?NULL;
}
// binary search
During //FindInEPG, serviceID and eventID unite as keyword
//FindInEPG is a fictitious time, thinks to search in nownext information, and this moment, eventID was substituted by NextFlag
BOOL?EPG::QuickFind(UINT16?ServiceID,UINT16?eventID,BOOL?FindInEPG,int*IndexFound)
{
int?left=0;
int?right=0;
int?rmid;
UINT32?tempID;
tempID=(ServiceID<<16)|eventID;
if(FindInEPG)
{
right=Weekly_EPG_Info_Number-1;
if(right<0)
{
*IndexFound=0;
return?FALSE;
}
mid=(right+left)/2;
while(left<=right)
{
mid=(right+left)/2;
if(tempID<((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].event_id))
right=mid-1;
else if (tempID > ((Weekly_EPG_Info[mid].service_id <<16)
|Weekly_EPG_Info[mid].event_id))
left=mid+1;
else if(tempID == ((Weekly_EPG_Info[mid].service_id <<16)
|Weekly_EPG_Info[mid].event_id))
{
*IndexFound=mid;
return?TRUE;
}
}
if(tempID<((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].event_id))
{
*IndexFound=mid;
return?FALSE;
}
else?if(tempID==((Weekly_EPG_Info[mid].service_id<<16)|Weekly_EPG_Info[mid].event_id))
{
*IndexFound=mid;
return?TRUE;
}
else
{
*IndexFound=mid+1;
return?FALSE;
}
}
else//find?in?NowNextInfo
{
// notice that this moment, eventID was substituted by NextFlag
right=Now_Next_Info_Number-1;
left=0;
if(right<0)
{
*IndexFound=0;
return?FALSE;
}
mid=(right+left)/2;
|(int)Now_Next_Info[1].NextFlag));
while(left<=right)
{
mid=(right+left)/2;
if(tempID<((Now_Next_Info[mid].service_id<<16)|(int)Now_Next_Info[mid].NextFlag))
right=mid-1;
else if (tempID > ((Now_Next_Info[mid].service_id <<16)
|(int)Now_Next_Info[mid].NextFlag))
left=mid+1;
else if(tempID == ((Now_Next_Info[mid].service_id <<16)
|(int)Now_Next_Info[mid].NextFlag))
{
*IndexFound=mid;
return?TRUE;
}
}
if(tempID<((Now_Next_Info[mid].service_id<<16)|(int)Now_Next_Info[mid].NextFlag))
{
*IndexFound=mid;
return?FALSE;
}
else?if(tempID==((Now_Next_Info[mid].service_id<<16)|(int)Now_Next_Info[mid].NextFlag))
{
*IndexFound=mid;
return?TRUE;
}
else
{
*IndexFound=mid+1;
return?FALSE;
}
}
}
void?CleanEPG(void*pvParam)
{
while(1)
{
Clear up the EPG data // every day one time
Delay(1000*3600*24);
EPG_DVBC.EPGList_GabageRemove();
}
return;
}
EPG.H
#ifndef?EPG_h
#define?EPG_h
#define?max_events_per_program?7*24
#define?NEXT?TRUE
#define?NOW?FALSE
typedef?struct?SHORT_EVENT_DESC_STRUCT
{
/*?for?short_event_descriptor()*/
UCHAR8?event_name_length;
UCHAR8 event_name_str[30]; // 15 Chinese characters
UCHAR8?text_length;
UCHAR8 text_str[30]; // 15 Chinese characters
};
typedef?struct EXT_EVENT_DESC_STRUCT
{
/*?for?extended_event_descriptor() */
UCHAR8?ISO_639_language_code[4];
int item_description_length[MAX_NUM_OF_ITEMS];
UCHAR8?item_description_char[MAX_NUM_OF_ITEMS][30];
int item_length[MAX_NUM_OF_ITEMS];
UCHAR8?item_char[MAX_NUM_OF_ITEMS][30];
UCHAR8?text_length;
UCHAR8?text_char[128];
};
struct?Now_Next_INFO_STRUCT
{
UINT16 service_id;
UINT16 event_id;
DVBTIME start_time;
DVBTIME end_time;
UINT32 duration;
BOOL NextFlag;
SHORT_EVENT_DESC_STRUCT short_event_desc;
};
struct?Weekly_EPG_INFO_STRUCT
{
UINT16 service_id;
UINT16 event_id;
DVBTIME start_time;
DVBTIME end_time;
UINT32 duration;
SHORT_EVENT_DESC_STRUCT short_event_desc;
};
struct?Ext_EPG_INFO_STRUCT
{
UINT16 service_id;
UINT16 event_id;
DVBTIME start_time;
DVBTIME end_time;
UINT32 duration;
EXT_EVENT_DESC_STRUCT ext_event_desc;
};
void?CleanEPG(void*pvParam);
class?EPG{
public:
CORE_TASK_ID?TaskID_CleanEPG;
EPG();
~EPG();
BOOL?Init(void);
BOOL?AddNowNextInfo(tagDVBEIT_EVENT_ENTRY_STRUCT?*?pShortEvent);
BOOL?AddEPGList(tagDVBEIT_EVENT_ENTRY_STRUCT?*?pEPG);
BOOL?ADDExtEPGList(tagDVBEIT_EVENT_ENTRY_STRUCT?*?pExtEPG);
BOOL?EPGList_GabageRemove(void);
Now_Next_INFO_STRUCT?*?GetNowNextInfo(UINT16serviceID,BOOL?Current);
Weekly_EPG_INFO_STRUCT?*?Get_EPG_Info_InOneDay(UINT16?serviceID,UCHAR8?Date,int
IndexOfRecords);
int?Get_Now_Next_Info_Number(void);
int?Get_Weekly_EPG_Info_Number(void);
void?outputNowNextInfo(void);
void?outputEPGListInfo(void);
void?PrintEPGofOneDay(UINT16?ServiceID,UCHAR8?Day);
private:
int?Max_Now_Next_Info_Number;
int?Now_Next_Info_Number;
CORE_SEM_ID?EPG_LOCK;
CORE_SEM_ID?NowNext_LOCK;
int?Max_Weekly_EPG_Info_Number;
int?Weekly_EPG_Info_Number;
int?China_TimeZone;
int?Max_Ext_EPG_Info_Number;
int?Ext_EPG_Info_Number;
Int DaysToKeep; The fate of // reservation EPG
Now_Next_INFO_STRUCT *Now_Next_Info;
Weekly_EPG_INFO_STRUCT *Weekly_EPG_Info;
Ext_EPG_INFO_STRUCT *Ext_EPG_Info;
BOOL?QuickFind(UINT16?ServiceID,UINT16?eventID,BOOL?FindInEPG,int*IndexFound);
int?QuickLocateMultiEPG(UINT16?ServiceID,UCHAR8?Date,int*MatchedNumber);
int?Get_NowNext_ServiceID_Index(UINT16?serviceID,BOOL?NextFlag);
int?Get_EPG_ServiceID_Index(UINT16?serviceID,UINT16?eventID);
};
#endif
Embodiment 1 has automatic maintenance function, but the set information retention time, but carry out garbage-cleaning every day one time, overflow to prevent data, it is stable to guarantee to work long hours.Simultaneously, its information storage and retrieval speed is fast, and calling interface is simple.It also has good portability, except that digital television set, also extends in other receiving equipment.