Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_linkPassiveSerial.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_linkPassiveSerial.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jul 7 2002
00005     copyright            : (C) 2002 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "LOW_linkPassiveSerial.h"
00020 
00021 
00022 
00023 //=====================================================================================
00024 //
00025 // constructors
00026 //
00027 
00028 LOW_linkPassiveSerial::LOW_linkPassiveSerial( const LOW_portSerialFactory::portSpecifier_t &inSerPortSpec,
00029                                               const bool inAllowProgPulse) :
00030   LOW_link( false, false, inAllowProgPulse)
00031 {
00032   serialPort   = LOW_portSerialFactory::new_portSerial( inSerPortSpec);
00033 
00034   resetLinkAdapter();
00035   resetBus(); // to detect a missing adapter
00036 }
00037 
00038   
00039 
00040 LOW_linkPassiveSerial::~LOW_linkPassiveSerial()
00041 {
00042   serialPort->tty_flush();
00043 
00044   delete serialPort;
00045 }
00046 
00047 
00048 
00049 //=====================================================================================
00050 //
00051 // touch data methods
00052 //
00053 
00054 bool LOW_linkPassiveSerial::touchBit( const bool inSendBit, const strongPullup_t inPullup)
00055 {
00056   commLock lock( *this);
00057   
00058   uint8_t         serSendByte;
00059   bool            retVal;
00060 
00061   serialPort->tty_flush();
00062 
00063   // get bit ready to be sent
00064   serSendByte = inSendBit ? 0xFF : 0x00;
00065 
00066   // Send the bit
00067   serialPort->tty_write( serSendByte);
00068 
00069   uint8_t tmpByte = serialPort->tty_readByte();        
00070   if ( tmpByte & 0x01 )
00071     retVal = true;
00072   else
00073     retVal = false;
00074   
00075   strongPullup( inPullup);
00076   
00077   return retVal;
00078 }  
00079     
00080 
00081 uint8_t LOW_linkPassiveSerial::touchByte( const uint8_t inSendByte, const strongPullup_t inPullup)
00082 {
00083   commLock lock( *this);
00084   
00085   uint8_t  mask    = 0x01;
00086   uint8_t  retVal  = 0x00;
00087   
00088   for( int a=0; a<8; a++) {
00089     retVal |= touchBit( inSendByte & mask) ? mask : 0x00;
00090     mask <<= 1;
00091   }
00092   
00093   strongPullup( inPullup);
00094   
00095   return retVal;
00096 }
00097 
00098   
00099 //=====================================================================================
00100 //
00101 // misc methods
00102 //
00103 
00104 void LOW_linkPassiveSerial::resetLinkAdapter()
00105 {
00106   commLock lock( *this);
00107   
00108   serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size, 
00109                              LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00110   
00111   serialPort->tty_flush();
00112 }
00113 
00114     
00115 bool LOW_linkPassiveSerial::resetBus()
00116 {
00117   commLock lock( *this);
00118   
00119   const uint8_t   resetSendByte = 0xF0;
00120   
00121   bool            devFound = false;
00122     
00123   try {
00124     
00125     // Flush the input and output buffers
00126     serialPort->tty_flush();
00127     
00128     serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size, 
00129                                LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B10472_speed);
00130     
00131     // Send the reset pulse
00132     serialPort->tty_write( resetSendByte);
00133 
00134     uint8_t tmpByte = serialPort->tty_readByte();
00135 
00136     if( tmpByte == 0 )  // if answer is still zero, then it is a short to ground
00137       throw comm_error( "Possible short to ground detected", __FILE__, __LINE__);
00138 
00139     // If the byte read is not what we sent, check for an error
00140     // For now just return a 1 and discount any errors??
00141     if( tmpByte != resetSendByte )
00142       devFound = true; // got a response of some type
00143     else
00144       devFound = false; // no device responding
00145   }
00146   catch( ... ) {
00147     
00148     try { 
00149       serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size, 
00150                                  LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00151     }
00152     catch( ... ) {}
00153     
00154     throw;
00155   }  
00156   
00157   serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size, 
00158                              LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00159 
00160   return devFound;
00161 }
00162 
00163 
00164 void LOW_linkPassiveSerial::strongPullup( const unsigned long /*inMilliSecs*/)
00165 {
00166   commLock lock( *this);
00167 
00168   LOW_platformMisc::secSleep( strongPullupEmuTime);
00169 }
00170 
00171 
00172 void LOW_linkPassiveSerial::strongPullup( const strongPullup_t /*inPullupTimes*/)
00173 {
00174   commLock lock( *this);
00175 
00176   LOW_platformMisc::secSleep( strongPullupEmuTime);
00177 }
00178 
00179 
00180 void LOW_linkPassiveSerial::programPulse( const unsigned long /*inMicroSecs*/)
00181 {
00182   commLock lock( *this);
00183 
00184   if ( ! allowProgPulse )
00185     throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00186 
00187   if ( ! hasProgramPulse )
00188     throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00189 
00190   throw internal_error( "Program pulse not available, should never be reached", __FILE__, __LINE__);
00191 }
00192 
00193 
00194 void LOW_linkPassiveSerial::programPulse( const progPulse_t /*inPulseTime*/)
00195 {
00196   commLock lock( *this);
00197 
00198   if ( ! allowProgPulse )
00199     throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00200 
00201   if ( ! hasProgramPulse )
00202     throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00203 
00204   throw internal_error( "Program pulse not available, should never be reached", __FILE__, __LINE__);
00205 }

Generated on Tue Feb 3 11:30:25 2004 for OneWireLibrary++ by doxygen 1.3.2