00001 #ifndef DIGITALETHERCATINPUTDEVICE_HPP 00002 #define DIGITALETHERCATINPUTDEVICE_HPP 00003 00004 #include "rtt/dev/DigitalInInterface.hpp" 00005 #include <vector> 00006 00007 namespace RTT 00008 { 00012 class DigitalEtherCATInputDevice 00013 : public DigitalInInterface 00014 { 00015 public: 00016 std::vector<bool> mchannels; 00017 unsigned int nbofchannels; 00018 unsigned int startb; 00019 unsigned char* mstartaddress; 00020 00021 DigitalEtherCATInputDevice(unsigned char* startaddress, unsigned int start_bit, unsigned int channels=32) 00022 : DigitalInInterface("DigitalEtherCATInputDevice"), 00023 mchannels(channels,false), 00024 nbofchannels(channels), 00025 startb(start_bit), 00026 mstartaddress(startaddress) 00027 {} 00028 00029 00030 virtual unsigned int nbOfInputs() const 00031 { 00032 return nbofchannels; 00033 } 00034 00035 virtual bool isOn( unsigned int bit = 0) const 00036 { 00037 if ( bit < mchannels.size() ) 00038 return readBit(0); 00039 return false; 00040 } 00041 00042 virtual bool isOff( unsigned int bit = 0) const 00043 { 00044 if ( bit < mchannels.size() ) 00045 return !readBit(0); 00046 return true; 00047 } 00048 00049 virtual bool readBit( unsigned int bit = 0) const 00050 { 00051 if ( bit < nbofchannels ) { 00052 unsigned char tmp = *mstartaddress; 00053 tmp = tmp >> startb + bit; 00054 return tmp & 0x01; 00055 } 00056 return false; 00057 } 00058 00059 virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const 00060 { 00061 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() ) 00062 return 0; 00063 return 0; 00064 } 00065 00066 }; 00067 00068 00069 } 00070 00071 00072 #endif