pike.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cams/pike.h>
00025 #include <cams/cam_exceptions.h>
00026
00027 #include <fvutils/system/camargp.h>
00028
00029 #include <cstring>
00030 #include <cstdlib>
00031
00032 using namespace std;
00033 using namespace fawkes;
00034
00035 namespace firevision {
00036 #if 0
00037 }
00038 #endif
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define AVT_WHITE_BALANCE_REGISTER (0x0F0080C)
00049
00050
00051 #define AVT_AUTOFNC_AOI_REGISTER (0x0390)
00052 #define AVT_AF_AREA_POSITION_REGISTER (0x0394)
00053 #define AVT_AF_AREA_SIZE_REGISTER (0x0398)
00054
00055
00056 #define AVT_VERSION_INFO1_REGISTER (0x1000010)
00057 #define AVT_VERSION_INFO3_REGISTER (0x1000018)
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 typedef struct {
00074 uint32_t xuints : 12;
00075 uint32_t yuints : 12;
00076 uint32_t reserved3 : 1;
00077 uint32_t on_off : 1;
00078 uint32_t reserved2 : 1;
00079 uint32_t show_work_area : 1;
00080 uint32_t reserved1 : 3;
00081 uint32_t presence_inq : 1;
00082 } avt_autofnc_aoi_t;
00083
00084
00085 typedef struct {
00086 uint32_t top : 16;
00087 uint32_t left : 16;
00088 } avt_af_area_position_t;
00089
00090
00091 typedef struct {
00092 uint32_t height : 16;
00093 uint32_t width : 16;
00094 } avt_af_area_size_t;
00095
00096
00097 typedef struct {
00098 uint32_t uc_version : 16;
00099 uint32_t uc_type_id : 16;
00100 } avt_version_info1_t;
00101
00102
00103 typedef struct {
00104 uint32_t fpga_version : 16;
00105 uint32_t camera_type_id : 16;
00106 } avt_version_info3_t;
00107
00108
00109
00110
00111
00112 PikeCamera::PikeCamera(const CameraArgumentParser* cap)
00113 : FirewireCamera( cap )
00114 {
00115 __aoi_left = 0;
00116 __aoi_top = 0;
00117 __aoi_width = 0;
00118 __aoi_height = 0;
00119 __aoi_show_work_area = false;
00120
00121 __set_autofnc_aoi = false;
00122
00123 if ( cap->has( "autofnc_aoi" ) )
00124 {
00125 __set_autofnc_aoi = true;
00126 parse_set_autofnc_aoi( cap->get( "autofnc_aoi" ).c_str() );
00127 }
00128 }
00129
00130
00131 PikeCamera::~PikeCamera()
00132 {
00133 }
00134
00135 void
00136 PikeCamera::open()
00137 {
00138 try
00139 {
00140 FirewireCamera::open();
00141 } catch ( Exception &e )
00142 { throw; }
00143
00144 if ( !_opened )
00145 { throw Exception( "PikeCamera::open: FirewireCamera::open dit not succed" ); }
00146
00147 if ( !set_autofunction_aoi( __aoi_left, __aoi_top, __aoi_width, __aoi_height,
00148 __aoi_show_work_area ) )
00149 {
00150 throw Exception( "PikeCamera::PikeCamera: setting autofnc AOI failed." );
00151 }
00152 }
00153
00154 void
00155 PikeCamera::print_info()
00156 {
00157 FirewireCamera::print_info();
00158
00159 uint32_t value;
00160 dc1394error_t err = dc1394_get_register( _camera,
00161 AVT_VERSION_INFO1_REGISTER,
00162 &value );
00163
00164 if ( err != DC1394_SUCCESS )
00165 {
00166 throw Exception( "Pike::print_info; dc1394_get_register(AVT_VERSION_INFO1_REGISTER) failed\n" );
00167 }
00168
00169 avt_version_info1_t version1;
00170 memcpy( (void*) &version1, (void*) &value, sizeof(uint32_t) );
00171
00172 err = dc1394_get_register( _camera,
00173 AVT_VERSION_INFO3_REGISTER,
00174 &value );
00175
00176 if ( err != DC1394_SUCCESS )
00177 {
00178 throw Exception( "Pike::print_info; dc1394_get_register(AVT_VERSION_INFO3_REGISTER) failed\n" );
00179 }
00180
00181 avt_version_info3_t version3;
00182 memcpy( (void*) &version3, (void*) &value, sizeof(uint32_t) );
00183
00184 printf( "uC type ID: %d uC version: %x camera type id: %d FPGA version: %x\n",
00185 version1.uc_type_id, version1.uc_version, version3.camera_type_id, version3.fpga_version );
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 bool
00197 PikeCamera::set_autofunction_aoi( unsigned int left,
00198 unsigned int top,
00199 unsigned int width,
00200 unsigned int height,
00201 bool show_work_area )
00202 {
00203 if ( !_opened )
00204 { return false; }
00205
00206 if ( !__set_autofnc_aoi )
00207 { return true; }
00208
00209 avt_autofnc_aoi_t aoi;
00210 avt_af_area_position_t position;
00211 avt_af_area_size_t size;
00212
00213 aoi.show_work_area = show_work_area;
00214 aoi.on_off = true;
00215
00216 position.left = left;
00217 position.top = top;
00218
00219 size.width = width;
00220 size.height = height;
00221
00222 dc1394error_t err;
00223
00224 uint32_t value = 0;
00225 memcpy( (void*) &value, (void*) &aoi, sizeof( value ) );
00226
00227 err = dc1394_set_adv_control_register( _camera,
00228 AVT_AUTOFNC_AOI_REGISTER,
00229 value );
00230
00231 if ( err != DC1394_SUCCESS )
00232 {
00233 throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AUTOFNC_AOI_REGISTER) failed\n" );
00234 }
00235
00236 memcpy( (void*) &value, (void*) &position, sizeof( value ) );
00237 err = dc1394_set_adv_control_register( _camera,
00238 AVT_AF_AREA_POSITION_REGISTER,
00239 value );
00240
00241 if ( err != DC1394_SUCCESS )
00242 {
00243 throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_POSITION_REGISTER) failed\n" );
00244 }
00245
00246 memcpy( (void*) &value, (void*) &size, sizeof( value ) );
00247 err = dc1394_set_adv_control_register( _camera,
00248 AVT_AF_AREA_SIZE_REGISTER,
00249 value );
00250
00251 if ( err != DC1394_SUCCESS )
00252 {
00253 throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_SIZE_REGISTER) failed\n" );
00254 }
00255
00256 err = dc1394_get_adv_control_register( _camera,
00257 AVT_AUTOFNC_AOI_REGISTER,
00258 &value );
00259 if ( err != DC1394_SUCCESS )
00260 {
00261 throw Exception( "Pike::set_autofunction_aoi; dc1394_get_register(AVT_AUTOFNC_AOI_REGISTER) failed\n" );
00262 }
00263
00264 memcpy ( (void*) &aoi, (void*) &value, sizeof( value ) );
00265
00266 return aoi.on_off;
00267 }
00268
00269
00270
00271
00272
00273
00274 void
00275 PikeCamera::parse_set_autofnc_aoi( const char* aoi )
00276 {
00277
00278
00279 string a = aoi;
00280
00281 string::size_type pos;
00282
00283 pos = a.find( "x", 0 );
00284 if ( pos == string::npos )
00285 { throw Exception( "Illegal autofnc AOI parameter" ); }
00286 string left = a.substr( 0, pos );
00287 a = a.substr( pos + 1 );
00288
00289 pos = a.find( "+", 0 );
00290 if ( pos == string::npos )
00291 { throw Exception( "Illegal autofnc AOI parameter" ); }
00292 string top = a.substr( 0, pos );
00293 a = a.substr( pos + 1 );
00294
00295 pos = a.find( "x", 0 );
00296 if ( pos == string::npos )
00297 { throw Exception( "Illegal autofnc AOI parameter" ); }
00298 string width = a.substr( 0, pos );
00299 a = a.substr( pos + 1 );
00300
00301 string height;
00302 string show;
00303 pos = a.find( "-", 0 );
00304 if ( pos == string::npos )
00305 {
00306 height = a;
00307 __aoi_show_work_area = false;
00308 }
00309 else
00310 {
00311 height = a.substr( 0, pos );
00312 show = a.substr( pos + 1 );
00313
00314 __aoi_show_work_area = ( show == "show" ) ? true : false;
00315 }
00316
00317 __aoi_left = atoi( left.c_str() );
00318 __aoi_top = atoi( top.c_str() );
00319 __aoi_width = atoi( width.c_str() );
00320 __aoi_height = atoi( height.c_str() );
00321 }
00322
00323 }