00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00031
00032
00033 const std::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
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
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
00072
00073 LOW_devDS1820::~LOW_devDS1820()
00074 {
00075 }
00076
00077
00078
00079
00080
00081
00082
00083 bool LOW_devDS1820::getIsExternalPowered() const
00084 {
00085 return isExternalPowered;
00086 }
00087
00088
00089 void LOW_devDS1820::cmd_ConvertT() const
00090 {
00091 linkLock lock( *this);
00092
00093 cmd_MatchROM();
00094
00095 if ( isExternalPowered ) {
00096 getLink().writeData( ConvertT_COMMAND);
00097
00098
00099 while ( getLink().readDataBit() == false );
00100 }
00101 else {
00102
00103 getLink().writeData( ConvertT_COMMAND, LOW_link::pullUp_1048);
00104 }
00105 }
00106
00107
00108 void LOW_devDS1820::cmd_ReadScratchpad( scratchpadDS1820_t *outScratchpad) const
00109 {
00110 linkLock lock( *this);
00111
00112 cmd_MatchROM();
00113 getLink().writeData( ReadScratchpad_COMMAND);
00114
00115 byteVec_t scratchpad = byteVec_t( sizeof( scratchpadDS1820_t));
00116 getLink().readData( scratchpad);
00117 if ( LOW_helper_CRC::calcCRC8( scratchpad) != 0x00 )
00118 throw LOW_helper_CRC::crc_error( "CRC error in read scratchpad", __FILE__, __LINE__);
00119
00120 for ( unsigned int a=0; a<=sizeof( scratchpadDS1820_t); a++)
00121 (reinterpret_cast<uint8_t *>(outScratchpad))[a] = scratchpad[a];
00122 }
00123
00124
00125 void LOW_devDS1820::cmd_WriteScratchpad( const uint8_t inTL, const uint8_t inTH) const
00126 {
00127 linkLock lock( *this);
00128
00129 cmd_MatchROM();
00130
00131 byteVec_t outData;
00132 outData.push_back( static_cast<uint8_t>( WriteScratchpad_COMMAND));
00133 outData.push_back( inTH);
00134 outData.push_back( inTL);
00135
00136 getLink().writeData( outData);
00137 }
00138
00139
00140 void LOW_devDS1820::cmd_CopyScratchpad() const
00141 {
00142 linkLock lock( *this);
00143
00144 cmd_MatchROM();
00145
00146 if ( isExternalPowered ) {
00147 getLink().writeData( CopyScratchpad_COMMAND);
00148 }
00149 else {
00150
00151 getLink().writeData( CopyScratchpad_COMMAND, LOW_link::pullUp_1048);
00152 }
00153 }
00154
00155
00156 void LOW_devDS1820::cmd_RecallE2() const
00157 {
00158 linkLock lock( *this);
00159
00160 cmd_MatchROM();
00161
00162 if ( isExternalPowered ) {
00163 getLink().writeData( RecallE2_COMMAND);
00164
00165
00166 while ( getLink().readDataBit() == false );
00167 }
00168 else {
00169
00170 getLink().writeData( RecallE2_COMMAND, LOW_link::pullUp_1048);
00171 }
00172 }
00173
00174
00175 bool LOW_devDS1820::cmd_ReadPowerSupply() const
00176 {
00177 linkLock lock( *this);
00178
00179 cmd_MatchROM();
00180 getLink().writeData( ReadPowerSupply_COMMAND);
00181
00182 return getLink().readDataBit();
00183 }
00184