Mohammed Ibrahim

 

The requirements for RKE project is taken from https://cruizbyte.co.in/training-blog/f/remote-keyless-entry

The RKE project has following features:
1. Door Lock
2. Door Unlock
3. Tail-gate open
4. Vehicle Search 
5. Panic Alarm
6. Auto Locking
7. Auto un-locking
8. Auto re-locking
9. Emergency Unlocking
10. Anti-Theft Alarm function
11. Beep function
12. Mute/ Un mute function.

The following application is  developed for RKE implementation.

The system level block diagram of RKE is given below




//==============Program for RKE Feature Application=====


//=Initializing the variable for remote keyless entry Button=

bool lock_button, unlock_button, trunk_button;

 

//========Declaring the variables for Input Parameters===

bool driver_dr_switch, passenger_dr_switch, rear_lh_dr_switch, rear_rh_dr_switch, trunk_dr_switch;

 //Initializing the variable for dr switches

int  Key_cylinder_switch =2; //1-OFF, 2-ON/ACC

int speed_sensor_input,  dr_unlock_button_press_timer, dr_lock_button_press_timer, battery_power;

 

//=======Declaring the variables for Output Parameters===

bool hazard_lamp, alarm_horn, RCM_module, buzzer;

bool driver_dr_solenoid_valve, passenger_dr_solenoid_valve, rear_lh_dr_solenoid_valve;

bool rear_rh_dr_solenoid_valve, trunk_dr_solenoid_valve, Driver_center_lock, vehicle_armed;

//=================== Function DECLARATION========

//=============== Hazard lamp Lock Function==================

void hazard_lamp_lock()          //Declaring functions to activate hazardous lamp and alarm horn when RKE locks the door

{

  hazard_lamp = alarm_horn = 1;

  delay(500);

  hazard_lamp = alarm_horn = 0;

}

//============== Hazard lamp Unlock Function=========

void hazard_lamp_unlock()

{

  int i;

  for (i = 1; i <= 2; i++)

  {

    hazard_lamp = alarm_horn = 1;

    delay(500);

    hazard_lamp = alarm_horn = 0;

  }

}

//========= Function to check all the doors are closed======

