From 214cc168fd7a2c07d1c114de520c17a813846bef Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Thu, 23 Jul 2015 09:43:26 -0700 Subject: [PATCH] Merged Marcin's AVC-LAN driver --- AVCLanDriver.h | 4 +- GlobalDef.h | 4 +- Schematic.png | Bin 0 -> 16408 bytes ToyotaAuxEnabler.c | 8 - avclandrv.c | 933 +++++++++++++++++++++++++++++++++++++++++++++ avclandrv.h | 135 +++++++ com232.c | 122 ++++++ com232.h | 54 +++ sniffer.c | 288 ++++++++++++++ 9 files changed, 1536 insertions(+), 12 deletions(-) create mode 100644 Schematic.png create mode 100644 avclandrv.c create mode 100644 avclandrv.h create mode 100644 com232.c create mode 100644 com232.h create mode 100644 sniffer.c diff --git a/AVCLanDriver.h b/AVCLanDriver.h index b2e7623..6b156d8 100644 --- a/AVCLanDriver.h +++ b/AVCLanDriver.h @@ -41,8 +41,8 @@ #define START_BIT_LENGTH 372 //186*2 #define START_BIT_HOLD_ON_LENGTH 336 //168*2 -#define AVC_OUT_EN() sbi(PORTD, 6); sbi(DDRD, 6); sbi(DDRD, 7); sbi(ACSR, ACD); -#define AVC_OUT_DIS() cbi(PORTD, 6); cbi(DDRD, 6); cbi(DDRD, 7); cbi(ACSR, ACD); +#define AVC_OUT_EN() sbi(PORTD, 6); sbi(DDRD, 6); sbi(DDRD, 7); sbi(ACSR, ACD); // Output mode +#define AVC_OUT_DIS() cbi(PORTD, 6); cbi(DDRD, 6); cbi(DDRD, 7); cbi(ACSR, ACD); // Read mode #define AVC_SET_1() sbi(PORTD, 6); #define AVC_SET_0() cbi(PORTD, 6); diff --git a/GlobalDef.h b/GlobalDef.h index a472912..d91f91a 100644 --- a/GlobalDef.h +++ b/GlobalDef.h @@ -31,8 +31,8 @@ #define LED_PORT PORTB #define LEDOUT _BV(PORT5) -#define sbi(port, bit) (port) |= (1 << (bit)) -#define cbi(port, bit) (port) &= ~(1 << (bit)) +#define sbi(port, bit) (port) |= (1 << (bit)) // Set bit (i.e. to 1) +#define cbi(port, bit) (port) &= ~(1 << (bit)) // Clear bit (i.e. set bit to 0) /*-------------------------------------------------------------------------------------------------- Type definitions diff --git a/Schematic.png b/Schematic.png new file mode 100644 index 0000000000000000000000000000000000000000..0c8f006b9f9432d0016605b668cada002a59c4ea GIT binary patch literal 16408 zcmeIZXH-+c_b7@8l3*bO0TBcaARtwm6se&FY0^ZxQUwH*-a!n#gc11KS@bRV%x(aXB`p}xfnGi1%2=7t*ong z#XL8|F5L)!Yzqw3N`uvKvO3hYJX#xt-ZEmXc*Dd!CyWCb*Dohz8<uFOnszj1BMFaEQU(JCv)O%z|5mWn{H-2^K{&FCCJt$ALEWxYke7YU?F3m|`G zU%G3^)evsIR*<4}RLn(_i%Zv1fb=Q1B3MwTTQZ9~ z-il)mQv^5b$$$wi`vt||B?xq?AoV^E$BD96Fp3^9Y>mNX@%u}Kyhg$+G3Nou7dMAj z19s~6%iLh3V$JZnzeXwh$?G#JL#FGAlu))8?Z)XkdwfZ=o=%@=-ESjOH!M>A7!;T5 z;?nkPlGr7zj@?kNQlB8P)_51_z0?z74rc7iq2Bod4Dpc)FiN(r_>KBv$(l5xy%wa1 zd|bN?Q2$QrX(RP12@NbQlaitadU~Dt@USIi3)J8OQ^xx+SSH3G^ltzvIVkAoGCKwp z;cy6feo|jQOqE{^gBu#oZP^(-*WNkxKB+hTy+aDQmsy{qZD+t;7&Y)$QGbi)3j6)* zpqtcHz(?T^OXlS zo_?f*3+JH0aDpmoB_$HAYS8yiRS^*w2diEjl1Lv>V+B;%Q9-S&fB1`+%EKgg1N#0< zaCyoO8F}1Bu-<+|Uf}M-t(IYZXF@J@IB_t|@$ziMWI)(Ad^Xw143$=mmuNVwu5(a^ zCaBb*e=`~#eLB|2v6sTtZ-9F@(IqbiPaH}FO;H+#B9IR*1n*DQR<9dk^EK}@_d_TEC{?1H2Zq*>7hngy0K;p(4&x<+zWn3!*JM6mh z$Io#&R~M;wXb@*tKH9&hVqnc@OzVDNov){QqCQ=68 zP?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^p4R4+R;tJFaHWwO_3?!@0+A!i7IwA&zr@qG$K-8D9t0 z@~6}BPg5-B5nE~t5^p^-Xu22yZETitNUgC$#b`sHg}2%I2!SfZ5}*H+ zX*. + + Portions of the following source code are: + Copyright (C) 2006 Marcin Slonicki . + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + ----------------------------------------------------------------------- + this file is a part of the TOYOTA Corolla MP3 Player Project + ----------------------------------------------------------------------- + http://www.softservice.com.pl/corolla/avc + + May 28 / 2009 - version 2 + +*/ + +#include +#include +//#include // Unnecessary? +#include "avclandrv.h" +#include "com232.h" +#include "GlobalDef.h" + + +//------------------------------------------------------------------------------ + +#define AVC_OUT_EN() sbi(PORTD, 6); sbi(DDRD, 6); sbi(DDRD, 7); sbi(ACSR, ACD); +#define AVC_OUT_DIS() cbi(PORTD, 6); cbi(DDRD, 6); cbi(DDRD, 7); cbi(ACSR, ACD); +#define AVC_SET_1() sbi(PORTD, 6); +#define AVC_SET_0() cbi(PORTD, 6); + + +byte CD_ID_1; +byte CD_ID_2; + +byte HU_ID_1; +byte HU_ID_2; + +byte parity_bit; + +byte repeatMode; +byte randomMode; + +byte playMode; + +byte cd_Disc; +byte cd_Track; +byte cd_Time_Min; +byte cd_Time_Sec; + +byte answerReq; + +// we need check answer (to avclan check) timeout +// when is more then 1 min, FORCE answer. +byte check_timeout; + +#define SW_ID 0x11 // 11 For my stereo + +// commands +const byte stat1[] = { 0x4, 0x00, 0x00, 0x01, 0x0A }; +const byte stat2[] = { 0x4, 0x00, 0x00, 0x01, 0x08 }; +const byte stat3[] = { 0x4, 0x00, 0x00, 0x01, 0x0D }; +const byte stat4[] = { 0x4, 0x00, 0x00, 0x01, 0x0C }; + +// Updated avclandrv.c had these +const u08 stat5[] = { 0x6, 0x00, 0x12, 0x5C, 0x43, 0x02, 0x00 }; +const u08 stat6[] = { 0x4, 0x00, 0x58, 0x63, 0xE0 }; + +// broadcast +const byte lan_stat1[] = { 0x3, 0x00, 0x01, 0x0A }; +const byte lan_reg[] = { 0x3, SW_ID, 0x01, 0x00 }; +const byte lan_init[] = { 0x3, SW_ID, 0x01, 0x01 }; +const byte lan_check[] = { 0x3, SW_ID, 0x01, 0x20 }; +const byte lan_playit[] = { 0x4, SW_ID, 0x01, 0x45, 0x63 }; + + + +const byte play_req1[] = { 0x4, 0x00, 0x25, 0x63, 0x80 }; + +#ifdef __AVENSIS__ + const byte play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42 }; +#else + const byte play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x01, 0x00 }; +#endif + +const byte play_req3[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x41, 0x00 }; +const byte stop_req[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x01 }; +const byte stop_req2[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x41 }; + + +// answers +const byte CMD_REGISTER[] = {0x1, 0x05, 0x00, 0x01, SW_ID, 0x10, 0x63 }; +const byte CMD_STATUS1[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1A }; +const byte CMD_STATUS2[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x18 }; +const byte CMD_STATUS3[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1D }; +const byte CMD_STATUS4[] = {0x1, 0x05, 0x00, 0x01, 0x00, 0x1C, 0x00 }; +byte CMD_CHECK[] = {0x1, 0x06, 0x00, 0x01, SW_ID, 0x30, 0x00, 0x00 }; + +const byte CMD_STATUS5[] = {0x1, 0x05, 0x00, 0x5C, 0x12, 0x53, 0x02 }; +const byte CMD_STATUS5A[] = {0x0, 0x05, 0x5C, 0x31, 0xF1, 0x00, 0x00 }; + +const byte CMD_STATUS6[] = {0x1, 0x06, 0x00, 0x5C, 0x32, 0xF0, 0x02, 0x00 }; + + +const byte CMD_PLAY_OK1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x50, 0x01 }; +const byte CMD_PLAY_OK2[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x52, 0x01 }; +const byte CMD_PLAY_OK3[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 }; +byte CMD_PLAY_OK4[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }; + +const byte CMD_STOP1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x53, 0x01 }; +byte CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x00, 0x00,0x00, 0x00, 0x00, 0x80 }; + +const byte CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02 }; + +//------------------------------------------------------------------------------ + + +// DONE: Timing adjusted, however refactoring may make code more clear/efficient +//------------------------------------------------------------------------------ +void AVC_HoldLine() +{ + STOPEvent; + + // wait for free line + byte line_busy = 1; + + TCNT0 = 0; + do { + while (INPUT_IS_CLEAR) { + /* The comparison value was originally 25 with CK64 (tick period of 4.34 us) + at a clock frequency 14.7456MHz. + For a more accurate tick period of .5 us at 16MHz, the value should be approximately 225*/ + if (TCNT0 >= 225) break; + } + if (TCNT0 > 216) line_busy=0; + } while (line_busy); + + // switch to out mode + AVC_OUT_EN(); + AVC_SET_1(); + + STARTEvent; +} + +// DONE: No changes necessary +//------------------------------------------------------------------------------ +void AVC_ReleaseLine() +{ + AVC_SET_0(); + AVC_OUT_DIS(); +} +//------------------------------------------------------------------------------ + + +// DONE: No changes necessary +//------------------------------------------------------------------------------ +void AVCLan_Init() +{ + // OUTPUT ( set as input for comparator ) + cbi(PORTD, 6); + cbi(DDRD, 6); + + // INPUT + cbi(PORTD, 7); + cbi(DDRD, 7); + + // Analog comparator + + cbi(ADCSRB, ACME); // Analog Comparator Multiplexer Enable - NO + /* + cbi(ACSR, ACBG); // Analog Comparator Bandgap Select + // ACI: Analog Comparator Interrupt Flag + + cbi(ACSR, ACIE); // Analog Comparator Interrupt Enable - NO + cbi(ACSR, ACIC); // Analog Comparator Input Capture Enable - NO + */ + cbi(ACSR, ACIS1); // Analog Comparator Interrupt Mode Select + cbi(ACSR, ACIS0); // Comparator Interrupt on Output Toggle + + cbi(ACSR, ACD); // Analog Comparator Disable - NO + + TCCR0B = _BV(CS01); // Timer 0 prescaler = 8 ( 2 count / us ) + + message_len = 0; + answerReq = cmNull; + check_timeout = 0; + + cd_Disc = 1; + cd_Track = 1; + cd_Time_Min = 0; + cd_Time_Sec = 0; + repeatMode = 0; + randomMode = 0; + playMode = 0; + CD_Mode = stStop; + +} + +// DONE: Timing adjusted, however refactoring may make code more clear/efficient +//------------------------------------------------------------------------------ +byte AVCLan_Read_Byte(byte length) +{ + byte bite = 0; + + while (1) { + while (INPUT_IS_CLEAR); + TCNT0 = 0; + while (INPUT_IS_SET); + if ( TCNT0 < 72 ) { + bite++; + parity_bit++; + } + length--; + if (!length) return bite; + bite = bite << 1; + } +} + +// DONE: Timing adjusted +//------------------------------------------------------------------------------ +byte AVCLan_Send_StartBit() +{ + AVC_SET_1(); + TCNT0 = 0; + while( TCNT0 < 333 ); + + AVC_SET_0(); + TCNT0 = 0; + while( TCNT0 < 61 ); + + return 1; +} + +// DONE: Timing adjusted. Comparison values are timer ticks, not us. +//------------------------------------------------------------------------------ +void AVCLan_Send_Bit1() +{ + AVC_SET_1(); + TCNT0 = 0; + while( TCNT0 < 41 ); + + AVC_SET_0(); + TCNT0 = 0; + while( TCNT0 < 33 ); // 12-21 us +} + +// DONE: Timing adjusted +//------------------------------------------------------------------------------ +void AVCLan_Send_Bit0() +{ + AVC_SET_1(); + TCNT0 = 0; + while( TCNT0 < 65 ); // 28-37 us + + AVC_SET_0(); + TCNT0 = 0; + while( TCNT0 < 9 ); // 00-09 us +} + +// DONE: Timing adjusted. +//------------------------------------------------------------------------------ +byte AVCLan_Read_ACK() +{ + byte time = 0; + + AVC_SET_1(); + TCNT0 = 0; + while( TCNT0 < 39 ); + + AVC_SET_0(); + TCNT0 = 0; + while( TCNT0 < 3 ); + + + AVC_OUT_DIS(); // switch to read mode + TCNT0 = 1; + while(1) { + time = TCNT0; + if (INPUT_IS_SET && (TCNT0 > 1)) break; + if (TCNT0 > 41) return 1; // Not sure if this fix is intent correct + } + + while(INPUT_IS_SET); + AVC_OUT_EN(); // back to write mode + return 0; + +} + +// DONE: Timing adjusted. +//------------------------------------------------------------------------------ +byte AVCLan_Send_ACK() +{ + TCNT0 = 0; + while (INPUT_IS_CLEAR) { + if (TCNT0 >= 225) return 0; // max wait time + } + + AVC_OUT_EN(); + + AVC_SET_1(); + TCNT0 = 0; + while( TCNT0 < 65 ); //28-37 + + AVC_SET_0(); + TCNT0 = 0; + while( TCNT0 < 9 ); //00-09 + + AVC_OUT_DIS(); + + return 1; +} + +// DONE: var 'byte' adjusted to 'bite' to avoid reserved word conflict +//------------------------------------------------------------------------------ +byte AVCLan_Send_Byte(byte bite, byte len) +{ + byte b; + if (len==8) { + b = bite; + } else { + b = bite << (8-len); + } + + while (1) { + if ( (b & 128)!=0 ) { + AVCLan_Send_Bit1(); + parity_bit++; + } else { + AVCLan_Send_Bit0(); + } + len--; + if (!len) { + //if (INPUT_IS_SET) RS232_Print("SBER\n"); // Send Bit ERror + return 1; + } + b = b << 1; + } + +} + +// DONE: Nothing needed. +//------------------------------------------------------------------------------ +byte AVCLan_Send_ParityBit() +{ + if ( (parity_bit & 1)!=0 ) { + AVCLan_Send_Bit1(); + //parity_bit++; + } else { + AVCLan_Send_Bit0(); + } + parity_bit=0; + return 1; +} + +// DONE: Nothing needed. +//------------------------------------------------------------------------------ +byte CheckCmd(byte *cmd) +{ + byte i; + byte *c; + byte l; + + c = cmd; + l = *c++; + + for (i=0; i 2286 ) { // Originally 254 + STARTEvent; + RS232_Print("LAN>T1\n"); + return 0; + } + } + + + if ( TCNT0 < 90 ) { // !!!!!!! 20 !!!!!!!!!!! (Originally 10) + STARTEvent; + RS232_Print("LAN>T2\n"); + return 0; + } + + + + broadcast = AVCLan_Read_Byte(1); + + parity_bit = 0; + master1 = AVCLan_Read_Byte(4); + master2 = AVCLan_Read_Byte(8); + if ((parity_bit&1)!=AVCLan_Read_Byte(1)) { + STARTEvent; + return 0; + } + + parity_bit = 0; + slave1 = AVCLan_Read_Byte(4); + slave2 = AVCLan_Read_Byte(8); + if ((parity_bit&1)!=AVCLan_Read_Byte(1)) { + STARTEvent; + return 0; + } + // is this command for me ? + if ((slave1==CD_ID_1)&&(slave2==CD_ID_2)) { + for_me=1; + } + + if (for_me) AVCLan_Send_ACK(); + else AVCLan_Read_Byte(1); + + parity_bit = 0; + AVCLan_Read_Byte(4); // control - always 0xF + if ((parity_bit&1)!=AVCLan_Read_Byte(1)) { + STARTEvent; + return 0; + } + if (for_me) AVCLan_Send_ACK(); + else AVCLan_Read_Byte(1); + + parity_bit = 0; + message_len = AVCLan_Read_Byte(8); + if ((parity_bit&1)!=AVCLan_Read_Byte(1)) { + STARTEvent; + return 0; + } + if (for_me) AVCLan_Send_ACK(); + else AVCLan_Read_Byte(1); + + if (message_len > MAXMSGLEN) { +// RS232_Print("LAN> Command error"); + STARTEvent; + return 0; + } + + for (i=0; i= 225 ) break; + } + if ( TCNT0 > 216 ) line_busy=0; + } while (line_busy); + + + // switch to output mode + AVC_OUT_EN(); + + AVCLan_Send_StartBit(); + AVCLan_Send_Byte(0x1, 1); // regular communication + + + parity_bit = 0; + AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master + AVCLan_Send_Byte(CD_ID_2, 8); + AVCLan_Send_ParityBit(); + + AVCLan_Send_Byte(HU_ID_1, 4); // HeadUnit ID as slave + AVCLan_Send_Byte(HU_ID_2, 8); + + AVCLan_Send_ParityBit(); + + if (AVCLan_Read_ACK()) { + AVC_OUT_DIS(); + STARTEvent; + RS232_Print("E1\n"); + return 1; + } + + + AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE + AVCLan_Send_ParityBit(); + if (AVCLan_Read_ACK()) { + AVC_OUT_DIS(); + STARTEvent; + RS232_Print("E2\n"); + return 2; + } + + AVCLan_Send_Byte(data_len, 8);// data length + AVCLan_Send_ParityBit(); + if (AVCLan_Read_ACK()) { + AVC_OUT_DIS(); + STARTEvent; + RS232_Print("E3\n"); + return 3; + } + + for (i=0;i= 225 ) break; + } + if ( TCNT0 > 216 ) line_busy=0; + } while (line_busy); + + + AVC_OUT_EN(); + + AVCLan_Send_StartBit(); + AVCLan_Send_Byte(0x0, 1); // broadcast + + parity_bit = 0; + AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master + AVCLan_Send_Byte(CD_ID_2, 8); + AVCLan_Send_ParityBit(); + + AVCLan_Send_Byte(0x1, 4); // all audio devices + AVCLan_Send_Byte(0xFF, 8); + AVCLan_Send_ParityBit(); + AVCLan_Send_Bit1(); + + AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE + AVCLan_Send_ParityBit(); + AVCLan_Send_Bit1(); + + AVCLan_Send_Byte(data_len, 8); // data lenght + AVCLan_Send_ParityBit(); + AVCLan_Send_Bit1(); + + for (i=0;i ")); + for (i=0; i. + + Portions of the following source code are: + Copyright (C) 2006 Marcin Slonicki . + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + ----------------------------------------------------------------------- + this file is a part of the TOYOTA Corolla MP3 Player Project + ----------------------------------------------------------------------- + http://www.softservice.com.pl/corolla/avc + + May 28 / 2009 - version 2 + +*/ + + +#ifndef __AVCLANDRV_H +#define __AVCLANDRV_H +//------------------------------------------------------------------------------ +#include "GlobalDef.h" + +#define STOPEvent cbi(TIMSK1, TOIE1); cbi(UCSR0B, RXCIE0); +#define STARTEvent sbi(TIMSK1, TOIE1); sbi(UCSR0B, RXCIE0); + + +#define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message(); + +void AVC_HoldLine(); +void AVC_ReleaseLine(); + +#define MAXMSGLEN 32 + +// Head Unid ID +extern byte HU_ID_1; // 0x01 +extern byte HU_ID_2; // 0x40 + +extern byte CD_ID_1; // 0x03 +extern byte CD_ID_2; // 0x60 + + +// DVD CHANGER +//#define CD_ID_1 0x02 +//#define CD_ID_2 0x50 + +#define cmNull 0 +#define cmStatus1 1 +#define cmStatus2 2 +#define cmStatus3 3 +#define cmStatus4 4 + + +#define cmRegister 100 +#define cmInit 101 +#define cmCheck 102 +#define cmPlayIt 103 +#define cmBeep 110 + +#define cmNextTrack 120 +#define cmPrevTrack 121 +#define cmNextDisc 122 +#define cmPrevDisc 123 + +#define cmScanModeOn 130 +#define cmScanModeOff 131 + +#define cmPlayReq1 5 +#define cmPlayReq2 6 +#define cmPlayReq3 7 +#define cmStopReq 8 +#define cmStopReq2 9 + +typedef enum { stStop=0, stPlay=1 } cd_modes; +cd_modes CD_Mode; + + +byte broadcast; +byte master1; +byte master2; +byte slave1; +byte slave2; +byte message_len; +byte message[MAXMSGLEN]; + +byte data_control; +byte data_len; +byte data[MAXMSGLEN]; + +byte AVCLan_Read_Message(); +void AVCLan_Send_Status(); + +void AVCLan_Init(); +void AVCLan_Register(); +byte AVCLan_SendData(); +byte AVCLan_SendAnswer(); +byte AVCLan_SendDataBroadcast(); +byte AVCLan_Command(byte command); + +byte HexInc(byte data); +byte HexDec(byte data); +byte Dec2Toy(byte data); + +extern byte check_timeout; + +extern byte cd_Disc; +extern byte cd_Track; +extern byte cd_Time_Min; +extern byte cd_Time_Sec; + +extern byte playMode; + + +byte AVCLan_SendMyData(byte *data_tmp, byte s_len); +byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len); + +void ShowInMessage(); +void ShowOutMessage(); + +//------------------------------------------------------------------------------ +extern byte answerReq; +//------------------------------------------------------------------------------ +#endif diff --git a/com232.c b/com232.c new file mode 100644 index 0000000..d88ea11 --- /dev/null +++ b/com232.c @@ -0,0 +1,122 @@ +/* + Copyright (C) 2006 Marcin Slonicki . + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + ----------------------------------------------------------------------- + this file is a part of the TOYOTA Corolla MP3 Player Project + ----------------------------------------------------------------------- + http://www.softservice.com.pl/corolla/avc + + May 28 / 2009 - version 2 + +*/ + +#include +#include +#include +#include "com232.h" + + +//------------------------------------------------------------------------------ +void RS232_Init(void) +{ + // init LED + sbi(DDRB, 5); + cbi(PORTB, 5); + + RS232_RxCharBegin = RS232_RxCharEnd = 0; + + UCSR0A = 0; + UCSR0B = ((1< '9') + Character += 'A' - '0' - 10; + RS232_SendByte(Character); +} +//------------------------------------------------------------------------------ +void RS232_PrintHex8(u08 Data) +{ + RS232_PrintHex4(Data >> 4); + RS232_PrintHex4(Data); +} +//------------------------------------------------------------------------------ +void RS232_PrintDec(u08 Data) +{ + if (Data>99) { + RS232_SendByte('*'); + return; + } + if (Data<10) { + RS232_SendByte('0'+Data); + return; + } + u08 c; + u16 v,v1; + v = Data; + v1 = v/10; + c = '0' + (v-v1*10); + RS232_SendByte('0'+v1); + RS232_SendByte(c); +} +//------------------------------------------------------------------------------ +void RS232_PrintDec2(u08 Data) +{ + if (Data<10) RS232_SendByte('0'); + RS232_PrintDec(Data); +} +//------------------------------------------------------------------------------ diff --git a/com232.h b/com232.h new file mode 100644 index 0000000..bd5a2f5 --- /dev/null +++ b/com232.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2006 Marcin Slonicki . + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + ----------------------------------------------------------------------- + this file is a part of the TOYOTA Corolla MP3 Player Project + ----------------------------------------------------------------------- + http://www.softservice.com.pl/corolla/avc + + May 28 / 2009 - version 2 + +*/ + +#ifndef __COM232_H +#define __COM232_H +//------------------------------------------------------------------------------ + +#include "const.h" + +//------------------------------------------------------------------------------ + +u08 RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd; +u08 readkey; +//------------------------------------------------------------------------------ + +void RS232_Init(void); +extern void RS232_S(u16 str_addr); +extern void RS232_SendByte(u08 Data); +extern void RS232_Print(char* pBuf); +extern void RS232_PrintHex4(u08 Data); +extern void RS232_PrintHex8(u08 Data); +extern void RS232_PrintDec(u08 Data); +extern void RS232_PrintDec2(u08 Data); + +//------------------------------------------------------------------------------ +// LED +#define LED_ON() cbi(PORTB, 5) +#define LED_OFF() sbi(PORTB, 5) + +//------------------------------------------------------------------------------ +#endif diff --git a/sniffer.c b/sniffer.c new file mode 100644 index 0000000..ab5a051 --- /dev/null +++ b/sniffer.c @@ -0,0 +1,288 @@ +/* + Copyright (C) 2006 Marcin Slonicki . + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + ----------------------------------------------------------------------- + this file is a part of the TOYOTA Corolla MP3 Player Project + ----------------------------------------------------------------------- + http://www.softservice.com.pl/corolla/avc + + May 28 / 2009 - version 2 + +*/ + + + +#include +#include +#include + +#include "GlobalDef.h" +#include "com232.h" +#include "avclandrv.h" + + +// ------------------------------------------------------------------------------------- +void Setup(); + +byte rcv_command[5]; +byte rcv_pos = 0; +byte rcv_time_clr = 0; + +// ------------------------------------------------------------------------------------- + + + + +// ------------------------------------------------------------------------------------- +// MAIN PROGRAM +// +int main() +{ +// byte h; + + + byte readSeq = 0; + byte s_len = 0; + byte s_dig = 0; + byte s_c[2]; + byte i; + byte data_tmp[32]; + + Setup(); + + + + RS232_S((u16)PSTR("AVCLan reader 1.00\nReady\n\n")); + LED_OFF(); + RS232_S((u16)PSTR("T - device id\n")); + RS232_S((u16)PSTR("H - HU id\n")); + RS232_S((u16)PSTR("S - read sequence\n")); + RS232_S((u16)PSTR("W - send command\n")); + RS232_S((u16)PSTR("Q - send broadcast\n")); + RS232_S((u16)PSTR("L/l - log on/off\n")); + RS232_S((u16)PSTR("K/k - seq. echo on/off\n")); + RS232_S((u16)PSTR("R/r - register device\n")); + + + + while (1) { + + if (INPUT_IS_SET) { // if message from some device on AVCLan begin + LED_ON(); + AVCLan_Read_Message(); + // show message + } else { + LED_OFF(); + // check command from HU + if (answerReq != 0) AVCLan_SendAnswer(); + } + + // HandleEvent + switch (Event) { + case EV_STATUS: Event &= ~EV_STATUS; + AVCLan_Send_Status(); + break; + } + + + // Key handler + if (RS232_RxCharEnd) { + cbi(UCSR0B, RXCIE0); // disable RX complete interrupt + readkey = RS232_RxCharBuffer[RS232_RxCharBegin];// read begin of received Buffer + RS232_RxCharBegin++; + if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty + RS232_RxCharBegin = RS232_RxCharEnd = 0; // do reset Buffer + sbi(UCSR0B, RXCIE0); // enable RX complete interrupt + switch (readkey) { + case 'T': if (readSeq) { + CD_ID_1 = data_tmp[0]; + CD_ID_2 = data_tmp[1]; + RS232_Print("DEV ID SET: 0x"); + RS232_PrintHex8(CD_ID_1); + RS232_PrintHex8(CD_ID_2); + RS232_Print("\n"); + showLog = 1; + readSeq=0; + } else { + showLog = 0; + RS232_Print("DEV ID > \n"); + readSeq = 1; + s_len=0; + s_dig=0; + s_c[0]=s_c[1]=0; + } + break; + + case 'H': if (readSeq) { + HU_ID_1 = data_tmp[0]; + HU_ID_2 = data_tmp[1]; + RS232_Print("HU ID SET: 0x"); + RS232_PrintHex8(HU_ID_1); + RS232_PrintHex8(HU_ID_2); + RS232_Print("\n"); + showLog = 1; + readSeq=0; + } else { + showLog = 0; + RS232_Print("HU ID > \n"); + readSeq = 1; + s_len=0; + s_dig=0; + s_c[0]=s_c[1]=0; + } + break; + + case 'S': showLog = 0; + RS232_Print("READ SEQUENCE > \n"); + readSeq = 1; + s_len=0; + s_dig=0; + s_c[0]=s_c[1]=0; + break; + case 'W' : showLog = 1; + readSeq=0; + AVCLan_SendMyData(data_tmp, s_len); + break; + case 'Q' : showLog = 1; + readSeq=0; + AVCLan_SendMyDataBroadcast(data_tmp, s_len); + break; + + + case 'R': RS232_Print("REGIST:\n"); + AVCLan_Command( cmRegister ); + TCNT0 = 0; + while( TCNT0 < 135 ); + CHECK_AVC_LINE; + break; + case 'r': AVCLan_Register(); + break; + + + case 'l': RS232_Print("Log OFF\n"); + showLog = 0; + break; + case 'L': RS232_Print("Log ON\n"); + showLog = 1; + break; + + case 'k': RS232_Print("str OFF\n"); + showLog2 = 0; + break; + case 'K': RS232_Print("str ON\n"); + showLog2 = 1; + break; + + default : + if (readSeq==1) { + s_c[s_dig]=readkey; + + s_dig++; + if (s_dig==2) { + if (s_c[0]<':') s_c[0] -= 48; + else s_c[0] -= 55; + data_tmp[s_len] = 16 * s_c[0]; + if (s_c[1]<':') s_c[1] -= 48; + else s_c[1] -= 55; + data_tmp[s_len] += s_c[1]; + s_len++; + s_dig=0; + s_c[0]=s_c[1]=0; + } + if (showLog2) { + RS232_Print("CURRENT SEQUENCE > "); + for (i=0; i