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

LOW_devDS1820.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_devDS1820.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jul 6 2002
00005     copyright            : (C) 2002 by Harald Roelle, Helmut Reiser
00006     email                : roelle@informatik.uni-muenchen.de, reiser@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_devDS1820.h"
00020 #include "LOW_platformMisc.h"
00021 #include "LOW_helper_msglog.h"
00022 #include "LOW_deviceFactory.h"
00023 #include "LOW_netSegment.h"
00024 #include "LOW_helper_crc.h"
00025 
00026 
00027 
00028 //=====================================================================================
00029 //
00030 // static initializer
00031 //
00032 
00033 const string LOW_devDS1820::familyName = "DS1820";
00034 
00035 int LOW_devDS1820::initHelper = initialize();
00036 int LOW_devDS1820::initialize()
00037 {
00038   LOW_deviceFactory::registerSpecificCtor( familyCode, &LOW_devDS1820::new_Instance);
00039   return 0;
00040 }
00041 
00042 
00043 
00044 //=====================================================================================
00045 //
00046 // static methods
00047 //
00048   
00049 LOW_device* LOW_devDS1820::new_Instance( LOW_netSegment &inNetSegment, const LOW_deviceID &inDevID)
00050 {
00051   return new LOW_devDS1820( inNetSegment, inDevID);
00052 }
00053 
00054 
00055 
00056 //=====================================================================================
00057 //
00058 // public constructors
00059 //
00060 
00061 LOW_devDS1820::LOW_devDS1820( LOW_netSegment &inSegment, const LOW_deviceID &inDevID) : 
00062   LOW_device( inSegment, inDevID, familyCode)
00063 {
00064   if ( inSegment.getHasExternalPower() )
00065     isExternalPowered = cmd_ReadPowerSupply();
00066   else
00067     isExternalPowered = false;
00068 
00069   cmd_RecallE2();
00070     
00071   LOW_helper_msglog::printDebug( LOW_helper_msglog::devDS1820_dl, "isExternalPowered: %d", isExternalPowered);
00072 }
00073 
00074 
00075 LOW_devDS1820::~LOW_devDS1820()
00076 {
00077 }
00078 
00079 
00080 //=====================================================================================
00081 //
00082 // public methods
00083 //
00084 
00085 bool LOW_devDS1820::getIsExternalPowered() const
00086 {
00087   return isExternalPowered;
00088 }
00089 
00090 
00091 void LOW_devDS1820::cmd_ConvertT() const
00092 {
00093   linkLock  lock( *this);
00094   
00095   cmd_MatchROM();
00096   
00097   if ( isExternalPowered ) {
00098     getLink().writeData( ConvertT_COMMAND);
00099     
00100     // poll bits to detect conversion has finished
00101     while ( getLink().readDataBit() == false );
00102   }
00103   else {
00104     // pull up
00105     getLink().writeData( ConvertT_COMMAND, LOW_link::pullUp_1048);
00106   }
00107 }
00108 
00109     
00110 void LOW_devDS1820::cmd_ReadScratchpad( scratchpadDS1820_t *outScratchpad) const
00111 {
00112   linkLock  lock( *this);
00113   
00114   cmd_MatchROM();  
00115   getLink().writeData( ReadScratchpad_COMMAND);
00116   
00117   byteVec_t scratchpad = byteVec_t( sizeof( scratchpadDS1820_t));
00118   getLink().readData( scratchpad);
00119   if ( LOW_helper_CRC::calcCRC8( scratchpad) != 0x00 )
00120     throw LOW_helper_CRC::crc_error( "CRC error in read scratchpad", __FILE__, __LINE__);
00121 
00122   for ( unsigned int a=0; a<=sizeof( scratchpadDS1820_t); a++)
00123     ((uint8_t *)outScratchpad)[a] = scratchpad[a];
00124 }
00125 
00126 
00127 void LOW_devDS1820::cmd_WriteScratchpad( const uint8_t inTL, const uint8_t inTH) const
00128 {
00129   linkLock  lock( *this);
00130   
00131   cmd_MatchROM();
00132   
00133   byteVec_t outData;
00134   outData.push_back( WriteScratchpad_COMMAND);
00135   outData.push_back( inTH);
00136   outData.push_back( inTL);
00137   
00138   getLink().writeData( outData);
00139 }
00140 
00141     
00142 void LOW_devDS1820::cmd_CopyScratchpad() const
00143 {
00144   linkLock  lock( *this);
00145   
00146   cmd_MatchROM();
00147   
00148   if ( isExternalPowered ) {
00149     getLink().writeData( CopyScratchpad_COMMAND);
00150   }
00151   else {
00152     // pull up
00153     getLink().writeData( CopyScratchpad_COMMAND, LOW_link::pullUp_1048);
00154   }
00155 }
00156 
00157     
00158 void LOW_devDS1820::cmd_RecallE2() const
00159 {
00160   linkLock  lock( *this);
00161   
00162   cmd_MatchROM();
00163   
00164   if ( isExternalPowered ) {
00165     getLink().writeData( RecallE2_COMMAND);
00166     
00167     // poll bits to detect recalling has finished
00168     while ( getLink().readDataBit() == false );
00169   }
00170   else {
00171     // pull up
00172     getLink().writeData( RecallE2_COMMAND, LOW_link::pullUp_1048);
00173   }
00174 }
00175 
00176 
00177 bool LOW_devDS1820::cmd_ReadPowerSupply() const
00178 {
00179   linkLock  lock( *this);
00180 
00181   cmd_MatchROM();  
00182   getLink().writeData( ReadPowerSupply_COMMAND);
00183   
00184   return getLink().readDataBit();
00185 }
00186 

Generated on Sun Jan 12 21:07:43 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001