-
Notifications
You must be signed in to change notification settings - Fork 0
/
avclandrv.c
883 lines (720 loc) · 21.2 KB
/
avclandrv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
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 <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "timer.h"
#include "avclandrv.h"
#include "com232.h"
#include "const.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);
u08 CD_ID_1;
u08 CD_ID_2;
u08 HU_ID_1;
u08 HU_ID_2;
u08 parity_bit;
u08 repeatMode;
u08 randomMode;
u08 playMode;
u08 cd_Disc;
u08 cd_Track;
u08 cd_Time_Min;
u08 cd_Time_Sec;
u08 answerReq;
// we need check answer (to avclan check) timeout
// when is more then 1 min, FORCE answer.
u08 check_timeout;
#define SW_ID 0x12
// commands
const u08 stat1[] = { 0x4, 0x00, 0x00, 0x01, 0x0A };
const u08 stat2[] = { 0x4, 0x00, 0x00, 0x01, 0x08 };
const u08 stat3[] = { 0x4, 0x00, 0x00, 0x01, 0x0D };
const u08 stat4[] = { 0x4, 0x00, 0x00, 0x01, 0x0C };
// broadcast
const u08 lan_stat1[] = { 0x3, 0x00, 0x01, 0x0A };
const u08 lan_reg[] = { 0x3, SW_ID, 0x01, 0x00 };
const u08 lan_init[] = { 0x3, SW_ID, 0x01, 0x01 };
const u08 lan_check[] = { 0x3, SW_ID, 0x01, 0x20 };
const u08 lan_playit[] = { 0x4, SW_ID, 0x01, 0x45, 0x63 };
const u08 play_req1[] = { 0x4, 0x00, 0x25, 0x63, 0x80 };
#ifdef __AVENSIS__
const u08 play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42 };
#else
const u08 play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x01, 0x00 };
#endif
const u08 play_req3[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x41, 0x00 };
const u08 stop_req[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x01 };
const u08 stop_req2[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x41 };
// answers
const u08 CMD_REGISTER[] = {0x1, 0x05, 0x00, 0x01, SW_ID, 0x10, 0x63 };
const u08 CMD_STATUS1[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1A };
const u08 CMD_STATUS2[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x18 };
const u08 CMD_STATUS3[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1D };
const u08 CMD_STATUS4[] = {0x1, 0x05, 0x00, 0x01, 0x00, 0x1C, 0x00 };
u08 CMD_CHECK[] = {0x1, 0x06, 0x00, 0x01, SW_ID, 0x30, 0x00, 0x00 };
const u08 CMD_STATUS5[] = {0x1, 0x05, 0x00, 0x5C, 0x12, 0x53, 0x02 };
const u08 CMD_STATUS5A[] = {0x0, 0x05, 0x5C, 0x31, 0xF1, 0x00, 0x00 };
const u08 CMD_STATUS6[] = {0x1, 0x06, 0x00, 0x5C, 0x32, 0xF0, 0x02, 0x00 };
const u08 CMD_PLAY_OK1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x50, 0x01 };
const u08 CMD_PLAY_OK2[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x52, 0x01 };
const u08 CMD_PLAY_OK3[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
u08 CMD_PLAY_OK4[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 };
const u08 CMD_STOP1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x53, 0x01 };
u08 CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x00, 0x00,0x00, 0x00, 0x00, 0x80 };
const u08 CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02 };
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void AVC_HoldLine()
{
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) line_busy=0;
} while (line_busy);
// switch to out mode
AVC_OUT_EN();
AVC_SET_1();
STARTEvent;
}
//------------------------------------------------------------------------------
void AVC_ReleaseLine()
{
AVC_SET_0();
AVC_OUT_DIS();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void AVCLan_Init()
{
// AVCLan TX+/TX- : internal comparator PINB2, PINB3
// 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, ACIS1); // Analog Comparator Interrupt Mode Select
cbi(ACSR, ACIS0); // Comparator Interrupt on Output Toggle
cbi(ACSR, ACD); // Analog Comparator Disbale - NO
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;
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_Byte(u08 length)
{
u08 byte = 0;
u08 wT;
while (1) {
while (INPUT_IS_CLEAR);
timer0_start();
while (INPUT_IS_SET);
wT = TCNT0;
if (wT<8) {
byte++;
parity_bit++;
}
length--;
if (!length) return byte;
byte = byte << 1;
}
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_StartBit()
{
AVC_SET_1();
//measured about 166us target is 166
_delay_us(166);
AVC_SET_0();
//with value 30 measured 35us decreased to 25 target is 30
_delay_us(25);
return 1;
}
//------------------------------------------------------------------------------
void AVCLan_Send_Bit1()
{
AVC_SET_1();
//measured about 20us target is 20
_delay_us(20);
AVC_SET_0();
//measured about 21us target is 20
_delay_us(16); // 12-21
}
//------------------------------------------------------------------------------
void AVCLan_Send_Bit0()
{
AVC_SET_1();
//measured about 32us target is 32
_delay_us(32); // 28-37
AVC_SET_0();
//with value 4 measured 5.3us increase to 5 target is 7
_delay_us(5); // 00-09
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_ACK()
{
u08 time = 0;
AVC_SET_1();
_delay_us(19);
AVC_SET_0();
_delay_us(1);
AVC_OUT_DIS(); // switch to read mode
timer0_source(CK64);
timer0_start();
while(1) {
time = TCNT0;
if (INPUT_IS_SET && (time > 1)) break;
if (time > 20) return 1;
}
while(INPUT_IS_SET);
AVC_OUT_EN();// back to write mode
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_ACK()
{
timer0_source(CK64); //update every 1us
timer0_start();
while (INPUT_IS_CLEAR) {
if (TCNT0 >= 25) return 0; // max wait time
}
AVC_OUT_EN();
AVC_SET_1();
//like sending "0"
_delay_us(32); //28-37
AVC_SET_0();
_delay_us(5); //00-09
AVC_OUT_DIS();
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_Byte(u08 byte, u08 len)
{
u08 b;
if (len==8) {
b = byte;
} else {
b = byte << (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;
}
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_ParityBit()
{
if ( (parity_bit & 1)!=0 ) {
AVCLan_Send_Bit1();
//parity_bit++;
} else {
AVCLan_Send_Bit0();
}
parity_bit=0;
return 1;
}
//------------------------------------------------------------------------------
u08 CheckCmd(u08 *cmd)
{
u08 i;
u08 *c;
u08 l;
c = cmd;
l = *c++;
for (i=0; i<l; i++) {
if (message[i] != *c) return 0;
c++;
}
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_Message()
{
STOPEvent; // disable timer1 interrupt
u08 T = 0;
u08 i;
u08 for_me = 0;
//RS232_Print("$ ");
timer0_source(CK64);
// check start bit
timer0_start();
while (INPUT_IS_SET) {
T=TCNT0;
if (T>254) {
STARTEvent;
RS232_Print("LAN>T1\n");
return 0;
}
}
if (T<10) { // !!!!!!! 20 !!!!!!!!!!!
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<message_len; i++) {
parity_bit = 0;
message[i] = 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);
}
}
STARTEvent;
if (showLog) ShowInMessage();
if (for_me) {
if (CheckCmd((u08*)stat1)) { answerReq = cmStatus1; return 1; }
if (CheckCmd((u08*)stat2)) { answerReq = cmStatus2; return 1; }
if (CheckCmd((u08*)stat3)) { answerReq = cmStatus3; return 1; }
if (CheckCmd((u08*)stat4)) { answerReq = cmStatus4; return 1; }
if (CheckCmd((u08*)play_req1)) { answerReq = cmPlayReq1; return 1; }
if (CheckCmd((u08*)play_req2)) { answerReq = cmPlayReq2; return 1; }
if (CheckCmd((u08*)play_req3)) { answerReq = cmPlayReq3; return 1; }
if (CheckCmd((u08*)stop_req)) { answerReq = cmStopReq; return 1; }
if (CheckCmd((u08*)stop_req2)) { answerReq = cmStopReq2; return 1; }
} else { // broadcast check
if (CheckCmd((u08*)lan_playit)) { answerReq = cmPlayIt; return 1; }
if (CheckCmd((u08*)lan_check)) {
answerReq = cmCheck;
CMD_CHECK[6]=message[3];
return 1;
}
if (CheckCmd((u08*)lan_reg)) { answerReq = cmRegister; return 1; }
if (CheckCmd((u08*)lan_init)) { answerReq = cmInit; return 1; }
if (CheckCmd((u08*)lan_stat1)) { answerReq = cmStatus1; return 1; }
}
answerReq = cmNull;
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendData()
{
u08 i;
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) 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 lenght
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E3\n");
return 3;
}
for (i=0;i<data_len;i++) {
AVCLan_Send_Byte(data[i], 8);// data byte
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E4(");
RS232_PrintDec(i);
RS232_Print(")\n");
return 4;
}
}
// back to read mode
AVC_OUT_DIS();
STARTEvent;
if (showLog) ShowOutMessage();
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendDataBroadcast()
{
u08 i;
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) 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<data_len;i++) {
AVCLan_Send_Byte(data[i], 8); // data byte
AVCLan_Send_ParityBit();
AVCLan_Send_Bit1();
}
AVC_OUT_DIS();
STARTEvent;
if (showLog) ShowOutMessage();
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendAnswerFrame(u08 *cmd)
{
u08 i;
u08 *c;
u08 b;
c = cmd;
b = *c++;
data_control = 0xF;
data_len = *c++;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
if (b)
return AVCLan_SendData();
else
return AVCLan_SendDataBroadcast();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendMyData(u08 *data_tmp, u08 s_len)
{
u08 i;
u08 *c;
c = data_tmp;
data_control = 0xF;
data_len = s_len;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
return AVCLan_SendData();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendMyDataBroadcast(u08 *data_tmp, u08 s_len)
{
u08 i;
u08 *c;
c = data_tmp;
data_control = 0xF;
data_len = s_len;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
return AVCLan_SendDataBroadcast();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendInitCommands()
{
u08 r;
const u08 c1[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
const u08 c2[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x02 };
const u08 c3[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3F, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c4[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3D, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c5[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x39, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c6[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x31, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c7[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x21, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c8[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x90, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
const u08 c9[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 cA[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
r = AVCLan_SendAnswerFrame((u08*)c1);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c2);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c3);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c4);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c5);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c6);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c7);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c8);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c9);
if (!r) r = AVCLan_SendAnswerFrame((u08*)cA);
return r;
}
//------------------------------------------------------------------------------
void AVCLan_Send_Status()
{
// disc track t_min t_sec
u08 STATUS[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80 };
STATUS[7] = cd_Disc;
STATUS[8] = cd_Track;
STATUS[9] = cd_Time_Min;
STATUS[10] = cd_Time_Sec;
STATUS[11] = 0;
AVCLan_SendAnswerFrame((u08*)STATUS);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
u08 AVCLan_SendAnswer()
{
u08 r = 0 ;
switch (answerReq) {
case cmStatus1: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS1);
break;
case cmStatus2: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS2);
break;
case cmStatus3: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS3);
break;
case cmStatus4: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS4);
break;
case cmRegister: r = AVCLan_SendAnswerFrame((u08*)CMD_REGISTER);
break;
case cmInit:
r = AVCLan_SendInitCommands();
break;
case cmCheck: r = AVCLan_SendAnswerFrame((u08*)CMD_CHECK);
check_timeout = 0;
CMD_CHECK[6]++;
RS232_Print("AVCCHK\n");
break;
case cmPlayReq1: playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK1);
break;
case cmPlayReq2:
case cmPlayReq3: playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK2);
if (!r) r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK3);
CD_Mode = stPlay;
break;
case cmPlayIt: playMode = 1;
RS232_Print("PLAY\n");
CMD_PLAY_OK4[7]=cd_Disc;
CMD_PLAY_OK4[8]=cd_Track;
CMD_PLAY_OK4[9]=cd_Time_Min;
CMD_PLAY_OK4[10]=cd_Time_Sec;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK4);
if (!r) AVCLan_Send_Status();
CD_Mode = stPlay;
break;
case cmStopReq:
case cmStopReq2: CD_Mode = stStop;
playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_STOP1);
CMD_STOP2[7]=cd_Disc;
CMD_STOP2[8]=cd_Track;
CMD_STOP2[9]=cd_Time_Min;
CMD_STOP2[10]=cd_Time_Sec;
r = AVCLan_SendAnswerFrame((u08*)CMD_STOP2);
break;
case cmBeep: AVCLan_SendAnswerFrame((u08*)CMD_BEEP);
break;
}
answerReq = cmNull;
return r;
}
//------------------------------------------------------------------------------
void AVCLan_Register()
{
RS232_Print("REG_ST\n");
AVCLan_SendAnswerFrame((u08*)CMD_REGISTER);
RS232_Print("REG_END\n");
//AVCLan_Command( cmRegister );
AVCLan_Command( cmInit );
}
//------------------------------------------------------------------------------
u08 AVCLan_Command(u08 command)
{
u08 r;
answerReq = command;
r = AVCLan_SendAnswer();
/*
RS232_Print("ret=");
RS232_PrintHex8(r);
RS232_Print("\n");
*/
return r;
}
//------------------------------------------------------------------------------
u08 HexInc(u08 data)
{
if ((data & 0x9)==0x9)
return (data + 7);
return (data+1);
}
//------------------------------------------------------------------------------
u08 HexDec(u08 data)
{
if ((data & 0xF)==0)
return (data - 7);
return (data-1);
}
//------------------------------------------------------------------------------
// encode decimal valute to 'toyota' format :-)
// ex. 42 (dec) = 0x42 (toy)
u08 Dec2Toy(u08 data)
{
u08 d,d1;
d = (u32)data/(u32)10;
d1 = d * 16;
d = d1 + (data - 10*d);
return d;
}
//------------------------------------------------------------------------------
void ShowInMessage()
{
if (message_len==0) return;
AVC_HoldLine();
RS232_S((u16)PSTR("HU < ("));
if (broadcast==0) RS232_S((u16)PSTR("bro) "));
else RS232_Print("dir) ");
RS232_PrintHex4(master1);
RS232_PrintHex8(master2);
RS232_Print("| ");
RS232_PrintHex4(slave1);
RS232_PrintHex8(slave2);
RS232_Print("| ");
u08 i;
for (i=0;i<message_len;i++) {
RS232_PrintHex8(message[i]);
RS232_Print(" ");
}
RS232_Print("\n");
AVC_ReleaseLine();
}
//------------------------------------------------------------------------------
void ShowOutMessage()
{
u08 i;
AVC_HoldLine();
RS232_S((u16)PSTR("out > "));
for (i=0; i<data_len; i++) {
RS232_PrintHex8(data[i]);
RS232_SendByte(' ');
}
RS232_Print("\n");
AVC_ReleaseLine();
}
//------------------------------------------------------------------------------