I am trying to get Odrive working with C++ over USB.
I am using libusb to facilitate the communication between my machine and Odrive.
I am first trying to retrieve the JSON endpoints definition from within the USB itself.
Per the documentation I am creating my request like so and sending it to endpoint 0:
81 0 0 80 40 0 0 0 0 0 1 0
I can then get a response from the Odrive and then try to retrieve the rest of the JSON. So I will send another request like so:
82 0 0 80 40 0 0 0 0 0 1 0
I am getting a response from the Odrive but it is always the exact same and so I am not sure what is going wrong here. The response I am getting is (minus the first 2 bytes):
The payload of your request needs to contain the number of bytes you already received. If you always set it to 0, you always get the beginning of the json
Something like this:
do {
serialize(send_payload, (int)received_json.size());
endpoint_request(0, receive_payload, send_payload, true, 64, false);
send_payload.clear();
for (u8 byte : receive_payload) {
received_json.push_back(byte);
//printf("%c", byte);
//fflush(stdout);
}
} while (receive_payload.size());
BTW It’s strange that you receive anything at all. Usually the last two bytes should contain the firmware crc.
Awesome that was the missing piece of the puzzle thanks for your help!
The CRC for endpoint 0 is the protocol version but for all other endpoints it’s the CRC of the JSON.
Do you know how large the JSON is currently? I am trying to ensure I did everything properly.
Ok so everything is working now thanks a lot for your help.
I’ve moved on to trying to use other endpoints. I started off with endpoint 5 to try to retrieve the SN.
The issue is I am not 100% sure if my JSON CRC is correct.
In the documentation it takes you to a sample calculator that you can use to calculate the CRC16.
I am not clear if the initial value should be 0x0001 or 0x1337 but neither of the CRCs generated from the retrieved JSON seem to work (0x23F7 or 0xD67B).
I am querying endpoint 5 like so but keep receiving a timeout response:
Ok I learned from another forum that the CRC should be 0xD271 but I am not sure what the difference is in the calculation since I used the same algo from the documentation.
You can send a request with endpoint 0 and 0xffffffff in the payload. You then receive a 32-bit number with the crc being the upper 16 bits. Don’t know if this is official behavior, but it works