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

📄 dvb_db.c

📁 DVB软件,基于CT216软件的开发源程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
    
	    if( (pgmItem.u16TypeEX&MASK_OF_FAVORITE_GROUP)==0 )    
	    {
		    return (-1);    // non-favority first
	    }    
		else
		{
		    return (1);
		}	
	}
#else
	DVB_TPReadDetailEx(pgmItem.u8TransponderIndex , &stTpDetail1, &stTpRel1);
	DVB_TPReadDetailEx(pgmItem2.u8TransponderIndex, &stTpDetail2, &stTpRel2);
    
    if(stTpRel1.u16SatIdx==stTpRel2.u16SatIdx)
    {
    
    	if( ((pgmItem.u16TypeEX&MASK_OF_FAVORITE_GROUP)!=0 && (pgmItem2.u16TypeEX&MASK_OF_FAVORITE_GROUP)!=0)
    	    || ((pgmItem.u16TypeEX&MASK_OF_FAVORITE_GROUP)==0 && (pgmItem2.u16TypeEX&MASK_OF_FAVORITE_GROUP)==0) )
    	{
    		return ( PU8TOU16(pu16idx1)-PU8TOU16(pu16idx2) );
    	}
    	else
    	{    
    	    if( (pgmItem.u16TypeEX&MASK_OF_FAVORITE_GROUP)==0 )   
    	    {
    		    return (-1);    // non-favority first
    	    }    
    		else
    		{
    		    return (1);
    		}	
    	}
    }
    else
        return (stTpRel1.u16SatIdx-stTpRel2.u16SatIdx);
#endif	
}
/*******************************************************************************************/          

int free_service_compare(unsigned pu16idx1, unsigned pu16idx2)
{
#ifndef NO_SATELLITE
	DB_TpDetailEx	stTpDetail1, stTpDetail2;
	DB_TpRel		stTpRel1, stTpRel2;
#endif
	
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx1), &pgmItem);
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx2), &pgmItem2);

#ifdef NO_SATELLITE
	if( (pgmItem.u8Type&0x40)==(pgmItem2.u8Type&0x40) )
	{
		return ( PU8TOU16(pu16idx1)-PU8TOU16(pu16idx2) );
	}
	else
	{
	    if( (pgmItem.u8Type&0x40)==0 )
	    {
		    return (-1);    // free first
	    }    
		else
		{
		    return (1);
		}	
	}
#else
	DVB_TPReadDetailEx(pgmItem.u8TransponderIndex , &stTpDetail1, &stTpRel1);
	DVB_TPReadDetailEx(pgmItem2.u8TransponderIndex, &stTpDetail2, &stTpRel2);
    
    if(stTpRel1.u16SatIdx==stTpRel2.u16SatIdx)
    {
    	if( (pgmItem.u8Type&0x40)==(pgmItem2.u8Type&0x40) )
    	{
    		return ( PU8TOU16(pu16idx1)-PU8TOU16(pu16idx2) );
    	}
    	else
    	{
    	    if( (pgmItem.u8Type&0x40)==0 )
    	    {
    		    return (-1);    // free first
    	    }
			else
			{
    		    return (1);
			}	
    	}
    }
    else
        return (stTpRel1.u16SatIdx-stTpRel2.u16SatIdx);
#endif	
}
/*******************************************************************************************/          

int scramble_service_compare(unsigned pu16idx1, unsigned pu16idx2)
{
#ifndef NO_SATELLITE
	DB_TpDetailEx	stTpDetail1, stTpDetail2;
	DB_TpRel		stTpRel1, stTpRel2;
#endif
	
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx1), &pgmItem);
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx2), &pgmItem2);

#ifdef NO_SATELLITE
	if( (pgmItem.u8Type&0x40)==(pgmItem2.u8Type&0x40) )
	{
		return ( PU8TOU16(pu16idx1)-PU8TOU16(pu16idx2) );
	}
	else
	{
	    if( (pgmItem.u8Type&0x40)!=0 )
	    {
		    return (-1);    // free first
	    }    
		else
		{
		    return (1);
		}	
	}

#else
	DVB_TPReadDetailEx(pgmItem.u8TransponderIndex , &stTpDetail1, &stTpRel1);
	DVB_TPReadDetailEx(pgmItem2.u8TransponderIndex, &stTpDetail2, &stTpRel2);

	if(stTpRel1.u16SatIdx == stTpRel2.u16SatIdx)
    {
    	if( (pgmItem.u8Type&0x40)==(pgmItem2.u8Type&0x40) )
    	{
    		return ( PU8TOU16(pu16idx1)-PU8TOU16(pu16idx2) );
    	}
    	else
    	{
    	    if( (pgmItem.u8Type&0x40)!=0 )
    	    {
    		    return (-1);    // free first
    	    }   
    		else
    		{
    		    return (1);
    		}	
    	}
    }
    else
        return (stTpRel1.u16SatIdx-stTpRel2.u16SatIdx);
#endif	
}
/*******************************************************************************************/          

