jint Java_dk_itu_eyedroid_io_protocols_InputStreamUSBCamera_prepareCamera( JNIEnv* env,jobject thiz, jint videoid){ int ret; if(camerabase<0){ camerabase = checkCamerabase(); } ret = opendevice(camerabase + videoid); if(ret != ERROR_LOCAL){ ret = initdevice(); } if(ret != ERROR_LOCAL){ ret = startcapturing(); if(ret != SUCCESS_LOCAL){ stopcapturing(); uninitdevice (); closedevice (); LOGE("device resetted"); } } if(ret != ERROR_LOCAL){ rgb = (int *)malloc(sizeof(int) * (IMG_WIDTH*IMG_HEIGHT)); ybuf = (int *)malloc(sizeof(int) * (IMG_WIDTH*IMG_HEIGHT)); } return ret; }
jint Java_ch_nuicell_ecam_CameraPreview_prepareCamera( JNIEnv* env,jobject thiz, jint videoid) { int ret; if(camerabase<0) { camerabase = checkCamerabase(); } ret = opendevice(camerabase + videoid); if(ret != ERROR_LOCAL) { ret = initdevice(); } if(ret != ERROR_LOCAL) { ret = startcapturing(); if(ret != SUCCESS_LOCAL) { stopcapturing(); uninitdevice (); closedevice (); LOGE("device resetted"); } } if(ret != ERROR_LOCAL) { rgb = (int *)malloc(sizeof(int) * (IMG_WIDTH*IMG_HEIGHT)); ybuf = (int *)malloc(sizeof(int) * (IMG_WIDTH*IMG_HEIGHT)); } return ret; }
static int opendevice(int drive) { HANDLE h; DWORD ret; BYTE b; char drv_name[512]; sprintf(drv_name,"\\\\.\\fdraw%d",drive); h = CreateFile(drv_name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (h == INVALID_HANDLE_VALUE) return 0; b = 2; // 250Kbps if (!DeviceIoControl(h, IOCTL_FD_SET_DATA_RATE, &b, sizeof b, NULL, 0, &ret, NULL)) { printf("IOCTL_FD_SET_DATA_RATE=%d failed err=%d\n", b, GetLastError()); closedevice(); return 0; } b = 0; if (!DeviceIoControl(h, IOCTL_FD_SET_DISK_CHECK, &b, sizeof b, NULL, 0, &ret, NULL)) { printf("IOCTL_FD_SET_DISK_CHECK=%d failed err=%d\n", b, GetLastError()); closedevice(); return 0; } if (!DeviceIoControl(h, IOCTL_FD_LOCK_FDC, 0,0, 0, 0, &ret, NULL)) { printf("IOCTL_FD_LOCK_FDC=%d failed err=%d\n", b, GetLastError()); closedevice(); return 0; } return 1; }
void Java_ch_nuicell_ecam_CameraPreview_stopCamera(JNIEnv* env,jobject thiz) { stopcapturing (); uninitdevice (); closedevice (); if(rgb) free(rgb); if(ybuf) free(ybuf); fd = -1; }
void Java_dk_itu_eyedroid_io_protocols_InputStreamUSBCamera_stopCamera(JNIEnv* env,jobject thiz){ stopcapturing (); uninitdevice (); closedevice (); if(rgb) free(rgb); if(ybuf) free(ybuf); fd = -1; }
void Java_com_example_test1_CameraPreview_stopCamera(JNIEnv* env,jobject thiz){ stopcapturing (); uninitdevice (); closedevice (); if(rgb) free(rgb); if(ybuf) free(ybuf); fd = -1; }
void Java_com_usb_camera_android_SingleCameraPreview_stopCamera(JNIEnv* env,jobject thiz){ stopcapturing (); uninitdevice (); closedevice (); if(rgb) free(rgb); if(ybuf) free(ybuf); fd = -1; }
void Java_com_camera_simpledoublewebcams2_CameraPreview_stopCamera(JNIEnv* env,jobject thiz){ int i; for(i=0 ; i<CAMERANUM ; i++){ if(fd[i]!=-1) stopcapturing (i); if(fd[i]!=-1) uninitdevice (i); if(fd[i]!=-1) closedevice (i); fd[i] =-1; if(rgb[i]) free(rgb[i]); } }
cVFDStatus::~cVFDStatus() { closedevice(); }
DWORD WINAPI DumpThreadProc( LPVOID lpParameter) { unsigned int i,j,k,m,n,ret; int l; FD_SCAN_PARAMS sp; FD_SCAN_RESULT *sr; FD_READ_WRITE_PARAMS rwp; FD_CMD_RESULT cmdr; SECTORCONFIG* sectorconfig; floppydumperparams * params; unsigned char * tempstr; unsigned char * trackbuffer; unsigned char b; int tracksize,retry,gap3len,trackformat; unsigned long rotationtime,rpm,bitrate,tracklen; unsigned long total_size,numberofsector_read,number_of_bad_sector; CYLINDER* currentcylinder; SIDE* currentside; params=(floppydumperparams*)lpParameter; params->flopemu->hxc_printf(MSG_DEBUG,"Starting Floppy dump..."); tempstr=(char*)malloc(1024); trackbuffer=0; tracksize=0; if(checkversion()) { if(opendevice(params->drive)) { total_size=0; numberofsector_read=0; number_of_bad_sector=0; sr=malloc(sizeof(FD_ID_HEADER)*256 + 1); params->floppydisk->floppyBitRate=VARIABLEBITRATE; params->floppydisk->floppyNumberOfSide=params->number_of_side; params->floppydisk->floppyNumberOfTrack=params->number_of_track; params->floppydisk->floppySectorPerTrack=-1; seek(0, 0); sprintf(tempstr,"Checking drive RPM..."); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); rotationtime=200000; if (!DeviceIoControl(h, IOCTL_FD_GET_TRACK_TIME, 0, 0, &rotationtime, sizeof(rotationtime), &ret, NULL)) { sprintf(tempstr,"Error during RPM checking :%d ",GetLastError()); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump: IOCTL_FD_GET_TRACK_TIME error %d...",GetLastError()); closedevice(); free(tempstr); params->status=0; return 0; } params->floppydisk->tracks=(CYLINDER**)malloc(sizeof(CYLINDER*)*params->floppydisk->floppyNumberOfTrack); rpm=60000/(rotationtime/1000); params->flopemu->hxc_printf(MSG_DEBUG,"Drive RPM: %d",rpm); sprintf(tempstr,"Drive RPM: %d",rpm); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); if(rpm>280 && rpm<320) rpm=300; if(rpm>340 && rpm<380) rpm=360; bitrate=500000; sprintf(tempstr,"Starting reading disk..."); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); for(i=0;i<params->floppydisk->floppyNumberOfTrack;i++) { params->floppydisk->tracks[i]=(CYLINDER*)malloc(sizeof(CYLINDER)); currentcylinder=params->floppydisk->tracks[i]; currentcylinder->number_of_side=params->floppydisk->floppyNumberOfSide; currentcylinder->sides=(SIDE**)malloc(sizeof(SIDE*)*currentcylinder->number_of_side); memset(currentcylinder->sides,0,sizeof(SIDE*)*currentcylinder->number_of_side); for(j=0;j<params->floppydisk->floppyNumberOfSide;j++) { currentcylinder->floppyRPM=rpm; currentcylinder->sides[j]=malloc(sizeof(SIDE)); memset(currentcylinder->sides[j],0,sizeof(SIDE)); currentside=currentcylinder->sides[j]; seek(i*params->double_step, j); l=0; do { m=0; while(tm[m].index!=l) { m++; } memset(sr,0,sizeof(FD_ID_HEADER)*256 + 1); if(tm[m].encoding_mode) { sp.flags=FD_OPTION_MFM; trackformat=ISOFORMAT_DD; } else { sp.flags=0x00; trackformat=ISOFORMAT_SD; } sp.head=j; bitrate=tm[m].bitrate; b = tm[m].bitrate_code; if (!DeviceIoControl(h, IOCTL_FD_SET_DATA_RATE, &b, sizeof b, NULL, 0, &ret, NULL)) { printf("IOCTL_FD_SET_DATA_RATE=%d failed err=%d\n", b, GetLastError()); closedevice(); params->status=0; return 0; } if (!DeviceIoControl(h, IOCTL_FD_SCAN_TRACK, &sp, sizeof sp, sr, sizeof(FD_ID_HEADER)*256 + 1, &ret, NULL)) { params->flopemu->hxc_printf(MSG_DEBUG,"IOCTL_FD_SCAN_TRACK error %d ...",GetLastError()); } if(sr->count) { n=0; while(tm[n].index) { n++; } k=tm[n].index; tm[n].index=tm[m].index; tm[m].index=k; } else { DeviceIoControl(h, IOCTL_FD_RESET, NULL, 0, NULL, 0, &ret, NULL); } l++; }while(l<8 && !sr->count); sectorconfig=(SECTORCONFIG*)malloc(sizeof(SECTORCONFIG)*sr->count); memset(sectorconfig,0,sizeof(SECTORCONFIG)*sr->count); params->flopemu->hxc_printf(MSG_DEBUG,"Track %d side %d: %d sectors found : ",i,j,sr->count); seek(i*params->double_step, j); if( sr->Header[0].cyl==sr->Header[sr->count-1].cyl && sr->Header[0].head==sr->Header[sr->count-1].head && sr->Header[0].sector==sr->Header[sr->count-1].sector && sr->Header[0].size==sr->Header[sr->count-1].size ) { sr->count--; } for(k=0;k<sr->count;k++) { params->flopemu->hxc_printf(MSG_DEBUG,"Sector %.2d, Track ID: %.3d, Head ID:%d, Size: %d bytes, Bitrate:%dkbits/s, %s",sr->Header[k].sector,sr->Header[k].cyl,sr->Header[k].head,128<<sr->Header[k].size,bitrate/1000,trackformat==ISOFORMAT_SD?"FM":"MFM"); if(tm[m].encoding_mode) { rwp.flags=FD_OPTION_MFM; } else { rwp.flags=0x00; } rwp.cyl=sr->Header[k].cyl; rwp.phead=j; rwp.head=sr->Header[k].head; rwp.sector=sr->Header[k].sector; rwp.size=sr->Header[k].size; rwp.eot=sr->Header[k].sector+1; rwp.gap=10; if((128<<sr->Header[k].size)>128) { rwp.datalen=255; } else { rwp.datalen=128; } retry=5; trackbuffer=realloc(trackbuffer,tracksize+(128<<sr->Header[k].size)); do { retry--; }while(!DeviceIoControl(h, IOCTL_FDCMD_READ_DATA, &rwp, sizeof rwp, &trackbuffer[tracksize], 128<<sr->Header[k].size, &ret, NULL) && retry); if(!retry) { DeviceIoControl(h, IOCTL_FD_GET_RESULT,0, 0, &cmdr, sizeof(FD_CMD_RESULT), &ret, NULL); params->flopemu->hxc_printf(MSG_DEBUG,"Read Error ! ST0: %.2x, ST1: %.2x, ST2: %.2x",cmdr.st0,cmdr.st1,cmdr.st2); number_of_bad_sector++; } total_size=total_size+(128<<sr->Header[k].size); numberofsector_read++; sectorconfig[k].cylinder=sr->Header[k].cyl; sectorconfig[k].head=sr->Header[k].head; sectorconfig[k].sector=sr->Header[k].sector; sectorconfig[k].sectorsize=(128<<sr->Header[k].size); tracksize=tracksize+(128<<sr->Header[k].size); sprintf(tempstr,"%d Sector(s) Read, %d bytes, %d Bad sector(s)",numberofsector_read,total_size,number_of_bad_sector); SetDlgItemText(params->windowshwd,IDC_EDIT2,tempstr); } currentside->number_of_sector=sr->count; currentside->bitrate=bitrate; tracklen=(bitrate/(rpm/60))/4; currentside->tracklen=tracklen; currentside->databuffer=malloc(currentside->tracklen); memset(currentside->databuffer,0,currentside->tracklen); currentside->flakybitsbuffer=0; currentside->timingbuffer=0; currentside->indexbuffer=malloc(currentside->tracklen); memset(currentside->indexbuffer,0,currentside->tracklen); fillindex(currentside->tracklen-1,currentside,2500,TRUE,1); gap3len=20; BuildISOTrack(params->flopemu,trackformat,currentside->number_of_sector,1,512,j,i,gap3len,trackbuffer,currentside->databuffer,¤tside->tracklen,0,0,sectorconfig); sprintf(tempstr,"Track %d side %d: %d sectors, %dkbits/s, %s",i,j,sr->count,bitrate/1000,trackformat==ISOFORMAT_SD?"FM":"MFM"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); free(sectorconfig); free(trackbuffer); trackbuffer=0; tracksize=0; } } closedevice(); sprintf(tempstr,"Done !"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); sprintf(tempstr,"%d Sector(s) Read, %d bytes, %d Bad sector(s)",numberofsector_read,total_size,number_of_bad_sector); SetDlgItemText(params->windowshwd,IDC_EDIT2,tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Done ! %d sectors read, %d bad sector(s), %d bytes read",numberofsector_read,number_of_bad_sector,total_size); loadfloppy("Floppy Dump",params->floppydisk,0); free(tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump..."); params->status=0; return 0; } } sprintf(tempstr,"Error while opening fdrawcmd, see: http://simonowen.com/fdrawcmd"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); free(tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump..."); params->status=0; return 0; }