1
0
mirror of https://github.com/Oleg-Stepanenko-owo/IEBUS synced 2025-06-25 00:36:13 +00:00

Added new lock logic for received commands

This commit is contained in:
Oleg Stepanenko 2016-02-23 17:19:13 +02:00
parent a136f6f0e5
commit 406d68ab92
8 changed files with 125 additions and 95 deletions

View File

@ -530,38 +530,38 @@ bool AVCLanDrv::isAvcBusFree (void)
void AVCLanDrv::printMessage(bool incoming) void AVCLanDrv::printMessage(bool incoming)
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
{ {
if (!bSDLog.bRedyToLog) return; /* if (!bSDLog.bRedyToLog) return;
char sss[15] = {0}; char sss[15] = {0};
sprintf(sss, "[%u]", millis()); sprintf(sss, "[%u]", millis());
bSDLog.print(sss); bSDLog.print(sss);
if (incoming) { if (incoming) {
bSDLog.print('<'); bSDLog.print('<');
} else { } else {
bSDLog.print('>'); bSDLog.print('>');
} }
if (broadcast == AVC_MSG_BROADCAST) { if (broadcast == AVC_MSG_BROADCAST) {
bSDLog.print("b "); bSDLog.print("b ");
} else { } else {
bSDLog.print("d "); bSDLog.print("d ");
} }
bSDLog.printHex4((uint8_t)(masterAddress >> 8)); bSDLog.printHex4((uint8_t)(masterAddress >> 8));
bSDLog.printHex8((uint8_t)(masterAddress)); bSDLog.printHex8((uint8_t)(masterAddress));
bSDLog.print(' '); bSDLog.print(' ');
bSDLog.printHex4(uint8_t(slaveAddress >> 8)); bSDLog.printHex4(uint8_t(slaveAddress >> 8));
bSDLog.printHex8((uint8_t) slaveAddress); bSDLog.printHex8((uint8_t) slaveAddress);
bSDLog.print(' '); bSDLog.print(' ');
bSDLog.printHex8((uint8_t) dataSize); bSDLog.printHex8((uint8_t) dataSize);
bSDLog.print(' '); bSDLog.print(' ');
for (byte i = 0; i < dataSize; i++) { for (byte i = 0; i < dataSize; i++) {
bSDLog.printHex8((uint8_t)message[i]); bSDLog.printHex8((uint8_t)message[i]);
} }
bSDLog.println(); bSDLog.println(); */
// bSDLog._update(); // bSDLog._update();
} }
@ -609,3 +609,5 @@ byte AVCLanDrv::getActionID(const AvcInCmdTable messageTable[], byte mtSize)
//} //}
AVCLanDrv avclan; AVCLanDrv avclan;

View File

@ -111,32 +111,34 @@ class AVCLanDrv {
word headAddress; word headAddress;
byte dataSize; byte dataSize;
byte message[AVC_MAXMSGLEN]; byte message[AVC_MAXMSGLEN];
// byte event; // byte event;
byte actionID; byte actionID;
bool readonly; bool readonly;
void begin (); void begin ();
byte readMessage (void); byte readMessage (void);
// byte sendMessage (void); // byte sendMessage (void);
// byte sendMessage (const AvcOutMessage*); // byte sendMessage (const AvcOutMessage*);
void printMessage (bool incoming); void printMessage (bool incoming);
bool isAvcBusFree (void); bool isAvcBusFree (void);
byte getActionID (const AvcInCmdTable messageTable[], byte mtSize); byte getActionID (const AvcInCmdTable messageTable[], byte mtSize);
// byte getActionID (const AvcInMaskedMessageTable messageTable[], byte mtSize); // byte getActionID (const AvcInMaskedMessageTable messageTable[], byte mtSize);
// void loadMessage (const AvcOutMessage*); // void loadMessage (const AvcOutMessage*);
private: private:
bool _parityBit; bool _parityBit;
word readBits (byte nbBits); word readBits (byte nbBits);
byte _readMessage (void); byte _readMessage (void);
// byte _sendMessage (void); // byte _sendMessage (void);
// void sendStartBit (void); // void sendStartBit (void);
void send1BitWord (bool data); void send1BitWord (bool data);
// void send4BitWord (byte data); // void send4BitWord (byte data);
// void send8BitWord (byte data); // void send8BitWord (byte data);
// void send12BitWord (word data); // void send12BitWord (word data);
// bool readAcknowledge (void); // bool readAcknowledge (void);
// bool handleAcknowledge (void); // bool handleAcknowledge (void);
}; };
extern AVCLanDrv avclan; extern AVCLanDrv avclan;
#endif #endif

View File

