/*@!Encoding:1252*/

variables
{
  enum eKLineInitType
  {
    FIVE_BAUD = 1,
    FAST,
    NONE
  };
  
  enum waitRetValue
  {
    TIMEOUT = 0,
    EVENT_OCCURED = 1,
    TIMEOUT_ERROR = -92
  };
  
  const long kReturnSuccess = 0;
  
  BYTE gKLine_ReportBytes = 0;
  
  dword gMsgChannel = 0;
  
  const long kRetSuccess = 0;
  const long kRetFail = -1;
  
  char cIniTypeNames[4][20] = { "", "5 Baud Init", "Fast Init", "No Init" };
  
  enum eKlineBusErrors
  {
     NO_ERROR                = 0,
     CHECKSUM_ERROR          = 1,
     FMT_ERROR_ONEBYTE       = 2,
     FMT_ERROR_THREEBYTE     = 3,
     LENGTH_ERROR_SHORT      = 4,
     LENGTH_ERROR_LONG       = 5,
     WRONG_TESTER_ADDRESS    = 6,
     WRONG_ECU_ADDRESS       = 7,
     WRONG_ECU_ADDRESS_SC    = 8
  }; 
  
  enum eKLineKeyByte1
  {
    EXTONEBYTEFMT = 0xD5, // Extended Timing - One Byte Header - Format Byte
    EXTONEBYTELEN = 0xD6, // Extended Timing - One Byte Header - Additional Length Byte
    EXTONEBYTEBM  = 0x57, // Extended Timing - One Byte Header - Both Modes
    EXTTSFMT      = 0xD9, // Extended Timing - Target/Source Address - Format Byte
    EXTTSLEN      = 0xDA, // Extended Timing - Target/Source Address - Additional Length Byte
    EXTTSBM       = 0x5B, // Extended Timing - Target/Source Address - Both Modes
    EXTBTHFMT     = 0x5D, // Extended Timing - Both Types of Header - Format Byte
    EXTBTHLEN     = 0x5E, // Extended Timing - Both Types of Header - Additional Length Byte
    EXTBTHBM      = 0xDF, // Extended Timing - Both Types of Header - Both Modes
    NOMONEBYTEFMT = 0xE5, // Normal Timing - One Byte Header - Format Byte
    NOMONEBYTELEN = 0xE6, // Normal Timing - One Byte Header - Additional Length Byte
    NOMONEBYTEBM  = 0x67, // Normal Timing - One Byte Header - Both Modes
    NOMTSFMT      = 0xE9, // Normal Timing - Target/Source Address - Format Byte
    NOMTSLEN      = 0xEA, // Normal Timing - Target/Source Address - Additional Length Byte
    NOMTSBM       = 0x6B, // Normal Timing - Target/Source Address - Both Modes
    NOMBTHFMT     = 0x6D, // Normal Timing - Both Types of Header - Format Byte
    NOMBTHLEN     = 0x6E, // Normal Timing - Both Types of Header - Additional Length Byte
    NOMBTHBM      = 0xEF  // Normal Timing - Both Types of Header - Both Modes
  };
}

byte CalculateChecksum(byte rawPDU[], int pduLength)
{
  int i;
  byte checkSum;
  i = 0;
 
  for (i = 0; i < pduLength; ++i)
  {
    checkSum += rawPDU[i];
  }
  
  return checkSum;
}