示例#1
0
文件: fs.c 项目: victor-tr/armor2016
s32 saveToDbFile(char *fileName, void *inData, u16 len, bool bAppend)
{
    OUT_DEBUG_2("saveToDbFile(\"%s\")\r\n", fileName);

	u32 written_bytes = 0;


    s32 fh = Ql_FS_Open(fileName, QL_FS_READ_WRITE);
	if (QL_RET_OK > fh) {
		OUT_DEBUG_1("Error %d occured while opening file \"%s\".\r\n", fh, fileName);
		return fh;
	}

    s32 ret = 0;
    if (bAppend) {
        ret = Ql_FS_Seek(fh, 0, QL_FS_FILE_END);
        if (ret < QL_RET_OK) {
            Ql_FS_Close(fh);
            OUT_DEBUG_1("Error %d occured while seeking file \"%s\".\r\n", ret, fileName);
            return ret;
        }
    }

    ret = Ql_FS_Write(fh, (u8 *)inData, len, &written_bytes);
	if (QL_RET_OK > ret) {
        Ql_FS_Close(fh);
		OUT_DEBUG_1("Error %d occured while writting file \"%s\".\r\n", ret, fileName);
		return ret;
	}

    Ql_FS_Close(fh);
    OUT_DEBUG_3("%d bytes %s to file \"%s\".\r\n", written_bytes, bAppend ? "appended" : "written", fileName);
    return written_bytes;
}
bool fgEPO_Verify_File(int pEpoFile)
{

	long cur_pos;
	long len;

	
	//cur_pos = ftell( pEpoFile );
	cur_pos = Ql_FS_GetFilePosition(pEpoFile);

	//fseek( pEpoFile, 0, SEEK_END );
	Ql_FS_Seek(pEpoFile,0,QL_FS_FILE_END);

	//len = ftell( pEpoFile );
	len = Ql_FS_GetFilePosition( pEpoFile );

	//fseek( pEpoFile, cur_pos, SEEK_SET );
	Ql_FS_Seek(pEpoFile,cur_pos,QL_FS_FILE_CURRENT);
	return (len != 0) && ((len%MTK_EPO_SET_LNG)==0);
}
int i2EPO_Get_Num_Pkt(int pEpoFile)
{
	long cur_pos;
	long len;
    
#if 1
	cur_pos = Ql_FS_GetFilePosition(pEpoFile);
	Ql_FS_Seek(pEpoFile,0,QL_FS_FILE_END);

	len = Ql_FS_GetFilePosition( pEpoFile );
	Ql_FS_Seek(pEpoFile,cur_pos,QL_FS_FILE_CURRENT);
#else

	cur_pos = ftell( pEpoFile );
	fseek( pEpoFile, 0, SEEK_END );

	len = ftell( pEpoFile );
	ftell( pEpoFile, cur_pos, SEEK_SET );
#endif
	return ((len/MTK_EPO_SET_LNG * 32)%3 == 0)? (len/MTK_EPO_SET_LNG * 32)/3 : (int)(len/MTK_EPO_SET_LNG * 32)/3  + 1 ;
}
bool fgEPO_Get_One_Pkt(int u2EpoSeq, int pEpoFile,unsigned char *szData)
{
        u32   loopi = 0;
        u32  act_len = 0;
        u32 result;
	char checksum = 0;

	unsigned char buf[6+2+72*3+1+2]={0};
	
	unsigned char framehead[6]={0x04,0x24,0xE3,0x00,0xD3,0x02};
	unsigned char frametail[2]={0x0D,0x0A};
	int pos=0;
      	u16 wSeq = u2EpoSeq;
    
	Ql_memcpy(buf,framehead,sizeof(framehead));
	pos=6;
	
	buf[pos++]=(u8)wSeq ;	
	buf[pos++] = (u8)((wSeq >> 8 ) & 0xff);

	Ql_FS_Seek(pEpoFile,u2EpoSeq * 3 *MTK_EPO_SAT_LNG,QL_FS_FILE_CURRENT);	
        result = Ql_FS_Read(pEpoFile,&buf[pos],MTK_EPO_SAT_LNG*3,&act_len);
           
	pos = MTKBIN_3EPO_PKT_LNG - 2;

	Ql_memcpy(&buf[pos],frametail,sizeof(frametail));

	for(loopi=2;loopi<MTKBIN_3EPO_PKT_LNG-3;loopi++)
	{
		checksum = checksum^buf[loopi];
	}
		
	buf[MTKBIN_3EPO_PKT_LNG - 3] = checksum;


	for(loopi=0;loopi<MTKBIN_3EPO_PKT_LNG;loopi++)
	{		
		*(szData+loopi) = *(buf+loopi);
	}

	return TRUE;
}
示例#5
0
文件: fs.c 项目: victor-tr/armor2016
s32 readFromDbFile(char *fileName, void *outData, u16 len, s32 offset)
{
    OUT_DEBUG_2("readFromDbFile(\"%s\")\r\n", fileName);

	u32 read_bytes = 0;
	s32 ret = QL_RET_OK;


    s32 fh = Ql_FS_Open(fileName, QL_FS_READ_ONLY);
	if (QL_RET_OK > fh) {
		OUT_DEBUG_1("Error %d occured while opening file \"%s\".\r\n", fh, fileName);
		return fh;
	}

    if (offset) {
        ret = Ql_FS_Seek(fh, offset, QL_FS_FILE_BEGIN);
		if (ret < QL_RET_OK) {
            Ql_FS_Close(fh);
			OUT_DEBUG_1("Error %d occured while seeking file \"%s\".\r\n", ret, fileName);
			return ret;
		}
	}

    ret = Ql_FS_Read(fh, (u8 *)outData, len, &read_bytes);
	if (QL_RET_OK != ret) {
        Ql_FS_Close(fh);
		OUT_DEBUG_1("Error %d occured while reading file \"%s\".\r\n", ret, fileName);
		return ret;
	}

//	*(outData + read_bytes) = '\0';
    Ql_FS_Close(fh);
	OUT_DEBUG_3("%d bytes read from file \"%s\".\r\n", read_bytes, fileName);

    return read_bytes;
}