📄 diag_l3_vag.c
字号:
/*
* !!! INCOMPLETE !!!!
*
* 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.
*
*************************************************************************
*
* Diag
*
* L3 driver for Volkswagen Audi Group (VAG) protocol (on ISO9141 interface
* with 5 baud init using specific keywords)
*
*
* XXX NOT YET WRITTEN
*/
#include <stdlib.h>
#include <stdio.h>
#include "diag_os.h" /* operating specific includes */
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include "diag.h"
#include "diag_l1.h"
#include "diag_l2.h"
#include "diag_l3.h"
#include "diag_err.h"
#include "diag_general.h"
#include "diag_vag.h"
static char *cvsid = "$Id: diag_l3_vag.c,v 1.3 2002/04/03 04:56:40 bjorn_helgaas Exp $";
#define DIAG_MODULE "diag_l3_vag"
/*
* Insert the L3 layer on top of the layer 2 connection
*
*/
int
diag_l3_vag_start(diag_l3_conn_t *d_l3_conn)
{
struct diag_l2_data l2data;
diag_l2_conn_t *d_l2_conn;
/* 5 baud init has been done, make sure we got the correct keybytes */
d_l2_conn = d_l3_conn->d_l3l2_conn;
(void)diag_l2_ioctl(d_l2_conn, DIAG_IOCTL_GET_L2_DATA, (void *)&l2data);
if (diag_l2_debug & DIAG_DEBUG_INIT)
printf("%s: start L2 KB 0x%x 0x%x need 0x01 0x8A\n",
DIAG_MODULE, l2data.kb1, l2data.kb2);
if (l2data.kb1 != 0x01)
return(DIAG_ERR_WRONGKB);
if (l2data.kb2 != 0x8A)
return(DIAG_ERR_WRONGKB);
/* OK, ISO 9141 keybytes are correct ! */
/* Get the initial stuff the ECU tells us */
return(0);
}
int
diag_l3_vag_stop(diag_l3_conn_t *d_l3_conn)
{
/* Send a stop message to the ECU */
return(0);
}
/*
* Send a Message doing all the handshaking needed
*/
int diag_l3_vag_send(diag_l3_conn_t *d_l3_conn, diag_msg_t *msg)
{
return (0);
}
/*
* RX callback, called as data received from L2. If we get a full message,
* call L3 callback routine
*/
void
diag_l3_vag_rcv_callback(void *handle, diag_msg_t *msg)
{
}
/*
* Receive a Message frame (building it as we get small amounts of data)
*
* - timeout expiry will cause return before complete packet
*
* Successful packet receive will call the callback routine with the message
*/
int
diag_l3_vag_recv(diag_l3_conn_t *d_l3_conn, int timeout,
void (* rcv_call_back)(void *handle ,diag_msg_t *) , void *handle)
{
return (0);
}
/*
* This is called without just the VW protocol data
*/
char *
diag_l3_vag_decode(diag_l3_conn_t *d_l3_conn, diag_msg_t *msg)
{
static char buf[1024];
char buf2[128];
char buf3[16];
char *s;
int i;
sprintf(buf, "Block Len 0x%x, Counter 0x%x ");
switch (msg->data[2])
{
case 0x05:
s = "Clear DTCs";
break;
case 0x06:
s = "End Comms";
break;
case 0x07:
s = "Request DTCs";
break;
case 0x08:
s = "Read Data (single)";
break;
case 0x09:
s = "Ack";
break;
case 0xF6:
s = "ASCII Data";
break;
case 0xFC:
s = "Hex Data";
break;
default:
sprintf(buf3, "0x%x", buf[2]);
s = buf3;
break;
}
sprintf(buf2, "Command: %s: ", s);
strcat(buf, buf2);
sprintf(buf2, "Data : ");
strcat(buf, buf2);
for (i=3; i < msg->data[0]; i++)
{
sprintf(buf2, "0x%x ", msg->data[i]);
strcat(buf, buf2);
}
strcat(buf, "\n");
return(buf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -