Example #1
0
static int writeByte(U8 b) {
  outbuff[outPoint ++] = b;
  if(outPoint == BUFFSIZE) {
    flushOut();
  }
  return 0;
}
Example #2
0
void Esp8266<T>::sendCommand(const String &command) const
{
  flushIn();
  _serial.print(command);
  _serial.print(F("\r\n"));
  flushOut();
}
/************************************************************************
Function  : Put
Parameters: S    pointer to bytes being put into output buffer
            Len  number of bytes to be put in output buffer
Returns   : nothing

Put places bytes into OutBuffer so they may be later flushed out into
the standard output stream.
************************************************************************/
void Put(char *S,int Len)
{
   int i;

   for (i = 0; i < Len; i++)
   {
      *CurOutPtr++ = S[i];                   /* place byte in buffer */
      if (CurOutPtr >= OutBuffer+BufSize)    /* if buffer overflows */
         flushOut(BufSize);                  /* flush the buffer */
   }
}
/************************************************************************
Function  : Main

Returns   : zero on successful execution
               3 on an error condition

The main routine allocates memory for the input and output buffers.
Characters are then read from the input buffer building the line buffer
that will be sent to the filter processor.  Lines are read and filtered
until the end of input is reached.
************************************************************************/
int main(void)
{
   char c;
   int i, Type;
   unsigned long core;

   setmode(1,O_BINARY);               /* set standard out to binary mode */
   NoLines = FALSE;                   /* No lines have been read yet */
   core = farcoreleft();              /* get available memory */
   if (core > 64000U)                 /* limit buffers to total of 64000 */
      BufSize = 64000U;               /* bytes */
   else
      BufSize = (unsigned)core;
   if ((InBuffer = malloc(BufSize)) == NULL) /* allocate buffer space */
      exit(3);                        /* abort if error occured */
   CurInPtr = InBuffer;               /* split buffer */
   BufSize = BufSize/2;               /* between input and output buffers */
   OutBuffer = InBuffer + BufSize;
   CurOutPtr = OutBuffer;
   LinePtr = Line;                    /* set line buffer pointer */
   CurBufLen = 0;                     /* and reset buffer size to zero */
   Put(PipeId,PipeIdLen);             /* Identify process to message window */
   while ((c = NextChar()) != 0)      /* read characters */
   {
      if ((c == 13) || (c == 10))     /* build line until new line is seen */
      {
         *LinePtr = 0;
         ProcessLine(Line);           /* then filter the line */
         LinePtr = Line;
      }
      /* characters are added to line only up to 132 characters */
      else if ((FP_OFF(LinePtr) - FP_OFF(&Line)) < 132)
      {
         *LinePtr = c;
         LinePtr++;
      }
   }
   *LinePtr = 0;
   ProcessLine(Line);                  /* filter last line */
   if (NoLines)                        /* if no lines */
   {
      Type = MsgNewLine;               /* send something to the */
      i = 1;                           /* message window */
      Put((char *)&Type,1);
      Put((char *)&i,2);
      Put((char *)&i,2);
      Put(" ",2);
   }
   EndMark = MsgEoFile;                /* indicate end of input to */
   Put(&EndMark,1);                    /* message window */
   flushOut((unsigned)(CurOutPtr-OutBuffer));  /* flush out remaining buffer */

   return  0;                          /* everything went ok */
}
Example #5
0
bool Esp8266<T>::send(unsigned char channelId, const char *bytes, const unsigned length) const
{
  String cmd = buildSetCommand(F("CIPSEND"), String(channelId), length);
  sendCommand(cmd);

  // Is module ready to get data?
  if (!wasCommandSuccessful())
    return false;

  // Write data
  _serial.write(bytes, length);
  flushOut();

  return wasCommandSuccessful();
}
/***********************************************************************
Function  : main

Returns   : zero for successful execution
	    3    if an error is encountered

The main routine allocates buffers for the input and output buffer.
Characters are then read from the input buffer building the line buffer
that will be sent to the filter processor.  Lines are read and filtered
until the end of input is reached.
***********************************************************************/
int main( void )
{
   char c;
   unsigned long core;

   setmode(1,O_BINARY);               /* set output stream to binary mode */
   core = farcoreleft();
   if (core > 64000U)
      BufSize = 64000U;
   else BufSize = (unsigned)core;     /* get available memory */
                                      /* stay under 64K */
   if ((CurInPtr = malloc(BufSize)) == NULL) /* allocate buffer space */
      exit(3);
#if 0
   processor = NULL;                  /* set current processor to none */
#endif

   InBuffer = CurInPtr;               /* input buffer is first half of space */
   BufSize = BufSize/2;               /* output buffer is 2nd half */
   OutBuffer = InBuffer + BufSize;
   CurOutPtr = OutBuffer;             /* set buffer pointers */
   LinePtr = Line;
   CurBufLen = 0;
   Put(PipeId,PipeIdLen);             /* send ID string to message window */
   while ((c = NextChar()) != 0)      /* read characters */
   {
      if ((c == 13) || (c == 10))     /* build until line end */
      {
         *LinePtr = 0;
         ProcessLine(Line);           /* filter the line */
         LinePtr = Line;
      }
      /* characters are added to buffer up to 132 characters max */
      else if ((FP_OFF(LinePtr) - FP_OFF(&Line)) < 132)
      {
         *LinePtr = c;                /* add to line buffer */
         LinePtr++;
      }
   }
   *LinePtr = 0;
   ProcessLine(Line);                 /* filter last line */
   EndMark = MsgEoFile;
   Put(&EndMark,1);                   /* indicate end of input to
                                         the message window */
   flushOut((unsigned)(CurOutPtr-OutBuffer));     /* flush the buffer */
   return 0;                          /* return OK */
}
Example #7
0
File: debug.c Project: fmccabe/cafe
void dC(termPo w) {
  outMsg(logFile, "%,*T\n", displayDepth, w);
  flushOut();
}
Example #8
0
int main(int argc, char **argv) {
  PHASH freq = NewHash();
  int freqfid, codefid;
  int nrSource, delta;
  double clk;
  int count = 0;

  INDATA srcFile, compFile;
  
  /* Must be passed the name of a file to compress */
  if(argc < 2) {
    printf("Must give a file to compress\n");
    exit(1);
  }
  TIMESTART(clk);

  initLFIOFile(&srcFile, argv[1]);
  
  /* Read the file, 2 bytes at a time and create the frequency table */
  nrSource = 0;
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    nrSource += 2;
    bumpFrequency(freq, wrd);
  }
  finishIOFile(&srcFile);
  printf("Read %d bytes\n", nrSource);
  /* Open the code and frequency files */
  freqfid = CREAT("huffman.freq");
  codefid = CREAT("huffman.code");
  compressfid = CREAT("huffman.compressed");
  if(freqfid < 0 || codefid < 0 || compressfid < 0) {
    ERROR0(1, "Cannot create frequency and code files\n");
  }
  createCompressTables(freq, freqfid, codefid);
  close(freqfid); close(codefid);
  FreeHash(freq);
  
  /* Now read again and compress */
  initCompressor("huffman.code");
  initLFIOFile(&srcFile, argv[1]);
  outPoint = 0; written = 0;
  startCompress(&writeByte);
  /* Read the file, 2 bytes at a time and compress */
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    writeCompressedSymbol(wrd);
  }
  endCompress();
  flushOut();
  close(compressfid);
  finishIOFile(&srcFile);

  /* Now decompress and compare */
  for(count=0;count<30;count++) {
    initLFIOFile(&compFile, "huffman.compressed");
    initLFIOFile(&srcFile, argv[1]);
    startDecompress();
    delta = nrSource;
    while(delta > 0) {
      int comp = fetchCompressedSymbol(&compFile);
      int src  = fetchWordLE(&srcFile);
      if(src != comp) {
        ERROR3(-1, "Src(%04x) != Comp(%04x) (at offset %d)\n",
               src, comp, nrSource - delta);
      }
      delta -= 2;
    }
    endDecompress(&compFile);
    finishIOFile(&srcFile); finishIOFile(&compFile);
  }
  finalizeCompressor();


  TIMESTOP(clk);
  
  // sm: according to my man pages, the 'l' flag doesn't apply
  // to the 'f' format, which is always a double argument
  printf("Source %d bytes. Compressed %d bytes. Ratio: %5.2f\n",
         nrSource, written, (double)nrSource / (double)written);
  printf("Run hufftest in %8.3fms\n", clk / 1000.0);
  exit (0);
  return 0;
}
Example #9
0
void Esp8266<T>::flush() const
{
  flushOut();
  flushIn();
}