int door_closed() {

  if (driver_dr_switch == 1 && passenger_dr_switch == 1 && rear_lh_dr_switch == 1 && rear_rh_dr_switch == 1 && trunk_dr_switch == 1)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//========== Function to check all the doors are open====

int door_opened() {

  if (driver_dr_switch == 0 || passenger_dr_switch == 0 || rear_lh_dr_switch == 0 || rear_rh_dr_switch == 0 || trunk_dr_switch == 0)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//======== Function to lock the door solenoid valves =======

int door_lock() {

  driver_dr_solenoid_valve = passenger_dr_solenoid_valve = rear_lh_dr_solenoid_valve = rear_rh_dr_solenoid_valve = trunk_dr_solenoid_valve = 1;

  Serial.println("All doors are locked successfully");

  vehicle_armed = 1;

}

//======== Function to Unlock the door solenoid valves =====

int door_unlock() {

  driver_dr_solenoid_valve = passenger_dr_solenoid_valve = rear_lh_dr_solenoid_valve = rear_rh_dr_solenoid_valve = 0;

  Serial.println("All doors are unlocked successfully");

  vehicle_armed = 0;

}

 

//=== Function to check the doors are unlocked for theft ====

bool door_unlock_check_theft()

{

  if (driver_dr_solenoid_valve == 0 || passenger_dr_solenoid_valve == 0 || rear_lh_dr_solenoid_valve == 0 || rear_rh_dr_solenoid_valve == 0 || trunk_dr_solenoid_valve == 0 || driver_dr_switch == 0 || passenger_dr_switch == 0 || rear_lh_dr_switch == 0 || rear_rh_dr_switch == 0 || trunk_dr_switch == 0 )

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

 

//==== Function to check all the doors are locked====

bool door_lock_check()

{

  if (driver_dr_solenoid_valve == passenger_dr_solenoid_valve == rear_lh_dr_solenoid_valve == rear_rh_dr_solenoid_valve == trunk_dr_solenoid_valve == 1)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//====== Alarm function declaration==========================

 

int timer_alarm() {

  while (millis() <= 30003)

  {

    Serial.println("Hazard lamp with alarm horn activated for 30s");

    hazard_lamp = alarm_horn =  1;

    delay(500);

    hazard_lamp = alarm_horn = 0;

  }

}

//============Beep Function================================

int beep_function()

{

  while (door_opened() == 1 && millis()<30000) //when all doors are locked

  {

    buzzer = 1;

    Serial.println("Buzzer ON,Please close the door");

  }

  if(door_opened() == 0)

  {

    buzzer = 0;

    Serial.println("Buzzer off");

  }

}

void setup() {

  Serial.begin(9600);

 

  //======== Door lockig Comments ===========

  //Condition to lock all the doors when lock button input received

  void RKE_lock_Func();

  {

    if (lock_button == 1 && dr_lock_button_press_timer < 3)

    {

        if (door_closed() == 1)

        {

          if(battery_power<30)                                                     //Monitorig RKE battery

          {

            Serial.println("RKE battery is too low");

          }

          door_lock();

          hazard_lamp_lock();

          while(door_opened()==1)

          {

          beep_function();

          if (unlock_button == 0 && ( Key_cylinder_switch == 2 || door_unlock_check_theft() == 1) )                       //Anti-theft alarm activation while opening of any doors after vehicle armed

          {

            hazard_lamp = alarm_horn = 1;

            Serial.println("Alert!!! Theft attempt");

          }

        }

        }

        else

        {

          Serial.println("Please close all doors and try again");

        }

    }

  }

  //=condition to check vehicle speed is above 20km/hr then automatically close all doors - Auto lock

  if (Key_cylinder_switch == 2)

  {

    if (speed_sensor_input > 20 )

    {

      door_lock();

    }

  }

  //=Condition to check driver door lock knob is closed then close all the door - Center lock=====

  if (door_closed() == 1)

  {

    if (Driver_center_lock == 1)

    {

      door_lock();

      hazard_lamp_lock();

      beep_function();

    }

 

  }

 

  //=========== Door Unlocking =====================

  //======Condition to unlock all the doors by getting input from RKE======

  if (unlock_button == 1 && vehicle_armed == 1 )

  {

    if (dr_unlock_button_press_timer < 3)

    {

      door_unlock();

      millis();

      hazard_lamp_unlock();         //Auto-relocking

      while (door_closed() == 1)

      {

        Serial.println("Timer begins");

        if (millis() > 30000)

        {

          door_lock();

          hazard_lamp_lock();

        }

      }

    }

   

    if(dr_unlock_button_press_timer > 3)

    {

    switch (Key_cylinder_switch)

    {

      case 1:

            timer_alarm();

            break;

      case 2:

            timer_alarm();

            break;

               }

    }

    else

    {

      Serial.println("Task incomplete");

    }

     }

   //=======Condition to unlock all the doors when key turned off - Auto Unlocking====

   if (Key_cylinder_switch == 1 && speed_sensor_input == 0)

  {

    door_unlock();

    hazard_lamp_unlock();

  }

  //=====Condition to unlock all the doors at emergency suituation=========

  if (RCM_module == 1) //During accident or any emergency all doors unlocked

  {

    door_unlock();

    hazard_lamp = alarm_horn = 1;

    Serial.print("Alert!!!All doors opened");

  }

  //=========Condition to unlock trunk door========

  if (trunk_button == 1 )

  {

    int i;

    if (trunk_dr_solenoid_valve == 1)

    {

      trunk_dr_solenoid_valve = 0;

      Serial.println("trunk door unlocked successfully");

      for ( i = 1; i <= 4; i++)

      {

        hazard_lamp = 1;

        delay(500);

        hazard_lamp = 0;

      }

    }

  }

 

  //==============mute/unmute function===============

  int m;

  if (lock_button == 1) //checking vehicle locked

  {

    while (dr_lock_button_press_timer >= 3 && millis()<30000)

    {

      buzzer = alarm_horn = 0;

      Serial.println("buzzer muted");

      while(m>2)

      {

        hazard_lamp = 1;

        delay(500);

        hazard_lamp = 0;

        m++;

      }

    }

  }

  //=======Special conditions if any doors opened with RKE locked hazazard lamp flash for five times with alarm=====  if (lock_button == 1 && dr_lock_button_press_timer < 3)

  {

    if (door_opened() == 1)

    {

      int i;

      Serial.println("please close all the doors");

      for (i = 1; i <= 5; i++)

      {

        hazard_lamp = alarm_horn = 1;

        delay(500);

        hazard_lamp = alarm_horn = 0;

      }

    }

  }

  //====Condition to lock the door if driver door closed but any other door opened ====

  if (door_opened() == 1)

  {

    if (lock_button == 1 && dr_lock_button_press_timer <= 3)

    {

      if (driver_dr_switch == 1)

      {

        driver_dr_solenoid_valve = 1;

        Serial.println("Driver door closed");

        if (passenger_dr_switch == 1)

        {

          passenger_dr_solenoid_valve = 1;

          Serial.println("Passenger door closed");

        }

        else

        {

          Serial.println("Please close Passenger door");

        }

        if (rear_lh_dr_switch == 1)

        {

          rear_lh_dr_solenoid_valve = 1;

          Serial.println("rear lh door  closed");

        }

        else

        {

          Serial.println("Please close rear lh door");

        }

        if (rear_rh_dr_switch == 1)

        {

          rear_rh_dr_solenoid_valve = 1;

          Serial.println("rear rh door closed");

        }

        else

        {

          Serial.println("Please close rear rh door");

        }

        if (trunk_dr_switch == 1)

        {

          trunk_dr_solenoid_valve = 1;

        }

        else

        {

          Serial.println("Please close trunk door");

        }

        hazard_lamp_lock();

      }

    }

  }

// =====If driver door is opened while RKE locking========

if (lock_button == 1 && dr_lock_button_press_timer <= 3)

{

  if(driver_dr_switch == 0)

  {

    Serial.println("RKE lock function not activated and close the driver door and relock with RKE");

  }

}

 RKE TEST report





//**************************************************************

CAN Instrument Cluster Implementation

The requirements for IC is taken from https://cruizbyte.co.in/training-blog/f/instrument-cluster-tell-tales-and-warning-lights

A CAN restbus simulation is configured for sending and receiving CAN messages. CAN  messages are decoded for IC tell-tales status signals  & application is developed based on CAN DBC file. Few messages are sent to other nodes in the CAN bus.

Tell-tale status is simulated in Serial terminal with a serial print show casing CAN signal value table description such as ON, OFF, BLINK & Reserved.




//====Instrument Cluster Tell Tale Implementation with CAN

#include <SPI.h>                        

//Including CAN communication Header

#include <mcp2515.h>                   

#include "ArduinoEasynextion.h"

struct can_frame canMsg;                

MCP2515 mcp2515(10);

//=====Declaring Variables for input parameters========

int FOG_LAMP_SIGNAL, VEHICLE_ARMED_STATUS, REAR_FOG_LAMP, HEAD_LAMP_HIGH_BEAM;

int TURN_LEFT[2] , TURN_RIGHT[2], DRIVER_DOOR_SIGNAL, PASSENGER_DOOR_SIGNAL;  

int REAR_LH_DOOR,REAR_RH_DOOR, TAILGATE_OPEN_WARN, DOOR_AJAR_WARN;

int PARKING_BRAKE_STATUS,LOW_WASHER_FLUID;

int GLOW_PLUG, WATER_IN_FUEL, CRUISE_CONTROL[2], OIL_PRESS, CHECK_ENGINE[2], OBD_CHECK;

int ENGINE_SPEED[8],Start_stop, Battery_warn, DPF_Warn_lamp, DEF_Warn_lamp, REDUCED_POWER;

int EPS_WARN, VEHICLE_SPEED[8], FR_LH_W_SPEED[8],FR_RH_W_SPEED[8], RR_LH_W_SPEED[8];

int RR_RH_W_SPEED[8];

int Vehicle_overspeed_warn, EPB_WARN, ABS_MALFUNCTION, ESP_WARN_LAMP[2];

int lock_signal, unlock_signal, Trunk_unlock_signal, Search_func, Mute_func;

int seat_belt_warn,Pass_Airbag_cuttoff, Airbag_warn, Warn_4WD[2],Lock_4WD, Transmission_warn;

int FR_LH_Tire_press[4],FR_RH_Tire_press[4],RR_LH_Tire_press[4],RR_RH_Tire_press[4],Tire_press_warn;

//====Declaring Variables to store the Data from CAN Message

int canmsg_350_1[8], canmsg_355_1[8], canmsg_365_1, canmsg_370_1[8],canmsg_380_1[8], canmsg_390_1;

int canmsg_360_1, canmsg_395_1,canmsg_400[8],canMsg_350_byte_1, canMsg_350_byte_2,canMsg_355_byte_1;

int canMsg_355_byte_2,canMsg_355_byte_3, canMsg_360_byte_1;

//===Declaring CAN meassage to Transmit==========

struct can_frame canMsg1;

struct can_frame canMsg2;

struct can_frame canMsg3;

struct can_frame canMsg4;

struct can_frame canMsg5;

struct can_frame canMsg6;

struct can_frame canMsg7;

struct can_frame canMsg8;

struct can_frame canMsg9;

 void setup() {

  Serial.begin(115200);                        //Baud-Rate

  mcp2515.reset();

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);

  mcp2515.setNormalMode();

 

  Serial.println("------- CAN Read ----------");

  Serial.println("ID  DLC   DATA");

}

 

void loop() {

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {

    //========RECEIVE BCM CAN MESSAGE DATA=========

    if (canMsg.can_id == 0x350)

       {

      for (int i = 0; i < canMsg.can_dlc; i++)  { // print the data

        canmsg_350_1[i] = canMsg.data[i];

      }

      if(canMsg.can_id == 0x350)

      {

        Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print(" ");

      }

        for (int i = 0; i < canMsg.can_dlc; i++)

      {

        Serial.print(canmsg_350_1[i]);

        Serial.print("  "); 

      }

  

        Serial.println();

          for(int i=0;i<=7;i++)

          {

            if(canmsg_350_1[0] & (1<<i))

            {

              if(i==0)

              {

                  FOG_LAMP_SIGNAL=1; 

              }

              if(i==1)

              {

                VEHICLE_ARMED_STATUS =1;

              }

              if(i==2 )

              {

                REAR_FOG_LAMP=1;

              }

              if(i==3 )

              {

                HEAD_LAMP_HIGH_BEAM=1;

              }

              if(i==4 || i==5)

              {

                 if(i==4)

                 {

                   TURN_LEFT[0]=1;

                 }

                 else

                   {

                      TURN_LEFT[1]=1;

                   }

              }

              if(i==6 || i==7)

              {

                   if(i==6)

                 {

                   TURN_RIGHT[0]=1;

                 }

                 else

                   {

                   TURN_RIGHT[1]=1;

                   }

              }

            }

            else if(0)

            {

               if(i==0)

              {

                FOG_LAMP_SIGNAL=0;

              }

              if(i==1)

              {

                VEHICLE_ARMED_STATUS =0;

              }

              if(i == 2)

              {

                REAR_FOG_LAMP=0;

              }

              if(i == 3)

              {

                HEAD_LAMP_HIGH_BEAM=0;

              }

              if(i==4 || i==5)

              {

                   if(i==4)

                 {

                   TURN_LEFT[0]=0;

                 }

                 else

                   {

                   TURN_LEFT[1]=0;

                   }

              }

              if(i==6 || i==7)

              {

                   if(i==6)

                 {

                   TURN_RIGHT[0]=0;

                 }

                 else

                   {

                   TURN_RIGHT[1]=0;

                   }

              }

           }

          }

          for(int i=0;i<=7;i++)

          {

            if(canmsg_350_1[1] & (1<<i))

            {

              if(i==0)

              {

                  DRIVER_DOOR_SIGNAL=1; 

              }

              if(i==1)

              {

                PASSENGER_DOOR_SIGNAL =1;

              }

              if(i==2 )

              {

                REAR_LH_DOOR=1;

              }

              if(i==3 )

              {

                REAR_RH_DOOR=1;

              }

              if(i==4)

              {

                 TAILGATE_OPEN_WARN=1;

              }

              if(i==5)

              {

                   DOOR_AJAR_WARN=1;

              }

              if(i == 6)

              {

                PARKING_BRAKE_STATUS =1;

              }

              if(i == 7)

              {

                LOW_WASHER_FLUID =1;

              }

            }

            else if(0)

            {

               if(i==0)

              {

                DRIVER_DOOR_SIGNAL=0;

              }

              if(i==1)

              {

                PASSENGER_DOOR_SIGNAL =0;

              }

              if(i == 2)

              {

                REAR_LH_DOOR=0;

              }

              if(i == 3)

              {

               REAR_RH_DOOR=0;

              }

              if(i==4)

              {

                TAILGATE_OPEN_WARN=0;

              }

              if(i==5)

              {

                   DOOR_AJAR_WARN=0;

              }

              if(i == 6)

              {

                PARKING_BRAKE_STATUS =0;

              }

              if(i == 7)

              {

                LOW_WASHER_FLUID =0;

              }

            } 

          }

//======================================Fog_Lamp Signal=========================================

if (FOG_LAMP_SIGNAL == 0){Serial.println("Fog Lamp off ");}

else{Serial.println("Fog Lamp ON ");}

//===========VEHICLE_ARMED_STATUS_Lamp Signal==============

if (VEHICLE_ARMED_STATUS == 0){Serial.println("VEHICLE_ARMED_STATUS Lamp off ");}

else{Serial.println("VEHICLE_ARMED_STATUS Lamp ON ");}

 

//===========HEAD_LAMP_HIGH_BEAM LAMP Signal=================

if (HEAD_LAMP_HIGH_BEAM == 0){Serial.println("HEAD_LAMP_HIGH_BEAM off ");}

else{Serial.println("HEAD_LAMP_HIGH_BEAM ON ");}

 

//==========TURN_LEFT LAMP Signal==================

 {

 if(TURN_LEFT[0] == 0 && TURN_LEFT[1] == 0)

 {Serial.println("TURN_LEFT_lamp OFF");}

  else if(TURN_LEFT[0] == 0 && TURN_LEFT[1] == 1)

          { Serial.println("TURN_LEFT_lamp ON");}

  else if (TURN_LEFT[0] == 1 && TURN_LEFT[1] == 0)

           {Serial.println("Reserved");}

  else if (TURN_LEFT[0] == 1 && TURN_LEFT[1] == 1)        

           {Serial.println("TURN_LEFT_lamp Fast blink");}

 }

//============TURN_RIGHT LAMP Signal=================

 {

 if(TURN_RIGHT[0] == 0 && TURN_RIGHT[1] == 0)

 {Serial.println("TURN_RIGHT_lamp OFF");}

  else if(TURN_RIGHT[0] == 0 && TURN_RIGHT[1] == 1)

          { Serial.println("TURN_RIGHT_lamp ON");}

  else if (TURN_RIGHT[0] == 1 && TURN_RIGHT[1] == 0)

           {Serial.println("Reserved");}

  else if (TURN_RIGHT[0] == 1 && TURN_RIGHT[1] == 1)        

           {Serial.println("TURN_RIGHT_lamp Fast blink");}

         

 }

//========DRIVER_DOOR_SIGNAL LAMP Signal=====

if (DRIVER_DOOR_SIGNAL == 0){Serial.println("DRIVER_DOOR_SIGNAL_lamp off ");}

else{Serial.println("DRIVER_DOOR_SIGNAL_lamp ON ");}

 

//========PASSENGER_DOOR_SIGNAL LAMP Signal=========

if (PASSENGER_DOOR_SIGNAL == 0){Serial.println("PASSENGER_DOOR_SIGNAL_lamp off ");}

else{Serial.println("PASSENGER_DOOR_SIGNAL_lamp ON ");}

 

//=======REAR_LH_DOOR LAMP Signal================

if (REAR_LH_DOOR == 0){Serial.println("REAR_LH_DOOR_SIGNAL_lamp off ");}

else{Serial.println("REAR_LH_DOOR_SIGNAL_lamp ON ");}

 

//=============REAR_RH_DOOR LAMP Signal==============

if (REAR_RH_DOOR == 0){Serial.println("REAR_RH_DOOR_SIGNAL_lamp off ");}

else{Serial.println("REAR_RH_DOOR_SIGNAL_lamp ON ");}

 

//=========TAILGATE_OPEN_WARN LAMP Signal==============

if (TAILGATE_OPEN_WARN == 0){Serial.println("TAILGATE_OPEN_WARN LAMP off ");}

else{Serial.println("TAILGATE_OPEN_WARN LAMP ON ");}

 

//=========DOOR_AJAR_WARN LAMP Signal===============

if (DOOR_AJAR_WARN == 0){Serial.println("DOOR_AJAR_WARN LAMP off ");}

else{Serial.println("DOOR_AJAR_WARN LAMP ON ");}

 

//=====PARKING_BRAKE_STATUS LAMP Signal===============

if (PARKING_BRAKE_STATUS == 0){Serial.println("PARKING_BRAKE_STATUS LAMP off ");}

else{Serial.println("PARKING_BRAKE_STATUS LAMP ON ");}

 

//=========LOW_WASHER_FLUID LAMP Signal==========

if (LOW_WASHER_FLUID == 0){Serial.println("LOW_WASHER_FLUID LAMP off ");}

else{Serial.println("LOW_WASHER_FLUID LAMP ON ");}

    }

//==========RECEIVE ECU CAN MESSAGE DATA=================

    if (canMsg.can_id == 0x355)

       Serial.print(canMsg.can_id,HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print(" ");

    {

     

      for (int i = 0; i < canMsg.can_dlc; i++)  {

        canmsg_355_1[i] = canMsg.data[i];

      }

        for (int i = 0; i < canMsg.can_dlc; i++)

      {

        Serial.print(canmsg_355_1[i],HEX);

        Serial.print("  "); 

      }

      Serial.println();

          for(int i=0;i<=7;i++)

          {

            if(canmsg_355_1[0] & (1<<i))

            {  

              if(i == 0)

              {

               GLOW_PLUG=1;   

              }

              if(i == 1)

              {

               WATER_IN_FUEL=1;   

              }

              if(i==2 || i==3)

              {

                   if(i==2)

                 {

                   CRUISE_CONTROL[0]=1;

                 }

                 else

                   {

                   CRUISE_CONTROL[1]=1;

                   }

              }

              if(i == 4)

              {

               OIL_PRESS=1;   

              }

              if(i==5 || i==6)

              {

                   if(i==5)

                 {

                   CHECK_ENGINE[0]=1;

                 }

                 else

                   {

                   CHECK_ENGINE[1]=1;

                   }

              }

              if(i == 7)

              {

               OBD_CHECK=1;   

              }

            }

            else if(0)

            {

              if(i == 0)

              {

               GLOW_PLUG=0;   

              }

              if(i == 1)

              {

               WATER_IN_FUEL=0;   

              }

              if(i==2 || i==3)

              {

                   if(i==2)

                 {

                   CRUISE_CONTROL[0]=0;

                 }

                 else

                   {

                   CRUISE_CONTROL[1]=0;

                   }

              }

              if(i == 4)

              {

               OIL_PRESS=0;   

              }

              if(i==5 || i==6)

              {

                   if(i==5)

                 {

                   CHECK_ENGINE[0]=0;

                 }

                 else

                   {

                   CHECK_ENGINE[1]=0;

                   }

              }

              if(i == 7)

              {

               OBD_CHECK=0;   

              }

            }

  }

  for(int i=0;i<=7;i++)

          {

            if(canmsg_355_1[1] & (1<<i))

            {  

              ENGINE_SPEED[i]=1;

            }

            else

            {

              ENGINE_SPEED[i]=0;

            }

            }

  for(int i=0;i<=7;i++)

          {

            if(canmsg_355_1[2] & (1<<i))

            {  

              if(i==0)

              {

                Start_stop=1;

              }

              if(i==1)

              {

                Battery_warn=1;

              }

              if(i==2)

              {

                DPF_Warn_lamp=1;

              }

              if(i==3)

              {

                DEF_Warn_lamp=1;

              }

              if(i==4)

              {

                REDUCED_POWER=1;

              }

            }

            else if(0)

            {

              if(i==0)

              {

                Start_stop=0;

              }

              if(i==1)

              {

                Battery_warn=0;

              }

              if(i==2)

              {

                DPF_Warn_lamp=0;

              }

              if(i==3)

              {

                DEF_Warn_lamp=0;

              }

              if(i==4)

              {

                REDUCED_POWER=0;

              }

             

            }

            }

//========================================GLOW_PLUG LAMP Signal================================

if (GLOW_PLUG == 0){Serial.println("GLOW_PLUG LAMP off ");}

else{Serial.println("GLOW_PLUG LAMP ON ");}

 

//================WATER_IN_FUEL LAMP Signal==============

if (WATER_IN_FUEL == 0){Serial.println("WATER_IN_FUEL LAMP off ");}

else{Serial.println("WATER_IN_FUEL LAMP ON ");}

 

//============CRUISE_CONTROL LAMP Signal==========

 {

 if(CRUISE_CONTROL[0] == 0 && CRUISE_CONTROL[1] == 0)

 {Serial.println("CRUISE_CONTROL OFF");}

  else if(CRUISE_CONTROL[0] == 0 && CRUISE_CONTROL[1] == 1)

          { Serial.println("CRUISE_CONTROL ON");}

  else if (CRUISE_CONTROL[0] == 1 && CRUISE_CONTROL[1] == 0)

           {Serial.println("Reserved");}

  else if (CRUISE_CONTROL[0] == 1 && CRUISE_CONTROL[1] == 1)        

           {Serial.println("CRUISE_CONTROL Fast blink");}

 }

}

//==========READ DATA FROM EPS CAN MESSAGE=============

  if (canMsg.can_id == 0x365)

    {

       Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

      for (int i = 0; i < canMsg.can_dlc; i++)  {

        canmsg_365_1 = canMsg.data[i];

      }

        Serial.print(canmsg_365_1,HEX);

        Serial.print("  "); 

        Serial.println();

            if(canmsg_365_1 & (1<<0))

            {  

              EPS_WARN =1;

            }

            else

            {

              EPS_WARN =0;

            }

            }

 //========READ CAN MESSAGE FROM  ESP======================

 if(canMsg.can_id == 0x370)

  {

     Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

      for (int i = 0; i < canMsg.can_dlc; i++)  {

        canmsg_370_1[i] = canMsg.data[i];

      }

      for (int i = 0; i < canMsg.can_dlc; i++)

        {

        Serial.print(canmsg_370_1[i],HEX);

        Serial.print("  ");

        } 

        canmsg_370_1[0] = random(0,255);

        Serial.println();

      for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[0] & (1<<i))

            {  

              VEHICLE_SPEED[i] = 1;

            }

            else if(0)

            {

              VEHICLE_SPEED[i] = 0;

            }

          }

      for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[1] & (1<<i))

            {  

              FR_LH_W_SPEED[i] = 1;

            }

            else if(0)

            {

              FR_LH_W_SPEED[i] = 0;

            }

          }

          for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[2] & (1<<i))

            {  

              FR_RH_W_SPEED[i] = 1;

            }

            else if(0)

            {

              FR_RH_W_SPEED[i] = 0;

            }

          }

          for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[3] & (1<<i))

            {  

              RR_LH_W_SPEED[i] = 1;

            }

            else if(0)

            {

              RR_LH_W_SPEED[i] = 0;

            }

          }

          for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[4] & (1<<i))

            {  

              RR_RH_W_SPEED[i] = 1;

            }

            else if(0)

            {

              RR_RH_W_SPEED[i] = 0;

            }

          }

          for(int i=0;i<=7;i++)

          {

            if(canmsg_370_1[5] & (1<<i))

            { 

              if(i==0)

              {

                Vehicle_overspeed_warn = 1;

              }

              if(i==1)

              {

                EPB_WARN = 1;

              }

              if(i==2)

              {

                ABS_MALFUNCTION = 1;

              }

              if(i==3 || i == 4)

              {

                if(i==3)

                {

                  ESP_WARN_LAMP[0] = 1;

                }

                else

                {

                  ESP_WARN_LAMP[1] = 1;

                }

              }

             

            }

            else if(0)

            {

              if(i==0)

              {

                Vehicle_overspeed_warn = 0;

              }

              if(i==1)

              {

                EPB_WARN = 0;

              }

              if(i==2)

              {

                ABS_MALFUNCTION = 0;

              }

              if(i==3 || i == 4)

              {

                if(i==3)

                {

                  ESP_WARN_LAMP[0] = 0;

                }

                else

                {

                  ESP_WARN_LAMP[1] = 0;

                }

              }

            }

             

           

}

}

