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

📄 rs232topcapp.c

📁 dvr
💻 C
字号:
/********************************************************************
	
	Copyright (C) 2003 UBiSYS Technology Limited.
	All rights reserved.	
	
    author    : dahlsse
    created   : 2004-03-01
    filename  : UBi9021Test.c
    tab size  : 4
    purpose   : UBi9021 File System Test Routine
    target mcu:
    notes     : test each items by enabling : "#if 0" ---> "#if 1"
	history   :	
	
*********************************************************************/
#include "types.h"

#ifdef RS232_TO_PC_TRANSFER

#include "8052reg.h"
//#include	"UBiCMN.h"
#include	"RS232toPCapp.h"
//#include	"DevIO.h"
//#include	"UsbMass.h"
//#include	"SCSI.h"
//#include	"Fat.h"
//#include	"File.h"
#include "gosd.h"
#include "ghdd.h"
#include <stdio.h>
#include "lib.h"
#ifdef LANIF
#include "socket.h"
#endif

#include "sio.h"
#include "gio.h"
#include "key.h"

u16 GetFrameCount(u8 *buf, u16 size);
//static U8 volatile res = 0;

//=====================================================================
//extern xdata u8 gv_usb_in_use;
      u8*  pBUF;//pointer to gBUF
xdata u8   gBUF[512];
xdata u8   backup_frames = 2;
//=====================================================================


//====================================================================
//
//====================================================================
u16 GetFrameCount(u8 *buf, u16 size)
{
	u16 i;
	u16 cnt = 0;

	for(i=0;i<(size-4);i++)
	{
		if(buf[i]==0x00)
			if(buf[i+1]==0x00)
				if(buf[i+2]==0x01)
					if(buf[i+3]==0xF8)
						cnt++;
	}
	return cnt;
}

//====================================================================
//
//====================================================================
extern u8	key_check(void);
void RS232_move_frames(u8 hddIndex, u32 LBA, u16 frames)
{
	u32 cur_lba;
	u32 start_lba;
	u8 MM,DD,HH,MI,SS;
	u16 YY;
	u16 frame_cnt;
	u16 ch_num;
	u16 tot_frame_cnt;
	u8 ch;
	u8 str[12];
	u16 i;
	u8 audio_flag;
	u8 strbuf[40];
	u8 *blank_ln = "                              ";
	u8 pgs,j;
	//u8 mnb=1;
	u16 k;
//	u8 key;
	
	str[4] = '/';

	
	pBUF = (u8*)gBUF;
	
	// read current frame and get the time information
	// and channel information
	center_line(3, "COPY FRAMES TO BUFFER", 21);
	center_line(7, "DETECTING FRAMES", 16);
	mem_cpy(strbuf, "              ", 14);
	cur_lba = LBA;
	pgs = 0;
	while(1) // check audio packet and skip backward
	{
		HDD_ReadSector(hddIndex, cur_lba*8, pBUF);
		if((pBUF[0]&0x80)==0x00) // is it video packet?
			break;
		if(cur_lba==0) break;
		cur_lba--;
#ifdef DEBUG_USB
		printf("\n\r[%08lx] next..", cur_lba*8);
#endif
		//u32toa(cur_lba*8, &strbuf[5]);
		for(j=0;j<14;j++) strbuf[j] = (pgs>=j)?'.':' ';
		if(pgs>=13) pgs = 0;
		else pgs++;
		center_line(10,strbuf,14);
	}
	YY = (u8)pBUF[0];
	MM = pBUF[1];
	DD = pBUF[2];
	HH = pBUF[3];
	MI = pBUF[4];
	SS = pBUF[5];
	ch = pBUF[7];
	YY += 2000;
	YY -= 1980;
	if(ch&0x10) // quad mode
		ch_num = 1;
	else
	{
		ch_num = 0;
		if(ch&0x08) ch_num++;
		if(ch&0x04) ch_num++;
		if(ch&0x02) ch_num++;
		if(ch&0x01) ch_num++;
	}
	tot_frame_cnt = (ch_num * frames);
	//tot_frame_cnt = 1;
#ifdef DEBUG_USB
	printf("\n\rRS232_move_frames: ch_num=%d", (int) ch_num);
//	mem_dump((u16)&pBUF[0], 512);
#endif

	// search to backward to find one frame
	cur_lba = (LBA==0) ? LBA : LBA-1;
	frame_cnt = 0;
	while(1)
	{
		for(i=0;i<8;i++) // read 4KB
		{
			HDD_ReadSector(hddIndex, (cur_lba*8)+i, pBUF);
			for(j=0;j<14;j++) strbuf[j] = (pgs>=j)?'.':' ';
			if(pgs>=13) pgs = 0;
			else pgs++;
			center_line(10,strbuf,14);
			if((i==0) && (pBUF[0]&0x80))
				break;
			if(i==0)	frame_cnt = frame_cnt + GetFrameCount(&pBUF[8], 504);
			else		frame_cnt = frame_cnt + GetFrameCount(&pBUF[0], 512);
#ifdef DEBUG_USB
//			printf("\n\r[%08lx] frame_cnt=%d", cur_lba*8+i, (int)frame_cnt);
#endif
			if(frame_cnt >= (tot_frame_cnt+1))	break;
		}
		if(frame_cnt >= (tot_frame_cnt+1))	break;
		if(cur_lba==0) break;
		cur_lba--;
	}
	start_lba = cur_lba;
	center_line(7, blank_ln,30);
	center_line(10,blank_ln,30);
#ifdef DEBUG_USB
	printf("\n\rRS232_move_frames: frame_cnt=%02x start_lba=%08lx", (u16) frame_cnt, start_lba*8);
#endif
	// start move frames
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	{

		center_line(7,"MOVE FRAMES TO PC",17);
		mem_cpy(strbuf, "FRAMES [000/000]", 16);
		
//		num00=0;
//		secnum01=0;
//		secnum02=0;
			frame_cnt = 0;
			cur_lba = start_lba;
			pgs = 0;
			while(1)
			{
				audio_flag = 0;
				for(i=0;i<8;i++) // read 4KB
				{
					HDD_ReadSector(hddIndex, (cur_lba*8)+i, pBUF);
					if((i==0) && (pBUF[0]&0x80))
						audio_flag = 1;
					if(audio_flag==0)
					{
						if(i==0)	frame_cnt = frame_cnt + GetFrameCount(&pBUF[8], 504);
						else		frame_cnt = frame_cnt + GetFrameCount(&pBUF[0], 512);
					}
					
					//osd_showhexword(secnum01,16,3,1);
					//osd_showhexword(secnum02,16,2,1);
					
					for(k=0;k<512;k++)
					{
					     sio_putchar(gBUF[k]);
					     while(TI);
					     
					     delay_time(10, 5);
					     
					     //osd_showhexword(k,8,2,1);//show hex
					     //if(num00 == 512)
					     //{
					     //    num00 = 0;
					     //    secnum01++;
					     //}
					     //osd_showhexword(num00,8,3,1);//show hex
					     //key = key_check();
					     //if(key==X_STOP)
					     //      goto END_MOVE_FRAMES;
					     //else if(key==X_PAUSE)
					     //   mnb=1;
					}
					//secnum02++;
					//
					//key = key_check();
					//if(key==X_STOP)
					//	goto END_MOVE_FRAMES;
					//else if(key==X_PAUSE)
					//        mnb=1;
					//	
					//while(mnb)
					//{
					//	key = key_check();
					//        if(key==X_PLAY)
					//	     break;
					//	else if(key==X_CHALL)
					//	     mnb=0;
					//}

					mem_cpy(strbuf, "FRAMES [000/000]", 16);
					dtoa(frame_cnt, &strbuf[8], 3);
					dtoa(tot_frame_cnt, &strbuf[12], 3);
					//u32toa(cur_lba*8+i, &strbuf[21]);
					center_line(10,strbuf,16);
					
					for(j=0;j<14;j++) strbuf[j] = (pgs>=j)?'.':' ';
					if(pgs>=13) pgs = 0;
					else pgs++;
					center_line(11,strbuf,14);
					
					if(frame_cnt >= (tot_frame_cnt+1))	break;
				}
				if(frame_cnt >= (tot_frame_cnt+1))	break;
				cur_lba++;
			}
//		}

//END_MOVE_FRAMES:;

	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//while(1)
//{
//	key = key_check();
//	if(key==X_STOP)
//		break;
//}
}

#endif // VY_UBI9021



⌨️ 快捷键说明

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