How to add or edit items in command.txt and formula.txt

Discussion in 'PriiDash (TM)' started by 2009Prius, Jun 16, 2014.

  1. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,703
    484
    63
    Location:
    USA
    Vehicle:
    2009 Prius
    Let's take a look at the two files included in the package:
    command.txt:
    // init and query commands for gen 2 Prius, max line length 1024,
    // format: command 1,command 2,priority;//comments
    // init commands are marked by priority 0
    // query commands can be priority 1 or 2 or 3
    // AT PP commands that only needs to do once for each new ELM327 compatible device
    // ATPP01SV00,ATPP01ON,0;// turn on header by default (ATH1)
    // ATPP03SVFF,ATPP03ON,0;// set default time out time (ATSTFF)
    // ATPP0CSV02,ATPP0CON,0;// set default baud rate
    // ATPP24SVFF,ATPP24ON,0;// turn off CAN auto formatting by default (ATCAF0)
    // End of AT PP commands that only needs to do once
    STI,STDIX,0;//show firmware version, device version
    STSN,STSLCS,0;//show device serial number, PowerSave configuration
    ATPPS,[email protected],0; //show programmable parameters list, device description
    ATSP6,ATDPN,0; // set protocol to #6, check protocol should be 6
    ATL1,ATH1,0; // turn on line feed, turn on header
    ATCAF0,ATSTFF,0; // turn off formatting, set timeout in units of 4 ms; Flyer suggested using FF, may try shorter timeout in case Fujitsu goes to sleep erroneously
    ATSH7E2,0521C3C442D3,1;//query inverter & MG Nm & T, 12V, brake light
    ATSH7E0,03010E04,2;//query IGN & load
    ATSH7E0,0221CD,3;//query ICE torque (N-m) iceNm2
    ATSH7E0,05213C3E2E32,3;//query catT1&2 EVAP
    ATSH7E3,0421d0cecf,2;//query HV battery
    ATSH7E0,020105,3;//query ICE coolant T
    ATSH7E0,032133F5,3;//query atm, misfire
    ATSH7E3,022131,3;//DTC clear run dist
    ATSH7E0,020110,3;//MAF air flow rate (grams/sec) ((A*256)+B)/100


    formula.txt:
    // formula for gen 2 Prius, max line length 1024,
    // format: CAN ID (hex),IDstring,expression;//comments
    // for the expression: d[] holds CAN message data bytes (max 100 bytes),
    // v[] holds results (if more than one value, max 20 values)
    //022,aLR,d[0]*256+d[1]-0x200;// accelerometer in left-right direction (int)
    //023,aFB,d[0]*256+d[1]-0x200;// accelerometer in front-back direction (int)
    //022,aLR2,d[2]*256+d[3]-0x200;// accelerometer in left-right direction (int)
    //023,aFB2,-d[2]*256-d[3]+0x200;// accelerometer in front-back direction (int)
    022,aLR,(d[0]+d[2])*256+d[1]+d[3]-0x400;// accelerometer in left-right direction (int)
    023,aFB,(d[0]-d[2])*256+d[1]-d[3];// accelerometer in front-back direction (int)
    030,brake,d[4];// brake pedal; range 0 ~ 127 (int)
    039,iceT,((d[0]&0x7F)-(d[0]&0x80))*1.8+32;// ICE T
    03B,hvVA,v[0]=0.1*(((d[0]&#0111)-(d[0]&#1000))*256+d[1]),v[1]=d[2]*256+d[3];// HV battery amp, V
    0B1,speedF,v[0]=(d[0]*256+d[1])*0.01,v[1]=(d[2]*256+d[3])*0.01;// wheel speed front right , front left (in km/hr)
    0B3,speedR,v[0]=(d[0]*256+d[1])*0.01,v[1]=(d[2]*256+d[3])*0.01;// wheel speed rear right, rear left (in km/hr)
    0B4,speed,(d[5]*256+d[6])*0.01;// car speed (in km/hr)
    244,gaspdl,0.5*d[6];// gas pedal; range 0 ~ 100 (int)
    348,rpmtNm,v[0]=25*d[2],v[1]=((d[3]&#0001)-(d[3]&#0010))*256+d[4];// rpmt (target ICE RPM), torque in Nm
    3C8,rpm,32*d[2];// ICE RPM
    3CB,hvbat,v[0]=d[0],v[1]=d[1],v[2]=0.5*d[2],v[3]=0.5*d[3],v[4]=(d[4]&0x7F)-(d[4]&0x80),v[5]=(d[5]&0x7F)-(d[5]&0x80);// HV battery max discharge amp, max charge amp, dsc, soc, buC, blC
    3CF,oaTs,v[0]=((d[1]&0x7F)-(d[1]&0x80))*1.8+32,v[1]=((d[2]&0x7F)-(d[2]&0x80))*1.8+32;// OAT, intake T
    520,mlpr,(d[1]*256+d[2])/21600.0;// fuel injection: ml per ICE revolution
    52C,wT,d[1]*0.9+32;// ICE coolant T
    53F,odoint,(d[1]*256+d[2])*256+d[3];// ODO (integer part)
    540,shift,d[1]==0?"B":(d[1]==16?"D":(d[1]==32?"N":(d[1]==64?"R":(d[1]==128?"P":"?"))));//shift lever
    57F,light,d[1]==0?".":(d[1]==16?"p":(d[1]==48?"L":(d[1]==56?"H":"?")));//light
    5B6,door,d[2]==0?".":(d[2]==4?"R":(d[2]==64?"P":(d[2]==128?"D":"?")));//door
    5A4,fuel,d[1];//fuel in liters
    7EA61C3,mgsrpmNm,v[0]=d[2]*256+d[3]-0x3FFF,v[1]=0.125*(d[4]*256+d[5]-0x0FA0),v[2]=d[8]*256+d[9]-0x3FFF,v[3]=0.125*(d[10]*256+d[11]-0x0FA0);// MG2 RPM, torque, MG1 RPM, torque
    7EA61C3,brakeNm,v[0]=4*d[6],v[1]=4*d[7],v[2]=4*d[19]-512;//regenNm, brakeNm, mCylNm
    7EA61C3,icerpmNm,v[0]=0.01*(256*d[12]+d[13]),v[1]=256*d[14]+d[15],v[2]=256*d[16]+d[17];//target ICE kW, target ICE RPM, ICE RPM
    7EA61C3,invmgT,v[0]=d[26]-50,v[1]=d[27]-50,v[2]=d[28]-50,v[3]=d[29]-50,v[4]=d[45]-50;//inverter1 T, inverter2 T, MG1 T, MG2 T, converter T in deg C
    7EA61C3,auxV,0.001*(256*d[56]+d[57]);//12 V
    7EA61C3,brakelight,(d[63]&#0101)==#0101?"B":".";//brake light
    7E8410E,ignload,v[0]=0.5*d[2]-64,v[1]=0.39215686274509803*d[4];//IGN, load(0~100) (from standard OBD query)
    7E861CD,iceNm2,d[5]-128;// ICE torque in Nm (from query 21CD)
    7E8613C,catTevp,v[0]=(d[2]*256+d[3])*0.1-40,v[1]=(d[5]*256+d[6])*0.1-40,v[2]=d[8],v[3]=256*((d[10]&0x7F)-(d[10]&0x80))+d[11];// catT1 in deg C, catT2, evapVSV EVAP purge VSV, evapP EVAP vapor pressure (from query 213C3E2E32)
    7EB61D0,hvBVmnmxdsc,v[0]=0.01*(256*d[11]+d[12]-32768),v[1]=0.01*(256*d[14]+d[15]-32768),v[2]=d[70];//hvBVmin, hvBVmax, hvdsc
    7EB61D0,hvBR,v[1]=d[17],v[2]=d[18],v[3]=d[19],v[4]=d[20],v[5]=d[21],v[6]=d[22],v[7]=d[23],v[8]=d[24],v[9]=d[25],v[10]=d[26],v[11]=d[27],v[12]=d[28],v[13]=d[29],v[14]=d[30];// HV battery block resistance: start with v[1], not v[0]
    7EB61D0,hvBVa,v[1]=0.01*(256*d[35]+d[36]-32768),v[2]=0.01*(256*d[37]+d[38]-32768),v[3]=0.01*(256*d[39]+d[40]-32768),v[4]=0.01*(256*d[41]+d[42]-32768),v[5]=0.01*(256*d[43]+d[44]-32768),v[6]=0.01*(256*d[45]+d[46]-32768),v[7]=0.01*(256*d[47]+d[48]-32768);// HV battery block V first half: start with v[1], not v[0]
    7EB61D0,hvBVb,v[8]=0.01*(256*d[49]+d[50]-32768),v[9]=0.01*(256*d[51]+d[52]-32768),v[10]=0.01*(256*d[53]+d[54]-32768),v[11]=0.01*(256*d[55]+d[56]-32768),v[12]=0.01*(256*d[57]+d[58]-32768),v[13]=0.01*(256*d[59]+d[60]-32768),v[14]=0.01*(256*d[61]+d[62]-32768);// HV battery block V 2nd half
    7EB61D0,hvTs,v[0]=0.01*(256*d[64]+d[65]-32768),v[1]=0.2*(d[66]-128),v[2]=0.01*(256*d[74]+d[75]-32768),v[3]=0.01*(256*d[76]+d[77]-32768),v[4]=0.01*(256*d[78]+d[79]-32768);// HV battery air T, fan V, block Ts
    7E84105,wTobd,(d[2]-40)*1.8+32;// ICE coolant T from standard OBD query
    7E86133,atmmsf,v[0]=d[2],v[1]=25*d[4],v[2]=d[5],v[3]=d[6],v[4]=d[7],v[5]=d[8],v[6]=d[9],v[7]=d[10],v[8]=d[11],v[9]=d[12],v[10]=d[13];// atm (kPa), mfrpm: misfire RPM, mfload: misfire load, cyn 1~8
    7EB6131,dtcdist,256*d[2]+d[3];// dtcdist in km
    7E84110,maf,0.01*(256*d[2]+d[3]);//MAF air flow rate (grams/sec) ((A*256)+B)/100
    //7E84110,mlpr,(rpm>200?0.06*(256*d[2]+d[3])/rpm:0);// fuel injection: ml per ICE revolution; use MAF to estimate


    Now let's take a look at an example from the file command.txt:
    ATSH7E0,020105,3;//query ICE coolant T
    ATSH
    is the ELM command to set the "header", or which ECU to talk to. Here the ECU is 7E0. Next is the command to send. 02 means the command will have two bytes. 0105 is the two-byte long command. Lastly 3 means to do this query the least frequently (1: most frequently, 2: in between).
    The corresponding line in the file formula.txt is
    7E84105,wTobd,(d[2]-40)*1.8+32;// ICE coolant T from standard OBD query
    Notice that when the ECU replies the query, it adds 8 to its address, which now becomes 7E8. It also adds 40 to the first byte of the two-byte query command, which now becomes 4105. d[2] is the third data byte coming back (after 4105). The entire returned message looks like this:
    7E8 03 41 05 3C 00 00 00 00
    03
    indicates that there are three data bytes.

    If you have a different car, say gen 3 Prius, you can edit the two files to query and read the gen 3 codes. The easiest is probably to look up existing Torque formulas posted in some sub-forums of PriusChat. Good luck!

    Questions?
     
  2. hyera_rponzoni

    hyera_rponzoni New Member

    Joined:
    May 28, 2014
    3
    0
    0
    Vehicle:
    Other Electric Vehicle
    Model:
    N/A
    Hi Prius2009.
    Following your indications, I was able to finally obtain the informations I wanted from the can bus.
    However, I still have a problem to solve to add all the pids I use to acquire in Torque, right now I made a really bad looking trick to obtain the correct value:

    In command.txt I have:
    ATSH7C0,02212B,1; // Calculate HV System Indicator

    in formula.txt
    7C8612B,hsi,v[0]=d[2],v[1]=d[3],v[2]=d[4];

    the problem is, when Car_Data::decodeDriveData is called, frm-> id is 7C8 (1992) while the function is in the object mm_id_fn with id 7C8612B (130572587).
    For now I have forced to change id when 7C8 is required, but if I want to add more queries with 7c8 this is not gonna work anymore.
    There must be an error in what I've done but I don't understand how to read the full id when parsing the result. It's like the number of bytes after the command is wrong. (I put 02 like your example, 'cause my command is 212B).
    Any advice on this?

    I want to thank you again, I would have never been able to make it work without your help!

    Roberto
     
  3. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,703
    484
    63
    Location:
    USA
    Vehicle:
    2009 Prius
    Hi Roberto, Glad to know you are making progress. It was my fault: I hardcoded the lowest ECU address to distinguish passive from active frames and it looks like gen3 cars have lower addresses than gen2. Look in the function
    Car_Data::decode2
    and search for
    frm.id < 0x7E8 (there are more than one occasion)
    and change 7E8 to something like 700. That should fix it. Please give it a try and let me know if it works out or not. Thanks!
     
  4. hyera_rponzoni

    hyera_rponzoni New Member

    Joined:
    May 28, 2014
    3
    0
    0
    Vehicle:
    Other Electric Vehicle
    Model:
    N/A
    yay!!! that worked :)
     
  5. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,703
    484
    63
    Location:
    USA
    Vehicle:
    2009 Prius
Loading...
Similar Threads - edit items command
  1. 2009Prius
    Replies:
    1
    Views:
    12,790