// @(#) $Header: /usr/local/scalawags_cvs/Scalawags/Frc2006/supportfuncs.c,v 1.44 2006/02/17 20:09:14 abrown Exp $
/***********************************************************************
  * Copyright (C) 2003  Allen Brown
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the
  *   Free Software Foundation, Inc.
  *   59 Temple Place, Suite 330
  *   Boston, MA  02111-1307  USA
  * 
  * To contact the author of this software:
  *   Allen Brown
  *   PO Box J
  *   Corvallis, OR
  * 
  *   http://brown.armoredpenguin.com/~abrown/contact.html
  ***********************************************************************
  * This source file provides a grab bag of small functions that we find
  * useful in implementing the robot code.
  ***********************************************************************/
#define EXTERN extern
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  #include <unistd.h>
  #include <termios.h>
#endif
#if defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  #include "msgxfer.h"
#endif
#if defined(FRC_NOCOPROCESSOR) || defined(FRC_COPROCESSOR)
  #define ROM rom
  #define INLINE
#else
  #define ROM
  #define INLINE inline
#endif
#include "p18f8722.h"
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "user_routines_alt.h"
#include "supportfuncs.h"

void DisableBot(void)
{
  txdata.rc_pwm01 = 127;
  txdata.rc_pwm02 = 127;
  txdata.rc_pwm03 = 127;
  txdata.rc_pwm04 = 127;
  txdata.rc_pwm05 = 127;
  txdata.rc_pwm06 = 127;
  txdata.rc_pwm07 = 127;
  txdata.rc_pwm08 = 127;
  txdata.rc_pwm09 = 127;
  txdata.rc_pwm10 = 127;
  txdata.rc_pwm11 = 127;
  txdata.rc_pwm12 = 127;
  txdata.rc_pwm13 = 127;
  txdata.rc_pwm14 = 127;
  txdata.rc_pwm15 = 127;
  txdata.rc_pwm16 = 127;
} // DisableBot()

// -------------------------------------------------------------------

static int errorcount=0, warningcount=0, notecount=0;

void reportstart( ROM const char *file, const int line,
		  int type, ROM const char *mesg )
{
  // extern int errorcount, warningcount, notecount;
  char *typestrings[] = {"UNDEF","ERROR","WARNING","NOTE","UNDEF"};
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  switch(type)
  {
    case ERROR:
      errorcount++;
      break;
    case WARNING:
      warningcount++;
      break;
    case NOTE:
      notecount++;
      break;
    default:
      errorcount++;
      printf("%s:%d: internal error. type=%d.\n",__FILE__,__LINE__,type);
      return;
  }
  printf("%s %s:%d: %s", typestrings[type], file, line, mesg);
#endif
  return;
} // reportstart()

// -------------------------------------------------------------------
INLINE void reportint( const int number )
{
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  printf("%d", number);
#endif
  return;
} // reportint()

// -------------------------------------------------------------------
INLINE void reporttext( ROM const char *mesg )
{
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  printf("%s", mesg);
#endif
  return;
} // reporttext()

// -------------------------------------------------------------------
INLINE void reportend( ROM const char *mesg )
{
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  printf("%s\n", mesg);

  fflush(stdout);
#endif
  return;
} // reportend()

// -------------------------------------------------------------------
INLINE int reportsum( )
{
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
    || defined(ABSIMULATION_COPRSIM) \
    || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
  // extern int errorcount, warningcount, notecount;
  printf("reportsum: errors=%d, warnings=%d, notes=%d.\n",
    errorcount, warningcount, notecount);
  fflush(stdout);
#endif
  return errorcount;
} // reportsum()

// -------------------------------------------------------------------
INLINE int abs(int inp)
{
  return(inp<0 ? -inp : inp);
}

// -------------------------------------------------------------------
/*
 * $Log: supportfuncs.c,v $
 * Revision 1.44  2006/02/17 20:09:14  abrown
 * Don't initialize rightspeed and leftspeed.  Those are user specific vars.
 *
 * Revision 1.43  2006/02/08 04:40:10  abrown
 * Declare remaining strings as ROM type qualifier.
 *
 * Revision 1.42  2006/02/05 18:48:24  abrown
 * Make functions inline.  Use ROM keyword for strings on the FRC.
 *
 * Revision 1.41  2005/12/24 01:36:49  abrown
 * Split the old target ABSIMULATION_COPROCESSOR into two.  Now
 * ABSIMULATION_COPROCESSOR includes a physical coprocessor.  The new
 * target, ABSIMULATION_COPRSIM, includes a simulated coprocessor.
 *
 * Revision 1.40  2005/12/12 00:24:50  abrown
 * Remove reference to my old agilent email address.
 *
 * Revision 1.39  2005/05/14 03:31:40  go
 * Fixing up msgxfer linkages and general conditionals for different version.
 *
 * Revision 1.38  2005/05/13 23:56:33  abrown
 * Improve comments.  Remove some scruff.
 *
 * Revision 1.37  2005/04/30 17:49:10  abrown
 * First cut at changing obsolete defines to the new ones.
 *
 * Revision 1.36  2005/02/21 01:40:32  jeff
 * Attempted to get percent_exp working
 *
 * Revision 1.35  2005/02/20 03:38:43  abrown
 * Get rid of ^m's.
 *
 * Revision 1.34  2005/02/20 00:28:38  jeff
 * Removed external declaration of rightspeed and leftspeed, included user_routines.h
 *
 * Revision 1.33  2005/02/14 00:31:53  jeff
 * Ifdefed guts of report**** functions to be compiled only if ABSIMULATION is defined, camera code working in user_routines.c
 *
 * Revision 1.32  2005/02/13 20:18:56  abrown
 * The merge effort between FRC and simulator in main.  It doesn't
 * work on the FRC yet.  But it got checked in anyway, so now I
 * need to make it work quickly.
 *
 * Revision 1.31  2005/02/09 05:18:26  go
 * msgxfer modifications for Frc message compatibility.
 * Serial Read interrupt function for TTL port
 * Ring buffer handling for input port
 *
 * Revision 1.30  2005/02/05 02:43:30  jeff
 * Modified to compile under MPLab (fixed misplaced ifndefs and endifs)
 * Added comment about pwm position on robot
 *
 * Revision 1.29  2005/01/31 23:17:45  go
 * Added "set_raw_mode" function to supportfuncs
 * Added call to "set_raw_mode" to main and coprocessor
 *
 * Revision 1.28  2005/01/31 06:02:52  abrown
 * Fix problems pointing to msg_reader/msg_writer.
 *
 * Revision 1.27  2005/01/30 22:23:02  abrown
 * Merge in changes to msgxfer.  Unfortunately it now core dumps.
 * And there are some odd warnings.
 *
 * Revision 1.26  2005/01/25 04:13:18  jeff
 * Modified to compile in MPLAB; fixed includes.
 *
 * Revision 1.25  2005/01/09 05:15:00  abrown
 * Update to 2005 default code base. -- Allen Brown
 *
 * Revision 1.24  2004/12/29 05:40:21  abrown
 * Cleaned up a warning.
 *
 */
// -------------------------------------------------------------------


syntax highlighted by Code2HTML, v. 0.9.1