Follow this link to skip to the main content

analog_out.cc

Go to the documentation of this file.
00001 // -*-c++-*- 
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /** 
00004  * @file  analog_out.cc
00005  *
00006  * Analog output functions.
00007  *
00008  * <br>@b Designer(s):  Issa Nesnas,
00009  *                      Won Kim
00010  * <br>@b Author(s):    Won Kim,
00011  *                      Issa Nesnas
00012  * <br>@b Date:         August 16, 2002
00013  *
00014  * <b>Software License:</b><br>
00015  * <code>  http://claraty.jpl.nasa.gov/license/open_src/  or
00016  *         file: license/open_src.txt  </code>
00017  *
00018  * &copy; 2006, Jet Propulsion Laboratory, California Institute of Technology<br>
00019  *
00020  * $Revision: 1.3 $
00021  */ 
00022 //-----------------------------------------------------------------------------
00023 
00024 #include <iostream>
00025 #include "claraty/analog_out.h"
00026 
00027 #ifdef RTS_VXWORKS
00028 #include <sysLib.h>
00029 // #include <logLib.h>
00030 #endif
00031 
00032 // #define VERBOSE                      // for debugging
00033 
00034 namespace claraty {
00035 
00036 //-------------------------------------------------------------------------
00037 //------------------------<< analog_out Functions >>---------------------------
00038 //-------------------------------------------------------------------------
00039 
00040 AO::AO (AO_impl& ao_impl, int channel, float gain, float offset) :
00041   _ao_impl (ao_impl),
00042   _channel (channel),
00043   _gain (gain),
00044   _offset (offset)
00045 {
00046   /*
00047    *    if gain is 0 (default), assume conversion to Volt
00048    */
00049   if (gain == 0.0) {
00050     set_gain_for_V();           // unit in V
00051     set_offset_for_V();         // unit in V
00052   }
00053 
00054 #ifdef VERBOSE
00055 //  logMsg("AO: channel= %d, gain= %f, offset= %f\n", _channel, _gain, _offset);
00056   cout << "AO: channel = " << channel << "; gain = " << _gain << "; offset = " << _offset << endl;
00057 #endif
00058 
00059 
00060   output(0.);           // initialize to 0 V output
00061 
00062 }
00063 
00064 int AO::output(float data)
00065 {
00066 
00067   int data2 = (int) (data * _gain + _offset);
00068 
00069   _ao_impl.output(_channel, data2);
00070 
00071 #ifdef VERBOSE
00072 //  logMsg("AO::output(%f): _ao_impl.output(%d, %d)\n", data, _channel, data2);
00073   cout << "AO::output(" << dec << data << "): _ao_impl.output(" 
00074 << _channel << ", " << hex << data2 << "): " << dec << endl;
00075 #endif
00076 
00077   return 0;
00078 }
00079 //-------------------------------------------------------------------------
00080 
00081 void AO::set_gain_for_V()
00082 {
00083   _gain = _ao_impl.get_gain_for_V(_channel);
00084 }
00085 //-------------------------------------------------------------------------
00086 
00087 void AO::set_offset_for_V()
00088 {
00089   _offset = _ao_impl.get_offset_for_V(_channel);
00090 }
00091 //-------------------------------------------------------------------------
00092 
00093 } // namespace claraty