Skip to content

Commit

Permalink
Merge branch 'next' into GA-vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
pjt0620 committed Feb 9, 2021
2 parents 491093d + 439c910 commit 81d3f10
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 1,644 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.mkd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# OpenXC Vehicle Interface Firmware Changelog
## v8.2.0
* Removed: Removed messagepack format support

## v8.1.0
* BREAKING: VI-Firmware 8.0.0 is not backwards compatable due to stitched diagnostic responses and must be used with OpenXC-Python 2.1.0 or greater.
Expand Down
2 changes: 1 addition & 1 deletion docs/compile/example-builds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ while this builds the default firmware, ready for OBD2 requests for the chipKIT:
fab chipkit obd2 build
You can specify the message format with ``json``, ``protobuf``, or ``messagepack``:
You can specify the message format with ``json``, or ``protobuf``:

.. code-block:: sh
Expand Down
2 changes: 1 addition & 1 deletion docs/compile/makefile-opts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ These options are passed as shell environment variables to the Makefile, e.g.
By default, the output format is ``JSON``. Set this to ``PROTOBUF`` to use a
binary output format, described more in :doc:`/advanced/binary`.

Values: ``JSON``, ``PROTOBUF``, ``MESSAGEPACK``
Values: ``JSON``, ``PROTOBUF``

Default: ``JSON``

Expand Down
4 changes: 0 additions & 4 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ def json():
@task
def protobuf():
env.payload_format = "PROTOBUF"

@task
def messagepack():
env.payload_format = "MESSAGEPACK"

@task
def clean():
Expand Down
3 changes: 0 additions & 3 deletions src/commands/payload_format_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ bool openxc::commands::handlePayloadFormatCommand(openxc_ControlCommand* command
case openxc_PayloadFormatCommand_PayloadFormat_PROTOBUF:
format = PayloadFormat::PROTOBUF;
break;
case openxc_PayloadFormatCommand_PayloadFormat_MESSAGEPACK:
format = PayloadFormat::MESSAGEPACK;
break;
}

status = true;
Expand Down
72 changes: 18 additions & 54 deletions src/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,47 +294,47 @@ static openxc_VehicleMessage wrapDiagnosticResponseWithSabot(CanBus* bus,
return message;
}

const bool originalStitchAlgo = false;
static int prevFrame = -1;
static openxc_VehicleMessage wrapDiagnosticStitchResponseWithSabot(CanBus* bus,
const ActiveDiagnosticRequest* request,
const DiagnosticResponse* response, openxc_DynamicField value) {
openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero fill
message.type = openxc_VehicleMessage_Type_DIAGNOSTIC_STITCH;
message.diagnostic_stitch_response = {0};
message.diagnostic_stitch_response.bus = bus->address;
message.type = openxc_VehicleMessage_Type_DIAGNOSTIC;
message.diagnostic_response = {0};
message.diagnostic_response.bus = bus->address;

if(request->arbitration_id != OBD2_FUNCTIONAL_BROADCAST_ID) {
message.diagnostic_stitch_response.message_id = response->arbitration_id
message.diagnostic_response.message_id = response->arbitration_id
- DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET;
} else {
// must preserve responding arb ID for responses to functional broadcast
// requests, as they are the actual module address and not just arb ID +
// 8.
message.diagnostic_stitch_response.message_id = response->arbitration_id;
message.diagnostic_response.message_id = response->arbitration_id;
}

message.diagnostic_stitch_response.mode = response->mode;
message.diagnostic_stitch_response.pid = response->pid;
message.diagnostic_stitch_response.success = response->success;
message.diagnostic_stitch_response.negative_response_code =
message.diagnostic_response.mode = response->mode;
message.diagnostic_response.pid = response->pid;
message.diagnostic_response.success = response->success;
message.diagnostic_response.negative_response_code =
response->negative_response_code;

message.diagnostic_stitch_response.frame = prevFrame + 1;
message.diagnostic_response.frame = prevFrame + 1;
if (response->completed) {
message.diagnostic_stitch_response.frame = -1; // Marks the last frame in the response
message.diagnostic_response.frame = -1; // Marks the last frame in the response
} else {
message.diagnostic_stitch_response.success = true;
message.diagnostic_response.success = true;
}
prevFrame = message.diagnostic_stitch_response.frame;
prevFrame = message.diagnostic_response.frame;

if(response->payload_length > 0) {
if (request->decoder != NULL) {
message.diagnostic_stitch_response.value = value;
message.diagnostic_response.value = value;
} else {
memcpy(message.diagnostic_stitch_response.payload.bytes, response->payload,
memcpy(message.diagnostic_response.payload.bytes, response->payload,
response->payload_length);
message.diagnostic_stitch_response.payload.size = response->payload_length;
message.diagnostic_response.payload.size = response->payload_length;
message.diagnostic_response.total_size = response->payload_length;
}
}
return message;
Expand Down Expand Up @@ -405,38 +405,6 @@ static void sendPartialMessage(long timestamp,
(uint8_t*)messageBuffer, messageLen, MessageClass::SIMPLE);
}


// relayPartialFrame - Send the partial frame to the mobile device/web

static void relayPartialFrame(DiagnosticsManager* manager, // Only need for the callback
ActiveDiagnosticRequest* request,
const DiagnosticResponse* response,
Pipeline* pipeline) {

int frame = prevFrame + 1;
if (response->completed) {
frame = -1; // Marks the last frame in the response
}
prevFrame = frame;

// see wrapDiagnosticResponseWithSabot
sendPartialMessage(00, // long timestamp,
frame, // int frame
response->arbitration_id, // int message_id,
request->bus->address, // int bus,
0, // int total_size,
response->mode, // int mode,
response->pid, // int pid,
0, // int value, - when the payload is a bitfield or numeric - parsed value
response->negative_response_code, // int negative_response_code
(char *)response->payload, // char *payload
response->payload_length,
pipeline);

if (response->completed && (request->callback != NULL)) {
request->callback(manager, request, response, diagnostic_payload_to_integer(response));
}
}
#endif

static void relayDiagnosticResponse(DiagnosticsManager* manager,
Expand Down Expand Up @@ -514,11 +482,7 @@ static void receiveCanMessage(DiagnosticsManager* manager,

if (response.multi_frame) {
#if (MULTIFRAME != 0)
if (originalStitchAlgo) {
relayPartialFrame(manager, entry, &response, pipeline);
} else {
relayDiagnosticResponse(manager, entry, &response, pipeline, true); // Added 6/11/2020
}
relayDiagnosticResponse(manager, entry, &response, pipeline, true); // Added 6/11/2020
#endif
if (!response.completed) {
time::tick(&entry->timeoutClock);
Expand Down
62 changes: 9 additions & 53 deletions src/payload/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const char openxc::payload::json::SD_MOUNT_STATUS_COMMAND_NAME[] = "sd_mount_sta

const char openxc::payload::json::PAYLOAD_FORMAT_JSON_NAME[] = "json";
const char openxc::payload::json::PAYLOAD_FORMAT_PROTOBUF_NAME[] = "protobuf";
const char openxc::payload::json::PAYLOAD_FORMAT_MESSAGEPACK_NAME[] = "messagepack";

const char openxc::payload::json::COMMAND_RESPONSE_FIELD_NAME[] = "command_response";
const char openxc::payload::json::COMMAND_RESPONSE_MESSAGE_FIELD_NAME[] = "message";
Expand Down Expand Up @@ -67,6 +66,14 @@ static bool serializeDiagnostic(openxc_VehicleMessage* message, cJSON* root) {
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_PID_FIELD_NAME,
message->diagnostic_response.pid);

if (message->diagnostic_response.total_size > 0) {
// These next 2 fields are only in a stitched message frame
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_FRAME_FIELD_NAME,
message->diagnostic_response.frame);
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_TOTAL_SIZE_FIELD_NAME,
message->diagnostic_response.total_size);
}

if(message->diagnostic_response.negative_response_code != 0) {
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_NRC_FIELD_NAME,
message->diagnostic_response.negative_response_code);
Expand Down Expand Up @@ -98,55 +105,6 @@ static bool serializeDiagnostic(openxc_VehicleMessage* message, cJSON* root) {
return true;
}

static bool serializeStitchDiagnostic(openxc_VehicleMessage* message, cJSON* root) {
cJSON_AddNumberToObject(root, payload::json::BUS_FIELD_NAME,
message->diagnostic_stitch_response.bus);
cJSON_AddNumberToObject(root, payload::json::ID_FIELD_NAME,
message->diagnostic_stitch_response.message_id);
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_MODE_FIELD_NAME,
message->diagnostic_stitch_response.mode);
cJSON_AddBoolToObject(root, payload::json::DIAGNOSTIC_SUCCESS_FIELD_NAME,
message->diagnostic_stitch_response.success);
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_PID_FIELD_NAME,
message->diagnostic_stitch_response.pid);

// These next 2 fields are only in a stitched message frame
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_FRAME_FIELD_NAME,
message->diagnostic_stitch_response.frame);
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_TOTAL_SIZE_FIELD_NAME,
message->diagnostic_stitch_response.total_size);

if(message->diagnostic_stitch_response.negative_response_code != 0) {
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_NRC_FIELD_NAME,
message->diagnostic_stitch_response.negative_response_code);
}

if(message->diagnostic_stitch_response.value.type != openxc_DynamicField_Type_UNUSED) {
if (message->diagnostic_stitch_response.value.type == openxc_DynamicField_Type_NUM) {
cJSON_AddNumberToObject(root, payload::json::DIAGNOSTIC_VALUE_FIELD_NAME,
message->diagnostic_stitch_response.value.numeric_value);
} else {
cJSON_AddStringToObject(root, payload::json::DIAGNOSTIC_VALUE_FIELD_NAME,
message->diagnostic_stitch_response.value.string_value);
}
} else if(message->diagnostic_stitch_response.payload.size > 0) {
char encodedData[MAX_DIAGNOSTIC_PAYLOAD_SIZE];
const char* maxAddress = encodedData + sizeof(encodedData);
char* encodedDataIndex = encodedData;
encodedDataIndex += sprintf(encodedDataIndex, "0x");
for(uint8_t i = 0; i < message->diagnostic_stitch_response.payload.size &&
encodedDataIndex < maxAddress; i++) {
encodedDataIndex += snprintf(encodedDataIndex,
maxAddress - encodedDataIndex,
"%02x",
message->diagnostic_stitch_response.payload.bytes[i]);
}
cJSON_AddStringToObject(root, payload::json::DIAGNOSTIC_PAYLOAD_FIELD_NAME,
encodedData);
}
return true;
}

static bool serializeCommandResponse(openxc_VehicleMessage* message,
cJSON* root) {
const char* typeString = NULL;
Expand Down Expand Up @@ -624,7 +582,7 @@ int openxc::payload::json::serialize(openxc_VehicleMessage* message,
size_t finalLength = 0;
if(root != NULL) {
bool status = true;
if(message->type != openxc_VehicleMessage_Type_UNUSED) {
if(message->timestamp != 0) {
cJSON_AddNumberToObject(root, "timestamp", message->timestamp);
}
if(message->type == openxc_VehicleMessage_Type_SIMPLE) {
Expand All @@ -633,8 +591,6 @@ int openxc::payload::json::serialize(openxc_VehicleMessage* message,
status = serializeCan(message, root);
} else if(message->type == openxc_VehicleMessage_Type_DIAGNOSTIC) {
status = serializeDiagnostic(message, root);
} else if(message->type == openxc_VehicleMessage_Type_DIAGNOSTIC_STITCH) {
status =serializeStitchDiagnostic(message, root);
} else if(message->type == openxc_VehicleMessage_Type_COMMAND_RESPONSE) {
status = serializeCommandResponse(message, root);
} else {
Expand Down
1 change: 0 additions & 1 deletion src/payload/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern const char PREDEFINED_OBD2_REQUESTS_COMMAND_NAME[];

extern const char PAYLOAD_FORMAT_JSON_NAME[];
extern const char PAYLOAD_FORMAT_PROTOBUF_NAME[];
extern const char PAYLOAD_FORMAT_MESSAGEPACK_NAME[];

extern const char COMMAND_RESPONSE_FIELD_NAME[];
extern const char COMMAND_RESPONSE_MESSAGE_FIELD_NAME[];
Expand Down

0 comments on commit 81d3f10

Please sign in to comment.