// $Id: vin.h,v 1.4 2004/07/05 23:25:39 alpha Exp $
//
// 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 Header file for OpenOtto VIN functions.


#ifndef _OTTO_VIN_H
#define _OTTO_VIN_H


/// Encoded VIN fields
union otto_vin
{
  char vin[17];  ///< Full VIN
  struct
  {
    char country;  ///< Country
    char manufacturer;  ///< Manufacturer
    char type;  ///< Type or division
    char features[5];  ///< Vehicle features
    char check;  ///< Checksum
    char year;  ///< Year
    char plant;  ///< Assembly plant
    char seq[6];  ///< Sequence number
  }
  fields;  ///< Encoded fields  
};

/// Decoded VIN information
struct otto_vin_decoded
{
  char *vin;  ///< VIN
  char *country;  ///< Country of manufacture
  char *manufacturer;  ///< Manufacturer name (e.g., Ford)
  char *make;  ///< Make or division (e.g., Land Rover)
  char *model;  ///< Model name (e.g., Discovery)
  char *series;  ///< Model variant (e.g., SE)
  char *body;  ///< Body type (number of doors, etc.)
  char *engine;  ///< Engine size and fuel type
  char *transmission;  ///< Transmission, weight class
  char *weight;  ///< Gross vehicle weight rating (GVWR)
  char *emission;  ///< Emission system or rating
  char *restraint;  ///< Restraint system
  char *year;  ///< Model year
  char *plant;  ///< Assembly plant
  char *serial;  ///< Manufacturer sequence number
};

/// \brief VIN checksum calculation.
/// \return Calculated checksum, negative on error
int
otto_vinchecksum(
  union otto_vin *vin  ///< VIN to perform checksum on
);

/// \brief VIN lookup
/// \return Zero on success, error on failure
int
otto_vinlookup(
  union otto_vin *vin,  ///< VIN to perform decode on
  struct otto_vin_decoded *decoded  ///< Decoded VIN field information
);


#endif
