Ejemplo n.º 1
0
/*----------------------------------------------------------------------------*
*  NAME
*      SetImageFileName
*
*  DESCRIPTION
*      The file name of the image to be transferred.
*---------------------------------------------------------------------------*/
bool ImageFileHandler::OpenImageFile()
{
    bool fileOpened = false;
    if(mImgFile != NULL)
    {
        fclose(mImgFile);
        mImgFile = NULL;
    }

    FILE *imgFile = NULL;              // The image file to transfer
    // Try to open the specified file
    if(0 == fopen_s(&imgFile, mAsciiFileName, "rb+"))
    {
       fclose(imgFile);
       //if(fopen_s(&mImgFile, "OTATemp.img", "w+")) == 0)
       DeleteFileA(mTempFileName);
       CopyFileA(mAsciiFileName, mTempFileName, FALSE);

       if(0 == fopen_s(&mImgFile, mTempFileName, "rb+"))
       {
          fileOpened = true;

          // Try to determine the length of the specified file
          mImgFileSize = readFileLength(mImgFile);

          ResetTransfer();
       }
    }
    return (fileOpened && (mImgFileSize > 0));
}
Ejemplo n.º 2
0
A pString_Connection::readBurst(void)
{
  ipcWarn(wrnlvl(),"%t pString_Connection::readBurst\n");
  MSBuffer bbuff;
  A d,z=(A)0;
  I slen=readFileLength(),slen1,n,s,count;
  if(-1==slen)R(A)0;
  if(0==slen)
  {
    static char fmt[]="\343 IPC warning: pA::ReadBurst: read event with no data [%d]\n";
    Warn(fmt, handle());
  }

  /* create buff to hold it.  Fill buffer */
  slen1=slen?slen:4;
  bbuff.minofbuffer(mab(slen1));
  bbuff.maxofbuffer(bbuff.minofbuffer()+slen1);
  bbuff.reset();
  if(0>(n=readTheBuffer(&bbuff,slen1))) {mfbuffer(&bbuff); R(A)0;}
  if(0==n&&0==slen) {turnInReadOff(); mfbuffer(&bbuff); R(A)0;}

  d=getAobjFromBuffer(&bbuff);
  if((A)0==d){mfbuffer(&bbuff); R(A)0;}

  // determine how many more complete A-objects lie in bbuff
  count=1;
  for(C *cp=bbuff.get();cp<bbuff.put();cp+=s)
  {
    s=longAt(cp);
    cp+=sizeof(long);
    if(s<=bbuff.put()-cp)++count;
  }

  // create result
  z=gv(Et,count);
  for(int i=0;i<count;++i)z->p[i]=(I)aplus_nl;
  int idx=0;
  z->p[idx++]=(I)d;

  // retrieve additional A-objects from bbuff, fill in z
  while(idx<count)
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0==d)break;
    z->p[idx++]=(I)d;
  }
  if(idx<count)
  {
    ipcWarn(wrnlvl(),"%t burst mode aborted.  Possible data loss.\n");
  }

  // run once more to clear out bbuff and move partial object into connection
  // buffers
  if(bbuff.get()==bbuff.put())turnInReadOff();
  else
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0!=d || bbuff.get()!=bbuff.put())
    {
      ipcWarn(wrnlvl(),"%t burst buffer not cleared: %d %d %d\n",
	    d,bbuff.get(),bbuff.put());
    }
  }

  // free bbuff;
  mfbuffer(&bbuff);

  return z;     
}