@ -24,8 +24,9 @@
// // 10 680231020200 05 13000000001D0000DE - vol = 1 // // 10 680231020200 05 13000000001D0000DE - vol = 1
//}; //};
// { action_name, packed_size, end_off_packege_word(check_sum) }
const AvcInCmdTable mtSearchHead[] PROGMEM = { 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_DISPOFF, 0x08, 0x2F},
{ ACT_B_DISPFULL, 0x08, 0xBD}, { ACT_B_DISPFULL, 0x08, 0xBD},
{ ACT_B_DISPHULF, 0x08, 0xCF}, { ACT_B_DISPHULF, 0x08, 0xCF},
@ -33,8 +34,8 @@ const AvcInCmdTable mtSearchHead[] PROGMEM = {
{ ACT_CAM_OFF, 0x09, 0x30}, // Cam OFF { ACT_CAM_OFF, 0x09, 0x30}, // Cam OFF
// { ACT_DISP_HULF, 0x09, 0x30}, // display hulf color ??? // { ACT_DISP_HULF, 0x09, 0x30}, // display hulf color ???
{ ACT_DISP_OFF, 0x09, 0x2E}, // display off { ACT_DISP_OFF, 0x09, 0x2E}, // display off
{ ACT_TEL, 0x0A, 0xE3}, { ACT_TEL, 0x0A, 0xE3}, // start Tel Action
{ ACT_TEL_CANCEL, 0x0A, 0xDC} { ACT_TEL_CANCEL, 0x0A, 0xDC} // Cancel or End Call_ACTION
// { ACT_VOL, 0x0A, 0x06, {0x68, 0x02, 0x31, 0x02, 0x02, 0x00}, 0x00, {0x00}} //0x05 = 1 // { 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 ); // bSDLog.logs( mBuff );
} }
// AVCLan Navi & timer1 init,
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
void AVCLanHonda::begin() void AVCLanHonda::begin()
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
{ {
mVol = 0;
avclan.deviceAddress = 0x0131; avclan.deviceAddress = 0x0131;
bShowHondaDisp = false; bShowHondaDisp = false;
isHondaDisLast = false; isHondaDisLast = false;
bShowRearCam = false; bShowRearCam = false;
setWait( false );
setWaitTime( 0L ); setWaitTime( 0L );
setLockTime( 0L ); setLockTime( 0L );
@ -82,9 +80,9 @@ void AVCLanHonda::setWaitTime( const unsigned long mTime )
{ {
waitTime = mTime; waitTime = mTime;
if ( mTime > 0L ) { if ( mTime > 0L ) {
setWait(true); bWait = true;
} else { } else {
setWait(false); bWait = false;
} }
} }
@ -93,13 +91,8 @@ void AVCLanHonda::setLockTime( const unsigned long mTime )
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
{ {
lockTime = mTime; lockTime = mTime;
} bLock = true;
setWaitTime(0L);
//--------------------------------------------------------------------------------
void AVCLanHonda::setWait( const bool mWait )
//--------------------------------------------------------------------------------
{
bWait = mWait;
} }
// Use the last received message to determine the corresponding action ID, store it in avclan object // 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: case ACT_BUTTON_PRESS:
{ {
printAvcAction(ActionID); printAvcAction(ActionID);
if ( !bShowRearCam || !isWait() || ( getLockTime() < millis()) ) if ( !bShowRearCam || !isWait() || !isLockTime() )
{ {
setWaitTime( (unsigned long)((millis() + BUTT_WAIT)) ); setWaitTime( (unsigned long)((millis() + BUTT_WAIT)) );
} }
@ -145,7 +138,7 @@ void AVCLanHonda::processAction(AvcActionID ActionID)
{ {
bShowHondaDisp = false; bShowHondaDisp = false;
isHondaDisLast = false; isHondaDisLast = false;
printAvcAction(ActionID); printAvcAction(ActionID);
setLockTime( (unsigned long)(millis() + LOCK_TIME) ); setLockTime( (unsigned long)(millis() + LOCK_TIME) );
} }
break; break;
@ -179,7 +172,7 @@ void AVCLanHonda::tryToShowHondaDisp()
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
{ {
bWait = false; bWait = false;
if ( getLockTime() > millis() ) return; if ( isLockTime() ) return;
bShowHondaDisp = true; bShowHondaDisp = true;
} }
@ -191,4 +184,16 @@ void AVCLanHonda::falseHondaDis()
isHondaDisLast = false; isHondaDisLast = false;
} }
//--------------------------------------------------------------------------------
bool AVCLanHonda::isLockTime()
//--------------------------------------------------------------------------------
{
if ( bLock ) {
bLock = ( getLockTime() > millis() );
}
return bLock;
}
AVCLanHonda avclanHonda; AVCLanHonda avclanHonda;

View File

@ -20,7 +20,7 @@
#define DISABLE_TIMER1_INT (cbi(TIMSK1, TOIE1)); #define DISABLE_TIMER1_INT (cbi(TIMSK1, TOIE1));
#endif #endif
// адреса eeprom // адреса eeprom
#define E_MASTER1 0 #define E_MASTER1 0
#define E_MASTER2 1 #define E_MASTER2 1
#define E_READONLY 2 #define E_READONLY 2
@ -28,7 +28,7 @@
#define AVCLANDEVICE_NAME " Honda Kb1" #define AVCLANDEVICE_NAME " Honda Kb1"
#define AVCLANDEVICE_VERSION "0.0.7" #define AVCLANDEVICE_VERSION "0.0.8"
#define BUTT_WAIT 1000 #define BUTT_WAIT 1000
#define LOCK_TIME 700 #define LOCK_TIME 700
@ -37,7 +37,7 @@
typedef enum { typedef enum {
ACT_CAM_ON = 1, ACT_CAM_ON = 1,
ACT_CAM_OFF, ACT_CAM_OFF,
// ACT_DISP_HULF, // ACT_DISP_HULF,
ACT_DISP_OFF, ACT_DISP_OFF,
ACT_BUTTON_PRESS, ACT_BUTTON_PRESS,
ACT_B_DISPOFF, ACT_B_DISPOFF,
@ -45,7 +45,7 @@ typedef enum {
ACT_B_DISPHULF, ACT_B_DISPHULF,
ACT_TEL, ACT_TEL,
ACT_TEL_CANCEL ACT_TEL_CANCEL
// ACT_VOL // ACT_VOL
} AvcActionID; } AvcActionID;
@ -68,8 +68,9 @@ class AVCLanHonda
void setLockTime( const unsigned long mTime ); void setLockTime( const unsigned long mTime );
inline unsigned long getLockTime() const; inline unsigned long getLockTime() const;
bool isLockTime();
void setWait( const bool mWait );
inline bool isWait() const; inline bool isWait() const;
inline bool isShowRearCam() const; inline bool isShowRearCam() const;
@ -78,7 +79,6 @@ class AVCLanHonda
void checkWait(); void checkWait();
void checkLock(); void checkLock();
void falseHondaDis(); void falseHondaDis();
int mVol;
private: private:
@ -114,3 +114,5 @@ bool AVCLanHonda::isShowHondaDisp() const {
extern AVCLanHonda avclanHonda; extern AVCLanHonda avclanHonda;
#endif #endif

View File

@ -24,7 +24,7 @@ void setup()
sbi(LED_DDR, COMMUT_OUT); sbi(LED_DDR, COMMUT_OUT);
cbi(LED_PORT, COMMUT_OUT); cbi(LED_PORT, COMMUT_OUT);
bSDLog.begin(); // bSDLog.begin();
// Serial.begin(250000); // Serial.begin(250000);
// if (Serial) { // if (Serial) {
@ -42,41 +42,52 @@ void setup()
void loop() void loop()
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
{ {
if ( avclanHonda.isWait() ) { if ( avclanHonda.isShowRearCam() ) {
avclanHonda.checkWait(); HONDA_DIS_ON;
if (avclanHonda.isWait() == false) return;
avclanHonda.tryToShowHondaDisp();
} }
if ( INPUT_IS_SET ) { if ( !avclanHonda.isLockTime() )
byte res = avclan.readMessage(); {
if ( !res ) {
// //LOG if ( avclanHonda.isWait() ) {
// avclan.printMessage(true); avclanHonda.checkWait();
avclanHonda.getActionID(); if (avclanHonda.isWait() == false)
if ( avclan.actionID != ACT_NONE ) { avclanHonda.tryToShowHondaDisp();
avclanHonda.processAction( (AvcActionID)avclan.actionID ); }
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 );
}
} }
} }
} }
else
//ON a start target {
if ( 11500 > millis() ) { //ON a start target
HONDA_DIS_ON; // initalize if ( 11500 > millis() ) {
return; HONDA_DIS_ON; // initalize
} else if ( 18000 > millis() ) {
avclanHonda.falseHondaDis();
if ( !avclanHonda.isShowRearCam() ) {
HONDA_DIS_OFF;
return; 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; 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()
} }
} }

View File

@ -12,11 +12,11 @@ void SDLog::begin()
{ {
// canLog = false; // canLog = false;
bRedyToLog = false; bRedyToLog = false;
// // see if the card is present and can be initialized: // // see if the card is present and can be initialized:
// if (SD.begin(chipSelect)) { // if (SD.begin(chipSelect)) {
// bRedyToLog = true; // bRedyToLog = true;
// Serial.println(" READY TO LOG "); // Serial.println(" READY TO LOG ");
// } // }
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
@ -170,3 +170,5 @@ void SDLog::println(void)
//} //}
SDLog bSDLog; SDLog bSDLog;

View File

@ -38,3 +38,5 @@ extern SDLog bSDLog;
#endif //#SD_LOG_h #endif //#SD_LOG_h

View File

@ -44,3 +44,5 @@