00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <rtt/RTT.hpp>
00028
00029 #include "../drivers/lxrt/apci_lxrt.h"
00030 #include <rtt/os/fosi.h>
00031 #include "RelayCardapci2200.hpp"
00032 #include <rtt/Logger.hpp>
00033
00034 namespace RTT
00035 {
00036
00037 RelayCardapci2200::RelayCardapci2200( const std::string& name )
00038 : DigitalOutInterface( name ), output_cache(0)
00039 {
00040 Logger::In in("RelayCardapci2200");
00041
00042 log() << "Relay init."<< endlog(Debug);
00043 if ( ( apci2200 = apci2200_get_device() ) != 0)
00044 {
00045 log() << "Acquired apci2200 handle." << endlog(Info);
00046 apci2200_set_output_off( apci2200, ~output_cache );
00047 } else
00048 log() << "FAILED to acquire apci2200 handle." <<endlog(Error);
00049 }
00050
00051 RelayCardapci2200::~RelayCardapci2200()
00052 {}
00053
00054 void RelayCardapci2200::switchOn( unsigned int bit )
00055 {
00056 output_cache |= (1 << bit);
00057 apci2200_set_output_on( apci2200, output_cache );
00058 }
00059
00060 void RelayCardapci2200::switchOff( unsigned int bit )
00061 {
00062 output_cache &= ~(1 << bit);
00063 apci2200_set_output_off( apci2200, ~output_cache );
00064 }
00065
00066 void RelayCardapci2200::setBit( unsigned int bit, bool value )
00067 {
00068 if (value)
00069 {
00070 output_cache |= (1 << bit);
00071 apci2200_set_output_on( apci2200, output_cache );
00072 }
00073 else
00074 {
00075 output_cache &= ~(1 << bit);
00076 apci2200_set_output_off( apci2200, ~output_cache );
00077 }
00078 }
00079
00080 void RelayCardapci2200::setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
00081 {
00082 unsigned int mask = ( (~0 << (stop_bit + 1)) | (~0 >> (sizeof(unsigned int) * 8 - start_bit)) );
00083 output_cache &= mask;
00084 output_cache |= (value << start_bit);
00085 apci2200_set_output_on( apci2200, output_cache );
00086 apci2200_set_output_off( apci2200, ~output_cache);
00087 }
00088
00089 bool RelayCardapci2200::checkBit(unsigned int n) const
00090 {
00091 return (output_cache >> n) & 0x1;
00092 }
00093
00094 unsigned int RelayCardapci2200::checkSequence( unsigned int start_bit, unsigned int stop_bit ) const
00095 {
00096 unsigned int mask = (( 1 << (stop_bit - start_bit + 1) ) - 1);
00097 return (output_cache >> start_bit) & mask;
00098 }
00099
00100 unsigned int RelayCardapci2200::nbOfOutputs() const
00101 {
00102 return apci2200_get_number_off_digital_outputs();
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 }