From 406d68ab92fe3ef3de2c3f21902e81e31b535b8c Mon Sep 17 00:00:00 2001 From: Oleg Stepanenko Date: Tue, 23 Feb 2016 17:19:13 +0200 Subject: [PATCH] Added new lock logic for received commands --- AVCLan_mini/AVCLanDrv.cpp | 54 +++++++++++++++-------------- AVCLan_mini/AVCLanDrv.h | 24 +++++++------ AVCLan_mini/AVCLanHonda.cpp | 43 +++++++++++++---------- AVCLan_mini/AVCLanHonda.h | 14 ++++---- AVCLan_mini/AVCLan_mini.ino | 69 ++++++++++++++++++++++--------------- AVCLan_mini/SD_Log.cpp | 12 ++++--- AVCLan_mini/SD_Log.h | 2 ++ AVCLan_mini/config.h | 2 ++ 8 files changed, 125 insertions(+), 95 deletions(-) diff --git a/AVCLan_mini/AVCLanDrv.cpp b/AVCLan_mini/AVCLanDrv.cpp index 74d1b27..3f61668 100644 --- a/AVCLan_mini/AVCLanDrv.cpp +++ b/AVCLan_mini/AVCLanDrv.cpp @@ -530,38 +530,38 @@ bool AVCLanDrv::isAvcBusFree (void) void AVCLanDrv::printMessage(bool incoming) //-------------------------------------------------------------------------------- { - if (!bSDLog.bRedyToLog) return; + /* if (!bSDLog.bRedyToLog) return; - char sss[15] = {0}; - sprintf(sss, "[%u]", millis()); - bSDLog.print(sss); + char sss[15] = {0}; + sprintf(sss, "[%u]", millis()); + bSDLog.print(sss); - if (incoming) { - bSDLog.print('<'); - } else { - bSDLog.print('>'); - } - if (broadcast == AVC_MSG_BROADCAST) { - bSDLog.print("b "); - } else { - bSDLog.print("d "); - } + if (incoming) { + bSDLog.print('<'); + } else { + bSDLog.print('>'); + } + if (broadcast == AVC_MSG_BROADCAST) { + bSDLog.print("b "); + } else { + bSDLog.print("d "); + } - bSDLog.printHex4((uint8_t)(masterAddress >> 8)); - bSDLog.printHex8((uint8_t)(masterAddress)); - bSDLog.print(' '); + bSDLog.printHex4((uint8_t)(masterAddress >> 8)); + bSDLog.printHex8((uint8_t)(masterAddress)); + bSDLog.print(' '); - bSDLog.printHex4(uint8_t(slaveAddress >> 8)); - bSDLog.printHex8((uint8_t) slaveAddress); - bSDLog.print(' '); + bSDLog.printHex4(uint8_t(slaveAddress >> 8)); + bSDLog.printHex8((uint8_t) slaveAddress); + bSDLog.print(' '); - bSDLog.printHex8((uint8_t) dataSize); - bSDLog.print(' '); + bSDLog.printHex8((uint8_t) dataSize); + bSDLog.print(' '); - for (byte i = 0; i < dataSize; i++) { - bSDLog.printHex8((uint8_t)message[i]); - } - bSDLog.println(); + for (byte i = 0; i < dataSize; i++) { + bSDLog.printHex8((uint8_t)message[i]); + } + bSDLog.println(); */ // bSDLog._update(); } @@ -609,3 +609,5 @@ byte AVCLanDrv::getActionID(const AvcInCmdTable messageTable[], byte mtSize) //} AVCLanDrv avclan; + + diff --git a/AVCLan_mini/AVCLanDrv.h b/AVCLan_mini/AVCLanDrv.h index 54722bb..e6147f8 100644 --- a/AVCLan_mini/AVCLanDrv.h +++ b/AVCLan_mini/AVCLanDrv.h @@ -111,32 +111,34 @@ class AVCLanDrv { word headAddress; byte dataSize; byte message[AVC_MAXMSGLEN]; -// byte event; + // byte event; byte actionID; bool readonly; void begin (); byte readMessage (void); -// byte sendMessage (void); -// byte sendMessage (const AvcOutMessage*); + // byte sendMessage (void); + // byte sendMessage (const AvcOutMessage*); void printMessage (bool incoming); bool isAvcBusFree (void); byte getActionID (const AvcInCmdTable messageTable[], byte mtSize); // byte getActionID (const AvcInMaskedMessageTable messageTable[], byte mtSize); -// void loadMessage (const AvcOutMessage*); + // void loadMessage (const AvcOutMessage*); private: bool _parityBit; word readBits (byte nbBits); byte _readMessage (void); -// byte _sendMessage (void); -// void sendStartBit (void); + // byte _sendMessage (void); + // void sendStartBit (void); void send1BitWord (bool data); -// void send4BitWord (byte data); -// void send8BitWord (byte data); -// void send12BitWord (word data); -// bool readAcknowledge (void); -// bool handleAcknowledge (void); + // void send4BitWord (byte data); + // void send8BitWord (byte data); + // void send12BitWord (word data); + // bool readAcknowledge (void); + // bool handleAcknowledge (void); }; extern AVCLanDrv avclan; #endif + + diff --git a/AVCLan_mini/AVCLanHonda.cpp b/AVCLan_mini/AVCLanHonda.cpp index d9f86d0..923487a 100644 --- a/AVCLan_mini/AVCLanHonda.cpp +++ b/AVCLan_mini/AVCLanHonda.cpp @@ -24,8 +24,9 @@ // // 10 680231020200 05 13000000001D0000DE - vol = 1 //}; +// { action_name, packed_size, end_off_packege_word(check_sum) } const AvcInCmdTable mtSearchHead[] PROGMEM = { - { ACT_BUTTON_PRESS, 0x08, 0xBE}, // Button press + { ACT_BUTTON_PRESS, 0x08, 0xBE}, // Button press { ACT_B_DISPOFF, 0x08, 0x2F}, { ACT_B_DISPFULL, 0x08, 0xBD}, { ACT_B_DISPHULF, 0x08, 0xCF}, @@ -33,8 +34,8 @@ const AvcInCmdTable mtSearchHead[] PROGMEM = { { ACT_CAM_OFF, 0x09, 0x30}, // Cam OFF // { ACT_DISP_HULF, 0x09, 0x30}, // display hulf color ??? { ACT_DISP_OFF, 0x09, 0x2E}, // display off - { ACT_TEL, 0x0A, 0xE3}, - { ACT_TEL_CANCEL, 0x0A, 0xDC} + { ACT_TEL, 0x0A, 0xE3}, // start Tel Action + { ACT_TEL_CANCEL, 0x0A, 0xDC} // Cancel or End Call_ACTION // { ACT_VOL, 0x0A, 0x06, {0x68, 0x02, 0x31, 0x02, 0x02, 0x00}, 0x00, {0x00}} //0x05 = 1 }; @@ -52,19 +53,16 @@ void printAvcAction( AvcActionID id ) // bSDLog.logs( mBuff ); } -// AVCLan Navi & timer1 init, //-------------------------------------------------------------------------------- void AVCLanHonda::begin() //-------------------------------------------------------------------------------- { - mVol = 0; avclan.deviceAddress = 0x0131; bShowHondaDisp = false; isHondaDisLast = false; bShowRearCam = false; - setWait( false ); setWaitTime( 0L ); setLockTime( 0L ); @@ -82,9 +80,9 @@ void AVCLanHonda::setWaitTime( const unsigned long mTime ) { waitTime = mTime; if ( mTime > 0L ) { - setWait(true); + bWait = true; } else { - setWait(false); + bWait = false; } } @@ -93,13 +91,8 @@ void AVCLanHonda::setLockTime( const unsigned long mTime ) //-------------------------------------------------------------------------------- { lockTime = mTime; -} - -//-------------------------------------------------------------------------------- -void AVCLanHonda::setWait( const bool mWait ) -//-------------------------------------------------------------------------------- -{ - bWait = mWait; + bLock = true; + setWaitTime(0L); } // Use the last received message to determine the corresponding action ID, store it in avclan object @@ -127,7 +120,7 @@ void AVCLanHonda::processAction(AvcActionID ActionID) case ACT_BUTTON_PRESS: { printAvcAction(ActionID); - if ( !bShowRearCam || !isWait() || ( getLockTime() < millis()) ) + if ( !bShowRearCam || !isWait() || !isLockTime() ) { setWaitTime( (unsigned long)((millis() + BUTT_WAIT)) ); } @@ -144,8 +137,8 @@ void AVCLanHonda::processAction(AvcActionID ActionID) if ( !bShowRearCam ) { bShowHondaDisp = false; - isHondaDisLast = false; - printAvcAction(ActionID); + isHondaDisLast = false; + printAvcAction(ActionID); setLockTime( (unsigned long)(millis() + LOCK_TIME) ); } break; @@ -179,7 +172,7 @@ void AVCLanHonda::tryToShowHondaDisp() //-------------------------------------------------------------------------------- { bWait = false; - if ( getLockTime() > millis() ) return; + if ( isLockTime() ) return; bShowHondaDisp = true; } @@ -191,4 +184,16 @@ void AVCLanHonda::falseHondaDis() isHondaDisLast = false; } +//-------------------------------------------------------------------------------- +bool AVCLanHonda::isLockTime() +//-------------------------------------------------------------------------------- +{ + if ( bLock ) { + bLock = ( getLockTime() > millis() ); + } + return bLock; +} + AVCLanHonda avclanHonda; + + diff --git a/AVCLan_mini/AVCLanHonda.h b/AVCLan_mini/AVCLanHonda.h index 49edb42..3498e66 100644 --- a/AVCLan_mini/AVCLanHonda.h +++ b/AVCLan_mini/AVCLanHonda.h @@ -20,7 +20,7 @@ #define DISABLE_TIMER1_INT (cbi(TIMSK1, TOIE1)); #endif -// адреса eeprom +// адреса eeprom #define E_MASTER1 0 #define E_MASTER2 1 #define E_READONLY 2 @@ -28,7 +28,7 @@ #define AVCLANDEVICE_NAME " Honda Kb1" -#define AVCLANDEVICE_VERSION "0.0.7" +#define AVCLANDEVICE_VERSION "0.0.8" #define BUTT_WAIT 1000 #define LOCK_TIME 700 @@ -37,7 +37,7 @@ typedef enum { ACT_CAM_ON = 1, ACT_CAM_OFF, -// ACT_DISP_HULF, + // ACT_DISP_HULF, ACT_DISP_OFF, ACT_BUTTON_PRESS, ACT_B_DISPOFF, @@ -45,7 +45,7 @@ typedef enum { ACT_B_DISPHULF, ACT_TEL, ACT_TEL_CANCEL -// ACT_VOL + // ACT_VOL } AvcActionID; @@ -68,8 +68,9 @@ class AVCLanHonda void setLockTime( const unsigned long mTime ); inline unsigned long getLockTime() const; + bool isLockTime(); + - void setWait( const bool mWait ); inline bool isWait() const; inline bool isShowRearCam() const; @@ -78,7 +79,6 @@ class AVCLanHonda void checkWait(); void checkLock(); void falseHondaDis(); - int mVol; private: @@ -114,3 +114,5 @@ bool AVCLanHonda::isShowHondaDisp() const { extern AVCLanHonda avclanHonda; #endif + + diff --git a/AVCLan_mini/AVCLan_mini.ino b/AVCLan_mini/AVCLan_mini.ino index 5c4a338..792b43f 100644 --- a/AVCLan_mini/AVCLan_mini.ino +++ b/AVCLan_mini/AVCLan_mini.ino @@ -24,7 +24,7 @@ void setup() sbi(LED_DDR, COMMUT_OUT); cbi(LED_PORT, COMMUT_OUT); - bSDLog.begin(); + // bSDLog.begin(); // Serial.begin(250000); // if (Serial) { @@ -42,41 +42,52 @@ void setup() void loop() //-------------------------------------------------------------------------------- { - if ( avclanHonda.isWait() ) { - avclanHonda.checkWait(); - if (avclanHonda.isWait() == false) - avclanHonda.tryToShowHondaDisp(); + if ( avclanHonda.isShowRearCam() ) { + HONDA_DIS_ON; + return; } - if ( INPUT_IS_SET ) { - byte res = avclan.readMessage(); - if ( !res ) { - // //LOG - // avclan.printMessage(true); - avclanHonda.getActionID(); - if ( avclan.actionID != ACT_NONE ) { - avclanHonda.processAction( (AvcActionID)avclan.actionID ); + if ( !avclanHonda.isLockTime() ) + { + + if ( avclanHonda.isWait() ) { + avclanHonda.checkWait(); + if (avclanHonda.isWait() == false) + avclanHonda.tryToShowHondaDisp(); + } + + if ( INPUT_IS_SET ) { + byte res = avclan.readMessage(); + if ( !res ) { + //LOG + // avclan.printMessage(true); + avclanHonda.getActionID(); + if ( avclan.actionID != ACT_NONE ) { + avclanHonda.processAction( (AvcActionID)avclan.actionID ); + } } } } - - //ON a start target - if ( 11500 > millis() ) { - HONDA_DIS_ON; // initalize - return; - } else if ( 18000 > millis() ) { - avclanHonda.falseHondaDis(); - if ( !avclanHonda.isShowRearCam() ) { - HONDA_DIS_OFF; + else + { + //ON a start target + if ( 11500 > millis() ) { + HONDA_DIS_ON; // initalize return; - } else { + } else if ( 18000 > millis() ) { + avclanHonda.falseHondaDis(); + if ( !avclanHonda.isShowRearCam() ) { + HONDA_DIS_OFF; + return; + } else { + HONDA_DIS_ON; + return; + } + } else if ( avclanHonda.getCommute() ) { HONDA_DIS_ON; - return; + } else { + HONDA_DIS_OFF; } - } else if ( avclanHonda.getCommute() ) { - HONDA_DIS_ON; - } else { - HONDA_DIS_OFF; } } @@ -98,3 +109,5 @@ void EERPOM_read_config() } } + + diff --git a/AVCLan_mini/SD_Log.cpp b/AVCLan_mini/SD_Log.cpp index 8e35ec8..2874063 100644 --- a/AVCLan_mini/SD_Log.cpp +++ b/AVCLan_mini/SD_Log.cpp @@ -12,11 +12,11 @@ void SDLog::begin() { // canLog = false; bRedyToLog = false; -// // see if the card is present and can be initialized: -// if (SD.begin(chipSelect)) { -// bRedyToLog = true; -// Serial.println(" READY TO LOG "); -// } + // // see if the card is present and can be initialized: + // if (SD.begin(chipSelect)) { + // bRedyToLog = true; + // Serial.println(" READY TO LOG "); + // } } //-------------------------------------------------------------------------------- @@ -170,3 +170,5 @@ void SDLog::println(void) //} SDLog bSDLog; + + diff --git a/AVCLan_mini/SD_Log.h b/AVCLan_mini/SD_Log.h index aaf35ac..20ca89a 100644 --- a/AVCLan_mini/SD_Log.h +++ b/AVCLan_mini/SD_Log.h @@ -38,3 +38,5 @@ extern SDLog bSDLog; #endif //#SD_LOG_h + + diff --git a/AVCLan_mini/config.h b/AVCLan_mini/config.h index 14f25d0..0cefab6 100644 --- a/AVCLan_mini/config.h +++ b/AVCLan_mini/config.h @@ -44,3 +44,5 @@ + +