//
// Copyright (c) 1999-2004 Darius Rad
//
// This file is part of the OpenOtto project.
//
// OpenOtto 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 2 of the License, or
// (at your option) any later version.
//

/// \file
/// \brief Diagnostic trouble code routines


#include <linux/types.h>
#include <assert.h>
#include <stdio.h>

#include <otto/otto.h>
#include <otto/packet.h>
#include <otto/data.h>



static const char _ID_[] __attribute__ ((unused)) =
"$Id: dtc.c,v 1.6 2004/07/05 23:25:06 alpha Exp $";


/// \todo use DTC character PRN
int
otto_dtc_tostring(
  union otto_dtc *dtc,
  char *str,
  size_t size
)
{
  assert(dtc != NULL);
  assert(str != NULL);
  assert(size >= 6);

  snprintf(
    str,
    size,
    "%c%x%x%x%x",
    (dtc->dtc.des == OTTO_DTC_POWERTRAIN) ? 'P' :
    (dtc->dtc.des == OTTO_DTC_CHASSIS) ? 'C' :
    (dtc->dtc.des == OTTO_DTC_BODY) ? 'B' :
    (dtc->dtc.des == OTTO_DTC_NETWORK) ? 'U' :
    'x',
    dtc->dtc.code1000,
    dtc->dtc.code100,
    dtc->dtc.code10,
    dtc->dtc.code1
  );

  return(0);
}


int
otto_dtclookup(
  union otto_dtc *dtc,
  char *desc,
  size_t size
)
{
  assert(dtc != NULL);
  assert(desc != NULL);

  char dtcstr[6];

  otto_dtc_tostring( dtc, dtcstr, sizeof(dtcstr) );

  // match dtcstr to id in XML db
  snprintf(
    desc,
    size,
    "NYI"
  );

  return(0);
}
