Thursday, September 27, 2012

Latest software

So I commented out the line calling the routine displaying text on the SID because it was causing issues with the I-Bus communications. For example, turning on either blinker, occasionally the indicators on the dash would not blink, or blink twice fast, as they time themselves with the outside blinker. The timing with the SID text display was interrupting this, and god knows what else. Of course, this is only an indication issue, the outside blinkers still work perfectly.


// ----------------------------------------------
// SECUDUINO
// http://secuduino.blogspot.com/
// By Igor Real
// 16/05/2011
//
// Saab CDC Changer Emulator, BlueSaab
// Seth Evans
// 27 Sep 2012
// ----------------------------------------------

#include <CAN.h>

int cdbutton;

void setup() {
  // set up CAN
  CAN.begin(47);  // Saab I-Bus is 47.619kbps
  Serial.begin(115200);
  cdbutton = 0;
  CAN_TxMsg.header.rtr=0;  // this value never changes
  CAN_TxMsg.header.length=8;  // this value never changes
}

void loop() {
  if (CAN.CheckNew()){
    CAN_TxMsg.data[0]++;
    CAN.ReadFromDevice(&CAN_RxMsg);
    //PrintBus();
    if (CAN_RxMsg.id==0x3C0){
      CDC();
      if (CAN_RxMsg.data[1]==0x24){
        cdbutton = 1;
        Serial.println("CDC");
      }
      else if (CAN_RxMsg.data[0]==0x80 && CAN_RxMsg.data[1]==0x14){
        cdbutton = 0;  
        Serial.println("Radio");
      }
    }

    if (cdbutton==1){
      CDC();
      delay(5);
      //iPodOn();
    }
    else {
      iPodOff();
    }
  }
}

void CDC(){
  CAN_TxMsg.id=0x3C8;  
  CAN_TxMsg.data[0]=0x80;
  CAN_TxMsg.data[1]=0x00;
  CAN_TxMsg.data[2]=0x3F;
  CAN_TxMsg.data[3]=0x41;
  CAN_TxMsg.data[4]=0x00;
  CAN_TxMsg.data[5]=0x00;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0xD0;
  CAN.send(&CAN_TxMsg);
}

void iPodOn(){
  CAN_TxMsg.id=0x348;
  CAN_TxMsg.data[0]=0x11;
  CAN_TxMsg.data[1]=0x02;
  CAN_TxMsg.data[2]=0x04;
  CAN_TxMsg.data[3]=0x19;
  CAN_TxMsg.data[4]=0x00;
  CAN_TxMsg.data[5]=0x00;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0x00;
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.id=0x328;  
  CAN_TxMsg.data[0]=0x42;
  CAN_TxMsg.data[1]=0x96;
  CAN_TxMsg.data[2]=0x02;
  CAN_TxMsg.data[3]=0x42; // B
  CAN_TxMsg.data[4]=0x6C; // l
  CAN_TxMsg.data[5]=0x75; // u
  CAN_TxMsg.data[6]=0x65; // e
  CAN_TxMsg.data[7]=0x53; // S
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.data[0]=0x01;
  CAN_TxMsg.data[3]=0x61; // a
  CAN_TxMsg.data[4]=0x61; // a
  CAN_TxMsg.data[5]=0x62; // b
  CAN_TxMsg.data[6]=0x20; // _
  CAN_TxMsg.data[7]=0x20; // _
  CAN.send(&CAN_TxMsg);
  delay(5);
}

void iPodOff(){
}

void PrintBus(){
  if (CAN_RxMsg.id==0x3C0){
    Serial.print(CAN_RxMsg.id,HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[0],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[1],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[2],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[3],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[4],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[5],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[6],HEX);
    Serial.print(";");
    Serial.println(CAN_RxMsg.data[7],HEX);
  }
}

No comments:

Post a Comment