/*
 * Copyright 2015 Mario Richter, Peter Stephan
 * This file is part of NeMo.
 *
 * NeMo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NeMo 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 NeMo.  If not, see <http://www.gnu.org/licenses/>.
 */

/*!
 * \file err.c
 * \ingroup	err
 * \brief	Errorhandling
 *
 */

/*!
 * \defgroup err Routinen zum Errorhandling
 */

#include "main.h"

/* ********************************************************************* */
/* Error-Messages */

const char errMsgs[MAX_ERRNO][ERRMSG_LEN] =
  { { "OK" },
    { "unknown command" },
    { "bad parameter" },
    { "too much params" },
    { "eeprom write error" },
    { "no light program" },
    { "no program active" }
  };


/* ********************************************************************* */
/* Error-Handling */

/*!
 * \ingroup err
 * \brief Error-Handler-Funktion
 *
 * Diese Routine gibt eine standardisierte Fehlermeldung aus, definiert über
 * die angegebene Fehlernummer (0 = OK, >=1 = Fehler). Die Fehlernumemrn und
 * die zugehörigen Meldungen sind im Array errMsgs definiert.
 */

void errMsg(uint8_t ind, uint8_t errno)
{
  if(errno == 0)
  {
    sendLine(ind, (char *)errMsgs[0]);
  }
  else if(errno < MAX_ERRNO)
  {
    sendStringP(ind, PSTR("ERR: "));
    sendLine(ind, (char *)errMsgs[errno]);
  }
  else
  {
    sendLineP(ind, PSTR("ERR: Unknown Error Number."));
  }
}