#ifdef ENABLE_LCN_SUPPORT
int lcns_compare(unsigned pu16idx1, unsigned pu16idx2)
{
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx1), &pgmItem);
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx2), &pgmItem2);

	return(pgmItem.u16LCN - pgmItem2.u16LCN);
}
#endif

#ifdef LCN_COUNTRY_CHECK_DISABLE    
int pcn_compare(unsigned pu16idx1, unsigned pu16idx2)
{
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx1), &pgmItem);
	DVB_ServiceRead (enSrvType, Address2Idx(pu16idx2), &pgmItem2);

	return(pgmItem.u16PCN - pgmItem2.u16PCN);
}
#endif

/*******************************************************************************************/          

u16 DVB_SortDB(EN_SERVICE_TYPE _enSrvType, EN_SORT_TYPE enType, u16 u16OrgIdx )
{
	enSrvType = _enSrvType;
	s16NumOfItems = DVB_ServiceGetTotal(enSrvType);
	
	if (pu16SortedArray)
	{
		DVB_MemoryFree((u8*)pu16SortedArray);
		pu16SortedArray = NULL;
	}
gen_point = 147;	
	pu16SortedArray = (u16*)DVB_MemoryAllocate( s16NumOfItems*sizeof(u16) );
	
	if(pu16SortedArray == NULL)
	{
		return u16OrgIdx;
	}
	
	if (pu16SortedArrayTemp)
	{
		DVB_MemoryFree((u8*)pu16SortedArrayTemp);
		pu16SortedArrayTemp = NULL;
	}	
	pu16SortedArrayTemp = (u16*)DVB_MemoryAllocate( s16NumOfItems*sizeof(u16) );
	if (pu16SortedArrayTemp == NULL)
	{
		DVB_MemoryFree((u8*)pu16SortedArray);
		pu16SortedArray = NULL;
			
		return u16OrgIdx;
	}
	
	for(s16temp=0; s16temp<s16NumOfItems; s16temp++)
	{
		*( pu16SortedArray+s16temp ) = 0 + s16temp;	/*u16Service_start_idx*/
	}
	
	memcpy (pu16SortedArrayTemp, pu16SortedArray, s16NumOfItems*sizeof(u16));
	switch(enType)
	{
		case EN_SORT_BY_SID: // sid
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), service_id_compare, u16OrgIdx, _enSrvType );
			break;
		case EN_SORT_BY_NAME_AZ:	// name
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), service_name_az_compare, u16OrgIdx, _enSrvType );
			break;
		case EN_SORT_BY_NAME_ZA:	// name
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), service_name_za_compare, u16OrgIdx, _enSrvType );
			break;
		case EN_SORT_BY_CHNO:	// tpidx, ch_no
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), channel_number_compare, u16OrgIdx, _enSrvType );
			break;
        case EN_SORT_BY_FAV:
        case EN_SORT_BY_FAVEX:
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), favority_compare, u16OrgIdx, _enSrvType );
            break;
        case EN_SORT_BY_NON_FAV:
        case EN_SORT_BY_NON_FAVEX:
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), non_favority_compare, u16OrgIdx, _enSrvType );
            break;
        case EN_SORT_BY_FREE:
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), free_service_compare, u16OrgIdx, _enSrvType );
            break;
        case EN_SORT_BY_CA:
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), scramble_service_compare, u16OrgIdx, _enSrvType );
            break;
#ifdef ENABLE_LCN_SUPPORT
		case EN_SORT_BY_LCNS:
			u16OrgIdx = qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), lcns_compare, u16OrgIdx, _enSrvType );
            break;
		case EN_SORT_BY_LCNS_SCR:
			u16OrgIdx = qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), lcns_compare, u16OrgIdx, _enSrvType );
			for(s16temp=0; (s16temp < s16NumOfItems) && (check_lcn_flag(_enSrvType, s16temp) == TRUE); s16temp++)
			{
				*( pu16SortedArray+s16temp ) = 0 + s16temp;	/*u16Service_start_idx*/
			}
			memcpy (pu16SortedArrayTemp, pu16SortedArray, s16temp*sizeof(u16));
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16temp, sizeof(u16), free_service_compare, u16OrgIdx, _enSrvType );
			for(s16temp2 = 0; s16temp < s16NumOfItems; s16temp++, s16temp2++)
			{
				*( pu16SortedArray+s16temp2 ) = 0 + s16temp;	/*u16Service_start_idx*/
			}
			memcpy (pu16SortedArrayTemp, pu16SortedArray, s16temp2*sizeof(u16));
			u16OrgIdx = (u16)qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16temp2, sizeof(u16), free_service_compare, u16OrgIdx, _enSrvType );
            break;

        #ifdef LCN_COUNTRY_CHECK_DISABLE    
        case EN_SORT_BY_PCN: // parsed channel number
			u16OrgIdx = qsort_ex( pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), pcn_compare, u16OrgIdx, _enSrvType );
        #endif            
#endif        
#ifdef TUI	
	case EN_SORT_BY_FREQ:	//pgm frequency,add by shawn
		u16OrgIdx= qsort_ex(pu16SortedArray, pu16SortedArrayTemp, s16NumOfItems, sizeof(u16), Channel_freq_compare, u16OrgIdx, _enSrvType);