//=======Receive DATA from RKE CAN Message==========

if(canMsg.can_id ==0x380)

{

  Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

for(int i =0;i<=canMsg.can_dlc; i++)

{

        canmsg_380_1[i] = canMsg.data[i];

}

     

        for (int i = 0; i <= canMsg.can_dlc; i++)

        {

        Serial.print(canmsg_380_1[i],HEX);

        Serial.print("  ");

        } 

        Serial.println();

        for(int i=0;i<=5;i++)

        {

          if(canmsg_380_1[0] & (1<<i))

          {

            if(i==0)

            {

              lock_signal = 1;

            }

            if(i == 1)

            {

              unlock_signal = 1;

            }

            if(i == 2)

            {

              Trunk_unlock_signal = 1;

            }

            if(i ==3)

            {

              Search_func=1;

            }

            if(i ==4)

            {

              Mute_func=1;

            }

           

          }

          else if(0)

          {

            if(i==0)

            {

              lock_signal = 0;

            }

            if(i == 1)

            {

              unlock_signal = 0;

            }

            if(i == 2)

            {

              Trunk_unlock_signal = 0;

            }

            if(i ==3)

            {

              Search_func=0;

            }

            if(i ==4)

            {

              Mute_func=1;

            }

          }

        }

}

//========Read DATA from SRS Message============

if(canMsg.can_id == 0x390)

{

   Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

  canmsg_390_1 = canMsg.data[0];

 

        Serial.print(canmsg_390_1,HEX);

        Serial.print("  "); 

        Serial.println();

       

for(int i = 0; i<=2;i++)

{

  if(canmsg_390_1 & (1<<i))

  {

    if(i==0)

    {

      seat_belt_warn=1;

    }

    if(i==1)

    {

      Pass_Airbag_cuttoff=1;

    }

    if(i==2)

    {

      Airbag_warn=1;

    }

   

  }

  else if(0)

  {

    if(i==0)

    {

      seat_belt_warn=0;

    }

    if(i==1)

    {

      Pass_Airbag_cuttoff=0;

    }

    if(i==2)

    {

      Airbag_warn=0;

    }

   

  }

}

 

}

//====Read DATA from TCCM CAN Message==================

if(canMsg.can_id == 0x360)

{

  Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

  canmsg_360_1 = canMsg.data[0];

  Serial.print(canmsg_360_1,HEX);

        Serial.print("  ");

        Serial.println();

for(int i = 0; i<=2;i++)

{

  if(canmsg_360_1 & (1<<i))

  { 

    if(i==0 ||i ==1)

    {

      Warn_4WD[i] = 1;

    }

    if(i==2)

    {

      Lock_4WD =1;

    }

  }

  else if(0)

  {

    if(i==0 ||i ==1)

    {

      Warn_4WD[i] = 0;

    }

    if(i==2)

    {

      Lock_4WD =0;

    }

  }

   

  }

}

//==Read DATA from TCU CAN Message==========================

if(canMsg.can_id == 0x395)

{

        Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

  canmsg_395_1 = canMsg.data[0];

        Serial.print(canmsg_395_1,HEX);

        Serial.print("  ");

        Serial.println();

for(int i = 0; i<=0;i++)

{

  if(canmsg_395_1 & (1<<i))

  { 

    if(i==0)

    {

      Transmission_warn = 1;

    }

  }

  else

  {

    if(i==0)

    {

      Transmission_warn = 0;

    } 

  }

}

}

//============Read DATA from TPMS CAN Message===========

if(canMsg.can_id == 0x400)

{

  Serial.print(canMsg.can_id, HEX);

        Serial.print(" ");

        Serial.print(canMsg.can_dlc, HEX);

        Serial.print("  ");

  for(int i=0;i<=canMsg.can_dlc;i++)

  {

    canmsg_400[i]=canMsg.data[i];

  }

  for (int i = 0; i <= canMsg.can_dlc; i++)

        {

        Serial.print(canmsg_400[i],HEX);

        Serial.print("  ");

        } 

        Serial.println();

  for(int i=0;i<=7;i++)

  {

    if(canmsg_400[0] & (1<<i))

    {

      if(i >=0 || i<=3)

      {

        FR_LH_Tire_press[i] = 1;

      }

      if(i> 3 || i<= 7)

      {

        FR_RH_Tire_press[i] = 1;

      }

    }

    else if(0)

    {

    if(i >=0 || i<=3)

    {

      FR_LH_Tire_press[i] = 0;

    }

    if(i> 3 || i<= 7)

      {

        FR_RH_Tire_press[i] = 0;

      }

   

    }

 }

 for(int i=0;i<=7;i++)

  {

    if(canmsg_400[1] & (1<<i))

    {

      if(i >=0 || i<=3)

      {

        RR_LH_Tire_press[i] = 1;

      }

      if(i> 3 || i<= 7)

      {

        RR_RH_Tire_press[i] = 1;

      }

     

    }

    else if(0)

    {

      if(i >=0 || i<=3)

      {

        RR_LH_Tire_press[i] = 0;

      }

      if(i> 3 || i<= 7)

      {

        RR_RH_Tire_press[i] = 0;

      }

    }

}

for(int i=0;i==0;i++)

  {

    if(canmsg_400[2] & (1<<i))

    {

      if(i ==0)

      {

        Tire_press_warn=1;

      }

    }

    else if(0)

    {

      if(i ==0)

      {

        Tire_press_warn=0;

      }

    }

}

}

//=======Send DATA to Instrument Cluster =======

//=======OIL_PRESS LAMP Signal========================

if (OIL_PRESS == 0){Serial.println("OIL_PRESSURE LAMP off ");}

else{Serial.println("OIL_PRESSURE LAMP ON ");}

 

//============CHECK_ENGINE LAMP Signal==============

 {

 if(CHECK_ENGINE[0] == 0 && CHECK_ENGINE[1] == 0)

 {Serial.println("CHECK_ENGINE LAMP OFF");}

  else if(CHECK_ENGINE[0] == 0 && CHECK_ENGINE[1] == 1)

          { Serial.println("CHECK_ENGINE LAMP ON");}

  else if (CHECK_ENGINE[0] == 1 && CHECK_ENGINE[1] == 0)

           {Serial.println("Reserved");}

  else if (CHECK_ENGINE[0] == 1 && CHECK_ENGINE[1] == 1)        

           {Serial.println("CHECK_ENGINE LAMP Fast blink");}

           }

//=============OBD_CHECK LAMP Signal===============

if (OBD_CHECK == 0){Serial.println("OBD_CHECK LAMP off ");}

else{Serial.println("OBD_CHECK LAMP ON ");}

 

//==========Start_stop LAMP Signal============

if (Start_stop == 0){Serial.println("Start_stop LAMP off ");}

else{Serial.println("Start_stop LAMP ON ");}

 

//=====Battery_warn LAMP Signal===================

if (Battery_warn == 0){Serial.println("Battery_warn LAMP off ");}

else{Serial.println("Battery_warn LAMP ON ");}

 

//============DPF_Warn_lamp LAMP Signal===========

if (DPF_Warn_lamp == 0){Serial.println("DPF_Warn_lamp LAMP off ");}

else{Serial.println("DPF_Warn_lamp LAMP ON ");}

 

//===========DEF_Warn_lamp LAMP Signal================

if (DEF_Warn_lamp == 0){Serial.println("DEF_Warn_lamp LAMP off ");}

else{Serial.println("DEF_Warn_lamp LAMP ON ");}

 

//=======REDUCED_POWER LAMP Signal======================

if (REDUCED_POWER == 0){Serial.println("REDUCED_POWER LAMP off ");}

else{Serial.println("REDUCED_POWER LAMP ON ");}

 

//==========EPS_WARN LAMP Signal====================

if (EPS_WARN == 0){Serial.println("EPS_WARN LAMP off ");}

else{Serial.println("EPS_WARN LAMP ON ");}

 

//====Vehicle_overspeed_warn LAMP Signal==============

if (Vehicle_overspeed_warn == 0){Serial.println("Vehicle_overspeed_warn LAMP off ");}

else{Serial.println("Vehicle_overspeed_warn LAMP ON ");}

 

//====EPB_WARN LAMP Signal===========================

if (EPB_WARN == 0){Serial.println("EPB_WARN LAMP off ");}

else{Serial.println("EPB_WARN LAMP ON ");}

 

//====ABS_MALFUNCTION LAMP Signal================

if (ABS_MALFUNCTION == 0){Serial.println("ABS_MALFUNCTION LAMP off ");}

else{Serial.println("ABS_MALFUNCTION LAMP ON ");}

 

//=======ESP_WARN LAMP Signal====================

 {

 if(ESP_WARN_LAMP[0] == 0 && ESP_WARN_LAMP[1] == 0)

 {Serial.println("ESP_WARN_ LAMP OFF");}

  else if(ESP_WARN_LAMP[0] == 0 && ESP_WARN_LAMP[1] == 1)

          { Serial.println("ESP_WARN LAMP ON");}

  else if (ESP_WARN_LAMP[0] == 1 && ESP_WARN_LAMP[1] == 0)

           {Serial.println("Reserved");}

  else if (ESP_WARN_LAMP[0] == 1 && ESP_WARN_LAMP[1] == 1)        

           {Serial.println("ESP_WARN LAMP Fast blink");}

           }

//=========lock_signal LAMP Signal==================

if (lock_signal == 0){Serial.println("lock_signal LAMP off ");}

else{Serial.println("lock_signal LAMP ON ");} 

 

//=============unlock_signal LAMP Signal===================

if (unlock_signal == 0){Serial.println("unlock_signal LAMP off ");}

else{Serial.println("unlock_signal LAMP ON ");}

 

//===========Trunk_unlock_signal LAMP Signal================

if (Trunk_unlock_signal == 0){Serial.println("Trunk_unlock_signal LAMP off ");}

else{Serial.println("Trunk_unlock_signal LAMP ON ");}

 

//===========Search_func LAMP Signal======================

if (Search_func == 0){Serial.println("Search_func LAMP off ");}

else{Serial.println("Search_func LAMP ON ");}

 

//=============Mute_func LAMP Signal=================

if (Mute_func == 0){Serial.println("Mute_func LAMP off ");}

else{Serial.println("Mute_func LAMP ON ");}

 

//==========seat_belt_warn LAMP Signal=============

if (seat_belt_warn == 0){Serial.println("seat_belt_warn LAMP off ");}

else{Serial.println("seat_belt_warn LAMP ON ");}

 

//=========Pass_Airbag_cuttoff LAMP Signal================

if (Pass_Airbag_cuttoff == 0){Serial.println("Pass_Airbag_cuttoff LAMP off ");}

else{Serial.println("Pass_Airbag_cuttoff LAMP ON ");}

 

//=========Airbag_warn LAMP Signal===================

if (Airbag_warn == 0){Serial.println("Airbag_warn LAMP off ");}

else{Serial.println("Airbag_warn LAMP ON ");}

 

//========Warn_4WD LAMP Signal=========================

 {

 if(Warn_4WD[0] == 0 && Warn_4WD[1] == 0)

 {Serial.println("Warn_4WD LAMP OFF");}

  else if(Warn_4WD[0] == 0 && Warn_4WD[1] == 1)

          { Serial.println("Warn_4WD LAMP ON");}

  else if (Warn_4WD[0] == 1 && Warn_4WD[1] == 0)

           {Serial.println("Reserved");}

  else if (Warn_4WD[0] == 1 && Warn_4WD[1] == 1)        

           {Serial.println("Warn_4WD LAMP Fast blink");}

           }

//==========Lock_4WD LAMP Signal=======================

if (Lock_4WD == 0){Serial.println("Lock_4WD LAMP off ");}

else{Serial.println("Lock_4WD LAMP ON ");}

 

//==============Transmission_warn LAMP Signal==========

if (Transmission_warn == 0){Serial.println("Transmission_warn LAMP off ");}

else{Serial.println("Transmission_warn LAMP ON ");}

 

//=========Tire_press_warn LAMP Signal================

if (Tire_press_warn == 0){Serial.println("Tire_press_warn LAMP off ");}

else{Serial.println("Tire_press_warn LAMP ON ");}

 

  }

//======Sending Message 350========================

  canMsg1.can_id  = 0x350;

  canMsg1.can_dlc = 2;

  //canMsg1.data[0] = (canMsg_350_byte_1,HEX);

  canMsg1.data[1] = canMsg_350_byte_2;

 

  canMsg1.data[0] = FOG_LAMP_SIGNAL | (VEHICLE_ARMED_STATUS<<1) | (REAR_FOG_LAMP<<2) | (HEAD_LAMP_HIGH_BEAM<<3) | (TURN_LEFT[0]<<4) | (TURN_LEFT[1]<<5) | (TURN_RIGHT[0]<<6) |(TURN_RIGHT[0]<<7);

  

  canMsg_350_byte_2 = DRIVER_DOOR_SIGNAL | (PASSENGER_DOOR_SIGNAL<<1) | (REAR_LH_DOOR << 2) | (REAR_RH_DOOR<<3) | (TAILGATE_OPEN_WARN<<4) | (DOOR_AJAR_WARN<<5) | (PARKING_BRAKE_STATUS << 6) | (LOW_WASHER_FLUID<<7);

  mcp2515.sendMessage(&canMsg1);

  //=======Sending Message 355=======================

  canMsg2.can_id  = 0x355;

  canMsg2.can_dlc = 3;

  canMsg2.data[0] = canMsg_355_byte_1;

  canMsg2.data[1] = canMsg_355_byte_2;

  canMsg2.data[1] = canMsg_355_byte_3;

 

  canMsg_355_byte_1 = GLOW_PLUG | (WATER_IN_FUEL<<1) | (CRUISE_CONTROL[0] << 2) | (CRUISE_CONTROL[1] << 3) | (OIL_PRESS << 4) | (CHECK_ENGINE[0] << 5) | (CHECK_ENGINE[1] << 6) | (OBD_CHECK<<7);

  //canMsg_355_byte_2 = ENGINE_SPEED[0] | (ENGINE_SPEED[1]<<1) | (ENGINE_SPEED[2]<<2) | (ENGINE_SPEED[3]<<3) | (ENGINE_SPEED[4]<<4) | (ENGINE_SPEED[5]<<5) | (ENGINE_SPEED[6]<<6) | (ENGINE_SPEED[7]<<7);

  canMsg_355_byte_3 = Start_stop | (Battery_warn<<1) | (DPF_Warn_lamp<<2) | (DEF_Warn_lamp<<3) | (REDUCED_POWER<<4);

  for(int i=0;i<=7;i++)

  {

  canMsg_355_byte_2 = canMsg_355_byte_2 | (ENGINE_SPEED[i]<<i);

  }

  mcp2515.sendMessage(&canMsg2);

  //===========Sending Message 360==========================

  canMsg3.can_id  = 0x360;

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = canMsg_360_byte_1;

  canMsg_360_byte_1 = Warn_4WD[0]| (Warn_4WD[1]<<1) | (Lock_4WD << 2);

  mcp2515.sendMessage(&canMsg3);

//=========Sending Message 365=====================

  canMsg4.can_id  = 0x365;

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = EPS_WARN;

  mcp2515.sendMessage(&canMsg4);

//==========Sending Message 370======================

  canMsg5.can_id  = 0x370;

  canMsg5.can_dlc = 6;

  canMsg5.data[0] = VEHICLE_SPEED[0] | (VEHICLE_SPEED[1]<<1) | (VEHICLE_SPEED[2]<<2) | (VEHICLE_SPEED[3]<<3) | (VEHICLE_SPEED[4]<<4) | (VEHICLE_SPEED[5]<<5) | (VEHICLE_SPEED[6]<<6) | (VEHICLE_SPEED[7]<<7);

  canMsg5.data[1] = FR_LH_W_SPEED[0] | (FR_LH_W_SPEED[1]<<1) | (FR_LH_W_SPEED[2]<<2) | (FR_LH_W_SPEED[3]<<3) | (FR_LH_W_SPEED[4]<<4) | (FR_LH_W_SPEED[5]<<5) | (FR_LH_W_SPEED[6]<<6) | (FR_LH_W_SPEED[7]<<7);

  canMsg5.data[2] = FR_RH_W_SPEED[0] | (FR_RH_W_SPEED[1]<<1) | (FR_RH_W_SPEED[2]<<2) | (FR_RH_W_SPEED[3]<<3) | (FR_RH_W_SPEED[4]<<4) | (FR_RH_W_SPEED[5]<<5) | (FR_RH_W_SPEED[6]<<6) | (FR_RH_W_SPEED[7]<<7);

  canMsg5.data[3] = RR_LH_W_SPEED[0] | (RR_LH_W_SPEED[1]<<1) | (RR_LH_W_SPEED[2]<<2) | (RR_LH_W_SPEED[3]<<3) | (RR_LH_W_SPEED[4]<<4) | (RR_LH_W_SPEED[5]<<5) | (RR_LH_W_SPEED[6]<<6) | (RR_LH_W_SPEED[7]<<7);

  canMsg5.data[4] = RR_RH_W_SPEED[0] | (RR_RH_W_SPEED[1]<<1) | (RR_RH_W_SPEED[2]<<2) | (RR_RH_W_SPEED[3]<<3) | (RR_RH_W_SPEED[4]<<4) | (RR_RH_W_SPEED[5]<<5) | (RR_RH_W_SPEED[6]<<6) | (RR_RH_W_SPEED[7]<<7);

  canMsg5.data[5] = Vehicle_overspeed_warn | EPB_WARN | ABS_MALFUNCTION | ESP_WARN_LAMP[0] | ESP_WARN_LAMP[1];

 

  mcp2515.sendMessage(&canMsg5);

//=============Sending Message 380=================

  canMsg6.can_id  = 0x380;

  canMsg6.can_dlc = 1;

  canMsg6.data[0] = lock_signal | (unlock_signal<<1) | (Trunk_unlock_signal<<2) | (Search_func<<3) | (Mute_func<<4);

  mcp2515.sendMessage(&canMsg6);

 

//=============Sending Message 390=================

  canMsg7.can_id  = 0x390;

  canMsg7.can_dlc = 1;

  canMsg7.data[0] = seat_belt_warn | (Pass_Airbag_cuttoff<<1) | (Airbag_warn<<2);

  mcp2515.sendMessage(&canMsg7);

 

//===========Sending Message 395=====================

  canMsg8.can_id  = 0x395;

  canMsg8.can_dlc = 1;

  canMsg8.data[0] = Transmission_warn;

  mcp2515.sendMessage(&canMsg8);

 

//================Sending Message 400=================

  canMsg9.can_id  = 0x400;

  canMsg9.can_dlc = 3;

  canMsg9.data[0] = FR_LH_Tire_press[0] | (FR_LH_Tire_press[1]<<1) | (FR_LH_Tire_press[2]<<2) | (FR_LH_Tire_press[3]<<3) | (VEHICLE_SPEED[4]<<4) | (FR_RH_Tire_press[5]<<5) | (FR_RH_Tire_press[6]<<6) | (FR_RH_Tire_press[7]<<7); 

  canMsg9.data[1] = RR_LH_Tire_press[0] | (RR_LH_Tire_press[1]<<1) | (RR_LH_Tire_press[2]<<2) | (RR_LH_Tire_press[3]<<3) | (RR_RH_Tire_press[4]<<4) | (RR_RH_Tire_press[5]<<5) | (RR_RH_Tire_press[6]<<6) | (RR_RH_Tire_press[7]<<7);

  canMsg9.data[2] = Tire_press_warn;

  mcp2515.sendMessage(&canMsg8);

}

//***********************************************************

CAN COMMUNICATION MATRIX    

Overview:

In this CAN DBC, have created twelve ECU’s in the vehicle and its messages and relevant signals. Using this dbc how the messages and signals are transmitting and receiving between ECU’s are analysed by converting into physical values.


About Network Nodes:

The ECU’s created in this DBC are listed below:

·         Body Control Module.(BCM)

·         Engine Management System.(EMS)

·         Electronic Power Steering Module.(EPS)

·         Electronic Stability Program.(ESP)

·         Instrument Cluster Module.(ICM)

·         In Vehicle Infotainment Module.(IVI)

·         Remote Keyless Entry.(RKE)

·         Supplementary Restraint System.(SRS)

·         Transfer Case Control Module.(TCCM)

·         Transmission Control Unit.(TCU)

·         Tire Pressure Monitoring System.(TPMS)

 CAN MESSAGES:

            Each CAN messages are created and mapped to their respective transmitting and receiving ECU’s. Multiple CAN signals are mapped inside single CAN message. The CAN-ID is used according to message prioritization and communication. Inside each messages, respective signal are mapped.

 


 Here comes the signal mapping done inside each message:

For example, the bit allocation inside Body control module Message ID 350 is shown below:

                                                BCM CAN Message Signal Mapped Layout


As body control module is responsible for transmitting following signal:

Ø  Turn Left Indicator

Ø  Turn Right Indicator

Ø  Fog Lamp Signal

Ø  Door Ajar Warning

Ø  Each Door Open/close Status

Ø  Washer Fluid Status

Ø  Low Fuel Indicator

Ø  Parking Brake Status, etc.,.

Bit allocation is done according to their individual function. If the signal responsible for only Warning Lamp On/Off means One bit is enough (0/1). If the signal need to transmit several functions like Warning Lamp On/Off/Blink for some duration then it requires two bit (On/Off/Blink/reserve). Like this all signals are mapped to their respective signals accordingly.

CAN SIGNALS:

                  CAN signals are individual piece of data about the vehicle. These signals are created and mapped to their corresponding messages to communicate through CAN bus.

                                                    Signal Creation In CAN DBC



In this signal as mentioned ABS malfunction signal created, this signal is responsible for indicating any malfunction inside ABS system and any issues found signal should pass through CAN bus by CAN message to IC module to On the ABS warning Lamp. Like this, all signals have to send their information through CAN bus.



RKE Implementation with CAN


//===========================Program for RKE Feature Application Using CAN ====

#include <SPI.h>

#include <mcp2515.h>

MCP2515 mcp2515(53);

//===============CAN Message Declaration===========================

struct can_frame canMsg1; //Door lock

struct can_frame canMsg2;//Theft Alarm

struct can_frame canMsg3;//Auto-lock

struct can_frame canMsg4;//Door Unlock

struct can_frame canMsg5;//Auto-relock

struct can_frame canMsg6;//Search Alarm

struct can_frame canMsg7;//Panic Alarm

struct can_frame canMsg8;//Trunk_door_unlock

struct can_frame canMsg9;//Auto_unlock

struct can_frame canMsg10;//Emergency_Function

//=======================================Variable Declaration========

int RKE_input_id_200[7];   //To get input from RKE

int lock_button, unlock_button, trunk_button; //Initializing the variable for remote keyless entry Button

 

bool driver_dr_switch, passenger_dr_switch, rear_lh_dr_switch, rear_rh_dr_switch, trunk_dr_switch; //Initializing the variable for dr switches

 

bool hazard_lamp, alarm_horn, RCM_module, buzzer;//Output device variable declaration

int  Key_cylinder_switch; //1-OFF, 2-ON, 3-Acc

 

int speed_sensor_input,  Button_press_timer, battery_power;

 

bool driver_dr_solenoid_valve, passenger_dr_solenoid_valve, rear_lh_dr_solenoid_valve, rear_rh_dr_solenoid_valve, trunk_dr_solenoid_valve, Driver_center_lock, vehicle_armed =1; //Initializing the variable for Solenoid valve

 

 

void setup() {

  Serial.begin(9600);

  mcp2515.reset();

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);

  mcp2515.setNormalMode();

  canMsg1.can_id = 0x100;

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x11;

  canMsg2.can_id = 0x100;

  canMsg2.can_dlc = 2;

  canMsg2.data[1] = 0x22;

  canMsg3.can_id = 0x100;

  canMsg3.can_dlc = 3;

  canMsg3.data[2] = 0x33;

  canMsg4.can_id = 0x100;

  canMsg4.can_dlc = 4;

  canMsg4.data[3] = 0x44;

  canMsg5.can_id = 0x100;

  canMsg5.can_dlc = 5;

  canMsg5.data[4] = 0x55;

  canMsg6.can_id = 0x100;

  canMsg6.can_dlc = 6;

  canMsg6.data[5] = 0x66;

  canMsg7.can_id = 0x100;

  canMsg7.can_dlc = 7;

  canMsg7.data[6] = 0x77;

  canMsg8.can_id = 0x100;

  canMsg8.can_dlc = 8;

  canMsg8.data[7] = 0x88;

  canMsg9.can_id = 0x110;

  canMsg9.can_dlc = 1;

  canMsg9.data[0] = 0x99;

  canMsg10.can_id = 0x110;

  canMsg10.can_dlc = 2;

  canMsg10.data[1] = 0xAA;

}

 

void loop() {

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {

    if (canMsg.can_id == 0x200)

    {

      for (int i = 0; i < canMsg.can_dlc; i++)

        RKE_input_id_200[0] = (canMsg.data[0]);

        Button_press_timer= (canMsg.data[1]);

        Key_cylinder_switch = (canMsg.data[2]);

        driver_dr_switch = (canMsg.data[3]);

        passenger_dr_switch = (canMsg.data[4]);

        rear_lh_dr_switch = (canMsg.data[5]);

        rear_rh_dr_switch = (canMsg.data[6]);

        trunk_dr_switch = (canMsg.data[7]);

        Serial.print("RKE_input_id_200[0]: ");

        Serial.println(RKE_input_id_200[0]);

    }

    if(canMsg.can_id == 0x210)

    {

      for (int i = 0; i < canMsg.can_dlc; i++)

        speed_sensor_input = (canMsg.data[0]);

        RCM_module= (canMsg.data[1]);

        battery_power = (canMsg.data[2]);

    }

  }

  switch (RKE_input_id_200[0]) {

    case 1:

      lock_button =1;

      RKE_lock_Func();                //This function includes locking the vehicle with RKE, Anti-theft alarm, RKE battery monitoring

      mute_func();                      //This function is for mute function

      special_condition_1();     //This function will execute when any door kept unclosed after getting RKE_lock comment

      special_condition_2();

      special_condition_3();

      break;

    case 2:

      unlock_button =2;

      RKE_unlock_Func();           //This function includes vehicle unlocking with RKE, vehicle search function and Panic alarm

      break;

    case 3:

      trunk_button = 3;

      RKE_input_id_200[0] = trunk_button;

      trunk_door_unlock();        //This function will unlock trunk door

      break;

  }

  //=Condition to unlock all the doors when key turned off - Auto Unlocking===

  //auto_unlock()

  if (Key_cylinder_switch == 3 && speed_sensor_input == 0 && unlock_button == 0)

  {

    door_unlock();

    Serial.println("hello :");

    Serial.print(unlock_button);

    hazard_lamp_unlock();

    mcp2515.sendMessage(&canMsg9);

  }

 

 

  //==========Condition to unlock all the doors at emergency suituation==========

  //emergency_unlock()

 

  if (RCM_module == 1)          //During accident or any emergency all doors unlocked

  {

    door_unlock();

    hazard_lamp = alarm_horn = 1;

    Serial.print("Alert!!!All doors opened");

    mcp2515.sendMessage(&canMsg10);

  }

 

  //======Condition to check driver door lock knob is closed then close all the door - Center lock======================

  //center_lock()

 

  if (door_closed() == 1)

  {

    if (Driver_center_lock == 1)

    {

      door_lock();

      hazard_lamp_lock();

      beep_function();

    }

  }

  //===condition to check vehicle speed is above 20km/hr then automatically close all doors - Auto lock================

  //autolock()

    if (Key_cylinder_switch == 2 && speed_sensor_input > 20 )

    {

        door_lock();

        mcp2515.sendMessage(&canMsg3);

    }

}

 

//=============== Function DECLARATION ===========================================

//===========Function Declaration for RKE function Execution==========================

int RKE_lock_Func()

{

  if (lock_button == 1 && Button_press_timer < 3)

  {

    if (door_closed() == 1)

    {

      if (battery_power < 30) //Monitorig RKE battery

      {

        Serial.println("RKE battery is too low");

      }

      door_lock();

      hazard_lamp_lock();

      mcp2515.sendMessage(&canMsg1);

      while (unlock_button == 0 &&( Key_cylinder_switch == 2 || door_unlock_check_theft() == 1)) //Anti-theft alarm activation while opening of any doors after vehicle armed

      {

        hazard_lamp = alarm_horn = 1;

        Serial.println("Alert!!! Theft attempt");

        mcp2515.sendMessage(&canMsg2);

        beep_function();

      }

 

    }

    else

    {

      Serial.println("Please close all doors and try again");

    }

 

  }

}

//=====Condition to unlock all the doors by getting input from RKE===========

int RKE_unlock_Func()

{

  if (unlock_button == 2 && vehicle_armed == 1 )

  {

    if (Button_press_timer < 3)

    {

      door_unlock();

      mcp2515.sendMessage(&canMsg4);

      millis();

      hazard_lamp_unlock();         //Auto-relocking

      while (door_closed() == 1)

      {

        Serial.println("Timer begins");

        if (millis() > 30000)

        {

          door_lock();

          mcp2515.sendMessage(&canMsg5);

          hazard_lamp_lock();

        }

      }

    }

 

    if (Button_press_timer > 3)

    {

      switch (Key_cylinder_switch)         //Panic and search function

      {

        case 1:

          Serial.println("Search Function activated");

          timer_alarm();

          mcp2515.sendMessage(&canMsg6);

          break;

        case 2:

          Serial.println("Panic Function activated");

          timer_alarm();

          Serial.println("Panic Function activated");

          mcp2515.sendMessage(&canMsg7);

          break;

 

      }

    }

  }

}

//=========Condition to unlock trunk door========================================

void trunk_door_unlock()

{

  if (trunk_button == 3 )

  {

    int i;

    if (trunk_dr_solenoid_valve == 1)

    {

      trunk_dr_solenoid_valve = 0;

      Serial.println("trunk door unlocked successfully");

      mcp2515.sendMessage(&canMsg8);

      for ( i = 1; i <= 4; i++)

      {

        hazard_lamp = 1;

        delay(500);

        hazard_lamp = 0;

      }

    }

  }

}

//========mute/unmute function=========================================

void mute_func()

{

  int m;

  if (lock_button == 1) //checking vehicle locked

  {

    while (Button_press_timer >= 3 && millis() < 30000)

    {

      buzzer = alarm_horn = 0;

      Serial.println("buzzer muted");

      while (m > 2)

      {

        hazard_lamp = 1;

        delay(500);

        hazard_lamp = 0;

        m++;

      }

 

    }

  }

}

//Special conditions : if any doors opened with RKE locked hazazard lamp flash for five times with alarm=====

void special_condition_1()

{

  if (lock_button == 1 && Button_press_timer < 3)

  {

    if (door_opened() == 1)

    {

      int i;

      Serial.println("please close all the doors");

      for (i = 1; i <= 5; i++)

      {

        hazard_lamp = alarm_horn = 1;

        delay(500);

        hazard_lamp = alarm_horn = 0;

      }

    }

  }

}

//  ===Condition to lock the door if driver door closed but any other door opened ==========

void special_condition_2()

{

  if (door_opened() == 1)

  {

    if (lock_button == 1 && Button_press_timer <= 3)

    {

      if (driver_dr_switch == 1)

      {

        driver_dr_solenoid_valve = 1;

        Serial.println("Driver door closed");

        if (passenger_dr_switch == 1)

        {

          passenger_dr_solenoid_valve = 1;

          Serial.println("Passenger door closed");

        }

        else

        {

          Serial.println("Please close Passenger door");

        }

        if (rear_lh_dr_switch == 1)

        {

          rear_lh_dr_solenoid_valve = 1;

          Serial.println("rear lh door  closed");

        }

        else

        {

          Serial.println("Please close rear lh door");

        }

        if (rear_rh_dr_switch == 1)

        {

          rear_rh_dr_solenoid_valve = 1;

          Serial.println("rear rh door closed");

        }

        else

        {

          Serial.println("Please close rear rh door");

        }

        if (trunk_dr_switch == 1)

        {

          trunk_dr_solenoid_valve = 1;

        }

        else

        {

          Serial.println("Please close trunk door");

        }

        hazard_lamp_lock();

 

      }

    }

  }

}

// =================If driver door is opened while RKE locking================

void special_condition_3()

{

  if (lock_button == 1 && Button_press_timer <= 3)

  {

    if (driver_dr_switch == 0)

    {

      Serial.println("RKE lock function not activated and close the driver door and relock with RKE");

    }

  }

}

 

//========================================= Hazard lamp Lock Function===================================

void hazard_lamp_lock()          //Declaring functions to activate hazardous lamp and alarm horn when RKE locks the door

{

  hazard_lamp = alarm_horn = 1;

  delay(500);

  hazard_lamp = alarm_horn = 0;

  Serial.println("Hazard lamp with alarm flash for one time");

}

//============== Hazard lamp Unlock Function=========================

void hazard_lamp_unlock()

{

  int i;

  for (i = 1; i <= 2; i++)

  {

    hazard_lamp = alarm_horn = 1;

    delay(500);

    hazard_lamp = alarm_horn = 0;

  }

  Serial.println("Hazard lamp with alarm flash for two time");

}

//============ Function to check all the doors are closed========================

int door_closed() {

  if (driver_dr_switch == 1 && passenger_dr_switch == 1 && rear_lh_dr_switch == 1 && rear_rh_dr_switch == 1 && trunk_dr_switch == 1)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//======================== Function to check all the doors are open=======

int door_opened() {

  if (driver_dr_switch == 0 || passenger_dr_switch == 0 || rear_lh_dr_switch == 0 || rear_rh_dr_switch == 0 || trunk_dr_switch == 0)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//============================ Function to lock the door solenoid valves ========

int door_lock() {

  driver_dr_solenoid_valve = passenger_dr_solenoid_valve = rear_lh_dr_solenoid_valve = rear_rh_dr_solenoid_valve = trunk_dr_solenoid_valve = 1;

  Serial.println("All doors are locked successfully");

  vehicle_armed = 1;

}

//============================= Function to Unlock the door solenoid valves ============

int door_unlock() {

  driver_dr_solenoid_valve = passenger_dr_solenoid_valve = rear_lh_dr_solenoid_valve = rear_rh_dr_solenoid_valve = 0;

  Serial.println("All doors are unlocked successfully");

  vehicle_armed = 0;

}

 

//================== Function to check the doors are unlocked for theft =======

bool door_unlock_check_theft()

{

  if (driver_dr_solenoid_valve == 0 || passenger_dr_solenoid_valve == 0 || rear_lh_dr_solenoid_valve == 0 || rear_rh_dr_solenoid_valve == 0 || trunk_dr_solenoid_valve == 0 || driver_dr_switch == 0 || passenger_dr_switch == 0 || rear_lh_dr_switch == 0 || rear_rh_dr_switch == 0 || trunk_dr_switch == 0 )

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

 

//============== Function to check all the doors are locked================

bool door_lock_check()

{

  if (driver_dr_solenoid_valve == passenger_dr_solenoid_valve == rear_lh_dr_solenoid_valve == rear_rh_dr_solenoid_valve == trunk_dr_solenoid_valve == 1)

  {

    return 1;

  }

  else

  {

    return 0;

  }

}

//================= Alarm function declaration=================================

 

int timer_alarm() {

  while (millis() <= 30003)

  {

    Serial.println("Hazard lamp with alarm horn activated for 30s");

    hazard_lamp = alarm_horn =  1;

    delay(500);

    hazard_lamp = alarm_horn = 0;

  }

}

//=========================Beep Function=======================================

int beep_function()

{

  while (door_opened() == 1 && millis() < 30000) //when all doors are locked

  {

    buzzer = 1;

    Serial.println("Buzzer ON,Please close the door");

  }

  if (door_opened() == 0)

  {

    buzzer = 0;

    Serial.println("Buzzer off");

  }

}

//=========================Seat Belt Warning Application===============================

//===================Declaring variables for Input Parameters============================

bool DR_seat_belt_button, PS_seat_belt_button, RR_LH_seat_belt_button;

bool RR_RH_seat_belt_button; //Input parameter

bool DR_Occupant_sensor, PS_Occupant_sensor, RR_LH_Occupant_sensor, RR_RH_Occupant_sensor;

int Key_cylinder_status , Speedometer, odometer ,Engine speed_sensor ;

//===================Declaring variables for Output Parameters===========================

bool Seat_belt_warn_lamp, buzzer;

void setup() {

  Serial.begin(9600);

}

 

void loop() {

 

//==================================Driver seat belt Remainder========================

 

  if (Key_cylinder_status ==2 && DR_seat_belt_button == 0)

  {

    while(millis()<6000)

  {

    Seat_belt_warn_lamp = buzzer=1;

    Serial.println("Seat_belt_warn_lamp and Buzzer On");

    delay(20);

    Seat_belt_warn_lamp =buzzer =0;

    Serial.println("Seat_belt_warn_lamp and Buzzer Off");

    delay(1180);

  }

   

    while(millis()>6000 && millis()<=10000)

    {

    Seat_belt_warn_lamp =1;

    Serial.println("Seat_belt_warn_lamp On");

    }

   }

   Seat_belt_warn_lamp =0;

   while(millis() >10000 && millis() <10005)

   {

   Serial.println("Seat_belt_warn_lamp Off");

   delay(3000);

   }

 

//====================Continous Seatbelt remainder while Vehicle Moving ==================

 

if ((Key_cylinder_status ==2 && DR_seat_belt_button == 0) && Engine_speed_sensor !=0 ||Speedometer !=0 || odometer >=0.5 )

  {

    if(millis()<32000 && millis()>28000)

    {

      Serial.println("WARNING! buckle the seat belt");

    }

      if(millis()>=28000 && millis()>38000)

      {

         Seat_belt_warn_lamp = buzzer=1;

    Serial.println("Seat_belt_warn_lamp and Buzzer On");

    delay(500);

    Seat_belt_warn_lamp =buzzer =0;

    Serial.println("Seat_belt_warn_lamp and Buzzer Off");

    delay(500);

      }

     

    }

    if((Key_cylinder_status ==2 && DR_seat_belt_button == 0) && (Speedometer>=25))

    {

      Seat_belt_warn_lamp = buzzer=1;

    Serial.println("Seat_belt_warn_lamp and Buzzer On");

    delay(500);

    Seat_belt_warn_lamp =buzzer =0;

    Serial.println("Seat_belt_warn_lamp and Buzzer Off");

    delay(500);

    }

 

//==================Continous suphosticated Seatbelt remainder =========================

 

if ((Key_cylinder_status ==2 && DR_seat_belt_button == 0) && Engine_speed_sensor !=0 ||Speedometer !=0 || odometer >=1 )

  {

    if(millis()<18000)

    {

      Serial.println("WARNING! buckle the seat belt");

    }

      if(millis()>=18000 && millis()>28000)

      {

         Seat_belt_warn_lamp = buzzer=1;

    Serial.println("Seat_belt_warn_lamp and Buzzer On");

    delay(500);

    Seat_belt_warn_lamp =buzzer =0;

    Serial.println("Seat_belt_warn_lamp and Buzzer Off");

    delay(500);

      }

     

    }

  if((Key_cylinder_status ==2 && DR_seat_belt_button == 0) && (Speedometer>=40))

    {

      Seat_belt_warn_lamp = buzzer=1;

    Serial.println("Seat_belt_warn_lamp and Buzzer On");

    delay(500);

    Seat_belt_warn_lamp =buzzer =0;

    Serial.println("Seat_belt_warn_lamp and Buzzer Off");

    delay(500);

    }

 

}

 

//***********************************************************************************************************