/*
 *  File: brick_log.c
 *  Date: 30 Oct 2001
 *  Acct: Albert Huang (ashuang)
 *  Desc: demonstrates data logging functionality
 *
 *  BUGS: kernel support for data logging was *hacked* in
 *	  this means that it was not done in proper form or 
 *	  style, and is likely to cause a program to crash
 *	  this may or may not be fixed in the future.
 *	  actually, in all likelihood, using the datalog will
 *	  probably cause your RCX to crash, so use it at
 *	  your own risk
 */

/* use getlog (probably /course/cs148/bin/getlog) to retrieve the log
 * file from an RCX brick
 */

#include <log.h>
#include <conio.h>
#include <unistd.h>

int main()
{
  int i;

  /* must declare how large the log file is going to be (in bytes) before we can use it */
  init_log(255);

  /* lprintf is the command we use to print to the log.  Treat it like a normal printf */
  lprintf("123456789012345678901234567890123456789012345678901234567890\n");

  lprintf("!\n");

  for (i=0; i<10; i++)
    {
      lprintf("testing %d\n", i);
    }

  lprintf("!");

  /* de-allocate the log */
  destroy_log();

  /* create a bigger log */
  init_log(5000);

  for (i=0; i<10; i++)
    {
      lprintf("%d - abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU", i);
      lprintf("\n     VWXYZ0123456789!@#$%^&*()-=[];',./<>?:\"{}_+|`~\n");
    }

  cputs("done");

  /* don't destroy the log after the program terminates.  Let the kernel 
     handle it (kinda..)
  */

  return 0;
}
