📄 dc1394_control.c
字号:
} nodes[extraId++]= i; } } } return nodes;}/***************************************************** dc1394_create_handle This creates a raw1394_handle If a handle can't be created, it returns NULL*****************************************************/raw1394handle_t dc1394_create_handle(int port) { raw1394handle_t handle; int i; dc1394_camerahandle *camera = malloc(sizeof(dc1394_camerahandle)); memset(camera, 0, sizeof(dc1394_camerahandle));#ifdef LIBRAW1394_OLD if (!(handle= raw1394_get_handle()))#else if (!(handle= raw1394_new_handle()))#endif { printf("(%s) Couldn't get raw1394 handle!\n",__FILE__); return NULL; } if (raw1394_set_port(handle, port) < 0) { if (handle != NULL) raw1394_destroy_handle(handle); printf("(%s) Couldn't raw1394_set_port!\n",__FILE__); return NULL; } camera->port = port; camera->ccr_base=0; camera->sw_version=0; for (i=0;i<NUM_MODE_FORMAT7;i++) { camera->format7_csr[i]=0; } raw1394_set_userdata( handle, (void*) camera ); return handle;}intdc1394_destroy_handle( raw1394handle_t handle ){ dc1394_camerahandle *camera; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if(camera) free(camera); if( handle != NULL ) raw1394_destroy_handle(handle); return DC1394_SUCCESS;}intdc1394_is_camera(raw1394handle_t handle, nodeid_t node, dc1394bool_t *value){ octlet_t offset; octlet_t ud_offset = 0; quadlet_t quadval = 0; dc1394bool_t ptgrey; /* Note on Point Grey (PG) cameras: Although not advertised, PG cameras are 'sometimes' compatible with IIDC specs. The following modifications have been tested with a stereo head, the BumbleBee. More cameras should be compatible, please consider contributing to the lib if your PG camera is not recognized. PG cams have a Unit_Spec_ID of 0xB09D, instead of the 0xA02D of classic IIDC cameras. Also, their software revision differs. I could only get a 1.14 version from my BumbleBee, other versions might exist. Damien */ /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_spec_ID (should be 0x00A02D for 1394 digital camera) */ offset=ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x12, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { quadval&=0xFFFFFFUL; } ptgrey=(quadval == 0x00B09DUL); if ( ! ( (quadval == 0x00A02DUL) || ptgrey) ) { *value= DC1394_FALSE; return DC1394_SUCCESS; } quadval = 0; /* get the unit_sw_version (should be 0x000100 - 0x000102 for 1394 digital camera) */ /* DRD> without this check, AV/C cameras show up as well */ offset = ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x13, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { quadval&=0xFFFFFFUL; } //fprintf(stderr,"0x%x\n",quadval); if ((quadval == 0x000100UL) || (quadval == 0x000101UL) || (quadval == 0x000102UL) || ((quadval == 0x000114UL) && ptgrey) || ((quadval == 0x800002UL) && ptgrey)) { *value= DC1394_TRUE; } else { *value= DC1394_FALSE; } return DC1394_SUCCESS;}intdc1394_get_sw_version(raw1394handle_t handle, nodeid_t node, int *version){ dc1394_camerahandle *camera; octlet_t offset; octlet_t ud_offset = 0; octlet_t udd_offset = 0; quadlet_t quadval = 0; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if (camera != NULL && camera->sw_version > 0) { *version = camera->sw_version; } else { /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { *version= -1; return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_sw_version */ offset = ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x13, &offset, &quadval)!=DC1394_SUCCESS) { *version = -1; return DC1394_FAILURE; } else { switch (quadval&0xFFFFFFUL) { case 0x100: *version=IIDC_VERSION_1_04; break; case 0x101: *version=IIDC_VERSION_1_20; break; case 0x102: *version=IIDC_VERSION_1_30; break; case 0x114: case 0x800002: /* get the unit_spec_ID (should be 0x00A02D for 1394 digital camera) */ if (GetConfigROMTaggedRegister(handle, node, 0x12, &ud_offset, &quadval)!=DC1394_SUCCESS) { *version = -1; return DC1394_FAILURE; } else { quadval&=0xFFFFFFUL; } if (quadval == 0x00B09DUL) *version=IIDC_VERSION_PTGREY; else *version = -1; break; } } } //fprintf(stderr,"sw version is %d\n",*version); /*IIDC 1.31 check*/ if (*version==IIDC_VERSION_1_30) { /* get the unit_dependent_directory offset */ offset= ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0xD4, &offset, &quadval)!=DC1394_SUCCESS) { *version = -1; return DC1394_FAILURE; } else { udd_offset=(quadval & 0xFFFFFFUL)*4+offset; } if (GetConfigROMTaggedRegister(handle, node, 0x38, &udd_offset, &quadval)!=DC1394_SUCCESS) { // if it fails here we return success with the most accurate version estimation: 1.30. // this is because the GetConfigROMTaggedRegister will return a failure both if there is a comm // problem but also if the tag is not found. In the latter case it simply means that the // camera version is 1.30 *version=IIDC_VERSION_1_30; return DC1394_SUCCESS; } else { //fprintf(stderr,"1.3x register is 0x%x\n",quadval); switch (quadval&0xFFFFFFUL) { case 0x10: *version=IIDC_VERSION_1_31; break; case 0x20: *version=IIDC_VERSION_1_32; break; case 0x30: *version=IIDC_VERSION_1_33; break; case 0x40: *version=IIDC_VERSION_1_34; break; case 0x50: *version=IIDC_VERSION_1_35; break; case 0x60: *version=IIDC_VERSION_1_36; break; case 0x70: *version=IIDC_VERSION_1_37; break; case 0x80: *version=IIDC_VERSION_1_38; break; case 0x90: *version=IIDC_VERSION_1_39; break; default: *version=IIDC_VERSION_1_30; break; } } } camera->sw_version=*version; return DC1394_SUCCESS;}voiddc1394_print_camera_info(dc1394_camerainfo *info) { quadlet_t value[2]; value[0]= info->euid_64 & 0xffffffff; value[1]= (info->euid_64 >>32) & 0xffffffff; printf("CAMERA INFO\n===============\n"); printf("Node: %x\n", info->id); printf("CCR_Offset: %Lux\n", info->ccr_offset); //L added by tim evers printf("UID: 0x%08x%08x\n", value[1], value[0]); printf("Vendor: %s\tModel: %s\n\n", info->vendor, info->model); fflush(stdout);}intdc1394_get_camera_info(raw1394handle_t handle, nodeid_t node, dc1394_camerainfo *info){ dc1394bool_t iscamera; int retval, len; octlet_t offset; quadlet_t value[2], quadval; unsigned int count; octlet_t ud_offset, udd_offset; dc1394_camerahandle *camera; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if ( (retval= dc1394_is_camera(handle, node, &iscamera)) != DC1394_SUCCESS ) {#ifdef SHOW_ERRORS printf("Error - this is not a camera (get_camera_info)\n");#endif return DC1394_FAILURE; } else if (iscamera != DC1394_TRUE) { return DC1394_FAILURE; } info->handle= handle; info->id= node; /* now get the EUID-64 */ if (GetCameraROMValue(handle, node, ROM_BUS_INFO_BLOCK+0x0C, &value[0]) < 0) { return DC1394_FAILURE; } if (GetCameraROMValue(handle, node, ROM_BUS_INFO_BLOCK+0x10, &value[1]) < 0) { return DC1394_FAILURE; } info->euid_64= ((u_int64_t)value[0] << 32) | (u_int64_t)value[1]; /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_dependent_directory offset */ offset= ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0xD4, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { udd_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* now get the command_regs_base */ offset= udd_offset; if (GetConfigROMTaggedRegister(handle, node, 0x40, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { info->ccr_offset= (octlet_t)(quadval & 0xFFFFFFUL)*4; if (camera != NULL) camera->ccr_base = CONFIG_ROM_BASE + info->ccr_offset; } /* get the vendor_name_leaf offset (optional) */ offset= udd_offset; info->vendor[0] = '\0'; if (GetConfigROMTaggedRegister(handle, node, 0x81, &offset, &quadval)==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the vendor name */ if (GetCameraROMValue(handle, node, offset, &value[0]) < 0) { return DC1394_FAILURE; } len= (int)(value[0] >> 16)*4-8; /* Tim Evers corrected length value */ if (len > MAX_CHARS) { len= MAX_CHARS; } offset+= 12; count= 0; /* grab the vendor name */ while (len > 0) { if (GetCameraROMValue(handle, node, offset+count, &value[0]) < 0) { return DC1394_FAILURE; } info->vendor[count++]= (value[0] >> 24); info->vendor[count++]= (value[0] >> 16) & 0xFFUL; info->vendor[count++]= (value[0] >> 8) & 0xFFUL; info->vendor[count++]= value[0] & 0xFFUL; len-= 4; } info->vendor[count]= '\0'; } /* get the model_name_leaf offset (optional) */ offset= udd_offset; info->model[0] = '\0'; if (GetConfigROMTaggedRegister(handle, node, 0x82, &offset, &quadval)==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the model name */ if (GetCameraROMValue(handle, node, offset, &value[0]) < 0) { return DC1394_FAILURE; } len= (int)(value[0] >> 16)*4-8; /* Tim Evers corrected length value */ if (len > MAX_CHARS) { len= MAX_CHARS; } offset+= 12; count= 0; /* grab the model name */ while (len > 0) { if (GetCameraROMValue(handle, node, offset+count, &value[0]) < 0) { return DC1394_FAILURE; } info->model[count++]= (value[0] >> 24); info->model[count++]= (value[0] >> 16) & 0xFFUL; info->model[count++]= (value[0] >> 8) & 0xFFUL; info->model[count++]= value[0] & 0xFFUL; len-= 4; } info->model[count]= '\0'; } return DC1394_SUCCESS;}/***************************************************** dc1394_get_camera_misc_info Collects other camera info registers*****************************************************/intdc1394_get_camera_misc_info(raw1394handle_t handle, nodeid_t node, dc1394_miscinfo *info){ quadlet_t value;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -