1. Attachments are working again! Check out this thread for more details and to report any other bugs.

Scanguage Xgauge how-to area (Please share your knowledge!)

Discussion in 'Gen 2 Prius Technical Discussion' started by Bob64, Feb 21, 2008.

  1. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Scanguage Xgauge/CAN network research thread

    Ok, I hope that this thread will create some discussion on the how-tos of getting the scangauge to pull the data that WE want out of the prius's CAN network.

    I believe I've managed to figure out how to decipher the PASSIVE messages that the battery ECU sends out. (Probably been done before, but hey, I don't see a guide to understanding it anywhere)

    Apparent Disadvantages: We're totally at the mercy of whatever interval the passive messages shoot out at as opposed to the "ACTIVE" message AMP code that is already out.

    For example: Battery Current (Amps)
    Interval: 8 ms (Blurringly fast)
    TXD: 0033
    RXF: 0100823B0000
    RXD: 140C
    MTH: 0001000A0000

    I did some quick testing, and it appears to match exactly what the other Scangauge code for amps gets, although the tenth place is blurringly fast.

    A quick explanation on how the above code works:

    First, lets understand exactly where the data is:
    Prius PHEV TechInfo - EAA-PHEV

    Lets look at the first row of data. First of all, I have no idea why they numbered the byte position the way it is layed out on the table... so I've simplified it a bit... Note: may not be accurate, but it's the best explanation I've been able to come up with.

    [​IMG]
    http://i11.photobucket.com/albums/a199/Bobc64/prius/priuspassivecan-1.gif

    We're interested in Bytes 3 and 4. Note that Current is 12 bits and that it is signed.
    Signing means that the most significant binary bit - when set - results in its value being negative.

    For example, in an 8 bit binary number 1111 1111, to convert into decimal you add -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1.

    It also means that bits 16-19 are unneeded.

    Anyway, on to the TXD of 0033.
    First, because these messages are PASSIVE, it means that these are broadcast automatically by the battery ECU, which according to the above wiki, does not even listen to messages on the CAN - it only sends.

    First, the ID of the passive messages is 03B.
    In order to change this into a fake message that the scangauge sends - you invert the last character's most significant binary bit. REMEMBER that the ID is in hexadecimal. If you convert 003B into binary, it becomes: 0000 0011 1011
    0000 0011 0011 (inverted last character's most insignificant bit)
    Then convert back to Hex: 033
    We need to first pad a 0 to the TXD, since the TXD field must be an even number of hex characters. Thus: "0033".

    Ok, based on the TXD, the scangauge will look for ANY reply with the last character's most significant binary bit flipped, ignoring the last 3 binary bits.
    This means that any replies with 0000 0011 1XXX will be accepted for further filtering, which is what the RxF (Receive Filter) does.

    RXF: 0100823B0000
    First, for simplicity's sake, lets separate them into 3 groups of 2 characters.
    01 00 - 82 3B - 00 00
    First lets take a look at the first two characters of group 1: "01"
    The 1st character means something special: If it is equal to a 0, do nothing. If it is equal to an 8, then it is a scangauge trip gauge.

    Since we're not making a trip gauge, we're going to leave it at 0.
    Lets look at the 2nd character of group 1: "1"
    This second character indicates to the scangauge where to look to match the other two characters with.
    This means that byte "1" MUST equal "00" in order to be processed further. If it doesn't, the message is discarded.

    The same concept applies to the other groups. EXCEPT the first character in the second group. If it equals an "8", it means that the FINAL value (after MTH is done) has a space after the decimal (for example, X.X). If it equals "4", it means that the FINAL value (after MTH is done) has two spaces after the decimal (for example, X.XX). If it equals "2" the final value is either "ON" or "OFF" depending on if the FINAL value is equal to a "1" or a "0".
    Thus, byte "2" MUST equal "3B" in order to be processed further. If it doesn't, the message is discarded.

    The first character in the 3rd group also means something special: if the value is 8, the final value is supposedly in hex (Have not gotten it to work yet).
    The filter seems to do nothing if the 2nd to 4th characters are "0"



    Now that we got a message that matches the filter, its time for RXD.
    RXD: 140C
    RxD tells the scangauge WHERE in the message our data is.
    Separate the RXD into 2 groups of 2 characters.
    14 0C
    The first group tells where the data starts. 00 is the first bit in the string, 08 is the first bit in the second byte, 10 is the first bit in the third byte. In this case, we want the 20th bit onwards.

    The second group is how LONG the values are. In this case, it is 12 bits long (C in hex).

    Onward to MTH.


    MTH: 0001000A0000
    Lets seperate this into 3 groups of 4 HEX characters.
    0001 000A 0000
    The first group means how much to multiply the value by.
    The second group means how much to divide the value by.
    the third group means how much to add/subtract the value by (this is a signed field)

    So in this case, we're multiplying by 1, dividing by 10 (A in hex = 10 in decimal), and then adding 0 to get the final amp value.

    Then call the gauge something. AMP works good.

    Observations with AMP values: (these numbers are off the top of my head at the moment and may be off)
    You'll now notice that the prius supposedly takes ~.9 amps when sitting idle, slow acceleration in EV mode takes about 22+ amps, and stealth glide takes about 5+ amps to maintain, warpstealth takes about 15+ amps to maintain.
    Other observations: You barely regenerate anything at 7mph, so best to shift into neutral and use friction brakes here to avoid use of creeping, which takes about 2-3 amps. Neutral = .9 amps, brakes brings it up to 1.3 amps. Headlights in neutral brings it up to about ~1.9 amps total.


    Anyway, if anyone has a clue as to how to get the hex mode special value in the first character of the 3rd group to work in the RxF area, please post in this thread and share some knowledge!

    My ultimate goal at this point is to pull inverter temp data, and I need help getting RAW hex data out of the CAN! It's being sent with an ID of 7E2 and a PID of C3 or C4!

    Please feel free to correct me if I'm wrong! (I'm still struggling to learn this CAN stuff!)
     
  2. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Ok, looks I screwed up a tad on the MTH somewhere - it doesn't show negative values right.
     
  3. ksstathead

    ksstathead Active Member

    Joined:
    May 1, 2007
    1,244
    245
    0
    Location:
    Kansas
    Vehicle:
    2010 Prius
    Model:
    III
    Glad to see your post. Just got my upgraded unit back & put trip FE in as a gauge. Ecstatic about that. Look forward to studying your post to start my learning curve on it.
     
  4. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Argh, there doesn't seem to be a way to have the scangauge treat 12bit signed values right! It only supports 16 bit signed values :/
     
  5. dogfriend

    dogfriend Human - Animal Hybrid

    Joined:
    Feb 26, 2007
    7,512
    1,188
    0
    Location:
    Carmichael, CA
    Vehicle:
    2007 Prius
    I don't know anything about CAN, but I just got a new ScanGauge so I was looking for info about the XGauge function.

    Anyway, I can follow your discussion above, but I noticed that on the PHEV wiki site, they use a different set of parameters for Current, namely the TXD is different. Comment?
    Picture 1.png

    Prius PHEV TechInfo - EAA-PHEV
     
  6. icarus

    icarus Senior Member

    Joined:
    Apr 12, 2007
    4,884
    976
    0
    Location:
    earth
    Vehicle:
    2007 Prius
    Model:
    N/A
    Bob64.

    I don't know a bit from a bite from a byte. I glaze over reading your post, but marvel at the knowlege you have to do any of that. Congrats. If you get the inverter temp code unlocked, it would be great if you would post it for us non-techno types.

    Thanks once again,

    Icarus

    PS. It took me hours to figure out that I had to enter some sort of code to get the scan to give me HV voltage and SOC. Once I figured it out it made sense,,,,sort of. Mostly black magic!
     
  7. RobH

    RobH Senior Member

    Joined:
    Sep 18, 2006
    2,369
    980
    70
    Location:
    Sunnyvale, California
    Vehicle:
    2006 Prius
    If the CAN protocol is only active in Ready mode, then what is used when they add a new keyfob? I watched a mechanic do it, and the scantool seemed to be interacting with the car even when it was OFF.
     
  8. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Apparently theres two ways to get Current.

    Active and passive.

    The ECU passively broadcasts the current without request, as well as other data, which is what my "tutorial" attempts to acquire.

    The active one that someone else figured out sends a message to the HV ECU or something, and requests the current data. Apparently that data is 16 bits, and not 12 bits when captured passively... which is why it appears to have working negative values. The passive message is broadcast every ~8ms, which is probably why the passive code is blurringly fast at refreshing when compared with the "Active" xgauge code - if you put the gauges side by side.

    As for adding keyfobs... perhaps this may answer your questions:
    Replacing A Lost Prius Smart Key
     
  9. Rokeby

    Rokeby Member

    Joined:
    Jan 21, 2008
    3,033
    708
    75
    Location:
    Ballamer, Merlin
    Vehicle:
    2008 Prius
    Good Lord above!

    Bob64, how you and the other posters working on this can see your way through what is to me an impenetrable thicket of numbers and hex codes is beyond me. A tip of the hat to all of you.

    What caught my interest in your posts was the mention of inverter temps. All the threads on grill blocking invariably say that being able to monitor them is of paramount importance.

    I want to add my encouragement to you and the other posters. Go boys go!

    My hope is that at the successful end of your efforts you will post the necessary numbers in the format given for the XGauge so plain folks like me, just a simple wooden boat builder, can put them into our ScanGauges. (What's the difference between being simple versus stupid?... You can brag about being simple!)

    I take it that if I sift carefullly through your post I can get the numers to put HV amps on my ScanGauge. I think I'll call it HVA.
     
  10. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Alas, but the above gauge is flawed: the scangauge does not handle negative values with the above "passive" gauge. I believe that its a limitation with the scangauge and can't be fixed at this point.
    You'll notice with the passive gauge that when you regen, the numbers will go crazy (consequence of the values being signed).

    Your better off using the "active" code that dogfriend mentioned in this thread. (It works with negative values, and it doesn't refresh blurringly fast.)

    Right now I'm trying to obtain some raw data from the people that worked on this: The new 2004 Toyota Prius : My CAN Project

    Since at this point, I'm unwilling to invest in the additional hardware to obtain it myself.
     
  11. dogfriend

    dogfriend Human - Animal Hybrid

    Joined:
    Feb 26, 2007
    7,512
    1,188
    0
    Location:
    Carmichael, CA
    Vehicle:
    2007 Prius
    Is there any other disadvantage to using the active Current code other than refresh speed? I haven't tried it yet, but I'm thinking the active code would still be plenty fast enough for a usable gauge.

    On my Ford Explorer, I have tried using a Palm based scan tool as a gauge, but the problem is that it doesn't refresh fast enough for most purposes (e.g the RPM lags by a second or so, making it useless for a real tach). The Ford is PWM based, not CAN based. I think the actual slowness is the Palm Pilot / software combo.
     
  12. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    the active code refreshes fast enough, about a second delay. Good enough if you want to monitor it. No downsides in using it. It works perfectly, as opposed to the passive method.

    The passive code refreshes TOO fast. Every 8 ms. Good if you want to build a plugin prius perhaps? :p
     
  13. prim2

    prim2 Junior Member

    Joined:
    Oct 6, 2007
    64
    0
    0
    Location:
    Toronto
    Vehicle:
    2008 Prius
    I have no knowledge of the codes, but I'm excited that someone is looking into X-Gauge inverter temp. If you are successful, MG1&2 temps would be very much appreciated too.

    Cheers,

    Geoff
     
  14. hobbit

    hobbit Senior Member

    Joined:
    Mar 23, 2005
    4,089
    468
    0
    Location:
    Bahstahn
    Vehicle:
    2004 Prius
    Model:
    N/A
    I didn't see this thread until now.
    .
    What are you using to passively read the raw update data?
    .
    _H*
     
  15. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    I'm using an scangauge II with xgauge.

    Trying to craft an xgauge to read raw data one byte at a time... working at the moment on a more detailed model of exactly what CAN traffic looks like so that I can figure out how to get the data I want from it easier.
     
  16. jayman

    jayman Senior Member

    Joined:
    Oct 21, 2004
    13,439
    641
    0
    Location:
    Winnipeg Manitoba
    Vehicle:
    2004 Prius
    The equipment you're using really isn't meant for passive mode, not fast enough to catch the SOF, especially a remote SOF. At work, we use Agilent 54600 and a newer Agilent 6000, they have the memory depth and speed to look at the data, both regular and extended bit

    I strongly suggest you look at some CAN tutorials, such as these

    http://cp.literature.agilent.com/litweb/pdf/5989-6316EN.pdf

    http://cp.literature.agilent.com/litweb/pdf/5989-5049EN.pdf

    http://cp.literature.agilent.com/litweb/pdf/5989-7312EN.pdf

    http://cp.literature.agilent.com/litweb/pdf/5989-7971EN.pdf

    Robert Bosch GmbH developed CANBus, this is the actual specification

    http://www.semiconductors.bosch.de/pdf/can2spec.pdf
     
  17. Bob64

    Bob64 Sapphire of the Blue Sky

    Joined:
    Apr 9, 2007
    1,540
    93
    0
    Location:
    Virginia
    Vehicle:
    2007 Prius
    Model:
    N/A
    Well, I don't really care at the moment about passive mode or not. I was just curious as to if it could be done or not with a scangauge.

    I've actually found that CAN specs sheet linked from wikipedia before you posted, and judging by the content there. I believe the Data Bytes section of EAA-PHEV wiki is incorrect.

    Prius PHEV TechInfo - EAA-PHEV

    Specifically Byte 2, since an ID requires more then one byte (3 hex characters) to fit... so I don't think its physically possible to stick the ECU id into 8 bits.

    I'm actually programming a simple "CAN packet" simulator thats slightly interactive. To help people visualize what is being sent... However I'm also trying to figure out if it also corresponds to the scangauge xgauge programming guide that linear logic has released. The part I'm a bit confused on is the RXF, since it doesn't seem to match up with the official specs of the CAN.

    Work in progress:
    [​IMG]
    http://i11.photobucket.com/albums/a199/Bobc64/prius/can.jpg
     
  18. jayman

    jayman Senior Member

    Joined:
    Oct 21, 2004
    13,439
    641
    0
    Location:
    Winnipeg Manitoba
    Vehicle:
    2004 Prius
    No, that doesn't look right. Wondering if there is a typo on their part?
     
  19. jstcd

    jstcd New Member

    Joined:
    Apr 30, 2008
    12
    26
    0
    Vehicle:
    Other Non-Hybrid
    Re: Fix for signed 12 bit value

    If the scan guage can't cope with a 12 bit signed value then you should be able to read four bits past the data you want, (ie for a total of 16bits), and then divide the resulting number by 16, which will shift it 4 bytes to the right, tossing out the garbage you orriginally recorded and leaving you with a correct left padded 16 bit signed value.

    So, if the problem code is:
    TXD: 0033
    RXF: 0100823B0000
    RXD: 140C
    MTH: 0001000A0000
    (12 bits divided by ten)

    Then
    TXD: 0033
    RXF: 0100823B0000
    RXD: 1410
    MTH: 000100A000000 (note the "A" is one digit to the left)
    (16bits results in a number 16 times bigger, divided by 160)

    Should produce the correct result with +- sign and everything.

    I have a Highlander Hybrid, and have yet to get any SOC/Amp/Volt reading yet, i think there must be subtle differences from the prius system, and of coure can't try this out to let you know if what i have said in theory hold true in practice.
     
  20. -CC-

    -CC- Just sipping fuel since '08

    Joined:
    Mar 9, 2008
    12
    0
    0
    Location:
    Michigan's Thumb
    Vehicle:
    2012 Prius c
    Model:
    Three
    In a nutshell, here are the three correct Prius specific X-Gauge settings. (The Battery Current RXF number had a typo on the ScanGauge site--this is the corrected version.)

    State Of Charge: TXD: 07E321CE RXF: 056186CE0000 RXD: 3008 Mth : 000A00020000 NAM: SOC

    Battery Current: TXD: 07E321CE RXF: 056186CE0000 RXD: 3810 Mth : 0001000AF333 NAM: BTA

    Battery Voltage: TXD: 0033 RXF: 0100023B0000 RXD: 2010 Mth : 000100010000 NAM: BTV

    "Prius Battery Current and State of Charge cannot be displayed at the same time."

    Peace,
    --CC--