#endif	
	}

	DVB_MemoryFree((u8*)pu16SortedArray);
	DVB_MemoryFree((u8*)pu16SortedArrayTemp);
	pu16SortedArray = NULL;
	pu16SortedArrayTemp = NULL;
	
	return u16OrgIdx;
}
/*******************************************************************************************/          

u32 DVB_DBGetDigest(void)
{
    u32temp = DB_VERSION;
    u32temp = (u32temp<<16)+(DB_BACKUP_BANK<<7)+(DB_DRAM_IMAGE<<6)+(DB_DATA_BANK);
    u32temp = u32temp^BANK_MAGIC;
    return u32temp;
}
/*******************************************************************************************/          

u16 DVB_DBGetVersion(void)
{
    return DB_VERSION;
}
/*******************************************************************************************/          

u16 DVB_DBGetBankNum(void)
{
    return DB_TOTAL_BANK;
}
/*******************************************************************************************/          

u16 DVB_DBGetStartBank(void)
{
    return u8DVB_DBStartBank;
}
/*******************************************************************************************/          

void DVB_DBSetStartBank(u8 u8StartBank)
{
    u8DVB_DBStartBank = u8StartBank;
}
/*******************************************************************************************/          

#ifdef FLASH_EEPROM

static u8 au8FileBlock[DB_FILE_BLOCK_SIZE];
static u8 u8BlockIdx;

bool8 FLASH_EEPROM_Read(u8 *pu8Data, u16 u16Length, u16 u16Offset)
{
    for(u32temp=u16Offset; u32temp<u16Offset+u16Length;)
    {
        DBFS_InfoRead(EN_GENERAL_FILE, u32temp/DB_FILE_BLOCK_SIZE, au8FileBlock);
        
        for(u8BlockIdx=u32temp%DB_FILE_BLOCK_SIZE; u8BlockIdx<DB_FILE_BLOCK_SIZE; u8BlockIdx++)
        {
            *pu8Data = au8FileBlock[u8BlockIdx];
            pu8Data++;
            u32temp++;

            if( u32temp>=u16Offset+u16Length )
            {
                break;
            }	
        }
    }
    
    return TRUE;
}
/*******************************************************************************************/          

bool8 FLASH_EEPROM_Write(u8 *pu8Data, u16 u16Length, u16 u16Offset)
{
//    DB_DBG(("\n [%x:%d]\n", u16Offset, u16Length));
    if(u16Length==0)
    {
        return FALSE;
    }
    u32temp = u16Offset;
    for(s16temp=u16Offset/DB_FILE_BLOCK_SIZE; s16temp<=(u16Offset+u16Length-1)/DB_FILE_BLOCK_SIZE; s16temp++)
    {
        DBFS_InfoRead(EN_GENERAL_FILE, s16temp, au8FileBlock);
        
        for(u8BlockIdx=u32temp%DB_FILE_BLOCK_SIZE; u8BlockIdx<DB_FILE_BLOCK_SIZE; u8BlockIdx++)
        {
            au8FileBlock[u8BlockIdx] = *pu8Data;
            pu8Data++;
            u32temp++;

            if( u32temp>=u16Offset+u16Length )
            {
                break;
            }	
        }
        
        DBFS_InfoWrite(EN_GENERAL_FILE, s16temp, au8FileBlock);
//        DB_DBG(("MMMMMMM %x: %02hx %02hx %02hx %02hx\n", s16temp*DB_FILE_BLOCK_SIZE, au8FileBlock[0], au8FileBlock[1], au8FileBlock[2], au8FileBlock[3]));
    }
    
    return TRUE;
}
/*******************************************************************************************/          

bool8 FLASH_EEPROM_Info(u8 *pu8BankID, u32 *pu32Address, u32 *pu32Length)
{
	return DBFS_GetTableInfo(EN_GENERAL_FILE, 0, pu8BankID, pu32Address, pu32Length);
}
/*******************************************************************************************/          

bool8 FLASH_EEPROM_ReadAll(u8 *pu8Buffer)
{
	return DBFS_GetTableData(EN_GENERAL_FILE, 0, pu8Buffer);
}
/*******************************************************************************************/          

#endif

#if 0 // Debug Only
void DVB_DBCheckDram(u8 u8Mode)
{
	u32 u32Addr;
	u32 u32Length;
	
	
	
	
	switch(u8Mode)
	{
		default:
		case 0:
			u32Length 	= 64*1024;
			u32Addr 	= (u32)DB_CACHE_DRAM_START;
			u32Addr 	+= u32Length;				
			DVB_DramDump(u32Addr, 100);
			break;
		case 1:			
			u32Addr 	= (u32)DB_DRAM_START;			
			DVB_DramDump(u32Addr, 100);
			break;
		case 9:
			u32Length 	= 64*1024;
			u32Addr 	= (u32)DB_CACHE_DRAM_START;
			u32Addr 	+= u32Length;	
			DVB_DramSet(u32Addr,0x55,u32Length);			
			break;			
	}
}
#endif

/*******************************************************************************************/          

⌨️ 快捷键说明

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