⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diag_dtc.c

📁 Freediag contains various drivers (ISO9141, ISO14230, SAEJ1850-VPW, SAEJ1850-PWM) for different adap
💻 C
字号:
/*
 *	freediag - Vehicle Diagnostic Utility
 *
 *
 * Copyright (C) 2001 Richard Almeida & Ibex Ltd (rpa@ibex.co.uk)
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *************************************************************************
 *
 *
 * DTC handling routines
 *
 */
#include <stdlib.h>
#include <stdio.h>

#include "diag_os.h" /* operating specific includes */

#include <fcntl.h>
#include <string.h>
#include <errno.h>

#include "diag.h"
#include "diag_l1.h"
#include "diag_l2.h"
#include "diag_general.h"
#include "diag_dtc.h"

static char *cvsid = "$Id: diag_dtc.c,v 1.3 2002/04/03 04:56:40 bjorn_helgaas Exp $";


void diag_dtc_init(void)
{

}

/*
 * DTC decoding routine
 *
 *
 * Passed
 *	data, len	:-	Data representing the DTC
 *	char *vehicle	:-	Vehicle name
 *	char *ecu	:-	ECU Name
 *	int protocol	:-	Protocol (see include file)
 */

char *
diag_dtc_decode(u_int8_t *data, int len, char *vehicle, char *ecu, int protocol)
{
	static char buf[1024];
	char area;

	switch (protocol)
	{
	case DIAG_DTC_PROTOCOL_J2012:
		if (len != 2)
			return("DTC too short for J1850 decode\n");

		switch ((data[0] >> 6) & 0x03)	/* Top 2 bits are area */
		{
		case 0:
			area = 'P';
			break;
		case 1:
			area = 'C';
			break;
		case 2:
			area = 'B';
			break;
		case 3:
			area = 'U';
			break;
		}
		sprintf(buf, "%c%02x%02x ", area, data[0] & 0x3f, data[1]&0xff);
		break;

	default:
		sprintf(buf, "Unknown Protocol %d\n", protocol);
		break;
	}
	return(buf);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -