extern "C" {
#endif
-// TODO This isn't true for multi frame messages - we may need to dynamically
-// allocate this in the future
-#define MAX_UDS_PAYLOAD_LENGTH 7
+// TODO This still doesn't have enough space for the largest possible
+// multiframe response. May need to dynamically allocate in the future.
+#define MAX_UDS_RESPONSE_PAYLOAD_LENGTH 255
+#define MAX_UDS_REQUEST_PAYLOAD_LENGTH 7
#define MAX_RESPONDING_ECU_COUNT 8
#define VIN_LENGTH 17
*
* arbitration_id - The arbitration ID to send the request.
* mode - The OBD-II mode for the request.
- * pid - (optional) The PID to request, if the mode requires one.
+ * has_pid - (optional) If the requests uses a PID, this should be true.
+ * pid - (optional) The PID to request, if the mode requires one. has_pid must
+ * be true.
* pid_length - The length of the PID field, either 1 (standard) or 2 bytes
- * (extended).
+ * (extended). If 0, it will be set automatically based on the request
+ * mode.
* payload - (optional) The payload for the request, if the request requires
* one. If payload_length is 0 this field is ignored.
* payload_length - The length of the payload, or 0 if no payload is used.
+ * no_frame_padding - false if sent CAN payloads should *not* be padded out to a
+ * full 8 byte CAN frame. Many ECUs require this, but others require the
+ * size of the CAN message to only be the actual data. By default padding
+ * is enabled (so this struct value can default to 0).
* type - the type of the request (TODO unused)
*/
typedef struct {
- uint16_t arbitration_id;
+ uint32_t arbitration_id;
uint8_t mode;
+ bool has_pid;
uint16_t pid;
uint8_t pid_length;
- uint8_t payload[MAX_UDS_PAYLOAD_LENGTH];
+ uint8_t payload[MAX_UDS_REQUEST_PAYLOAD_LENGTH];
uint8_t payload_length;
+ bool no_frame_padding;
DiagnosticRequestType type;
} DiagnosticRequest;
NRC_SUCCESS = 0x0,
NRC_SERVICE_NOT_SUPPORTED = 0x11,
NRC_SUB_FUNCTION_NOT_SUPPORTED = 0x12,
+ NRC_INCORRECT_LENGTH_OR_FORMAT = 0x13,
NRC_CONDITIONS_NOT_CORRECT = 0x22,
NRC_REQUEST_OUT_OF_RANGE = 0x31,
NRC_SECURITY_ACCESS_DENIED = 0x33,
* field isn't valid if 'completed' isn't true. If this is 'false', check
* the negative_response_code field for the reason.
* arbitration_id - The arbitration ID the response was received on.
+ * multi_frame - True if this response (whether completed or not) required
+ * multi-frame CAN support. Can be used for updating time-out functions.
* mode - The OBD-II mode for the original request.
* has_pid - If this is a response to a PID request, this will be true and the
* 'pid' field will be valid.
typedef struct {
bool completed;
bool success;
- uint16_t arbitration_id;
+ bool multi_frame;
+ uint32_t arbitration_id;
uint8_t mode;
bool has_pid;
uint16_t pid;
DiagnosticNegativeResponseCode negative_response_code;
- uint8_t payload[MAX_UDS_PAYLOAD_LENGTH];
+ uint8_t payload[MAX_UDS_RESPONSE_PAYLOAD_LENGTH];
uint8_t payload_length;
} DiagnosticResponse;
OBD2_MODE_ENHANCED_DIAGNOSTIC_REQUEST = 0x22
} DiagnosticMode;
-/* Public the signature for an optional function to be called when a diagnostic
+/* Public: The signature for an optional function to be called when a diagnostic
* request is complete, and a response is received or there is a fatal error.
*
* response - the completed DiagnosticResponse.
*/
typedef void (*DiagnosticResponseReceived)(const DiagnosticResponse* response);
-typedef float (*DiagnosticResponseDecoder)(const DiagnosticResponse* response);
-
/* Public: A handle for initiating and continuing a single diagnostic request.
*
* A diagnostic request requires one or more CAN messages to be sent, and one