//
// 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 Example dispatcher routine for received packets


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


static const char _ID_[] __attribute__ ((unused)) =
"$Id: dispatch.c,v 1.4 2004/07/07 16:14:01 alpha Exp $";


void
dispatch(
  union otto_packet pkt,  ///< raw network packet
  int flags  ///< mode flags for dispatch (single or three byte header, others?)
)
{

}

void
dispatch_single(
  union otto_packet pkt,
  int size
)
{

}

void
dispatch_three(
  union otto_packet pkt,
  int size
)
{
  if( pkt->consol1.hdr.h == OTTO_PKTHDRCS_ONEBYTE )
  {
    // consolidated single byte header
    unsigned char id;

    id = pkt->consol1.hdr.id_lo | (pkt->consol1.hdr.id_hi << 4);
  }
  else
  {
    // three byte header

    if( pkt->consol3.first.y == OTTO_PKTHDR_FUNCTIONAL )
    {
      // functional addressing

      if(
	 (pkt->consol3.func.target.w == OTTO_FUNCADR_TGTADR_STATUS) &&
	 (pkt->consol3.func.target.id == (OTTO_FUNCADR_LEGISLATED >> 1) )
      )
      {
	// diagnostic test modes

	case(pkt->consol3.func.data.fmt4.mode)
	{
	  case 0x01:  // request current powertrain diagnostic data
	    break;

 	  case 0x02:  // request powertrain freeze frame data
	    break;

	  // etc.

	}
      }
      else
      {
	// other functional responses

      }
    }
    else
    {
      // physical addressing

    }
  }
}

