OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [RspPacket.cpp] - Diff between revs 63 and 462

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 63 Rev 462
Line 33... Line 33...
#include <cstdio>
#include <cstdio>
 
 
#include "RspPacket.h"
#include "RspPacket.h"
#include "Utils.h"
#include "Utils.h"
 
 
 
 
using std::ostream;
using std::ostream;
using std::cerr;
using std::cerr;
using std::dec;
using std::dec;
using std::endl;
using std::endl;
using std::hex;
using std::hex;
using std::setfill;
using std::setfill;
using std::setw;
using std::setw;
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Constructor
//! Constructor
 
 
//! Allocate the new data buffer
//! Allocate the new data buffer
 
 
Line 58... Line 56...
{
{
  data = new char [_bufSize];
  data = new char [_bufSize];
 
 
}       // RspPacket ();
}       // RspPacket ();
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Destructor
//! Destructor
 
 
//! Give back the data buffer
//! Give back the data buffer
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Line 70... Line 67...
{
{
  delete [] data;
  delete [] data;
 
 
}       // ~RspPacket ()
}       // ~RspPacket ()
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Pack a string into a packet.
//! Pack a string into a packet.
 
 
//! A convenience version of this method.
//! A convenience version of this method.
 
 
Line 85... Line 81...
{
{
  int  slen = strlen (str);
  int  slen = strlen (str);
 
 
  // Construct the packet to send, so long as string is not too big, otherwise
  // Construct the packet to send, so long as string is not too big, otherwise
  // truncate. Add EOS at the end for convenient debug printout
  // truncate. Add EOS at the end for convenient debug printout
  if (slen >= bufSize)
        if (slen >= bufSize) {
    {
 
      cerr << "Warning: String \"" << str
      cerr << "Warning: String \"" << str
                << "\" too large for RSP packet: truncated\n" << endl;
                << "\" too large for RSP packet: truncated\n" << endl;
      slen = bufSize - 1;
      slen = bufSize - 1;
    }
    }
 
 
Line 98... Line 93...
  data[slen] = 0;
  data[slen] = 0;
  len        = slen;
  len        = slen;
 
 
}       // packStr ()
}       // packStr ()
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Get the data buffer size
//! Get the data buffer size
 
 
//! @return  The data buffer size
//! @return  The data buffer size
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int
int RspPacket::getBufSize()
RspPacket::getBufSize ()
 
{
{
  return  bufSize;
  return  bufSize;
 
 
}       // getBufSize ()
}       // getBufSize ()
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Get the current number of chars in the data buffer
//! Get the current number of chars in the data buffer
 
 
//! @return  The number of chars in the data buffer
//! @return  The number of chars in the data buffer
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int
int RspPacket::getLen()
RspPacket::getLen ()
 
{
{
  return  len;
  return  len;
 
 
}       // getLen ()
}       // getLen ()
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Set the number of chars in the data buffer
//! Set the number of chars in the data buffer
 
 
//! @param[in] _len  The number of chars to be set
//! @param[in] _len  The number of chars to be set
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void
void RspPacket::setLen(int _len)
RspPacket::setLen (int  _len)
 
{
{
  len = _len;
  len = _len;
 
 
}       // setLen ()
}       // setLen ()
 
 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//! Output stream operator
//! Output stream operator
 
 
//! @param[out] s  Stream to output to
//! @param[out] s  Stream to output to
//! @param[in]  p  Packet to output
//! @param[in]  p  Packet to output
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ostream &
ostream & operator<<(ostream & s, RspPacket & p)
operator<< (ostream   &s,
 
            RspPacket &p)
 
{
{
  return  s << "RSP packet: " << std::dec << std::setw (3) << p.getLen()
  return  s << "RSP packet: " << std::dec << std::setw (3) << p.getLen()
            << std::setw (0) << " chars, \"" << p.data << "\"";
            << std::setw (0) << " chars, \"" << p.data << "\"";
 
 
}       // operator<< ()
}       // operator<< ()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.