1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*!
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright(c) 2009 Apogee Instruments, Inc.
* \class FindDeviceUsb
* \brief searches through a number of usb devices looking for apogee devices
*
*/
#include "FindDeviceUsb.h"
#include <sstream>
#include "AltaIo.h"
#include "AscentBasedIo.h"
#include "AspenIo.h"
#include "apgHelper.h"
#include "helpers.h"
#include "CameraInfo.h"
#include "CamHelpers.h" // for vids and pids
#include "indimacros.h"
#if defined (WIN_OS)
#include "windozeHelpers.h"
#else
#include "linux/linuxHelpers.h"
#endif
////////////////////////////
// DTOR
FindDeviceUsb::~FindDeviceUsb()
{
}
////////////////////////////
// FIND
std::string FindDeviceUsb::Find()
{
std::string result;
try
{
std::vector< std::vector<uint16_t> > devs = GetApgDevices();
std::vector< std::vector<uint16_t> >::iterator iter;
for(iter = devs.begin(); iter != devs.end(); ++iter)
{
const uint16_t vid = (*iter).at(1);
const uint16_t pid = (*iter).at(2);
// deal with blank apogee devices
if( UsbFrmwr::CYPRESS_VID == vid )
{
std::string content = "<d>address="+help::uShort2Str( (*iter).at(0) ) +
",interface=usb,deviceType=camera,id=0xFFFF,firmwareRev=0xFFEE,model=AltaU-Blank,interfaceStatus=NA</d>";
result.append( content );
}
// deal with apogee devices
if( UsbFrmwr::APOGEE_VID == vid )
{
// ticket 53, repeat of something chwy found
// i think i only need to do this check on windoze
// check if the usb device is already opened by another
// process
if( IsDeviceAlreadyOpen( (*iter).at(0) ) )
{
continue;
}
if( UsbFrmwr::FILTER_WHEEL_PID == pid )
{
//right now no id's or firmware verions for the filterwheel
std::string content = "<d>address="+help::uShort2Str( (*iter).at(0) )+
",interface=usb,model=Filter Wheel,deviceType=filterWheel,id=0xFFFF,firmwareRev=0xFFEE</d>";
result.append( content );
}
if( UsbFrmwr::ALTA_USB_PID == pid )
{
std::string content = "<d>address="+help::uShort2Str( (*iter).at(0) )+
",interface=usb,deviceType=camera," +
AltaInfo( help::uShort2Str( (*iter).at(0) ) ) +"</d>";
result.append( content );
}
if( UsbFrmwr::ASCENT_USB_PID == pid )
{
std::string content = "<d>address="+help::uShort2Str( (*iter).at(0) )+
",interface=usb,deviceType=camera," +
AscentInfo( help::uShort2Str( (*iter).at(0) ) ) +"</d>";
result.append( content );
}
if( UsbFrmwr::ASPEN_USB_PID == pid )
{
std::string content = "<d>address="+help::uShort2Str( (*iter).at(0) )+
",interface=usb,deviceType=camera," +
AspenInfo(help::uShort2Str( (*iter).at(0) ) ) + "</d>";
result.append( content );
}
}
}
}
catch( std::exception & err )
{
// catch, log, and rethrow errors from parsecfgfile
apgHelper::LogErrorMsg( __FILE__, err.what(), __LINE__ );
throw;
}
if( result.empty() )
{
//no devices, return the no op string
result.append("<d></d>");
}
return result;
}
////////////////////////////
// ALTA INFO
std::string FindDeviceUsb::AltaInfo( const std::string & deviceAddr )
{
AltaIo usbIo( CamModel::USB, deviceAddr );
return( MkCamInfoStr( usbIo.GetId(), usbIo.GetFirmwareRev() ) );
}
////////////////////////////
// ASCENT INFO
std::string FindDeviceUsb::AscentInfo( const std::string & deviceAddr )
{
AscentBasedIo usbIo( CamModel::USB, deviceAddr );
return( MkCamInfoStr( usbIo.GetId(), usbIo.GetFirmwareRev() ) );
}
////////////////////////////
// ASPEN INFO
std::string FindDeviceUsb::AspenInfo( const std::string & deviceAddr )
{
AspenIo usbIo( CamModel::USB, deviceAddr );
return( MkCamInfoStr( usbIo.GetId(), usbIo.GetFirmwareRev() ) );
}
////////////////////////////
// MK CAM INFO STR
std::string FindDeviceUsb::MkCamInfoStr( const uint16_t Id, const uint16_t FrmwrRev )
{
std::stringstream infoStr;
infoStr << std::hex << std::showbase;
infoStr << "id=" << Id;
infoStr << ",firmwareRev=" << FrmwrRev;
infoStr << ",model=" << CamModel::GetPlatformStr( Id, false ).c_str();
infoStr << "-" << CamModel::GetModelStr( Id );
infoStr << ",interfaceStatus=NA";
return infoStr.str();
}
////////////////////////////
// GET APG DEVICES
std::vector< std::vector<uint16_t> > FindDeviceUsb::GetApgDevices()
{
#ifdef WIN_OS
//the winusbhelper is used by the com dll so
//it doesn't have the apgHelper name space
//so we catch and log its error here and then
//throw the full exception
std::vector< std::vector<uint16_t> > result;
try
{
result = windozeHelpers::GetDevicesWin();
}
catch( std::runtime_error & err )
{
apgHelper::throwRuntimeException( __FILE__, err.what(),
__LINE__, Apg::ErrorType_Connection );
}
return result;
#else
return linuxHelpers::GetDevicesLinux();
#endif
}
bool FindDeviceUsb::IsDeviceAlreadyOpen( const uint16_t deviceNum )
{
#ifdef WIN_OS
return windozeHelpers::IsDeviceAlreadyOpen( deviceNum );
#else
INDI_UNUSED(deviceNum);
return false;
#endif
}
|