Пример #1
0
void LOW_devDS2406::readMemUniversal( const uint16_t inStartAddr, byteVec_t &outBytes, 
                                      const uint16_t inMaxLen, const owCommand_t inCommand) const
{
  if ( inStartAddr >= inMaxLen )
    throw devDS2406_error( "Illegal address to read", __FILE__, __LINE__);
  
  if ( inStartAddr+outBytes.size() > inMaxLen )
    throw devDS2406_error( "Too many bytes to read", __FILE__, __LINE__);

  linkLock  lock( *this);
    
  byteVec_t  sendBytes = byteVec_t( 3);
  sendBytes[0] = inCommand;
  sendBytes[1] = inStartAddr&0xff;
  sendBytes[2] = inStartAddr>>8;
  
  cmd_MatchROM();

  getLink().writeData( sendBytes);
  getLink().readData( outBytes);
  
  if ( inStartAddr+outBytes.size() == inMaxLen ) { // read to end of mem => CRC16 checksumm is available
    uint16_t expectedCrc16 = 0x0000;
    expectedCrc16 |= (getLink().readDataByte() ^ 0xff);      // NOTE: CRC bytzes are sent _inverted_!
    expectedCrc16 |= (getLink().readDataByte() ^ 0xff) << 8; // NOTE: CRC bytzes are sent _inverted_!
    if ( LOW_helper_CRC::calcCRC16( outBytes, LOW_helper_CRC::calcCRC16( sendBytes)) != expectedCrc16 )
      throw LOW_helper_CRC::crc_error( "DS2406 - CRC error in read operation", __FILE__, __LINE__);
  }

  //getLink().resetBus();
}
Пример #2
0
void LOW_link::readData( byteVec_t &outBytes, const strongPullup_t inPullup)
{
  commLock lock( *this);

  byteVec_t  sendBytes = byteVec_t( outBytes.size(), 0xff);
  byteVec_t  recBytes;

  recBytes = touchBlock( sendBytes, inPullup);
  std::copy( recBytes.begin(), recBytes.end(), outBytes.begin());
}
Пример #3
0
byteVec_t LOW_link::touchBlock( const byteVec_t &inBytes, const strongPullup_t inPullup)
{
  if ( inBytes.size() == 0 ) return byteVec_t( 0);

  commLock lock( *this);

  byteVec_t retVal = byteVec_t( inBytes.size());

  for( unsigned int i=0; i<inBytes.size()-1; i++) {
    retVal[i] = touchByte( inBytes[i], pullUp_NONE);
  }
  retVal[inBytes.size()-1] = touchByte( inBytes[inBytes.size()-1], inPullup);
  
  return retVal;
}
Пример #4
0
void LOW_link::writeData( const byteVec_t &inSendBytes, const strongPullup_t inPullup)
{
  commLock lock( *this);

  byteVec_t readVec = touchBlock( inSendBytes, inPullup);

  for( unsigned int i=0; i<inSendBytes.size(); i++)
    if ( readVec[i] != inSendBytes[i] ) {
      throw comm_error( "Response not equal to sent byte", __FILE__, __LINE__);
    }
}
Пример #5
0
void LOW_devDS2406::cmd_WriteStatus( const uint8_t inStartAddr, const byteVec_t &inWriteBytes) const
{
  if ( inStartAddr+inWriteBytes.size() > 8 )
    throw devDS2406_error( "Too many bytes to write", __FILE__, __LINE__);
  
  if ( inStartAddr==0x05 || inStartAddr==0x06 )
    throw devDS2406_error( "Address not writeable", __FILE__, __LINE__);
  
  // not yet supported registers
  if ( /*inStartAddr>=0x00 &&*/ inStartAddr<=0x04 )
    throw devDS2406_error( "Access to address not supported in this version", __FILE__, __LINE__);
  
  linkLock  lock( *this);

  // only address 7 remains, i.e. address must be 7 and length of inWriteBytes is 1
  
  byteVec_t  sendBytes = byteVec_t( 4);
  sendBytes[0] = WriteStatus_COMMAND;
  sendBytes[1] = inStartAddr&0xff;
  sendBytes[2] = inStartAddr>>8;
  sendBytes[3] = inWriteBytes[0];
  
  cmd_MatchROM();

  getLink().writeData( sendBytes);
    
  uint16_t expectedCrc16 = 0x0000;
  expectedCrc16 |= (getLink().readDataByte() ^ 0xff);      // NOTE: CRC bytzes are sent _inverted_!
  expectedCrc16 |= (getLink().readDataByte() ^ 0xff) << 8; // NOTE: CRC bytzes are sent _inverted_!
  if ( LOW_helper_CRC::calcCRC16( sendBytes) != expectedCrc16 )
    throw LOW_helper_CRC::crc_error( "CRC error in write operation", __FILE__, __LINE__);

  //getLink().writeData( static_cast<uint8_t>(0xff));

  // skip validation byte
  //uint8_t validationByte = getLink().readDataByte();

  //getLink().resetBus();
}