Yes, I did write a couple modules to support OBDII communication. You
do indeed need to enable those devices to make any of it work. I
think that was all written about two years ago. The problem is, this
is one of those "he's got more ideas than time" sort of things. I'm
pretty sure that two years ago I tested it to work. There are indeed
two options. There is a module that allows the GEVCU wifi or bluetooth
module to pretend to be an ELM327 device. I think at the time I wrote
that we only had wifi but I was actually able to make it all work that
way - torque supports wifi connected devices. Now it should be easier
as more recent GEVCU boards have the capability to use bluetooth. The
other approach is to use canpidlistener which directly listens for
OBDII PID traffic and responds right over CAN. This would allow one to
use an ELM327 based bluetooth dongle. I think this had some limited
testing. But, in the meantime I believe there have been some changes
to the codebase and maybe it broke.
Now I'll answer the original questions with in-line quoting:
>> Here are I think the relevant pieces of code:
>>
>> 1) Set up Canbus mask and filter in GEVCU.ino:
>>
>> // eight = 5; //how many RX mailboxes
>> eight = 7; // Using two more mailboxes for ELM Bluetooth to Android
>> because ELM327Emu also uses two
>> sysPrefs->write(EESYS_CAN_RX_COUNT, eight);
>> ...
>> thirtytwo = 0x7f0; //standard frame, ignore bottom 4 bits
>> sysPrefs->write(EESYS_CAN_MASK5, thirtytwo);
>> sysPrefs->write(EESYS_CAN_MASK6, thirtytwo);
>> ...
>> thirtytwo = 0x651;
>> sysPrefs->write(EESYS_CAN_FILTER5, thirtytwo); // ELM327Bluetooth device
>> 0x651
>> sysPrefs->write(EESYS_CAN_FILTER6, thirtytwo);
Why use an ID of 0x651? You should be accepting frames in the 0x7E0
range. That's the ID that is likely to be used by ELM327 to ask you
(asking as the ECU) for a PID reply. You then reply with an address 8
higher. For instance, if ELM327 sends on 0x7E0 you reply on 0x7E8.
But, you've got the mask correct.
>>
>> 2) Create my device object during init in GEVCU.ino:
>>
>> ELM327Bluetooth *elmBT = new ELM327Bluetooth();
>>
>> 3) Attach to both CANbuses inside my ELM327_Bluetooth.cpp
>>
>> CanHandler::getInstanceCar()->attach(this, 0x651, 0x7f0, false); //
>> Callback for my device(?) and standard mask
>> CanHandler::getInstanceEV()->attach(this, 0x651, 0x7f0, false);
>>
Once again, use 0x7E0 not 0x651. This ID is not your device ID but
rather the CAN frame ID.
>> 4) Send a test frame to both Canbuses in a modified SerialConsole.cpp
>>
>> CAN_FRAME output;
>> output.length = 1;
>>
output.id = 0x651; // the ELM327Bluetooth device handler?
>> output.extended = 0;
>> output.rtr = 0;
>> output.fid = 0x0;
>> output.priority = 0;
>> output.data.bytes[0] = newValue;
>> ...
>>
>> CanHandler::getInstanceEV()->sendFrame(output);
>> CanHandler::getInstanceCar()->sendFrame(output);
>>
Same basic advice. But, yes, you seem to be calling sendFrame properly.
>> Now, I'm sure this is due to my incomplete understanding of Canbus
>> protocols and the existing code. Some points of confusion:
>>
>> - I see "id" in the Canbus frame object. Is this id the device id (and
>> therefore priority?) of the target device on the bus or is it for PIDs
>> because in some places in the code the id is clearly a PID? I figured that
>> the higher-level OBD2 protocol data like mode and PID would be encoded
>> inside the Canbus frame's generic data payload. Is Mode 1 always assumed?
>> I see nothing in the code where I can set the mode.
>>
>> - Am I using the filter and mask facility correctly? Do I put my device
>> id in the filter?
>>
>> - Am I attaching to the bus correctly?
>>
>> - Am I sending a frame correctly?
I think you're attaching to the bus more or less properly but your use
of IDs is wrong. You are sending properly. You are using masks
properly and I think you have the basic idea for the filter ID. Most
all of your troubles just come down to the frame ID. OBDII uses the
frame ID as a key for who is sending and what they want. ECUs listen
on 0x7E0 through 0x7E7. There is a broadcast address 0x7DF which
should make every ECU respond. Torque might use that ID so plan
accordingly. All ECUs reply 8 higher than their listening ID (even if
they are replying to 0x7DF). So, if torque sending 7DF and the ECU
would normally be 0x7E2 it replies on 0x7EA.
Mode 1 is where most all the magic happens. There are other modes but
mostly they're not relevant. The code in GEVCU can reply to mode 1, 3,
4, and 9. Mode 3 gives out fault codes. Mode 4 clears them. Mode 9 has
some more vehicle data like the VIN number of the car.
Wikipedia actually has a good article about all of this stuff:
https://en.wikipedia.org/wiki/OBD-II_PIDs