Ejemplo n.º 1
0
s32 CREATE_TABLE_FROM_DB_FILE(char *db_filename, void **pBuffer, u32 *db_file_size)
{
//	if (*pBuffer != NULL) {
//        OUT_DEBUG_1("The table of \"%s\" type already exists in RAM.\r\n", db_filename);
//		return ERR_DB_TABLE_ALREADY_EXISTS_IN_RAM;
//	}

	u32 local_size = 0;         // will be used if "db_file_size" parameter is not specified (is NULL)
    u32 *size = db_file_size ? db_file_size : &local_size;

    s32 ret = Ql_FS_GetSize(db_filename);
    if (ret < 0) return ret;
    else *size = ret;

    if (*pBuffer == NULL)
        *pBuffer = Ql_MEM_Alloc(*size);   // in bytes

    if (*pBuffer == NULL) {
        if (*size != 0) {
            OUT_DEBUG_1("Failed to get %d bytes from HEAP\r\n", *size);
            return ERR_GET_NEW_MEMORY_FAILED;
        } else {
            OUT_DEBUG_1("DB file \"%s\" is empty\r\n", db_filename);
            return ERR_DB_FILE_IS_EMPTY;
        }
    }

    OUT_DEBUG_2("CREATE_TABLE_FROM_DB_FILE(\"%s\") on address %p\r\n", db_filename, *pBuffer);

	ret = readFromDbFile(db_filename, *pBuffer, *size, 0);  // to read entire file
	if (ret < RETURN_NO_ERRORS) {
        Ql_MEM_Free(*pBuffer);
        *pBuffer = NULL;
		OUT_DEBUG_1("readFromDbFile() = %d error for \"%s\" file.\r\n", ret, db_filename);
		return ret;
	}

    Ar_System_writeSizeAllFiles((u32) ret + Ar_System_readSizeAllFiles());
	return RETURN_NO_ERRORS;
}
Ejemplo n.º 2
0
bool VerifyFileAndSendFirstEpoPacket(u8 *strFilePath)
{
    int ret = 0,filesize = 0;
    int sendLen = 0;
        
    if((strFilePath == NULL) || (Ql_strlen(strFilePath) == 0))
    {
         APP_DEBUG("VerifyFileAndSendFirstEpoPacket, strFilePath %s \r\n", strFilePath);             
        return FALSE;
    }
    ret = Ql_FS_Check((char*)strFilePath);
    if(ret != QL_RET_OK)
    {
        APP_DEBUG("Ql_FS_Check, strFilePath %s error \r\n", strFilePath);            
        return FALSE;
    }
    filesize = Ql_FS_GetSize((char*)strFilePath);       
    if(filesize < 0)
    {
        APP_DEBUG("Ql_FS_GetSize, filesize %d error \r\n ", filesize);            
        return FALSE;
    }       
    if (Ql_strncmp((char*)strFilePath,"RAM:", 4))
    {
        g_pEpoFile = Ql_FS_Open((char*)strFilePath, QL_FS_READ_ONLY);
    }
    else
    {
        g_pEpoFile = Ql_FS_OpenRAMFile((char*)strFilePath, QL_FS_READ_ONLY, filesize);
    }        
    // Read in the EPO file, and then verify the validity of EPO data. If the input EPO file is not in valid MTK EPO format, the
    // programmer shall terminate the process.
    if(g_pEpoFile < 0)
    {
        Ql_FS_Close(g_pEpoFile);
        APP_DEBUG("Ql_FS_OpenRAMFile, g_pEpoFile %d error \r\n ", g_pEpoFile);            
        return FALSE;
    }
    else
    {
        if (!fgEPO_Verify_File(g_pEpoFile))
        {
            Ql_FS_Close(g_pEpoFile);
            APP_DEBUG("fgEPO_Verify_File, g_pEpoFile %d error \r\n", g_pEpoFile);                    
            return FALSE;
        }
    }                    
    // Get total number of MTK_BIN_EPO packets that will be sent.
    g_i4NumSvEpoPkt =  i2EPO_Get_Num_Pkt(g_pEpoFile);       
    // Start EPO Data Transfer Protocol to send EPO data
    // fgEPO_Get_One_Pkt takes out three SAT data from the EPO file and encapsulated them in a MTK_BIN_EPO packet
    // with appropriate EPO SEQ number.
    // In order to save the total transferring time, we suggest to generate current EPO packet first, and then wait for
    // MTK_BIN_ACK_EPO acknowledge of the previous MTK_BIN_EPO packet from the GPS receiver.
    // The function fgEPO_Get_One_Pkt must be implemented by the programmer.
    g_u2LastEpoSeq = 0;
    g_u2EpoSeq = 0;
    Ql_memset(g_szPktData,0,sizeof(g_szPktData));
    if (fgEPO_Get_One_Pkt(g_u2EpoSeq, g_pEpoFile, g_szPktData))
    {
        sendLen =  MTKBIN_3EPO_PKT_LNG;
        ret = Ql_UART_Write(m_gnssUartPort,g_szPktData,sendLen);
        if (ret < sendLen)
        {
            APP_DEBUG("VerifyFileAndSendFirstEpoPacket Only part of bytes are written, %d/%d \r\n", ret, sendLen);            
            return FALSE;
        }
        // Update sequence number
        g_u2LastEpoSeq = g_u2EpoSeq;
        g_u2EpoSeq++;
        return TRUE;
    }
    else
    {
        APP_DEBUG("VerifyFileAndSendFirstEpoPacket fgEPO_Get_One_Pkt error \r\n");
        return FALSE;
    }

}