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

LOW_linkDS2480B.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_linkDS2480B.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jul 13 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 #include <memory>
00019 
00020 
00021 #include "LOW_linkDS2480B.h"
00022 #include "LOW_helper_msglog.h"
00023 
00024 #include "LOW_platformMisc.h"
00025 #include "LOW_IPCKeyGeneratorFactory.h"
00026 #include "LOW_portSerialFactory.h"
00027 #include "LOW_semaphoreSetFactory.h"
00028 #include "LOW_sharedMemSegmentFactory.h"
00029 
00030 
00031 LOW_linkDS2480B::LOW_linkDS2480B( const LOW_portSerialFactory::portSpecifier_t &inSerPortSpec, const RXPOL_val_t inRXPOL, 
00032                                   const bool inHasExternalPower, const bool inAllowProgPulse) :
00033   LOW_link( true, true, inHasExternalPower, inAllowProgPulse),
00034   receivePolarity( inRXPOL)
00035 {
00036   initCmdAvailTable();
00037 
00038   serialPort   = LOW_portSerialFactory::new_portSerial( inSerPortSpec);
00039   
00040   auto_ptr<LOW_IPCKeyGenerator> keyGenerator (LOW_IPCKeyGeneratorFactory::new_IPCKeyGenerator());
00041 
00042   semSet       = LOW_semaphoreSetFactory::new_semaphoreSet( keyGenerator->getSemSetKey( inSerPortSpec), semaphoreCount, 1);
00043   
00044   sharedMemSeg = LOW_sharedMemSegmentFactory::new_sharedMemSegment( keyGenerator->getSharedMemKey( inSerPortSpec), sizeof( sharedAttr_t));
00045   sharedAttr = (sharedAttr_t*)sharedMemSeg->get();
00046   
00047   sharedAttr->wireSpeed = flexible_speed;
00048   resetLinkAdapter();
00049   
00050   // configure the recommeded optimal parameters as of app note #148
00051   setPullDownSlewRate( PDSR_1_37);
00052   setWrite1LowTime( W1LT_11);
00053   setSampleOffsetWrite0Rec( SOW0RT_10);
00054 }
00055 
00056   
00057 LOW_linkDS2480B::~LOW_linkDS2480B()
00058 {
00059   serialPort->tty_flush();
00060   
00061   delete sharedMemSeg;
00062   delete semSet;
00063   delete serialPort;
00064 }
00065 
00066 
00067 //=====================================================================================
00068 //
00069 // touch data methods
00070 //
00071  
00072 bool LOW_linkDS2480B::touchBit( const bool inSendBit, const strongPullup_t inPullup)
00073 {
00074   commLock lock( *this);
00075   
00076   if ( inPullup != pullUp_NONE ) {
00077     setStrongPullupDuration_cmd( strongPullup_2_SPUD_val( inPullup));
00078   }
00079   
00080   return singleBit_cmd( inSendBit, (inPullup==pullUp_NONE)?false:true);
00081 }
00082 
00083  
00084 uint8_t LOW_linkDS2480B::touchByte( const uint8_t inSendByte, const strongPullup_t inPullup)
00085 {
00086   commLock lock( *this);
00087   
00088   if ( inPullup != pullUp_NONE ) {
00089     setStrongPullupDuration_cmd( strongPullup_2_SPUD_val( inPullup));
00090     pulse_cmd( true, false, true);
00091   }
00092   
00093   setMode( data_mode);
00094   
00095   serialPort->tty_write( inSendByte);
00096   if ( inSendByte == SwitchToCommandMode_Cmd )
00097     serialPort->tty_write( inSendByte);
00098   
00099   uint8_t retValue = serialPort->tty_readByte( (inPullup==pullUp_NONE)?false:true);
00100       
00101   if ( inPullup != pullUp_NONE ) {
00102     pulse_cmd( false, false, true);
00103   }
00104   
00105   return retValue;
00106 }
00107 
00108   
00109 byteVec_t LOW_linkDS2480B::touchBlock( const byteVec_t &inBytes, const strongPullup_t inPullup)
00110 {
00111   commLock lock( *this);
00112   
00113   byteVec_t            retValue   = byteVec_t( inBytes.size());
00114   byteVec_t            writeBytes;
00115     
00116   /* // This breaks on RedHat 7.2:
00117    * byteVec_t            writeBytes = byteVec_t( inBytes);
00118    * byteVec_t::iterator  iter = writeBytes.begin();
00119    * while( iter != writeBytes.end() ) {
00120    *  if ( *iter == SwitchToCommandMode_Cmd )
00121    *    writeBytes.insert( iter, SwitchToCommandMode_Cmd);
00122    *   iter++;
00123    * }
00124    */
00125    
00126   for( unsigned int a=0; a<inBytes.size(); a++) {
00127     writeBytes.push_back( inBytes[a]);
00128     if ( inBytes[a] == SwitchToCommandMode_Cmd )
00129       writeBytes.push_back( inBytes[a]);
00130   }
00131   
00132   if ( inPullup != pullUp_NONE ) {
00133     setStrongPullupDuration_cmd( strongPullup_2_SPUD_val( inPullup));
00134     pulse_cmd( true, false, true);
00135   }
00136   
00137   setMode( data_mode);
00138 
00139   serialPort->tty_write( writeBytes);
00140   serialPort->tty_read( retValue, (inPullup==pullUp_NONE)?false:true);
00141       
00142   if ( inPullup != pullUp_NONE ) {
00143     pulse_cmd( false, false, true);
00144   }
00145 
00146   return retValue;
00147 }
00148 
00149   
00150   
00151 //=====================================================================================
00152 //
00153 // read data methods
00154 //
00155   
00156 bool LOW_linkDS2480B::readDataBit( const strongPullup_t inPullup)
00157 {
00158   commLock lock( *this);
00159   
00160   return touchBit( true, inPullup);
00161 }
00162 
00163 
00164 uint8_t LOW_linkDS2480B::readDataByte( const strongPullup_t inPullup)
00165 {
00166   commLock lock( *this);
00167   
00168   return touchByte( 0xff, inPullup);
00169 }
00170 
00171 
00172 void LOW_linkDS2480B::readData( byteVec_t &outBytes, const strongPullup_t inPullup)
00173 {
00174   commLock lock( *this);
00175   
00176   byteVec_t  sendBytes = byteVec_t( outBytes.size(), 0xff);
00177   byteVec_t  recBytes;
00178   
00179   recBytes = touchBlock( sendBytes, inPullup);
00180   for( unsigned int a=0; a<recBytes.size(); a++)
00181     outBytes[a] = recBytes[a];
00182 }
00183 
00184 
00185     
00186 //=====================================================================================
00187 //
00188 // write data methods
00189 //
00190  
00191 void LOW_linkDS2480B::writeData( const bool inSendBit, const strongPullup_t inPullup)
00192 {
00193   commLock lock( *this);
00194   
00195   if ( touchBit( inSendBit, inPullup) != inSendBit )
00196     throw comm_error( "Response not equal to sent bit", __FILE__, __LINE__);
00197 }
00198 
00199 
00200 void LOW_linkDS2480B::writeData( const uint8_t inSendByte, const strongPullup_t inPullup)
00201 {
00202   commLock lock( *this);
00203   
00204   if ( touchByte( inSendByte, inPullup) != inSendByte )
00205     throw comm_error( "Response not equal to sent byte", __FILE__, __LINE__);
00206 }
00207 
00208 
00209 void LOW_linkDS2480B::writeData( const byteVec_t &inSendBytes, const strongPullup_t inPullup)
00210 {
00211   commLock lock( *this);
00212   
00213   byteVec_t readVec = touchBlock( inSendBytes, inPullup);
00214   
00215   for( unsigned int i=0; i<inSendBytes.size(); i++)
00216     if ( readVec[i] != inSendBytes[i] ) {
00217       throw comm_error( "Response not equal to sent byte", __FILE__, __LINE__);
00218     }
00219 }
00220 
00221   
00222     
00223 //=====================================================================================
00224 //
00225 // misc methods
00226 //
00227   
00228 void LOW_linkDS2480B::resetLinkAdapter()
00229 {
00230   commLock lock( *this);
00231   
00232   sharedAttr->internalMode = command_mode;
00233 
00234   //
00235   // begin with the standard speed
00236   //
00237   serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size, 
00238                              LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, 
00239                              LOW_portSerial::B9600_speed);
00240   
00241   serialPort->tty_flush(); // flush the buffers
00242     
00243   serialPort->tty_break(); // send a break to reset the DS2480
00244   LOW_platformMisc::milliSleep( 2); // delay to let line settle
00245 
00246   serialPort->tty_flush(); // flush the buffers
00247   
00248   //
00249   // let the DS2480 adapt to the serial speed
00250   //
00251   serialPort->tty_write( SerialSpeedAdapt_Cmd);
00252   serialPort->tty_flush( false, true);
00253   LOW_platformMisc::milliSleep( 4);
00254   
00255   //
00256   // configure desired serial speed and polarity
00257   //
00258   RBR_val_t serialSpeed;
00259   switch ( sharedAttr->wireSpeed ) {
00260     case normal_speed:     serialSpeed = RBR_9_6;   break;
00261     case flexible_speed:   serialSpeed = RBR_9_6;   break;
00262     case overdrive_speed:  serialSpeed = RBR_57_6;  break;
00263     default:               throw comm_error( "Unknown wire speed detected", __FILE__, __LINE__);
00264   }
00265   try {
00266     setRS232BaudRate_cmd( serialSpeed, receivePolarity);
00267   }                // ignore errors, result can't be right
00268   catch ( ...) {}  // because we're just setting the correct baud rate
00269   
00270   //
00271   // now switch the port to the new speed
00272   //
00273   switch ( sharedAttr->wireSpeed ) {
00274     case normal_speed:
00275       serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size, 
00276                                  LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, 
00277                                  LOW_portSerial::B9600_speed);
00278       break;
00279     
00280     case flexible_speed:
00281       serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size, 
00282                                  LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, 
00283                                  LOW_portSerial::B9600_speed);
00284       break;
00285     
00286     case overdrive_speed:
00287       serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size, 
00288                                  LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, 
00289                                  LOW_portSerial::B57600_speed);
00290       break;
00291     
00292     default:
00293       throw comm_error( "Unknown wire speed detected", __FILE__, __LINE__);
00294   }
00295   
00296   // do it again, to test wheter it was successfull
00297   setRS232BaudRate_cmd( serialSpeed, receivePolarity);
00298 }  
00299 
00300 
00301 bool LOW_linkDS2480B::resetBus()
00302 {
00303   commLock lock( *this);
00304   
00305   resetAnswer_t  answer;
00306   
00307   reset_cmd( &answer);
00308 
00309   hasProgramPulse = answer.isVppPresent;
00310 
00311   /** @todo Check if and how "alarming presence pulse" response works. */  
00312   switch( answer.busStatus ) {
00313     case oneWireShorted_busStat:        throw comm_error( "Short to ground detected", __FILE__, __LINE__);
00314     case noPresencePulse_busStat:       return false;
00315     case presencePulse_busStat:         // fall thru
00316     case alarmingPresencePulse_busStat: // fall thru
00317     default:                            return true;
00318   }
00319 }
00320 
00321  
00322 void LOW_linkDS2480B::strongPullup( const unsigned long inMilliSecs)
00323 {
00324   commLock lock( *this);
00325   
00326   setStrongPullupDuration_cmd( SPUD_inf);
00327   
00328   pulse_cmd( false, false, false);
00329   LOW_platformMisc::milliSleep( inMilliSecs); 
00330   serialPort->tty_write( PulseTermination_Cmd);
00331 }
00332 
00333     
00334 void LOW_linkDS2480B::programPulse()
00335 {
00336   commLock lock( *this);
00337   
00338   if ( ! allowProgPulse )
00339     throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00340 
00341   if ( ! hasProgramPulse )
00342     throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00343    
00344   setProgPulseDuration_cmd( PPD_512);
00345   pulse_cmd( false, true, false);
00346 }
00347 
00348 
00349 void LOW_linkDS2480B::doSearchSequence( const LOW_deviceIDRaw &inBranchVector, 
00350                                         LOW_deviceIDRaw &outFoundID, LOW_deviceIDRaw &outDiscrVec)
00351 {
00352   commLock lock( *this);
00353   
00354   byteVec_t  sendVector = byteVec_t( 16, 0x00);
00355 
00356   int bitPos = 0;
00357   for( int a=0; a<16; a++) {
00358     for( int b=0; b<4; b++) {
00359       if ( inBranchVector.getBit( bitPos)==true )
00360         sendVector[a] |= 0x01<<(2*b+1);
00361       
00362       bitPos++;
00363     }
00364   }
00365     
00366   searchAccelCtrl_cmd( true);
00367   byteVec_t recVector = touchBlock( sendVector);
00368   searchAccelCtrl_cmd( false);
00369   
00370   if ( recVector.size()!=16 )
00371     throw sizeMismatch_error( "Search received vector size mismatch", __FILE__, __LINE__);
00372   
00373   bitPos = 0;
00374   for( int a=0; a<16; a++) {
00375     for( int b=0; b<4; b++) {
00376       if ( recVector[a] & (0x01<<((2*b)+1)) )
00377         outFoundID.setBit( bitPos, true);
00378       else
00379         outFoundID.setBit( bitPos, false);
00380       
00381       if ( recVector[a] & (0x01<<(2*b)) )
00382         outDiscrVec.setBit( bitPos, true);
00383       else
00384         outDiscrVec.setBit( bitPos, false);
00385       
00386       bitPos++;
00387     }  
00388   }
00389   
00390 }
00391 
00392 
00393 //=====================================================================================
00394 //
00395 // DS2480B specific methods
00396 //
00397   
00398 void LOW_linkDS2480B::setWireSpeed( const wireSpeed_t inWireSpeed)
00399 {
00400   commLock lock( *this);
00401   
00402   sharedAttr->wireSpeed = inWireSpeed;
00403   
00404   resetLinkAdapter();
00405   resetBus();
00406 }
00407 
00408 
00409 LOW_linkDS2480B::wireSpeed_t LOW_linkDS2480B::getWireSpeed()
00410 {
00411   commLock lock( *this);
00412 
00413   return sharedAttr->wireSpeed;
00414 }
00415 
00416 
00417 void LOW_linkDS2480B::setPullDownSlewRate( const PDSR_val_t inPDSR)
00418 {
00419   commLock lock( *this);
00420   
00421   if ( sharedAttr->wireSpeed != flexible_speed )
00422     throw notAllowed_error( "Only configurable in flexible speed mode", __FILE__, __LINE__);
00423     
00424   setPullDownSlewRate_cmd( inPDSR);
00425 }
00426 
00427 
00428 LOW_linkDS2480B::PDSR_val_t LOW_linkDS2480B::getPullDownSlewRate()
00429 {
00430   commLock lock( *this);
00431   
00432   if ( sharedAttr->wireSpeed != flexible_speed )
00433     throw notAllowed_error( "Only allowed in flexible speed mode", __FILE__, __LINE__);
00434   
00435   return getPullDownSlewRate_cmd();
00436 }
00437 
00438 
00439 void LOW_linkDS2480B::setWrite1LowTime( const W1LT_val_t inW1LT)
00440 {
00441   commLock lock( *this);
00442   
00443   if ( sharedAttr->wireSpeed != flexible_speed )
00444     throw notAllowed_error( "Only configurable in flexible speed mode", __FILE__, __LINE__);
00445 
00446   setWrite1LowTime_cmd( inW1LT);
00447 }
00448 
00449 
00450 LOW_linkDS2480B::W1LT_val_t LOW_linkDS2480B::getWrite1LowTime()
00451 {
00452   commLock lock( *this);
00453   
00454   if ( sharedAttr->wireSpeed != flexible_speed )
00455     throw notAllowed_error( "Only allowed in flexible speed mode", __FILE__, __LINE__);
00456   
00457   return getWrite1LowTime_cmd();
00458 }
00459 
00460 
00461 void LOW_linkDS2480B::setSampleOffsetWrite0Rec( const SOW0RT_val_t inSOW0RT)
00462 {
00463   commLock lock( *this);
00464   
00465   if ( sharedAttr->wireSpeed != flexible_speed )
00466     throw notAllowed_error( "Only configurable in flexible speed mode", __FILE__, __LINE__);
00467 
00468   setSampleOffsetWrite0Rec_cmd( inSOW0RT);
00469 }
00470 
00471 
00472 LOW_linkDS2480B::SOW0RT_val_t LOW_linkDS2480B::getSampleOffsetWrite0Rec()
00473 {
00474   commLock lock( *this);
00475   
00476   if ( sharedAttr->wireSpeed != flexible_speed )
00477     throw notAllowed_error( "Only allowed in flexible speed mode", __FILE__, __LINE__);
00478   
00479   return getSampleOffsetWrite0Rec_cmd();
00480 }
00481 
00482 
00483 
00484 //=====================================================================================
00485 //
00486 // DS2480B commands
00487 //
00488 
00489 
00490 void LOW_linkDS2480B::reset_cmd( resetAnswer_t *outAnswer)
00491 {
00492   commLock lock( *this);
00493   
00494   setMode( command_mode);
00495 
00496   serialPort->tty_flush();
00497   
00498   uint8_t outByte = Reset_Cmd | (sharedAttr->wireSpeed&0x03)<<2;
00499   serialPort->tty_write( outByte);
00500   
00501   uint8_t reply = serialPort->tty_readByte();
00502   
00503   if ( (reply&0xc0) != (outByte&0xc0) )
00504     throw comm_error( "Unexpected reply from reset command", __FILE__, __LINE__);
00505 
00506   outAnswer->busStatus     = (busStatus_t)(reply&0x03);
00507   outAnswer->isVppPresent  = (reply>>5)&0x01;
00508   outAnswer->chipRevision  = (reply>>2)&0x07;
00509 }
00510 
00511 
00512 bool LOW_linkDS2480B::singleBit_cmd( const bool inBitVal, const bool inStrongPullup)
00513 {
00514   commLock lock( *this);
00515   
00516   setMode( command_mode);
00517 
00518   uint8_t outByte = SingleBit_Cmd | ((uint8_t)(inBitVal))<<4 | (sharedAttr->wireSpeed&0x03)<<2 | ((uint8_t)(inStrongPullup))<<1;
00519   serialPort->tty_write( outByte);
00520   
00521   uint8_t reply = serialPort->tty_readByte();
00522   
00523   if ( (reply&0xfc) != (outByte&0xfc) )
00524     throw comm_error( "Unexpected reply from single bit command", __FILE__, __LINE__);
00525 
00526   bool retVal = reply&0x01;
00527 
00528   if ( inStrongPullup ) {
00529     reply = serialPort->tty_readByte();
00530     if ( (reply&0xfc) != 0xec )
00531       throw comm_error( "Unexpected reply from single bit strong pullup response", __FILE__, __LINE__);
00532   }
00533   
00534   return retVal;
00535 }
00536 
00537 
00538 void LOW_linkDS2480B::pulse_cmd( const bool inArm, const bool inProgPulse, const bool inImmidiateTerm)
00539 {
00540   commLock lock( *this);
00541   
00542   setMode( command_mode);
00543 
00544   byteVec_t  outBytes;
00545   
00546   outBytes.push_back( Pulse_Cmd | ((uint8_t)(inProgPulse))<<4 | (0x03)<<2 | ((uint8_t)(inArm))<<1);
00547   if ( inImmidiateTerm )
00548     outBytes.push_back( PulseTermination_Cmd);
00549   
00550   serialPort->tty_write( outBytes);
00551   
00552   uint8_t reply = serialPort->tty_readByte();
00553   
00554   if ( (reply&0xfc) != (outBytes[0]&0xfc) )
00555     throw comm_error( "Unexpected reply from pulse command", __FILE__, __LINE__);
00556 }
00557 
00558 
00559 void LOW_linkDS2480B::searchAccelCtrl_cmd( const bool inAccelOn)
00560 {
00561   commLock lock( *this);
00562   
00563   setMode( command_mode);
00564 
00565   uint8_t outByte = SearchAccel_Cmd | ((uint8_t)(inAccelOn))<<4 | (sharedAttr->wireSpeed&0x03)<<2 ;
00566   serialPort->tty_write( outByte);
00567 }
00568 
00569 
00570 
00571 //=====================================================================================
00572 //
00573 // DS2480B configuration commands
00574 //
00575   
00576 void LOW_linkDS2480B::setPullDownSlewRate_cmd( const PDSR_val_t inPDSR)
00577 {
00578   writeConfigValue( PullDownSlewRate_cfgCmd, inPDSR);
00579 }
00580 
00581 LOW_linkDS2480B::PDSR_val_t LOW_linkDS2480B::getPullDownSlewRate_cmd()
00582 {
00583   return (PDSR_val_t)readConfigValue( PullDownSlewRate_cfgCmd);
00584 }
00585 
00586 
00587 void LOW_linkDS2480B::setProgPulseDuration_cmd( const PPD_val_t inPPD)
00588 {
00589   writeConfigValue( ProgPulseDuration_cfgCmd, inPPD);
00590 }
00591 
00592 LOW_linkDS2480B::PPD_val_t LOW_linkDS2480B::getProgPulseDuration_cmd()
00593 {
00594   return (PPD_val_t)readConfigValue( ProgPulseDuration_cfgCmd);
00595 }
00596 
00597 
00598 void LOW_linkDS2480B::setStrongPullupDuration_cmd( const SPUD_val_t inSPUD)
00599 {
00600   writeConfigValue( StrongPullupDuration_cfgCmd, inSPUD);
00601 }
00602 
00603 LOW_linkDS2480B::SPUD_val_t LOW_linkDS2480B::getStrongPullupDuration_cmd()
00604 {
00605   return (SPUD_val_t)readConfigValue( StrongPullupDuration_cfgCmd);
00606 }
00607 
00608 
00609 void LOW_linkDS2480B::setWrite1LowTime_cmd( const W1LT_val_t inW1LT)
00610 {
00611   writeConfigValue( Write1LowTime_cfgCmd, inW1LT);
00612 }
00613 
00614 LOW_linkDS2480B::W1LT_val_t LOW_linkDS2480B::getWrite1LowTime_cmd()
00615 {
00616   return (W1LT_val_t)readConfigValue( Write1LowTime_cfgCmd);
00617 }
00618 
00619 
00620 void LOW_linkDS2480B::setSampleOffsetWrite0Rec_cmd( const SOW0RT_val_t inSOW0RT)
00621 {
00622   writeConfigValue( SampleOffsetWrite0Rec_cfgCmd, inSOW0RT);
00623 }
00624 
00625 LOW_linkDS2480B::SOW0RT_val_t LOW_linkDS2480B::getSampleOffsetWrite0Rec_cmd()
00626 {
00627   return (SOW0RT_val_t)readConfigValue( SampleOffsetWrite0Rec_cfgCmd);
00628 }
00629 
00630 
00631 void LOW_linkDS2480B::setLoadSensorThreshold_cmd( const LST_val_t inLST)
00632 {
00633   writeConfigValue( LoadSensorThreshold_cfgCmd, inLST);
00634 }
00635 
00636 LOW_linkDS2480B::LST_val_t LOW_linkDS2480B::getLoadSensorThreshold_cmd()
00637 {
00638   return (LST_val_t)readConfigValue( LoadSensorThreshold_cfgCmd);
00639 }
00640 
00641 
00642 void LOW_linkDS2480B::setRS232BaudRate_cmd( const RBR_val_t inRBR, const RXPOL_val_t inRXPOL)
00643 {
00644   writeConfigValue( RS232BaudRate_cfgCmd, ((inRXPOL&0x01)<<2) | (inRBR&0x03) );
00645 }
00646 
00647 LOW_linkDS2480B::RBR_val_t LOW_linkDS2480B::getRS232BaudRate_cmd()
00648 {
00649   return (RBR_val_t)(readConfigValue( RS232BaudRate_cfgCmd) & 0x03);
00650 }
00651 
00652 LOW_linkDS2480B::RXPOL_val_t LOW_linkDS2480B::getRS232RxPol_cmd()
00653 {
00654   return (RXPOL_val_t)((readConfigValue( RS232BaudRate_cfgCmd)>>2) & 0x01);
00655 }
00656 
00657 
00658 
00659 //=====================================================================================
00660 //
00661 // internal methods
00662 //
00663 
00664 void LOW_linkDS2480B::writeConfigValue( const uint8_t inParamCode, const uint8_t inParamValue)
00665 {
00666   commLock lock( *this);
00667   
00668   uint8_t outByte       = (inParamCode&0x07)<<4 | (inParamValue&0x07)<<1 | 0x01;
00669   uint8_t expectedReply = outByte & ~0x01;
00670   
00671   setMode( command_mode);
00672 
00673   serialPort->tty_write( outByte);
00674   if ( serialPort->tty_readByte() != expectedReply )
00675     throw comm_error( "Unexpected reply while setting config value", __FILE__, __LINE__);
00676 }
00677   
00678   
00679 uint8_t LOW_linkDS2480B::readConfigValue( const uint8_t inParamCode)
00680 {
00681   commLock lock( *this);
00682   
00683   uint8_t outByte = (inParamCode&0x07)<<1 | 0x01;
00684   
00685   setMode( command_mode);
00686   
00687   serialPort->tty_write( outByte);
00688   
00689   uint8_t reply = serialPort->tty_readByte();
00690   if ( (reply&0x01)!=0x00 || (reply&0x70)!=(inParamCode&0x07)<<4 )
00691     throw comm_error( "Unexpected reply while getting config value", __FILE__, __LINE__);
00692 
00693   return (reply>>1)&0x03;
00694 }
00695 
00696 
00697 void LOW_linkDS2480B::setMode( const internalMode_t inMode)
00698 {
00699   if ( sharedAttr->internalMode == inMode )
00700     return;
00701 
00702   commLock lock( *this);
00703 
00704   if      ( sharedAttr->internalMode==command_mode && inMode==data_mode ) {
00705     serialPort->tty_write( SwitchToDataMode_Cmd);
00706     sharedAttr->internalMode = inMode;
00707   }
00708   else if ( sharedAttr->internalMode==data_mode && inMode==command_mode ) {
00709     serialPort->tty_write( SwitchToCommandMode_Cmd);
00710     sharedAttr->internalMode = inMode;
00711   }
00712   else {
00713     throw internal_error( "Illegal mode transition detected", __FILE__, __LINE__);
00714   }
00715 }
00716 
00717 
00718 
00719 
00720 //=====================================================================================
00721 //
00722 // misc methods
00723 //
00724 
00725 LOW_linkDS2480B::SPUD_val_t LOW_linkDS2480B::strongPullup_2_SPUD_val( const strongPullup_t inStrongPullup)
00726 {
00727   switch( inStrongPullup ) {
00728     case pullUp_16_4:  return SPUD_16_4;
00729     case pullUp_65_5:  return SPUD_65_5;
00730     case pullUp_131:   return SPUD_131;
00731     case pullUp_262:   return SPUD_262;
00732     case pullUp_524:   return SPUD_524;
00733     case pullUp_1048:  return SPUD_1048;
00734     default:           throw internal_error( "Unknown strongPullup value detected", __FILE__, __LINE__);
00735   }
00736 }
00737 
00738 
00739 void LOW_linkDS2480B::initCmdAvailTable()
00740 {
00741   cfgCmdAvailable[PullDownSlewRate_cfgCmd][normal_speed]         = false;
00742   cfgCmdAvailable[PullDownSlewRate_cfgCmd][flexible_speed]       = true;
00743   cfgCmdAvailable[PullDownSlewRate_cfgCmd][overdrive_speed]      = false;
00744 
00745   cfgCmdAvailable[ProgPulseDuration_cfgCmd][normal_speed]        = true;
00746   cfgCmdAvailable[ProgPulseDuration_cfgCmd][flexible_speed]      = true;
00747   cfgCmdAvailable[ProgPulseDuration_cfgCmd][overdrive_speed]     = true;
00748 
00749   cfgCmdAvailable[StrongPullupDuration_cfgCmd][normal_speed]     = true;
00750   cfgCmdAvailable[StrongPullupDuration_cfgCmd][flexible_speed]   = true;
00751   cfgCmdAvailable[StrongPullupDuration_cfgCmd][overdrive_speed]  = true;
00752 
00753   cfgCmdAvailable[Write1LowTime_cfgCmd][normal_speed]            = false;
00754   cfgCmdAvailable[Write1LowTime_cfgCmd][flexible_speed]          = true;
00755   cfgCmdAvailable[Write1LowTime_cfgCmd][overdrive_speed]         = false;
00756 
00757   cfgCmdAvailable[SampleOffsetWrite0Rec_cfgCmd][normal_speed]    = false;
00758   cfgCmdAvailable[SampleOffsetWrite0Rec_cfgCmd][flexible_speed]  = true;
00759   cfgCmdAvailable[SampleOffsetWrite0Rec_cfgCmd][overdrive_speed] = false;
00760 
00761   cfgCmdAvailable[LoadSensorThreshold_cfgCmd][normal_speed]      = true;
00762   cfgCmdAvailable[LoadSensorThreshold_cfgCmd][flexible_speed]    = true;
00763   cfgCmdAvailable[LoadSensorThreshold_cfgCmd][overdrive_speed]   = true;
00764 
00765   cfgCmdAvailable[RS232BaudRate_cfgCmd][normal_speed]            = true;
00766   cfgCmdAvailable[RS232BaudRate_cfgCmd][flexible_speed]          = true;
00767   cfgCmdAvailable[RS232BaudRate_cfgCmd][overdrive_speed]         = true;
00768 }
00769 

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