//------------------------------------------------------------------------------ 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*)stat5)) { answerReq = cmStatus5; 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; }
//------------------------------------------------------------------------------ int main() { PIN_Setup(); AVCLan_Init(); iPod_Init(); #ifdef MONITOR delay_ms(100); RS232_Print("********************** RESET *********************8\n"); #endif while (1) { //Wait1msForAVCLan(); if ((INPUT_IS_SET>0) & (ACC_IS_ON>0)) { // if message from some device on AVCLan begin AVCLan_Read_Message(); } else { // check command from HU if ((answerReq != 0) & (RXState == WAITING_FOR_FF)) AVCLan_SendAnswer(); } // HandleEvent if (((Event & EV_STATUS)>0) & (RXState == WAITING_FOR_FF)) { if (CD_Mode != stStop) { if ((CD_Mode == stFF) | (CD_Mode == stRR)) { if (!AVCLan_Send_Status(0x18)) Event &= ~EV_STATUS; } else { switch (playMode) { case 0: if (!AVCLan_Send_Status(0x03)) Event &= ~EV_STATUS; break; case 1: if (!AVCLan_Send_Status(0x10)) Event &= ~EV_STATUS; break; }; }; }; } if (Event & EV_DISPLAY) { if (!AVCLan_Send_Changer_Status()) Event &= ~EV_DISPLAY;; }; if (ACC_IS_ON) { // audio output if (CD_Mode == stStop) CHANNELS_OFF(); if (CD_Mode == stPlay) { if (AuxInput==Aux2) CHANNEL_TWO(); if (AuxInput==Aux1) CHANNEL_ONE(); } } else { CHANNELS_OFF(); CD_Mode = stStop; playMode = 0; }; // iPod if (AUX1ISIPOD) iPod_Poll(); if (!(ACC_IS_ON)) registered = 0; // zzzzz //if (sleepcounter > 5) // { // CHANNELS_OFF(); // sleep_mode(); // sleepcounter = 0; // } } // end while(1) }