• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

base_device_t.cpp

Go to the documentation of this file.
00001 /* Copyright (c) 2010, Cedrus Corporation
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  *
00008  * Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.  
00010  *
00011  * Redistributions in binary form must reproduce the above copyright
00012  * notice, this list of conditions and the following disclaimer in the
00013  * documentation and/or other materials provided with the distribution.
00014  *
00015  * Neither the name of Cedrus Corporation nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #include "base_device_t.h"
00033 #include "xid_device_config_t.h"
00034 #include "xid_con_t.h"
00035 #include "constants.h"
00036 
00037 
00038 cedrus::base_device_t::base_device_t(
00039     boost::shared_ptr<xid_con_t> xid_con,
00040     const std::wstring &devconfig_path)
00041     : xid_con_(xid_con),
00042       product_id_(-1),
00043       model_id_(0)
00044 {
00045     init_device(devconfig_path);
00046 }
00047 
00048 cedrus::base_device_t::~base_device_t()
00049 {}
00050 
00051 
00052 void cedrus::base_device_t::reset_rt_timer()
00053 {
00054     char return_info[200];
00055     xid_con_->send_xid_command(
00056         "e5", // reset rt timer Xid command
00057         2,
00058         return_info,
00059         sizeof(return_info),
00060         0);
00061 }
00062 
00063 void cedrus::base_device_t::reset_base_timer()
00064 {
00065     char return_info[200];
00066     xid_con_->send_xid_command(
00067         "e1", // reset base timer Xid command
00068         2,
00069         return_info,
00070         sizeof(return_info),
00071         0);
00072 }
00073 
00074 int cedrus::base_device_t::query_base_timer()
00075 {
00076     char return_info[200];
00077     int read = xid_con_->send_xid_command(
00078         "e3",
00079         2,
00080         return_info,
00081         sizeof(return_info),
00082         6);
00083 
00084     bool valid_response = (read == 6);
00085 
00086     if(valid_response)
00087     {
00088         union {
00089             int as_int;
00090             char as_char[4];
00091         } rt;
00092 
00093         for(int i = 0; i < 4; ++i)
00094         {
00095             rt.as_char[i] = return_info[2+i];
00096         }
00097         return rt.as_int;
00098     }
00099 
00100     return GENERAL_ERROR;
00101 }
00102 
00103 void cedrus::base_device_t::init_device(const std::wstring &devconfig_path)
00104 {
00105     product_id_ = get_inquiry("_d2",1,100,100);
00106 
00107     switch(product_id_)
00108     {
00109     case 0:
00110         device_name_ = "Cedrus Lumina LP-400 Response Pad System";
00111         break;
00112     case 1:
00113         device_name_ = "Cedrus SV-1 Voice Key";
00114         break;
00115     case 2:
00116         {
00117             model_id_ = get_inquiry("_d3", 1, 100, 100);
00118             switch(model_id_)
00119             {
00120             case 1:
00121                 device_name_ = "Cedrus RB-530";
00122                 break;
00123             case 2:
00124                 device_name_ = "Cedrus RB-730";
00125                 break;
00126             case 3:
00127                 device_name_ = "Cedrus RB-830";
00128                 break;
00129             case 4:
00130                 device_name_ = "Cedrus RB-834";
00131                 break;
00132             case -99:
00133                 device_name_ = "Invalid XID Device";
00134                 break;
00135             default:
00136                 device_name_ = "Unknown Cedrus RB Series Device";
00137             }
00138             break;
00139         }
00140     case 83:
00141         device_name_ = "Cedrus StimTracker";
00142         break;
00143     case -99:
00144         device_name_ = "Invalid XID Device";
00145         break;
00146     default:
00147         device_name_ = "Unknown XID device";
00148         break;
00149     }
00150 
00151     if(!devconfig_path.empty())
00152     {
00153         config_ = xid_device_config_t::config_for_device(
00154           product_id_, model_id_, devconfig_path);
00155 
00156         xid_con_->set_needs_interbyte_delay(
00157             config_->needs_interbyte_delay());
00158 
00159         xid_con_->set_digital_out_prefix(
00160             config_->digital_out_prefix());
00161     }
00162     else
00163     {
00164         xid_con_->set_needs_interbyte_delay(true);
00165         if(product_id_ == 83)
00166             xid_con_->set_digital_out_prefix('m');
00167     }
00168 }
00169 
00170 int cedrus::base_device_t::get_inquiry(
00171     const char in_command[],
00172     int expected_bytes_rec,
00173     int timeout,
00174     int delay)
00175 {
00176     int return_value = INVALID_RETURN_VALUE;
00177     char return_info[20];
00178     int last_byte = expected_bytes_rec -1;
00179 
00180     int bytes_returned = xid_con_->send_xid_command(
00181         in_command,
00182         0,
00183         return_info,
00184         sizeof(return_info),
00185         expected_bytes_rec,
00186         timeout,
00187         delay);
00188 
00189     if(bytes_returned > 0)
00190     {
00191         return_value = atoi(return_info);
00192 
00193         if(return_value == 0 && return_info[0] >= 'A')
00194         {
00195             return_value = return_info[last_byte];
00196         }
00197     }
00198 
00199     return return_value;
00200 }
00201 
00202 std::string cedrus::base_device_t::get_device_name()
00203 {
00204     return device_name_;
00205 }
00206 
00207 int cedrus::base_device_t::get_product_id() const
00208 {
00209     return product_id_;
00210 }
00211 
00212 int cedrus::base_device_t::get_model_id() const
00213 {
00214     return model_id_;
00215 }
00216 

Generated on Wed Dec 15 2010 13:17:12 for XID device library by  doxygen 1.7.2