mirror of
https://github.com/Oleg-Stepanenko-owo/IEBUS
synced 2025-07-04 21:26:29 +00:00
BF-infinitely loop; added new action
This commit is contained in:
parent
50d76d478e
commit
67457e86ea
@ -1,5 +1,6 @@
|
||||
#include "AVCLanDrv.h"
|
||||
#include "AVCLanHonda.h"
|
||||
#include "AVCLan_BT.h"
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanDrv::begin ()
|
||||
@ -503,41 +504,36 @@ bool AVCLanDrv::isAvcBusFree (void)
|
||||
void AVCLanDrv::printMessage(bool incoming)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
/* if (!bSDLog.bRedyToLog) return;
|
||||
if (!avclanBT.isLogging()) return;
|
||||
|
||||
char sss[15] = {0};
|
||||
sprintf(sss, "[%u]", millis());
|
||||
bSDLog.print(sss);
|
||||
|
||||
if (incoming) {
|
||||
bSDLog.print('<');
|
||||
if (incoming)
|
||||
{
|
||||
avclanBT.print("< ");
|
||||
} else {
|
||||
bSDLog.print('>');
|
||||
avclanBT.print("> ");
|
||||
}
|
||||
if (broadcast == AVC_MSG_BROADCAST) {
|
||||
bSDLog.print("b ");
|
||||
avclanBT.print("b ");
|
||||
} else {
|
||||
bSDLog.print("d ");
|
||||
avclanBT.print("d ");
|
||||
}
|
||||
avclanBT.printHex4(masterAddress >> 8);
|
||||
avclanBT.printHex8(masterAddress);
|
||||
avclanBT.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.printHex8((uint8_t) dataSize);
|
||||
bSDLog.print(' ');
|
||||
avclanBT.printHex4(slaveAddress >> 8);
|
||||
avclanBT.printHex8(slaveAddress);
|
||||
avclanBT.print(" ");
|
||||
avclanBT.printHex8(dataSize);
|
||||
|
||||
for (byte i = 0; i < dataSize; i++) {
|
||||
bSDLog.printHex8((uint8_t)message[i]);
|
||||
avclanBT.printHex8(message[i]);
|
||||
}
|
||||
bSDLog.println(); */
|
||||
// bSDLog._update();
|
||||
avclanBT.println();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Use the last received message to determine the corresponding action ID
|
||||
//--------------------------------------------------------------------------------
|
||||
byte AVCLanDrv::getActionID(const AvcInCmdTable messageTable[], byte mtSize)
|
||||
@ -548,7 +544,7 @@ byte AVCLanDrv::getActionID(const AvcInCmdTable messageTable[], byte mtSize)
|
||||
return ACT_NONE;
|
||||
}
|
||||
|
||||
byte idx = ((dataSize == 8) ? 0 : (dataSize == 9 ? 4 : 7)); // position in AvcInMessageTable
|
||||
byte idx = ((dataSize == 8) ? 0 : (dataSize == 9 ? 6 : 9)); // position in AvcInMessageTable
|
||||
|
||||
for (; idx < mtSize; ++idx) {
|
||||
if (dataSize != pgm_read_byte_near(&messageTable[idx].dataSize)) return ACT_NONE; // Because first unsized value from other range
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
//const AvcInMessageTable mtSearchHead[] PROGMEM = {
|
||||
// { ACT_BUTTON_PRESS, 0x08, 0x05, {0x59, 0x0D, 0x31, 0x02, 0x01}, 0x03, {0x21, 0x01, 0xBE}}, // Button press
|
||||
// { ACT_BUTTON_UP, 0x08, 0x05, {0x59, 0x0D, 0x31, 0x02, 0x01}, 0x03, {0x21, 0x01, 0xBE}}, // Button press
|
||||
// { ACT_B_DISPOFF, 0x08, 0x05, {0x59, 0x0D, 0x31, 0x02, 0x01}, 0x03, {0x22, 0x71, 0x2F}},
|
||||
// { ACT_B_DISPFULL, 0x08, 0x05, {0x59, 0x0D, 0x31, 0x02, 0x01}, 0x03, {0x20, 0x01, 0xBD}},
|
||||
// { ACT_B_DISPHULF, 0x08, 0x05, {0x59, 0x0D, 0x31, 0x02, 0x01}, 0x03, {0x22, 0x11, 0xCF}},
|
||||
@ -23,16 +23,23 @@
|
||||
// // 10 680231020200 05 13000000001D0000DE - vol = 1
|
||||
//};
|
||||
|
||||
//TODO: master -> 131
|
||||
// 09780D3103024B000009 - next track ?
|
||||
// 08590D3102012212D0
|
||||
// 08590D3102012213D1
|
||||
// 08590D3102012214D2
|
||||
|
||||
// { action_name, packed_size, end_off_packege_word(check_sum) }
|
||||
const AvcInCmdTable mtSearchHead[] PROGMEM = {
|
||||
{ ACT_BUTTON_PRESS, 0x08, 0xBE}, // Button press
|
||||
{ ACT_B_DISPOFF, 0x08, 0x2F},
|
||||
{ ACT_B_DISPFULL, 0x08, 0xBD},
|
||||
{ ACT_B_DISPHULF, 0x08, 0xCF},
|
||||
{ ACT_CAM_ON, 0x09, 0x31}, // Cam ON
|
||||
{ ACT_CAM_OFF, 0x09, 0x30}, // Cam OFF
|
||||
// { ACT_DISP_HULF, 0x09, 0x30}, // display hulf color ???
|
||||
{ ACT_DISP_OFF, 0x09, 0x2E}, // display off
|
||||
{ ACT_BUTTON_DOWN, 0x08, 0xBC}, // 08590D3102012000BC
|
||||
{ ACT_BUTTON_UP, 0x08, 0xBE}, // 08590D3102012101BE
|
||||
{ ACT_B_DISPOFF, 0x08, 0x2F}, // 08590D31020122712F
|
||||
{ ACT_B_DISPFULL_DOWN, 0x08, 0x43}, // 08590D310201228543
|
||||
{ ACT_B_DISPFULL_UP, 0x08, 0xBD}, // 08590D3102012001BD
|
||||
{ ACT_B_DISPHULF, 0x08, 0xCF}, // 08590D3102012211CF
|
||||
{ ACT_CAM_ON, 0x09, 0x31}, // 09590D31020194000031
|
||||
{ ACT_CAM_OFF, 0x09, 0x30}, // 09590D31020191020030
|
||||
{ ACT_DISP_OFF, 0x09, 0x2E}, // 09590D3102019100002E
|
||||
{ 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
|
||||
@ -95,7 +102,7 @@ void AVCLanHonda::processAction( AvcActionID ActionID )
|
||||
if ( bFirstStart_20 && (20000 < millis()) ) bFirstStart_20 = false;
|
||||
|
||||
switch ( ActionID ) {
|
||||
case ACT_BUTTON_PRESS:
|
||||
case ACT_BUTTON_UP:
|
||||
{
|
||||
if ( !bShowRearCam || !isWait() )
|
||||
{
|
||||
@ -111,9 +118,10 @@ void AVCLanHonda::processAction( AvcActionID ActionID )
|
||||
bShowHondaDisp = true;
|
||||
setWaitTime(0L);
|
||||
break;
|
||||
case ACT_DISP_OFF:
|
||||
if ( !bShowRearCam )
|
||||
{
|
||||
case ACT_B_DISPOFF:
|
||||
case ACT_B_DISPFULL_UP:
|
||||
case ACT_B_DISPHULF:
|
||||
if ( !bShowRearCam ) {
|
||||
// need freeze on 2000 sec after code receiving.
|
||||
bShowHondaDisp = false;
|
||||
bHondaDisLast = false;
|
||||
|
@ -36,11 +36,12 @@
|
||||
typedef enum {
|
||||
ACT_CAM_ON = 1,
|
||||
ACT_CAM_OFF,
|
||||
// ACT_DISP_HULF,
|
||||
ACT_DISP_OFF,
|
||||
ACT_BUTTON_PRESS,
|
||||
ACT_BUTTON_DOWN,
|
||||
ACT_BUTTON_UP,
|
||||
ACT_B_DISPOFF,
|
||||
ACT_B_DISPFULL,
|
||||
ACT_B_DISPFULL_DOWN,
|
||||
ACT_B_DISPFULL_UP,
|
||||
ACT_B_DISPHULF,
|
||||
ACT_TEL,
|
||||
ACT_TEL_CANCEL
|
||||
|
@ -2,21 +2,30 @@
|
||||
#include "AVCLan_BT.h"
|
||||
#include <SoftwareSerial.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
#define E_LOGG 0
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
SoftwareSerial mySerial(4, 3); // RX | TX
|
||||
char command_buff[15];
|
||||
int command_i;
|
||||
bool startCommand;
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::begin()
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
mySerial.begin(9600);
|
||||
mySerial.println("BlueTooth is ready");
|
||||
mySerial.println("log_on@ - start logging");
|
||||
mySerial.println("log_off@ - end logging");
|
||||
mySerial.println("save@ - save logging in EEPROM");
|
||||
mySerial.println("@log+@ - start logging");
|
||||
mySerial.println("@log-@ - end logging");
|
||||
mySerial.println("@save@ - save logging in EEPROM");
|
||||
logging = false;
|
||||
command_i = 0;
|
||||
startCommand = false;
|
||||
|
||||
EERPOM_read_config();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
@ -58,20 +67,90 @@ int AVCLanBT::available()
|
||||
void AVCLanBT::checkCommand( char command )
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
if ( command == '@' ) //end of command;
|
||||
{
|
||||
command_buff[command_i + 1] = '\0';
|
||||
if ( (command == '@') && !startCommand ) {
|
||||
startCommand = true;
|
||||
command_i = 0;
|
||||
} else if ( startCommand && (command != '@') ) {
|
||||
|
||||
if ( 0 == strcmp( command_buff, "log_on" ) ) logging = true;
|
||||
else if ( 0 == strcmp( command_buff, "log_off" ) ) logging = false;
|
||||
println(command_buff);
|
||||
Serial.print("logging - "); Serial.println(logging);
|
||||
}
|
||||
else
|
||||
{
|
||||
command_buff[command_i++] = command;
|
||||
} else if ( startCommand && (command == '@') ) {
|
||||
command_buff[command_i] = '\0';
|
||||
startCommand = false;
|
||||
|
||||
if ( 0 == strcmp( command_buff, "log+" ) ) {
|
||||
logging = true;
|
||||
mySerial.println(">>Logging ON<<");
|
||||
// Serial.println(">>Logging ON<<");
|
||||
} else if ( 0 == strcmp( command_buff, "log-" ) ) {
|
||||
mySerial.println(">>Logging OFF<<");
|
||||
// Serial.println(">>Logging OFF<<");
|
||||
logging = false;
|
||||
} else if ( 0 == strcmp( command_buff, "save" ) ) {
|
||||
EEPROM.write( E_LOGG, (int)logging );
|
||||
}
|
||||
|
||||
println(command_buff);
|
||||
// Serial.println(command_buff);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::println(void)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
print("\r\n");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::printHex4(uint8_t data)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
uint8_t c = data & 0x0f;
|
||||
c += c < 10 ? '0' : 'A' - 10 ;
|
||||
sendByte(c);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::printHex8(uint8_t data)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
printHex4(data >> 4);
|
||||
printHex4(data);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::printDec(uint8_t data)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
uint8_t buf[3];
|
||||
uint8_t i = 0;
|
||||
if (data == 0) {
|
||||
sendByte('0');
|
||||
return;
|
||||
}
|
||||
|
||||
while (data > 0) {
|
||||
buf[i++] = data % 10;
|
||||
data /= 10;
|
||||
}
|
||||
for (; i > 0; i--)
|
||||
sendByte((buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::sendByte(uint8_t val)
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
mySerial.write( val );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void AVCLanBT::EERPOM_read_config()
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
if (EEPROM.read(E_LOGG) == 1 ) logging = true;
|
||||
|
||||
logging ? mySerial.println(">>Logging ON<<") : mySerial.println(">>Logging OFF<<");
|
||||
}
|
||||
|
||||
AVCLanBT avclanBT;
|
||||
|
@ -17,7 +17,12 @@ class AVCLanBT
|
||||
|
||||
void println( char*);
|
||||
void print(const char*);
|
||||
void printHex4(uint8_t);
|
||||
void printHex8(uint8_t);
|
||||
void printDec(uint8_t);
|
||||
void println(void);
|
||||
|
||||
void sendByte(uint8_t);
|
||||
char read();
|
||||
|
||||
bool isLogging();
|
||||
@ -25,6 +30,7 @@ class AVCLanBT
|
||||
void checkCommand(char command );
|
||||
|
||||
private:
|
||||
void EERPOM_read_config();
|
||||
bool logging;
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,7 @@ int len = 0; //stores the length of the commands
|
||||
void setup()
|
||||
//--------------------------------------------------------------------------------
|
||||
{
|
||||
Serial.begin(9600);
|
||||
// Serial.begin(9600);
|
||||
|
||||
avclan.begin();
|
||||
avclanHonda.begin();
|
||||
@ -42,9 +42,8 @@ void loop()
|
||||
if (avclanBT.available())
|
||||
{
|
||||
len = avclanBT.available();
|
||||
int i;
|
||||
Serial.print("len ="); Serial.println(len);
|
||||
for (i = 0; i < len; i++)
|
||||
// Serial.print("len ="); Serial.println(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
avclanBT.checkCommand(avclanBT.read());
|
||||
}
|
||||
@ -67,8 +66,8 @@ void loop()
|
||||
if ( INPUT_IS_SET ) {
|
||||
byte res = avclan.readMessage();
|
||||
if ( !res ) {
|
||||
avclan.printMessage(true);
|
||||
error_count = 0;
|
||||
|
||||
avclanHonda.getActionID();
|
||||
if ( avclan.actionID != ACT_NONE ) {
|
||||
sprintf( BUFFF, "Action: %d", avclan.actionID );
|
||||
@ -97,13 +96,17 @@ void loop()
|
||||
}
|
||||
|
||||
if ( error_count > MAX_ERROR_COUNT ) {
|
||||
avclanHonda.bFirstStart_20 = false;
|
||||
error_count = 0;
|
||||
avclanHonda.setHondaDis(true);
|
||||
|
||||
LED_OFF;
|
||||
HONDA_DIS_ON;
|
||||
|
||||
sprintf(BUFFF, "Error: %d", errorID );
|
||||
avclanBT.println( BUFFF );
|
||||
avclan.begin();
|
||||
cli();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user