📄 diag.h
字号:
/* * freediag - Vehicle Diagnostic Utility * * CVSID $Id: diag.h,v 1.5 2002/09/11 16:24:59 rpalmeida Exp $ * * 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. * ************************************************************************* * * Library user header file */#include "diag_dtc.h" /* DTC parsing */#ifndef _DIAG_H_#define _DIAG_H_#include <sys/types.h>#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))/* * Generally used structures *//* * These are messages passed to or from the layer 2 and layer 3 code * which cause data to be transmitted to layer 1 * * The receiver of the message *must* copy the data if it wants it !!! */typedef struct diag_msg{ u_int8_t fmt; /* Message format, see flags below */ u_int8_t type; /* Type from received frame */ u_int8_t dest; /* Destination from received frame */ u_int8_t src; /* Source from received frame */ u_int8_t len; /* calculated data length */ u_int8_t *data; /* The data */ struct timeval rxtime; /* Processed time */ struct diag_msg *next; /* For lists of messages */ u_int8_t mcnt; /* Number of elements on this list */ u_int8_t *idata; /* For free() of data later */ u_int8_t iflags; /* Internal flags */} diag_msg_t;#define DIAG_MSG_IFLAG_MALLOC 1 /* We malloced; we Free *//* * Values for diag_msg_t.fmt (flags) *//* ISO Functional addressing */#define DIAG_FMT_ISO_FUNCADDR 0x01/* Received data is framed, ie not raw */#define DIAG_FMT_FRAMED 0x2/* Received data has had L2/L3 headers removed */#define DIAG_FMT_DATAONLY 0x4/* L2 checked the checksum */#define DIAG_FMT_CKSUMMED 0x8/* * Interface to L1 */#include "diag_l1.h"/* * Interface to L2 */#include "diag_l2.h"/* * Values for "cmd" parameter to diag_l2_ioctl() */#define DIAG_IOCTL_GET_L1_TYPE 0x2010 /* Get L1 Type, data is ptr to int */#define DIAG_IOCTL_GET_L1_FLAGS 0x2011 /* Get L1 Flags, data is ptr to int */#define DIAG_IOCTL_GET_L2_FLAGS 0x2021 /* Get the L2 flags (see fmt stuff )*/#define DIAG_IOCTL_GET_L2_DATA 0x2023 /* Get the L2 Keybytes etc into diag_l2_data passed to us */#define DIAG_IOCTL_SETSPEED 0x2101 /* Set speed, bits etc */ /* Struct diag_l2_ic is passed */#define DIAG_IOCTL_INITBUS 0x2201 /* Initialise the ecu bus, data is diag_l1_init *//* Used for L2_IOCTL_SETSPEED */struct diag_l2_ic{ int speed; /* Speed in bits per second */ int databits; /* Number of data bits */ int stopbits; /* Number of stop bits */ int parityflag; /* Parity flag */};/* Used for L2_IOCTL_GETDATA */struct diag_l2_data{ u_int8_t physaddr; /* Physical address of ECU */ u_int8_t kb1; /* Keybyte 0 */ u_int8_t kb2; /* Keybyte 1 */};/* * L2 flags returned from GET_L2_FLAGS *//* * Received data is sent upwards in frames (ie L3 doesn't have to try * and re-frame the code - this is done by timing windows or by the * protocol itself */#define DIAG_L2_FLAG_FRAMED 0x01/* * L2 interface assumes addressing is in header not data, and that * it must calculate the checksum */#define DIAG_L2_FLAG_DATA_ONLY 0x02/* * L2 does keep alive to ECU */#define DIAG_L2_FLAG_KEEPALIVE 0x04/* * L2 adds checksum */#define DIAG_L2_FLAG_DOESCKSUM 0x08/* * L2 startcomms() always suceeds, but only way to find out if * a connection really exists is to send some data and wait for * response. This is useful when connected to car networks such as CAN or J1850 * networks as oppose to normal diagnostic type interface such as ISO9141 */#define DIAG_L2_FLAG_CONNECTS_ALWAYS 0x10/* * Interface to L3 */#include "diag_l3.h"/* * General stuff *//* debug control */extern int diag_l0_debug;extern int diag_l1_debug;extern int diag_l2_debug;extern int diag_l3_debug;#define DIAG_DEBUG_OPEN 0x01 /* Open events */#define DIAG_DEBUG_CLOSE 0x02 /* Close events */#define DIAG_DEBUG_READ 0x04 /* Read events */#define DIAG_DEBUG_WRITE 0x08 /* Write events */#define DIAG_DEBUG_IOCTL 0x10 /* Ioctl stuff (setspeed etc) */#define DIAG_DEBUG_PROTO 0x20 /* Other protocol stuff */#define DIAG_DEBUG_INIT 0x40 /* Initialisation stuff */#define DIAG_DEBUG_DATA 0x80 /* Dump data depending on other flags */#define DIAG_DEBUG_TIMER 0x100 /* Timer stuff *//* * IOCTLs * * The IOCTL can be done to any layer, and it is passed downward with * each layer filling in info as needed (there are currently no clashes) * * L2/L3 ioctls are show below */int diag_l2_ioctl(diag_l2_conn_t *connection, int cmd, void *data);int diag_l3_ioctl(diag_l3_conn_t *connection, int cmd, void *data);/* * Message handling */diag_msg_t *diag_allocmsg(int datalen); /* Alloc a new message */diag_msg_t *diag_dupmsg(diag_msg_t *); /* Duplicate a message */diag_msg_t *diag_dupsinglemsg(diag_msg_t *); /* same, but just the 1st bit */void diag_freemsg(diag_msg_t *); /* Free a msg that we dup'ed *//* * DTC decoding * * Arguments * data, len :- Data representing the DTC * char *vehicle :- Vehicle name * char *ecu :- ECU Name * int protocol :- Protocol (see include file) * Returns * char * textual decode */char * diag_dtc_decode(u_int8_t *data, int len, char *vehicle, char *ecu, int protocol);/* Diagnostic Protocols */#define DIAG_DTC_PROTOCOL_J2012 1 /* SAE J2012 */#define DIAG_DTC_PROTOCOL_INT8 2 /* 8 bit integer */#define DIAG_DTC_PROTOCOL_INT16 3 /* 16 bit integer */#define DIAG_DTC_PROTOCOL_INT32 4 /* 32 bit integer */#define DIAG_DTC_PROTOOCOL_TEXT 5 /* Text String */#endif /* _DIAG_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -