📄 main_256.bak
字号:
#define ULONG unsigned int
#define UCHAR unsigned char
#define true 1
#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <bios.h>
#include <stdlib.h>
#include <mem.h>
#include <fcntl.h>
#include "eny.h"
typedef enum{ModeAV,ModeV,ModeA} Mode;
unsigned short* BaseAddress;
FILE *fp;
FILE *fp2;
void SetRecLED(int n)
{
char num;
num=inportb(0x104);
if(n==0)
num=num&0xfd;
else
num=num|2;
outportb(0x104,num);
}
void SetTestLED(int n)
{
char num;
num=inportb(0x104);
if(n==0)
num=num&0xfe;
else
num=num|1;
outportb(0x104,num);
}
void pulse_rec(FILE *fp, int pulse_num,int file_num)
{
struct time pulse_time; //used for save the time when pulse coming
struct date pulse_date;
if(fp == NULL)
{
printf("fp can not be null\n");
return;
}
gettime(&pulse_time);
getdate(&pulse_date);
fprintf(fp,"[ShotRecord %d]\n",pulse_num);
fprintf(fp,"VideoFlagPosition=%03d\n",file_num);
fprintf(fp,"ShotTime=%04d%03d%02d%02d%02d%02d\n\n",
pulse_date.da_year,pulse_date.da_mon,pulse_date.da_day,
pulse_time.ti_hour, pulse_time.ti_min, pulse_time.ti_sec);
fflush(fp);close(dup(fileno(fp)));
}
void main( )
{
unsigned int iii,file_num;
int i;
unsigned long icount,tmp;
static UCHAR port_102,IntSource,ImageData[25600];
unsigned short bb = 0x100;
char file1_flag,time_flag=0,pulse_flag,video_write=0,record_flag;
unsigned char str_header[]={0x00,0x00,0x01,0xb3,0x16,0x01,0x20,0x83,0x00,0xc0,0x20,0xa4};
char str_1[50],str_2[50],str_tmp[50];
time_t tt_1,tt_2,tt_tmp;
struct dfree free;
//FILE *fp2;
struct ffblk bk;
int pulse_number = 0;
int current_pulse_level=0;
int last_pulse_level=0;
/* verity();*/
SetTestLED(0);
SetRecLED(1);
getcwd(str_1,49);strcpy(str_tmp,str_1); //str_tmp = str_1 = current dir
mkdir(strcat(str_1,"\\video"));chdir(str_1);
file_num=0;
fp2=fopen("pulse.txt","at");
fseek(fp2, 0, SEEK_END);
fprintf(fp2,"begin to record\n");
i=findfirst("*.mpg",&bk,0);
fprintf(fp2,"%s\n",bk.ff_name);
fflush(fp2);close(dup(fileno(fp2)));
while(!i)
{
//remove(bk.ff_name);
i=findnext(&bk);
fprintf(fp2,"%d,%s\n",i,bk.ff_name);
fflush(fp2);close(dup(fileno(fp2)));
file_num++;
}
//file_num++;
fprintf(fp2,"file_num=%d\n",file_num);
//chdir(str_tmp);//str_tmp=c:\lve
strcat(str_1,"\\");
BaseAddress = &bb;
printf(" Start...\n");
HR_OnPowerUP(BaseAddress);
if(HR_InitDevice(BaseAddress,ModeAV) == 1)
HR_InitVCDVA(BaseAddress);
SetTestLED(1);
file1_flag=1;
//file_num=0;
/*printf("waiting...\n");
while(inportb(0x102)==0xfe);
*/
// SetLongTimeWDT(0x20);
// EnableWDT();FeedLongWDT();
HR_StartCapture(BaseAddress);
while(file1_flag!=0)
{
getdfree(getdisk()+1,&free);
icount =(unsigned long)(free.df_avail/(25600.0/free.df_sclus/free.df_bsec));
fprintf(fp2,"icount = %d\n",icount);
//if(icount<1000) file_num=0;
strcpy(str_tmp,str_1);strcat(str_tmp,itoa(file_num,str_2,10));strcat(str_tmp,".mpg");
fprintf(fp2,"crteat file %s\n",str_tmp);
fp=fopen(str_tmp,"wb");if(fp==NULL) continue;
if( (port_102& 1)==0)
{
tt_1 = time(NULL);record_flag=1;
SetRecLED(0);
fprintf(fp2,"led on\n");
fflush(fp2);close(dup(fileno(fp2)));
}
else
{
record_flag=0;
SetRecLED(1);
fprintf(fp2,"led off\n");
fflush(fp2);close(dup(fileno(fp2)));
}
fprintf(fp2,"record_flag =%d\n",record_flag);
fflush(fp2);close(dup(fileno(fp2)));
tt_1 = time(NULL);
printf("waiting\n");
HR_WriteAddress(BaseAddress,0x08,0x08);
file1_flag=1;iii=0;time_flag=0;pulse_flag=0;video_write=0;
while(file1_flag==1)
{
if(record_flag==1)
{
if( HR_ReadAddress(BaseAddress,0x0e)&0x02 )
{
// FeedLongWDT();
outportb(0x100,0x00);
i=0;
while( i++ < 256 ) ImageData[iii++] = inportb(0x101);
if(iii>=25600)
{
video_write++;
fwrite(ImageData,256,100,fp);
fflush(fp);close(dup(fileno(fp)));
iii=0;
}
//if(icount--<=0)
//{ file1_flag=2;printf("no disk sufficient space !!!\n");}
}
else //if( difftime(time(NULL),tt_1)<= 600)
{
port_102 = inportb(0x102);
time_flag = (( port_102& 1) == 1) ? (time_flag+1) : 0;
//pulse_flag = (( port_102& 2) == 0) ?(pulse_flag+1) : 0;//???????
last_pulse_level = current_pulse_level;
current_pulse_level = (( port_102& 2) == 2) ? 1 : 0;
if(time_flag>50)//if gpio0 = '1' for 50 cycles then stop record
{
record_flag=0;iii=0;
//file1_flag=2;
SetRecLED(1);
fprintf(fp2,"close file %d.mpg\n",file_num);
fflush(fp2);close(dup(fileno(fp2)));
printf("waiting\n");
}
if((current_pulse_level==1)&&(last_pulse_level ==0))
{
//pulse_flag=0;
pulse_number++;
pulse_rec(fp2,pulse_number,file_num);
fflush(fp2);close(dup(fileno(fp2)));
printf("pulse %d\n",pulse_number);
}
}
//else
//file1_flag=2;
}
else
{
time_flag = (((inportb(0x102) & 1) == 0) ? time_flag+1 : 0);
if(time_flag>50)
{
tt_1 = time(NULL);
record_flag=1;
file_num++;
strcpy(str_tmp,str_1);strcat(str_tmp,itoa(file_num,str_2,10));strcat(str_tmp,".mpg");
fprintf("crteat file %s\n",str_tmp);
fp=fopen(str_tmp,"wb");
if(fp==NULL)
fprintf("crteat file %s error\n",str_tmp);
HR_WriteAddress(BaseAddress,0x08,0x08);
SetRecLED(0);
printf("recording\n");
}
if( HR_ReadAddress(BaseAddress,0x0e)&0x02 )
{
// FeedLongWDT();
outportb(0x100,0x00);
i=0;
while( i++ < 256 ) inportb(0x101);
}
}
}
fclose(fp);
}
HR_StopCapture(BaseAddress);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -