📄 dc1394_control.c
字号:
/* * 1394-Based Digital Camera Control Library * Copyright (C) 2000 SMART Technologies Inc. * * Written by Gord Peters <GordPeters@smarttech.com> * Additions by Chris Urmson <curmson@ri.cmu.edu> * Additions by Damien Douxchamps <ddouxchamps@users.sf.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "dc1394_control.h"#include "config.h"#include "dc1394_internal.h"#include "dc1394_register.h"#include "dc1394_offsets.h" dc1394error_tdc1394_camera_set_broadcast(dc1394camera_t *camera, dc1394bool_t pwr){ if (pwr==DC1394_TRUE) { if (camera->broadcast==DC1394_FALSE) { camera->node_id_backup=camera->node; camera->node=63; camera->broadcast=DC1394_TRUE; } } else if (pwr==DC1394_FALSE) { if (camera->broadcast==DC1394_TRUE) { camera->node=camera->node_id_backup; camera->broadcast=DC1394_FALSE; } } else return DC1394_INVALID_ARGUMENT_VALUE; return DC1394_SUCCESS;}dc1394error_tdc1394_find_cameras(dc1394camera_t ***cameras_ptr, uint_t* numCameras){ return dc1394_find_cameras_platform(cameras_ptr, numCameras);}int_dc1394_get_iidc_version(dc1394camera_t *camera){ dc1394error_t err=DC1394_SUCCESS; quadlet_t quadval; octlet_t offset; if (camera == NULL) return DC1394_CAMERA_NOT_INITIALIZED; /* Note on Point Grey (PG) cameras: Although not always advertised, PG cameras are 'sometimes' compatible with IIDC specs. This is especially the case with PG stereo products. The following modifications have been tested with a stereo head (BumbleBee). Most other cameras should be compatible, please consider contributing to the lib if your PG camera is not recognized. PG cams sometimes 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 but other versions might exist. As PG is regularly providing firmware updates you might also install the latest one in your camera for an increased compatibility. Damien (updated 2005-04-30) */ if ( (camera->ud_reg_tag_12 != 0x000A02DUL) && (camera->ud_reg_tag_12 != 0x000B09DUL) ) { camera->iidc_version=-1; return DC1394_NOT_A_CAMERA; } switch (camera->ud_reg_tag_13&0xFFFFFFUL) { case 0x000100: camera->iidc_version=DC1394_IIDC_VERSION_1_04; break; case 0x000101: camera->iidc_version=DC1394_IIDC_VERSION_1_20; break; case 0x000102: camera->iidc_version=DC1394_IIDC_VERSION_1_30; break; case 0x000114: case 0x800002: if (camera->ud_reg_tag_12 == 0x000B09DUL) camera->iidc_version=DC1394_IIDC_VERSION_PTGREY; else camera->iidc_version = -1; // an error should be sent in this case break; default: return DC1394_INVALID_IIDC_VERSION; } /* IIDC 1.31 check */ if (camera->iidc_version==DC1394_IIDC_VERSION_1_30) { /* -- get the unit_dependent_directory offset -- We can do it here since we know it's a camera, and thus the UDD should exists This UDD will be re-checked after but it does not really matter. */ offset= camera->unit_directory; err=GetConfigROMTaggedRegister(camera, 0xD4, &offset, &quadval); DC1394_ERR_RTN(err, "Could not get unit dependent directory"); camera->unit_dependent_directory=(quadval & 0xFFFFFFUL)*4+offset; //fprintf(stderr,"1.30 detected\n"); offset=camera->unit_dependent_directory; err=GetConfigROMTaggedRegister(camera, 0x38, &offset, &quadval); if (err!=DC1394_SUCCESS) { if (err==DC1394_TAGGED_REGISTER_NOT_FOUND) { //fprintf(stderr,"not tag reg\n"); // 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 camera->iidc_version=DC1394_IIDC_VERSION_1_30; return DC1394_SUCCESS; } else DC1394_ERR_RTN(err, "Could not get tagged register 0x38"); } //fprintf(stderr,"test2\n"); switch (quadval&0xFFFFFFUL) { case 0x10: camera->iidc_version=DC1394_IIDC_VERSION_1_31; break; case 0x20: camera->iidc_version=DC1394_IIDC_VERSION_1_32; break; case 0x30: camera->iidc_version=DC1394_IIDC_VERSION_1_33; break; case 0x40: camera->iidc_version=DC1394_IIDC_VERSION_1_34; break; case 0x50: camera->iidc_version=DC1394_IIDC_VERSION_1_35; break; case 0x60: camera->iidc_version=DC1394_IIDC_VERSION_1_36; break; case 0x70: camera->iidc_version=DC1394_IIDC_VERSION_1_37; break; case 0x80: camera->iidc_version=DC1394_IIDC_VERSION_1_38; break; case 0x90: camera->iidc_version=DC1394_IIDC_VERSION_1_39; break; // if we arrived here without errors we suppose that the camera is at least 1.30. // we don't flag the camera as non compliant. default: camera->iidc_version=DC1394_IIDC_VERSION_1_30; break; } } //fprintf(stderr,"test\n"); return err;}dc1394error_tdc1394_update_camera_info(dc1394camera_t *camera){ dc1394error_t err; uint_t len, i, count; octlet_t offset; quadlet_t value[2], quadval; // init pointers to zero: camera->command_registers_base=0; camera->unit_directory=0; camera->unit_dependent_directory=0; camera->advanced_features_csr=0; for (i=0;i<DC1394_VIDEO_MODE_FORMAT7_NUM;i++) camera->format7_csr[i]=0; // return silently on all errors as a bad rom just means a device that is not a camera /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; err=GetConfigROMTaggedRegister(camera, 0xD1, &offset, &quadval); //fprintf(stderr,"Err: %d\n",err); if (err!=DC1394_SUCCESS) return err; camera->unit_directory=(quadval & 0xFFFFFFUL)*4+offset; /* get the vendor_id*/ offset= ROM_ROOT_DIRECTORY; err=GetConfigROMTaggedRegister(camera, 0x03, &offset, &quadval); //fprintf(stderr,"Err: %d\n",err); if (err==DC1394_SUCCESS) { camera->vendor_id=quadval & 0xFFFFFFUL; } else if (err==DC1394_TAGGED_REGISTER_NOT_FOUND) { camera->vendor_id=0; } else { DC1394_ERR_RTN(err, "Could not get vendor ID"); return err; } /* get the spec_id value */ offset=camera->unit_directory; err=GetConfigROMTaggedRegister(camera, 0x12, &offset, &quadval); if (err!=DC1394_SUCCESS) return err; camera->ud_reg_tag_12=quadval&0xFFFFFFUL; //fprintf(stderr,"12: 0x%x\n",camera->ud_reg_tag_12); /* get the iidc revision */ offset=camera->unit_directory; err=GetConfigROMTaggedRegister(camera, 0x13, &offset, &quadval); if (err!=DC1394_SUCCESS) return err; camera->ud_reg_tag_13=quadval&0xFFFFFFUL; //fprintf(stderr,"13: 0x%x\n",camera->ud_reg_tag_13); /* verify the version/revision and find the IIDC_REVISION value from that */ /* Note: this requires the UDD to be set in order to verify IIDC 1.31 compliance. */ err=_dc1394_get_iidc_version(camera); if (err==DC1394_NOT_A_CAMERA) return err; DC1394_ERR_RTN(err, "Problem inferring the IIDC version"); /* get the model_id*/ offset= camera->unit_directory; err=GetConfigROMTaggedRegister(camera, 0x17, &offset, &quadval); //fprintf(stderr,"Err: %d\n",err); if (err==DC1394_SUCCESS) { camera->model_id=quadval & 0xFFFFFFUL; } else if (err==DC1394_TAGGED_REGISTER_NOT_FOUND) { camera->model_id=0; } else { DC1394_ERR_RTN(err, "Could not get model ID"); return err; } /* get the unit_dependent_directory offset */ offset= camera->unit_directory; err=GetConfigROMTaggedRegister(camera, 0xD4, &offset, &quadval); DC1394_ERR_RTN(err, "Could not get unit dependent directory"); camera->unit_dependent_directory=(quadval & 0xFFFFFFUL)*4+offset; // at this point we know it's a camera so we start returning errors if registers // are not found //fprintf(stderr,"got a camera\n"); /* now get the EUID-64 */ err=GetCameraROMValue(camera, ROM_BUS_INFO_BLOCK+0x0C, &value[0]); if (err!=DC1394_SUCCESS) return err; err=GetCameraROMValue(camera, ROM_BUS_INFO_BLOCK+0x10, &value[1]); if (err!=DC1394_SUCCESS) return err; camera->euid_64= ((uint64_t)value[0] << 32) | (uint64_t)value[1]; /* now get the command_regs_base */ offset= camera->unit_dependent_directory; err=GetConfigROMTaggedRegister(camera, 0x40, &offset, &quadval); DC1394_ERR_RTN(err, "Could not get commands base address"); camera->command_registers_base= (octlet_t)(quadval & 0xFFFFFFUL)*4; /* get the vendor_name_leaf offset (optional) */ offset= camera->unit_dependent_directory; camera->vendor[0] = '\0'; err=GetConfigROMTaggedRegister(camera, 0x81, &offset, &quadval); if (err==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the vendor name */ err=GetCameraROMValue(camera, offset, &value[0]); DC1394_ERR_RTN(err, "Could not get vendor leaf length"); len= (uint_t)(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) { err=GetCameraROMValue(camera, offset+count, &value[0]); DC1394_ERR_RTN(err, "Could not get vendor string character"); camera->vendor[count++]= (value[0] >> 24); camera->vendor[count++]= (value[0] >> 16) & 0xFFUL; camera->vendor[count++]= (value[0] >> 8) & 0xFFUL; camera->vendor[count++]= value[0] & 0xFFUL; len-= 4; camera->vendor[count]= '\0'; } } /* if the tagged register is not found, don't make a fuss about it. */ else if (err!=DC1394_TAGGED_REGISTER_NOT_FOUND) { DC1394_ERR_RTN(err, "Could not get vendor leaf offset"); } /* get the model_name_leaf offset (optional) */ offset= camera->unit_dependent_directory; camera->model[0] = '\0'; err=GetConfigROMTaggedRegister(camera, 0x82, &offset, &quadval); //fprintf(stderr,"ERR CODE = %d\n",err); if (err==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the model name */ err=GetCameraROMValue(camera, offset, &value[0]); DC1394_ERR_RTN(err, "Could not get model name leaf length"); len= (uint_t)(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) { err=GetCameraROMValue(camera, offset+count, &value[0]); DC1394_ERR_RTN(err, "Could not get model name character"); camera->model[count++]= (value[0] >> 24); camera->model[count++]= (value[0] >> 16) & 0xFFUL; camera->model[count++]= (value[0] >> 8) & 0xFFUL; camera->model[count++]= value[0] & 0xFFUL; len-= 4; camera->model[count]= '\0'; } } /* if the tagged register is not found, don't make a fuss about it. */ else if (err!=DC1394_TAGGED_REGISTER_NOT_FOUND) { DC1394_ERR_RTN(err, "Could not get model name leaf offset"); } err=dc1394_video_get_iso_speed(camera, &camera->iso_speed); DC1394_ERR_RTN(err, "Could not get ISO channel and speed"); err=dc1394_video_get_mode(camera, &camera->video_mode); DC1394_ERR_RTN(err, "Could not get current video mode"); err=dc1394_video_get_framerate(camera, &camera->framerate); DC1394_ERR_RTN(err, "Could not get current video framerate"); err=dc1394_video_get_transmission(camera, &camera->is_iso_on); DC1394_ERR_RTN(err, "Could not get ISO status"); err=GetCameraControlRegister(camera, REG_CAMERA_BASIC_FUNC_INQ, &value[0]); DC1394_ERR_RTN(err, "Could not get basic functionalities"); camera->mem_channel_number = (value[0] & 0x0000000F) != 0; camera->bmode_capable = (value[0] & 0x00800000) != 0; camera->one_shot_capable = (value[0] & 0x00000800) != 0; camera->multi_shot_capable = (value[0] & 0x00001000) != 0; camera->adv_features_capable = (value[0] & 0x80000000) != 0; camera->can_switch_on_off = (value[0] & (0x1<<16)) != 0; if (camera->adv_features_capable>0) { // get advanced features CSR err=GetCameraControlRegister(camera,REG_CAMERA_ADV_FEATURE_INQ, &quadval); DC1394_ERR_RTN(err, "Could not get advanced features CSR"); camera->advanced_features_csr= (octlet_t)(quadval & 0xFFFFFFUL)*4; } if (camera->mem_channel_number>0) { err=dc1394_memory_get_load_ch(camera, &camera->load_channel); DC1394_ERR_RTN(err, "Could not get current load memory channel"); err=dc1394_memory_get_save_ch(camera, &camera->save_channel); DC1394_ERR_RTN(err, "Could not get current save memory channel"); } else { camera->load_channel=0; camera->save_channel=0; } return err;}voiddc1394_free_camera(dc1394camera_t *camera){ if (camera == NULL) return; dc1394_free_camera_platform (camera);}dc1394error_tdc1394_print_camera_info(dc1394camera_t *camera) { quadlet_t value[2]; value[0]= camera->euid_64 & 0xffffffff; value[1]= (camera->euid_64 >>32) & 0xffffffff; printf("------ Camera information ------\n"); printf("Vendor : %s\n", camera->vendor); printf("Model : %s\n", camera->model);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -