driver/src/sick_scan_common.cpp
std::string sick_scan::SickScanCommon::replyToString(const std::vector<unsigned char> &reply)
  {
    std::string reply_str;
    std::vector<unsigned char>::const_iterator it_start, it_end;
    int binLen = this->checkForBinaryAnswer(&reply);
    if (binLen == -1) // ASCII-Cmd
    {
      it_start = reply.begin();
      it_end = reply.end();
    }
    else
    {
      it_start = reply.begin() + 8; // skip header and length id
      it_end = reply.end() - 1; // skip CRC
    }
    bool inHexPrintMode = false;
    for (std::vector<unsigned char>::const_iterator it = it_start; it != it_end; it++)
    {
      // inHexPrintMode means that we should continue printing hex value after we started with hex-Printing
      // That is easier to debug for a human instead of switching between ascii binary and then back to ascii
      if (*it >= 0x20 && (inHexPrintMode == false)) // filter control characters for display
      {
        reply_str.push_back(*it);
      }
      else
      {
        if (binLen != -1) // binary
        {
          char szTmp[255] = {0};
          unsigned char val = *it;
          inHexPrintMode = true;
          sprintf(szTmp, "\\x%02x", val);
          for (size_t ii = 0; ii < strlen(szTmp); ii++)
          {
            reply_str.push_back(szTmp[ii]);
          }
        }
      }

    }
    return reply_str;
  }
/*!
  \brief convert ASCII or binary reply to a human readable string
  \param reply datablock, which should be converted
  \return human readable string (used for debug/monitoring output)
  */
\brief convert ASCII or binary reply to a human readable string
\param reply datablock, which should be converted
\return human readable string (used for debug/monitoring output)
\ brief convert ASCII or binary reply to a human readable string \ param reply datablock which should be converted \ return human readable string ( used for debug / monitoring output )
std::string sick_scan::SickScanCommon::replyToString(const std::vector<unsigned char> &reply)
  {
    std::string reply_str;
    std::vector<unsigned char>::const_iterator it_start, it_end;
    int binLen = this->checkForBinaryAnswer(&reply);
    if (binLen == -1) 
    {
      it_start = reply.begin();
      it_end = reply.end();
    }
    else
    {
      it_start = reply.begin() + 8; 
      it_end = reply.end() - 1; 
    }
    bool inHexPrintMode = false;
    for (std::vector<unsigned char>::const_iterator it = it_start; it != it_end; it++)
    {
      if (*it >= 0x20 && (inHexPrintMode == false)) 
      {
        reply_str.push_back(*it);
      }
      else
      {
        if (binLen != -1) 
        {
          char szTmp[255] = {0};
          unsigned char val = *it;
          inHexPrintMode = true;
          sprintf(szTmp, "\\x%02x", val);
          for (size_t ii = 0; ii < strlen(szTmp); ii++)
          {
            reply_str.push_back(szTmp[ii]);
          }
        }
      }
    }
    return reply_str;
  }
std :: string sick_scan :: SickScanCommon :: replyToString ( const std :: vector < unsigned char > & reply ) { std :: string reply_str ; std :: vector < unsigned char > :: const_iterator it_start , it_end ; int binLen = this -> checkForBinaryAnswer ( & reply ) ; if ( binLen == -1 ) { it_start = reply . begin ( ) ; it_end = reply . end ( ) ; } else { it_start = reply . begin ( ) + 8 ; it_end = reply . end ( ) - 1 ; } bool inHexPrintMode = false ; for ( std :: vector < unsigned char > :: const_iterator it = it_start ; it != it_end ; it ++ ) { if ( * it >= 0x20 && ( inHexPrintMode == false ) ) { reply_str . push_back ( * it ) ; } else { if ( binLen != -1 ) { char szTmp [ 255 ] = { 0 } ; unsigned char val = * it ; inHexPrintMode = true ; sprintf ( szTmp , " \\ " , val ) ; for ( size_t ii = 0 ; ii < strlen ( szTmp ) ; ii ++ ) { reply_str . push_back ( szTmp [ ii ] ) ; } } } } return reply_str ; }
\brief convert ASCII or binary reply to a human readable string
\param reply datablock, which should be converted
\return human readable string (used for debug/monitoring output)
\ brief convert ASCII or binary reply to a human readable string \ param reply datablock which should be converted \ return human readable string ( used for debug / monitoring output )
// ASCII-Cmd // skip header and length id // skip CRC // inHexPrintMode means that we should continue printing hex value after we started with hex-Printing // That is easier to debug for a human instead of switching between ascii binary and then back to ascii // filter control characters for display // binary