From 6e1a3c8908b3627880bc087715a7c50347a575da Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 30 Jun 2020 13:16:35 -0400 Subject: [PATCH 01/48] Add signals version check add code to check if signals version is the same as the firmware version --- src/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Makefile b/src/Makefile index 53e6c84fa..579c613f9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,6 +27,15 @@ $(error You do not have the necessary openxc-python installed: openxc-python $(T endif endif +# Verify signals.cpp version +ifneq ($(wildcard signals.cpp),) +Signals_Version = $(shell grep -Po '(?<=Generated\sfor\sv)\d+\.\S+(?=\sof\sthe\sOpenXC\sVI\sfirmware\.)' signals.cpp) +Firmware_Signals_Version = $(shell grep -Po '(?<=Signals:\s)\d+\.\S+' Versions) +ifneq ($(Signals_Version),$(Firmware_Signals_Version)) +$(error You are using an invalid signals.ccp version ($(Signals_Version)), This firmware supports ($(Firmware_Signals_Version))) +endif +endif + COLORS_AVAILABLE = $(shell command -v tput >/dev/null 2>&1; echo $$?) ifeq ($(COLORS_AVAILABLE),0) RED="$${txtbld}$$(tput setaf 1)" From 4cef128a58e8b68598403af2bbecb7af1860c5c7 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 30 Jun 2020 13:17:33 -0400 Subject: [PATCH 02/48] Add versions file add versions file and initial signals version number --- src/Versions | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/Versions diff --git a/src/Versions b/src/Versions new file mode 100644 index 000000000..40a5414aa --- /dev/null +++ b/src/Versions @@ -0,0 +1 @@ +Signals: 7.x From 11576ecbb12542cb619dace043caf78c19546ab9 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Mon, 20 Jul 2020 18:17:47 -0400 Subject: [PATCH 03/48] Add a default VIN value as well as logic for a 10% falure rate for debugging purposes. --- src/commands/commands.cpp | 6 +++++ src/commands/get_vin_command.cpp | 44 ++++++++++++++++++++++++++++++++ src/commands/get_vin_command.h | 12 +++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/commands/get_vin_command.cpp create mode 100644 src/commands/get_vin_command.h diff --git a/src/commands/commands.cpp b/src/commands/commands.cpp index 7d48b7f84..5f9818601 100644 --- a/src/commands/commands.cpp +++ b/src/commands/commands.cpp @@ -19,6 +19,7 @@ #include "commands/modem_config_command.h" #include "commands/rtc_config_command.h" #include "commands/sd_mount_status_command.h" +#include "commands/get_vin_command.h" using openxc::util::log::debug; @@ -63,6 +64,8 @@ static bool handleComplexCommand(openxc_VehicleMessage* message) { break; case openxc_ControlCommand_Type_SD_MOUNT_STATUS: status = openxc::commands::handleSDMountStatusCommand(); + case openxc_ControlCommand_Type_GET_VIN: + status = openxc::commands::handleGetVinCommand(); default: status = false; break; @@ -144,6 +147,7 @@ static bool validateControlCommand(openxc_VehicleMessage* message) { case openxc_ControlCommand_Type_DEVICE_ID: case openxc_ControlCommand_Type_PLATFORM: case openxc_ControlCommand_Type_SD_MOUNT_STATUS: + case openxc_ControlCommand_Type_GET_VIN: valid = true; break; case openxc_ControlCommand_Type_MODEM_CONFIGURATION: @@ -183,6 +187,8 @@ bool openxc::commands::validate(openxc_VehicleMessage* message) { void openxc::commands::sendCommandResponse(openxc_ControlCommand_Type commandType, bool status, char* responseMessage, size_t responseMessageLength) { + debug("Command response value %d", responseMessage); + debug("Command response value %s", responseMessage); openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; message.command_response.type = commandType; diff --git a/src/commands/get_vin_command.cpp b/src/commands/get_vin_command.cpp new file mode 100644 index 000000000..5a1ba61f9 --- /dev/null +++ b/src/commands/get_vin_command.cpp @@ -0,0 +1,44 @@ +#include "get_vin_command.h" + +#include "config.h" +#include "diagnostics.h" +#include "interface/usb.h" +#include "util/log.h" +#include "config.h" +#include "pb_decode.h" +#include +#include "signals.h" +#include +#include +#include + +using openxc::util::log::debug; +using openxc::config::getConfiguration; +using openxc::payload::PayloadFormat; +using openxc::signals::getCanBuses; +using openxc::signals::getCanBusCount; +using openxc::signals::getSignals; +using openxc::signals::getSignalCount; +using openxc::signals::getCommands; +using openxc::signals::getCommandCount; +using openxc::can::lookupBus; +using openxc::can::lookupSignal; + +namespace can = openxc::can; +namespace payload = openxc::payload; +namespace config = openxc::config; +namespace diagnostics = openxc::diagnostics; +namespace usb = openxc::interface::usb; +namespace uart = openxc::interface::uart; +namespace pipeline = openxc::pipeline; + +bool openxc::commands::handleGetVinCommand() { + char* vin; + bool status = false; + if((rand() % (10-1+1)+1)<=9) { + status = true; + vin = strdup(config::getConfiguration()->dummyVin); + sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); + } + return status; +} diff --git a/src/commands/get_vin_command.h b/src/commands/get_vin_command.h new file mode 100644 index 000000000..ffff35a6b --- /dev/null +++ b/src/commands/get_vin_command.h @@ -0,0 +1,12 @@ +#ifndef __GET_VIN_COMMAND_H__ +#define __GET_VIN_COMMAND_H__ + +namespace openxc { +namespace commands { + +bool handleGetVinCommand(); + +} // namespace commands +} // namespace openxc + +#endif // __GET_VIN_COMMAND_H__ \ No newline at end of file From bb2988e374926720f5b0ca3ffb84fc2896a4c935 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Tue, 21 Jul 2020 08:40:19 -0400 Subject: [PATCH 04/48] add get_vin setup in the config and payload json. --- src/config.cpp | 1 + src/config.h | 1 + src/payload/json.cpp | 7 +++++++ src/payload/json.h | 1 + 4 files changed, 10 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index 9df88f82b..5c4427d0b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -119,6 +119,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, version: "8.0.0", + dummyVin: "00000000123456789", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT, diff --git a/src/config.h b/src/config.h index 5f4c24fae..cb4865838 100644 --- a/src/config.h +++ b/src/config.h @@ -110,6 +110,7 @@ typedef enum { typedef struct { int messageSetIndex; const char* version; + const char* dummyVin; const char* platform; const char* environmentMode; openxc::payload::PayloadFormat payloadFormat; diff --git a/src/payload/json.cpp b/src/payload/json.cpp index 64965639d..a6954c76f 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -25,6 +25,7 @@ const char openxc::payload::json::PREDEFINED_OBD2_REQUESTS_COMMAND_NAME[] = "pre const char openxc::payload::json::MODEM_CONFIGURATION_COMMAND_NAME[] = "modem_configuration"; const char openxc::payload::json::RTC_CONFIGURATION_COMMAND_NAME[] = "rtc_configuration"; const char openxc::payload::json::SD_MOUNT_STATUS_COMMAND_NAME[] = "sd_mount_status"; +const char openxc::payload::json::GET_VIN_COMMAND_NAME[] = "get_vin"; const char openxc::payload::json::PAYLOAD_FORMAT_JSON_NAME[] = "json"; const char openxc::payload::json::PAYLOAD_FORMAT_PROTOBUF_NAME[] = "protobuf"; @@ -154,6 +155,8 @@ static bool serializeCommandResponse(openxc_VehicleMessage* message, typeString = payload::json::VERSION_COMMAND_NAME; } else if(message->command_response.type == openxc_ControlCommand_Type_DEVICE_ID) { typeString = payload::json::DEVICE_ID_COMMAND_NAME; + } else if(message->command_response.type == openxc_ControlCommand_Type_GET_VIN) { + typeString = payload::json::GET_VIN_COMMAND_NAME; } else if(message->command_response.type == openxc_ControlCommand_Type_PLATFORM) { typeString = payload::json::DEVICE_PLATFORM_COMMAND_NAME; } else if(message->command_response.type == openxc_ControlCommand_Type_DIAGNOSTIC) { @@ -565,6 +568,10 @@ size_t openxc::payload::json::deserialize(uint8_t payload[], size_t length, DEVICE_ID_COMMAND_NAME, strlen(DEVICE_ID_COMMAND_NAME))) { command->type = openxc_ControlCommand_Type_DEVICE_ID; } else if(!strncmp(commandNameObject->valuestring, + GET_VIN_COMMAND_NAME, strlen(GET_VIN_COMMAND_NAME))) { + command->type = openxc_ControlCommand_Type_GET_VIN; + } + else if(!strncmp(commandNameObject->valuestring, DEVICE_PLATFORM_COMMAND_NAME, strlen(DEVICE_PLATFORM_COMMAND_NAME))) { command->type = openxc_ControlCommand_Type_PLATFORM; } else if(!strncmp(commandNameObject->valuestring, diff --git a/src/payload/json.h b/src/payload/json.h index f77fbd4b3..260bdf166 100644 --- a/src/payload/json.h +++ b/src/payload/json.h @@ -12,6 +12,7 @@ namespace json { extern const char VERSION_COMMAND_NAME[]; extern const char DEVICE_ID_COMMAND_NAME[]; extern const char DEVICE_PLATFORM_COMMAND_NAME[]; +extern const char GET_VIN_COMMAND_NAME[]; extern const char DIAGNOSTIC_COMMAND_NAME[]; extern const char PASSTHROUGH_COMMAND_NAME[]; extern const char ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME[]; From 4f124852c723b6c58e6b8e6f5bfdab8df31303be Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Tue, 21 Jul 2020 08:56:44 -0400 Subject: [PATCH 05/48] remove debug statement from the code. --- src/commands/commands.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/commands/commands.cpp b/src/commands/commands.cpp index 5f9818601..9f45552bc 100644 --- a/src/commands/commands.cpp +++ b/src/commands/commands.cpp @@ -187,8 +187,6 @@ bool openxc::commands::validate(openxc_VehicleMessage* message) { void openxc::commands::sendCommandResponse(openxc_ControlCommand_Type commandType, bool status, char* responseMessage, size_t responseMessageLength) { - debug("Command response value %d", responseMessage); - debug("Command response value %s", responseMessage); openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; message.command_response.type = commandType; From aa611f7f690090cc0fa28fb6ce9aebcbea0437ad Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 28 Jul 2020 21:07:29 +0000 Subject: [PATCH 06/48] wip --- src/diagnostics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics.h b/src/diagnostics.h index f92e8b66e..c63a05a7c 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -14,7 +14,7 @@ /* Private: The maximum number of simultanous diagnostic requests. Increasing * this number will use more memory on the stack. */ -#define MAX_SIMULTANEOUS_DIAG_REQUESTS 20 +#define MAX_SIMULTANEOUS_DIAG_REQUESTS 5 /* Private: The maximum length for a human-readable name for a diagnostic * response. From f4dfb56672741434a79a93450a15dc61d83ee002 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 10 Aug 2020 19:41:05 +0000 Subject: [PATCH 07/48] Adding the get vin CAN bus sniffer code --- src/diagnostics.cpp | 41 ++++++++++++++++++++++++++++++++++ src/libs/openxc-message-format | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index c9d62e03f..f6b912ac9 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -439,6 +439,45 @@ static void relayPartialFrame(DiagnosticsManager* manager, // Only need for the } #endif +const int VIN_STORAGE_LENGTH = VIN_LENGTH+1; // 17 characters + 1 pad +const int VIN_SNIPPET_LENGTH = 6; // 6 VIN characters per CAN msg +unsigned char vinBuffer[VIN_STORAGE_LENGTH] = {0}; +bool vinComplete = false; + +void filterForVIN(CanMessage* message) { + + if ((message->id == 0x40a) && + (message->data[0] == 0xc1) && + (message->data[1] <= 0x02)) { + + // gja debug here! + char buffer[26]; + buffer[0] = '>'; + int indx=1; + for(int cnt=0; cntlength; cnt++) { + int c = (message->data[cnt] & 0xf0) >> 4; + buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; + c = (message->data[cnt] & 0x0f); + buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; + buffer[indx++] = ' '; + buffer[indx] = 0; + } + debug(buffer); + // gja debug above here! + + int index = message->data[1] * VIN_SNIPPET_LENGTH; + for(int cnt=2; cnt<8; cnt++, index++) { + vinBuffer[index] = message->data[cnt]; + } + + bool emptySpace = false; + for (int cnt=0; cntrecurringRequests, queueEntries) { receiveCanMessage(manager, bus, entry, message, pipeline); } diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index 4d032d51f..d1faeac39 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit 4d032d51fe161ea1aa7d8255e53f64f6b3ea09cf +Subproject commit d1faeac39637373d9a587df9dca1a4e588df5340 From 971c1fdde96f46ccb59ccef6fcc107103313fdd9 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 11 Aug 2020 22:55:22 +0000 Subject: [PATCH 08/48] Wire up Can sniff VIN messaging to command --- src/commands/get_vin_command.cpp | 11 ++++++++--- src/diagnostics.cpp | 8 ++++++++ src/diagnostics.h | 13 +++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/commands/get_vin_command.cpp b/src/commands/get_vin_command.cpp index 5a1ba61f9..b8e294045 100644 --- a/src/commands/get_vin_command.cpp +++ b/src/commands/get_vin_command.cpp @@ -35,10 +35,15 @@ namespace pipeline = openxc::pipeline; bool openxc::commands::handleGetVinCommand() { char* vin; bool status = false; - if((rand() % (10-1+1)+1)<=9) { + + if (openxc::diagnostics::haveVINfromCan()) { + status = true; + vin = (char *)openxc::diagnostics::getVIN(); + } else { status = true; vin = strdup(config::getConfiguration()->dummyVin); - sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); - } + } + sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); + return status; } diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index f6b912ac9..06f40399e 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -444,6 +444,14 @@ const int VIN_SNIPPET_LENGTH = 6; // 6 VIN characters per CAN msg unsigned char vinBuffer[VIN_STORAGE_LENGTH] = {0}; bool vinComplete = false; +bool openxc::diagnostics::haveVINfromCan() { + return vinComplete; +} + +unsigned char *openxc::diagnostics::getVIN() { + return vinBuffer; +} + void filterForVIN(CanMessage* message) { if ((message->id == 0x40a) && diff --git a/src/diagnostics.h b/src/diagnostics.h index f92e8b66e..89f309ca3 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -377,6 +377,19 @@ bool handleDiagnosticCommand(DiagnosticsManager* manager, void passthroughDecoder(const DiagnosticResponse* response, float parsed_payload, char* str_buf, int buf_size); + +/* +* If the VIN has been scanned from the CAN bus and stored +* this method will return true. +*/ +bool haveVINfromCan(); + +/* +* Get the VIN that was scanned from the CAN +*/ +unsigned char *getVIN(); + + } // namespace diagnostics } // namespace openxc From 9330b60b71e9189306b0eabe15b6484f2877d904 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Wed, 19 Aug 2020 21:41:32 +0000 Subject: [PATCH 09/48] Moved the get vin can filtering to a spot to receive all messages --- src/diagnostics.cpp | 4 +--- src/diagnostics.h | 5 +++++ src/platform/lpc17xx/canread.cpp | 6 ++++++ src/platform/pic32/canread.cpp | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index 06f40399e..9c89b8f6d 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -452,7 +452,7 @@ unsigned char *openxc::diagnostics::getVIN() { return vinBuffer; } -void filterForVIN(CanMessage* message) { +void openxc::diagnostics::filterForVIN(CanMessage* message) { if ((message->id == 0x40a) && (message->data[0] == 0xc1) && @@ -591,8 +591,6 @@ void openxc::diagnostics::receiveCanMessage(DiagnosticsManager* manager, CanBus* bus, CanMessage* message, Pipeline* pipeline) { ActiveDiagnosticRequest* entry; - filterForVIN(message); - TAILQ_FOREACH(entry, &manager->recurringRequests, queueEntries) { receiveCanMessage(manager, bus, entry, message, pipeline); } diff --git a/src/diagnostics.h b/src/diagnostics.h index 89f309ca3..cd468d747 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -389,6 +389,11 @@ bool haveVINfromCan(); */ unsigned char *getVIN(); +/* +* Sniff the can traffic for the specific VIN CAN messages +*/ +void filterForVIN(CanMessage* message); + } // namespace diagnostics } // namespace openxc diff --git a/src/platform/lpc17xx/canread.cpp b/src/platform/lpc17xx/canread.cpp index 717004c7a..6294eff03 100644 --- a/src/platform/lpc17xx/canread.cpp +++ b/src/platform/lpc17xx/canread.cpp @@ -2,6 +2,7 @@ #include "canutil_lpc17xx.h" #include "signals.h" #include "util/log.h" +#include "diagnostics.h" using openxc::util::log::debug; using openxc::signals::getCanBusCount; @@ -25,6 +26,10 @@ CanMessage receiveCanMessage(CanBus* bus) { return result; } +void filterForVinLocal(CanMessage* message) { + openxc::diagnostics::filterForVIN(message); +} + extern "C" { void CAN_IRQHandler() { @@ -32,6 +37,7 @@ void CAN_IRQHandler() { CanBus* bus = &getCanBuses()[i]; if((CAN_IntGetStatus(CAN_CONTROLLER(bus)) & 0x01) == 1) { CanMessage message = receiveCanMessage(bus); + filterForVinLocal(&message); if(shouldAcceptMessage(bus, message.id) && !QUEUE_PUSH(CanMessage, &bus->receiveQueue, message)) { // An exception to the "don't leave commented out code" rule, diff --git a/src/platform/pic32/canread.cpp b/src/platform/pic32/canread.cpp index 3b2207183..dbea37db5 100644 --- a/src/platform/pic32/canread.cpp +++ b/src/platform/pic32/canread.cpp @@ -3,6 +3,7 @@ #include "signals.h" #include "util/log.h" #include "power.h" +#include "diagnostics.h" namespace power = openxc::power; @@ -47,6 +48,7 @@ void openxc::can::pic32::handleCanInterrupt(CanBus* bus) { CAN::RX_CHANNEL_NOT_EMPTY, false); CanMessage message = receiveCanMessage(bus); + openxc::diagnostics::filterForVIN(&message); if(!QUEUE_PUSH(CanMessage, &bus->receiveQueue, message)) { // An exception to the "don't leave commented out code" rule, // this log statement is useful for debugging performance issues From 4ca48b72b8e9832545b680dcc4d0fa97e0c50cef Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Thu, 20 Aug 2020 20:28:21 +0000 Subject: [PATCH 10/48] Commented out debug code --- src/diagnostics.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index 9c89b8f6d..e89764685 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -459,18 +459,18 @@ void openxc::diagnostics::filterForVIN(CanMessage* message) { (message->data[1] <= 0x02)) { // gja debug here! - char buffer[26]; - buffer[0] = '>'; - int indx=1; - for(int cnt=0; cntlength; cnt++) { - int c = (message->data[cnt] & 0xf0) >> 4; - buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; - c = (message->data[cnt] & 0x0f); - buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; - buffer[indx++] = ' '; - buffer[indx] = 0; - } - debug(buffer); + // char buffer[26]; + // buffer[0] = '>'; + // int indx=1; + // for(int cnt=0; cntlength; cnt++) { + // int c = (message->data[cnt] & 0xf0) >> 4; + // buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; + // c = (message->data[cnt] & 0x0f); + // buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; + // buffer[indx++] = ' '; + // buffer[indx] = 0; + // } + // debug(buffer); // gja debug above here! int index = message->data[1] * VIN_SNIPPET_LENGTH; From 2a5cdfe9510e48e90a758c1b9fcc08d43614cf50 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Wed, 26 Aug 2020 13:46:36 -0400 Subject: [PATCH 11/48] Work in progress to get vin command from diagnostic. --- src/commands/get_vin_command.cpp | 35 +++++++++++++++++++++++++++----- src/diagnostics.cpp | 9 ++++++-- src/diagnostics.h | 1 + src/payload/json.cpp | 16 +++++++++++++++ src/pipeline.cpp | 3 +++ 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/commands/get_vin_command.cpp b/src/commands/get_vin_command.cpp index b8e294045..fa0ad06f2 100644 --- a/src/commands/get_vin_command.cpp +++ b/src/commands/get_vin_command.cpp @@ -11,6 +11,7 @@ #include #include #include +#include using openxc::util::log::debug; using openxc::config::getConfiguration; @@ -35,15 +36,39 @@ namespace pipeline = openxc::pipeline; bool openxc::commands::handleGetVinCommand() { char* vin; bool status = false; + vin = (char*)openxc::diagnostics::getVIN(); - if (openxc::diagnostics::haveVINfromCan()) { - status = true; - vin = (char *)openxc::diagnostics::getVIN(); - } else { + // if (openxc::diagnostics::haveVINfromCan()) { + // status = true; + // vin = (char *)openxc::diagnostics::getVIN(); + // } else + if(status == false) { + openxc_ControlCommand command = openxc_ControlCommand(); // Zero Fill + command.type = openxc_ControlCommand_Type_DIAGNOSTIC; + + command.type = openxc_ControlCommand_Type_DIAGNOSTIC; + command.diagnostic_request.action = + openxc_DiagnosticControlCommand_Action_ADD; + + command.diagnostic_request.request.bus = 1; + command.diagnostic_request.request.mode = 9; + command.diagnostic_request.request.message_id = 0x7e0; + command.diagnostic_request.request.pid = 2; + + diagnostics::handleDiagnosticCommand( + &getConfiguration()->diagnosticsManager, &command); + // sendCommandResponse(openxc_ControlCommand_Type_DIAGNOSTIC, status); + // vin = "test"; + diagnostics::sendRequests(&getConfiguration()->diagnosticsManager, &getCanBuses()[0]); + } + else { status = true; vin = strdup(config::getConfiguration()->dummyVin); } - sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); + // debug("Testing for Jamez line 66 getVinCommand.cpp"); + // debug(vin); + // debug((const char*)strlen(vin)); + // sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); return status; } diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index e89764685..1467023cd 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -546,7 +546,8 @@ static void relayDiagnosticResponse(DiagnosticsManager* manager, request->callback(manager, request, response, parsed_value); } } - +void sendCommandResponse(openxc_ControlCommand_Type commandType, + bool status, char* responseMessage, size_t responseMessageLength); static void receiveCanMessage(DiagnosticsManager* manager, CanBus* bus, ActiveDiagnosticRequest* entry, @@ -558,8 +559,12 @@ static void receiveCanMessage(DiagnosticsManager* manager, // coupled? &manager->shims[bus->address - 1], &entry->handle, message->id, message->data, message->length); - + debug("Raw Message for get_vin"); + debug((const char*)message->data); if (response.multi_frame) { + // checkForVinCommand(message); + char* vin = (char*)"receiveCanMessage"; + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); #if (MULTIFRAME != 0) if (originalStitchAlgo) { relayPartialFrame(manager, entry, &response, pipeline); diff --git a/src/diagnostics.h b/src/diagnostics.h index cd468d747..3df8c410a 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -389,6 +389,7 @@ bool haveVINfromCan(); */ unsigned char *getVIN(); +unsigned char *getDiagnosticVIN(); /* * Sniff the can traffic for the specific VIN CAN messages */ diff --git a/src/payload/json.cpp b/src/payload/json.cpp index a6954c76f..632721b06 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -234,6 +234,12 @@ static cJSON* serializeDynamicField(openxc_DynamicField* field) { } return value; } +void dumpNum(int value); +void dumpDouble(double value) { + char buff[20]; + sprintf(buff, "%f", value); + debug(buff); +} static bool serializeSimple(openxc_VehicleMessage* message, cJSON* root) { const char* name = message->simple_message.name; @@ -366,6 +372,8 @@ static void deserializeDiagnostic(cJSON* root, openxc_ControlCommand* command) { element = cJSON_GetObjectItem(request, "mode"); if(element != NULL) { + debug("mode"); + dumpNum(element->valueint); command->diagnostic_request.request.mode = element->valueint; } @@ -389,12 +397,16 @@ static void deserializeDiagnostic(cJSON* root, openxc_ControlCommand* command) { element = cJSON_GetObjectItem(request, "multiple_responses"); if(element != NULL) { + debug("multiple_responses:"); + dumpNum(element->valueint); command->diagnostic_request.request.multiple_responses = bool(element->valueint); } element = cJSON_GetObjectItem(request, "frequency"); if(element != NULL) { + debug("frequency:"); + dumpDouble(element->valuedouble); command->diagnostic_request.request.frequency = element->valuedouble; } @@ -402,9 +414,11 @@ static void deserializeDiagnostic(cJSON* root, openxc_ControlCommand* command) { element = cJSON_GetObjectItem(request, "decoded_type"); if(element != NULL) { if(!strcmp(element->valuestring, "obd2")) { + debug("decoded_type is obd2"); command->diagnostic_request.request.decoded_type = openxc_DiagnosticRequest_DecodedType_OBD2; } else if(!strcmp(element->valuestring, "none")) { + debug("decoded_type is none"); command->diagnostic_request.request.decoded_type = openxc_DiagnosticRequest_DecodedType_NONE; } @@ -412,6 +426,8 @@ static void deserializeDiagnostic(cJSON* root, openxc_ControlCommand* command) { element = cJSON_GetObjectItem(request, "name"); if(element != NULL && element->type == cJSON_String) { + debug("name"); + debug(element->valuestring); strcpy(command->diagnostic_request.request.name, element->valuestring); } diff --git a/src/pipeline.cpp b/src/pipeline.cpp index a7d7c79aa..e2721c7e9 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -80,6 +80,8 @@ void sendToUsb(Pipeline* pipeline, uint8_t* message, int messageSize, } conditionalFlush(pipeline, sendQueue, message, messageSize); + debug("sendtoUSB debug pipeline line 83"); + debug((const char*)message); sendToEndpoint(pipeline->usb->descriptor.type, sendQueue, &pipeline->usb->endpoints[OUT_ENDPOINT_INDEX].queue, message, messageSize); @@ -190,6 +192,7 @@ void openxc::pipeline::publish(openxc_VehicleMessage* message, break; } if(matched) { + debug("debug for Ja'mez pipeline line 195 %d", message->type); sendMessage(pipeline, payload, length, messageClass); } else { From ceb252b9cabe6892055e7ec650895c1c88b58fe1 Mon Sep 17 00:00:00 2001 From: vagrant Date: Thu, 27 Aug 2020 19:48:16 +0000 Subject: [PATCH 12/48] Add get vin from traffic and get vin from diagnostic for get_vin command complete. --- src/commands/get_vin_command.cpp | 29 ++++++-------- src/diagnostics.cpp | 68 ++++++++++++++++++++++++++++++-- src/diagnostics.h | 4 +- 3 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/commands/get_vin_command.cpp b/src/commands/get_vin_command.cpp index fa0ad06f2..d5cc3b3d5 100644 --- a/src/commands/get_vin_command.cpp +++ b/src/commands/get_vin_command.cpp @@ -34,15 +34,14 @@ namespace uart = openxc::interface::uart; namespace pipeline = openxc::pipeline; bool openxc::commands::handleGetVinCommand() { - char* vin; - bool status = false; - vin = (char*)openxc::diagnostics::getVIN(); - // if (openxc::diagnostics::haveVINfromCan()) { - // status = true; - // vin = (char *)openxc::diagnostics::getVIN(); - // } else - if(status == false) { + if (openxc::diagnostics::haveVINfromCan()) { + char* vin = (char *)openxc::diagnostics::getVIN(); + debug("Testing for Jamez line 66 getVinCommand.cpp"); + debug(vin); + debug((const char*)strlen(vin)); + sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, true, vin, strlen(vin)); + } else if(!openxc::diagnostics::haveVINfromCan()) { openxc_ControlCommand command = openxc_ControlCommand(); // Zero Fill command.type = openxc_ControlCommand_Type_DIAGNOSTIC; @@ -54,21 +53,17 @@ bool openxc::commands::handleGetVinCommand() { command.diagnostic_request.request.mode = 9; command.diagnostic_request.request.message_id = 0x7e0; command.diagnostic_request.request.pid = 2; + openxc::diagnostics::setVinCommandInProgress(true); diagnostics::handleDiagnosticCommand( &getConfiguration()->diagnosticsManager, &command); - // sendCommandResponse(openxc_ControlCommand_Type_DIAGNOSTIC, status); - // vin = "test"; diagnostics::sendRequests(&getConfiguration()->diagnosticsManager, &getCanBuses()[0]); } else { - status = true; - vin = strdup(config::getConfiguration()->dummyVin); + char* vin = strdup(config::getConfiguration()->dummyVin); + sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, true, vin, strlen(vin)); } - // debug("Testing for Jamez line 66 getVinCommand.cpp"); - // debug(vin); - // debug((const char*)strlen(vin)); - // sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, status, vin, strlen(vin)); + - return status; + return true; } diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index 1467023cd..bba6e1954 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -443,6 +443,7 @@ const int VIN_STORAGE_LENGTH = VIN_LENGTH+1; // 17 characters + 1 pad const int VIN_SNIPPET_LENGTH = 6; // 6 VIN characters per CAN msg unsigned char vinBuffer[VIN_STORAGE_LENGTH] = {0}; bool vinComplete = false; +bool vinCommandInProgress = false; bool openxc::diagnostics::haveVINfromCan() { return vinComplete; @@ -452,6 +453,10 @@ unsigned char *openxc::diagnostics::getVIN() { return vinBuffer; } +void openxc::diagnostics::setVinCommandInProgress(bool vinInProgress) { + vinCommandInProgress = vinInProgress; +} + void openxc::diagnostics::filterForVIN(CanMessage* message) { if ((message->id == 0x40a) && @@ -486,6 +491,59 @@ void openxc::diagnostics::filterForVIN(CanMessage* message) { } } +void dumpNum(int); +bool vinCommandFailed = false; +int selector = -1; + +void openxc::diagnostics::checkForVinCommand(CanMessage *message) { + + // Step 1: Check to see if get vin command is in progrees + debug("diag:checkForVinCommand"); + dumpNum(message->id); + if(message->id != 2024) { + return; + } + char buffer[18]; + int bufferindex = 0; + // Step 2: unpackage Can data into VIN buffer + if (message->length > 2) { + for(int index=0; indexlength; index++) { + int high = ((message->data[index] >> 4) & 0xf); + int letter = (high > 9) ? high - 10 + 'A' : high + '0'; + int low = (message->data[index] & 0xf); + int letter2 = (low > 9) ? low - 10 + 'A' : low + '0'; + buffer[bufferindex] = letter; bufferindex++; + buffer[bufferindex] = letter2; bufferindex++; + } + buffer[bufferindex] = 0; + debug(buffer); + } + + if (selector >= 3) selector = -1; + + selector++; + if(selector == 0) { + for(int cnt=5, index=0; cnt<8; cnt++, index++) { + vinBuffer[index] = message->data[cnt]; + } + } else if(selector == 1) { + for(int cnt=1, index=3; cnt<8; cnt++, index++) { + vinBuffer[index] = message->data[cnt]; + } + } else { + for(int cnt=1, index=10; cnt<8; cnt++, index++) { + vinBuffer[index] = message->data[cnt]; + } + // Step 3: When all of the VIN data is complete return sendCommandResponse with VIN + + char* vin = (char *)vinBuffer; + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); + setVinCommandInProgress(false); + // VIN command completed + vinComplete = true; + } +} + static void relayDiagnosticResponse(DiagnosticsManager* manager, ActiveDiagnosticRequest* request, const DiagnosticResponse* response, Pipeline* pipeline, @@ -561,10 +619,12 @@ static void receiveCanMessage(DiagnosticsManager* manager, &entry->handle, message->id, message->data, message->length); debug("Raw Message for get_vin"); debug((const char*)message->data); + // If this is a VIN command we don't want to send a diagnostic response. + if(vinCommandInProgress == true) { + openxc::diagnostics::checkForVinCommand(message); + return; + } if (response.multi_frame) { - // checkForVinCommand(message); - char* vin = (char*)"receiveCanMessage"; - openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); #if (MULTIFRAME != 0) if (originalStitchAlgo) { relayPartialFrame(manager, entry, &response, pipeline); @@ -1225,4 +1285,4 @@ void openxc::diagnostics::passthroughDecoder( } else { snprintf(str_buf, buf_size, "%f", parsed_payload); } -} +} \ No newline at end of file diff --git a/src/diagnostics.h b/src/diagnostics.h index 3df8c410a..9c4eefe1a 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -394,9 +394,11 @@ unsigned char *getDiagnosticVIN(); * Sniff the can traffic for the specific VIN CAN messages */ void filterForVIN(CanMessage* message); +void checkForVinCommand(CanMessage *message); +void setVinCommandInProgress(bool vinInProgress); } // namespace diagnostics } // namespace openxc -#endif // __DIAGNOSTICS_H__ +#endif // __DIAGNOSTICS_H__ \ No newline at end of file From 1ca357360d128d5d696337c21a0c7159238cf012 Mon Sep 17 00:00:00 2001 From: vagrant Date: Mon, 31 Aug 2020 14:16:39 +0000 Subject: [PATCH 13/48] remove some debug statements and small refactory. --- src/commands/diagnostic_request_command.cpp | 1 + src/commands/get_vin_command.cpp | 17 +++++------------ src/pipeline.cpp | 3 --- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/commands/diagnostic_request_command.cpp b/src/commands/diagnostic_request_command.cpp index ee2b4bf3d..4eba76ec2 100644 --- a/src/commands/diagnostic_request_command.cpp +++ b/src/commands/diagnostic_request_command.cpp @@ -33,6 +33,7 @@ namespace uart = openxc::interface::uart; namespace pipeline = openxc::pipeline; bool openxc::commands::handleDiagnosticRequestCommand(openxc_ControlCommand* command) { + openxc::diagnostics::setVinCommandInProgress(false); bool status = diagnostics::handleDiagnosticCommand( &getConfiguration()->diagnosticsManager, command); sendCommandResponse(openxc_ControlCommand_Type_DIAGNOSTIC, status); diff --git a/src/commands/get_vin_command.cpp b/src/commands/get_vin_command.cpp index d5cc3b3d5..1510eec3c 100644 --- a/src/commands/get_vin_command.cpp +++ b/src/commands/get_vin_command.cpp @@ -34,16 +34,14 @@ namespace uart = openxc::interface::uart; namespace pipeline = openxc::pipeline; bool openxc::commands::handleGetVinCommand() { + char* vin; if (openxc::diagnostics::haveVINfromCan()) { - char* vin = (char *)openxc::diagnostics::getVIN(); - debug("Testing for Jamez line 66 getVinCommand.cpp"); - debug(vin); - debug((const char*)strlen(vin)); - sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, true, vin, strlen(vin)); - } else if(!openxc::diagnostics::haveVINfromCan()) { + vin = (char *)openxc::diagnostics::getVIN(); + sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, true, vin, strlen(vin)); + } else { openxc_ControlCommand command = openxc_ControlCommand(); // Zero Fill - command.type = openxc_ControlCommand_Type_DIAGNOSTIC; + command.type = openxc_ControlCommand_Type_DIAGNOSTIC; command.type = openxc_ControlCommand_Type_DIAGNOSTIC; command.diagnostic_request.action = @@ -59,11 +57,6 @@ bool openxc::commands::handleGetVinCommand() { &getConfiguration()->diagnosticsManager, &command); diagnostics::sendRequests(&getConfiguration()->diagnosticsManager, &getCanBuses()[0]); } - else { - char* vin = strdup(config::getConfiguration()->dummyVin); - sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, true, vin, strlen(vin)); - } - return true; } diff --git a/src/pipeline.cpp b/src/pipeline.cpp index e2721c7e9..a7d7c79aa 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -80,8 +80,6 @@ void sendToUsb(Pipeline* pipeline, uint8_t* message, int messageSize, } conditionalFlush(pipeline, sendQueue, message, messageSize); - debug("sendtoUSB debug pipeline line 83"); - debug((const char*)message); sendToEndpoint(pipeline->usb->descriptor.type, sendQueue, &pipeline->usb->endpoints[OUT_ENDPOINT_INDEX].queue, message, messageSize); @@ -192,7 +190,6 @@ void openxc::pipeline::publish(openxc_VehicleMessage* message, break; } if(matched) { - debug("debug for Ja'mez pipeline line 195 %d", message->type); sendMessage(pipeline, payload, length, messageClass); } else { From 7ce3468706141313063b36cb0e51b2601a95b9fa Mon Sep 17 00:00:00 2001 From: garindae Date: Thu, 3 Sep 2020 16:50:09 -0400 Subject: [PATCH 14/48] Revert "wip" This reverts commit aa611f7f690090cc0fa28fb6ce9aebcbea0437ad. --- src/diagnostics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics.h b/src/diagnostics.h index c63a05a7c..f92e8b66e 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -14,7 +14,7 @@ /* Private: The maximum number of simultanous diagnostic requests. Increasing * this number will use more memory on the stack. */ -#define MAX_SIMULTANEOUS_DIAG_REQUESTS 5 +#define MAX_SIMULTANEOUS_DIAG_REQUESTS 20 /* Private: The maximum length for a human-readable name for a diagnostic * response. From 2a6c74f069fb974372d69f1dcdd0caa7fc8d7f99 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 8 Sep 2020 19:23:17 +0000 Subject: [PATCH 15/48] Updated submodule dependencies to point to current masters --- src/libs/openxc-message-format | 2 +- src/libs/uds-c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index 4d032d51f..1cf2be891 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit 4d032d51fe161ea1aa7d8255e53f64f6b3ea09cf +Subproject commit 1cf2be891920cc3e37b039a2a3c451c217d1cd4e diff --git a/src/libs/uds-c b/src/libs/uds-c index 59618bbae..ac44c3702 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit 59618bbae717b2e814c481e6b70f27ef9dce2713 +Subproject commit ac44c370233ce71062d671eb586beb242ac1de6f From 3d7f53d3ed7ad07347dfc50dbd419ea698f0b644 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 8 Sep 2020 20:26:59 +0000 Subject: [PATCH 16/48] updated submodule documentation --- src/libs/openxc-message-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index 1cf2be891..c04cb13d6 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit 1cf2be891920cc3e37b039a2a3c451c217d1cd4e +Subproject commit c04cb13d625e8cbcae5beef56094d0ae496193a9 From 6a5030d634440fa6ac6c7b0dc39b9a6fbec0c257 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 8 Sep 2020 23:35:26 +0000 Subject: [PATCH 17/48] Combined Stitch Diag REsponse with regular diag response --- src/diagnostics.cpp | 72 ++++++---------------- src/libs/openxc-message-format | 2 +- src/payload/json.cpp | 106 +++++++++++++++++---------------- src/pipeline.cpp | 1 - 4 files changed, 75 insertions(+), 106 deletions(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index 444eb6efd..f4d586162 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -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; @@ -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, @@ -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); diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index c04cb13d6..8c2f53c9f 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit c04cb13d625e8cbcae5beef56094d0ae496193a9 +Subproject commit 8c2f53c9fa5b23b35cf1720ba63ba7bd4afc6bd3 diff --git a/src/payload/json.cpp b/src/payload/json.cpp index 64965639d..81987fac4 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -67,6 +67,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); @@ -98,54 +106,54 @@ 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 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) { @@ -633,8 +641,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 { diff --git a/src/pipeline.cpp b/src/pipeline.cpp index a7d7c79aa..f2c8ad8d5 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -177,7 +177,6 @@ void openxc::pipeline::publish(openxc_VehicleMessage* message, matched = true; break; case openxc_VehicleMessage_Type_DIAGNOSTIC: - case openxc_VehicleMessage_Type_DIAGNOSTIC_STITCH: messageClass = MessageClass::DIAGNOSTIC; matched = true; break; From 96d25b095f74103009eb776d36141ca1d9add1ba Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 14 Sep 2020 20:23:49 +0000 Subject: [PATCH 18/48] Update version dependency to new python --- script/bootstrap/ci-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/bootstrap/ci-requirements.txt b/script/bootstrap/ci-requirements.txt index 556eee862..27d3e1c7a 100644 --- a/script/bootstrap/ci-requirements.txt +++ b/script/bootstrap/ci-requirements.txt @@ -1 +1 @@ -openxc==2.0.0 +openxc==2.1.0 From 2332ee0403e9f7716ef48b68d2c90840f01d3f4b Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 14 Sep 2020 21:01:35 +0000 Subject: [PATCH 19/48] Updating version release notes and version files to 8.1.0 --- CHANGELOG.mkd | 9 +++++++++ README.rst | 2 +- docs/conf.py | 4 ++-- docs/index.rst | 2 +- src/config.cpp | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd index d4d39df25..22d8808ff 100644 --- a/CHANGELOG.mkd +++ b/CHANGELOG.mkd @@ -1,5 +1,14 @@ # OpenXC Vehicle Interface Firmware Changelog +## 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. +* Fix: Crash with C5 Ble +* Fix: Modem Configuration fixed set proper baud rate for C5 Cellular +* Fix: Updates to ISOTP and UDS libraries to support diagnostic repsonse stitch release +* Feature: Large Diagnostic Responses are now passed up as smaller messages and stitched by clients +* Feature: Vin messages added to Emulator mode +* Feature: Sonarqube support added + ## v8.0.0 * BREAKING: This version requires updates to the virtual machine. 'vagrant up --provision' must be run after 'git pull'. * BREAKING: VI-Firmware 8.0.0 is not backwards compatable due to memory management updates and must be used with OpenXC-Python 2.0.0 or greater. diff --git a/README.rst b/README.rst index b543ec80d..e93e1a5a7 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /docs/_static/logo.png -:Version: 8.0.0 +:Version: 8.1.0 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/docs/conf.py b/docs/conf.py index a32aeb756..2a5ea75de 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,9 +49,9 @@ # built documents. # # The short X.Y version. -version = '8.0.0' +version = '8.1.0' # The full version, including alpha/beta/rc tags. -release = '8.0.0' +release = '8.1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index 67fe07a50..8c86c094e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /_static/logo.png -:Version: 8.0.0 +:Version: 8.1.0 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/src/config.cpp b/src/config.cpp index 9df88f82b..9bc30687e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -118,7 +118,7 @@ openxc::telitHE910::TelitDevice telitDevice = { openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, - version: "8.0.0", + version: "8.1.0", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT, From 192d95c0f994bfcdc4a023c8cb4850d27b271fc7 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Thu, 1 Oct 2020 13:49:21 -0400 Subject: [PATCH 20/48] Add logic to catch null return for get_vin command. --- src/config.cpp | 2 +- src/diagnostics.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 5c4427d0b..98195263b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -119,7 +119,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, version: "8.0.0", - dummyVin: "00000000123456789", + dummyVin: "Failed to get VIN tempory VIN is :00000000123456789", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT, diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index bba6e1954..fcd7337d0 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -537,10 +537,20 @@ void openxc::diagnostics::checkForVinCommand(CanMessage *message) { // Step 3: When all of the VIN data is complete return sendCommandResponse with VIN char* vin = (char *)vinBuffer; - openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); - setVinCommandInProgress(false); + if (vin) { + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); + setVinCommandInProgress(false); // VIN command completed - vinComplete = true; + vinComplete = true; + } else { + vin = strdup(config::getConfiguration()->dummyVin); + debug("get_vin Command failed."); + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); + setVinCommandInProgress(false); + // VIN command completed + vinComplete = true; + + } } } From 5e85e738f9f852f49d2b230a46dfd5ec7a7fac34 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:06:07 -0400 Subject: [PATCH 21/48] Minor edit to if statement to check for strlen of vin. --- src/diagnostics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index fcd7337d0..75a2ba865 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -537,7 +537,7 @@ void openxc::diagnostics::checkForVinCommand(CanMessage *message) { // Step 3: When all of the VIN data is complete return sendCommandResponse with VIN char* vin = (char *)vinBuffer; - if (vin) { + if (strlen(vin)) { openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); setVinCommandInProgress(false); // VIN command completed From 8f6f1028bdb7375d056547b9f39fd196891394f9 Mon Sep 17 00:00:00 2001 From: Ja'mez Stokes <49651248+jstoke53@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:14:47 -0400 Subject: [PATCH 22/48] fix typo in config.cpp. --- src/config.cpp | 2 +- src/diagnostics.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 98195263b..3ad82cdd9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -119,7 +119,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, version: "8.0.0", - dummyVin: "Failed to get VIN tempory VIN is :00000000123456789", + dummyVin: "Failed to get VIN temporary VIN is :00000000123456789", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT, diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index 75a2ba865..df4cbc0c2 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -537,13 +537,13 @@ void openxc::diagnostics::checkForVinCommand(CanMessage *message) { // Step 3: When all of the VIN data is complete return sendCommandResponse with VIN char* vin = (char *)vinBuffer; - if (strlen(vin)) { + if (strlen(vin) == VIN_LENGTH) { openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); setVinCommandInProgress(false); // VIN command completed vinComplete = true; } else { - vin = strdup(config::getConfiguration()->dummyVin); + vin = config::getConfiguration()->dummyVin; debug("get_vin Command failed."); openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); setVinCommandInProgress(false); From baec10d78523de2d839fc7f4518cd6c000d70b60 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Thu, 1 Oct 2020 19:15:01 +0000 Subject: [PATCH 23/48] Sending Get Vin error response after timeout --- src/diagnostics.cpp | 63 +++++++++++++++++---------------------------- src/diagnostics.h | 1 + 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index df4cbc0c2..ae295a46a 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -34,6 +34,15 @@ namespace time = openxc::util::time; namespace pipeline = openxc::pipeline; namespace obd2 = openxc::diagnostics::obd2; +const int VIN_STORAGE_LENGTH = VIN_LENGTH+1; // 17 characters + 1 pad +const int VIN_SNIPPET_LENGTH = 6; // 6 VIN characters per CAN msg +unsigned char vinBuffer[VIN_STORAGE_LENGTH] = {0}; +bool vinComplete = false; +bool vinCommandInProgress = false; +int selector = -1; +void dumpNum(int); + + // receiveCanMessage - called from vi_firmware every time a CanMessage // is QUEUE_POP from the busses' receiveQueue // MULTIFRAME 0 The Old way Before 2020 (no multiframe messages) @@ -112,6 +121,10 @@ static void cleanupRequest(DiagnosticsManager* manager, request_string); LIST_REMOVE(entry, listEntries); cancelRequest(manager, entry); + + if (vinCommandInProgress) { + openxc::diagnostics::sendGetVinError(); + } } } } @@ -439,12 +452,6 @@ static void relayPartialFrame(DiagnosticsManager* manager, // Only need for the } #endif -const int VIN_STORAGE_LENGTH = VIN_LENGTH+1; // 17 characters + 1 pad -const int VIN_SNIPPET_LENGTH = 6; // 6 VIN characters per CAN msg -unsigned char vinBuffer[VIN_STORAGE_LENGTH] = {0}; -bool vinComplete = false; -bool vinCommandInProgress = false; - bool openxc::diagnostics::haveVINfromCan() { return vinComplete; } @@ -463,21 +470,6 @@ void openxc::diagnostics::filterForVIN(CanMessage* message) { (message->data[0] == 0xc1) && (message->data[1] <= 0x02)) { - // gja debug here! - // char buffer[26]; - // buffer[0] = '>'; - // int indx=1; - // for(int cnt=0; cntlength; cnt++) { - // int c = (message->data[cnt] & 0xf0) >> 4; - // buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; - // c = (message->data[cnt] & 0x0f); - // buffer[indx++] = (c > 9) ? (c - 10 + 'a') : c + '0'; - // buffer[indx++] = ' '; - // buffer[indx] = 0; - // } - // debug(buffer); - // gja debug above here! - int index = message->data[1] * VIN_SNIPPET_LENGTH; for(int cnt=2; cnt<8; cnt++, index++) { vinBuffer[index] = message->data[cnt]; @@ -491,14 +483,10 @@ void openxc::diagnostics::filterForVIN(CanMessage* message) { } } -void dumpNum(int); -bool vinCommandFailed = false; -int selector = -1; void openxc::diagnostics::checkForVinCommand(CanMessage *message) { // Step 1: Check to see if get vin command is in progrees - debug("diag:checkForVinCommand"); dumpNum(message->id); if(message->id != 2024) { return; @@ -537,23 +525,20 @@ void openxc::diagnostics::checkForVinCommand(CanMessage *message) { // Step 3: When all of the VIN data is complete return sendCommandResponse with VIN char* vin = (char *)vinBuffer; - if (strlen(vin) == VIN_LENGTH) { - openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); - setVinCommandInProgress(false); - // VIN command completed - vinComplete = true; - } else { - vin = config::getConfiguration()->dummyVin; - debug("get_vin Command failed."); - openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); - setVinCommandInProgress(false); - // VIN command completed - vinComplete = true; - - } + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 1, vin, strlen(vin)); + setVinCommandInProgress(false); + vinComplete = true; } } +void openxc::diagnostics::sendGetVinError() { + + char *errorGetVin = (char *)"Unable to get VIN - timeout"; + + openxc::commands::sendCommandResponse(openxc_ControlCommand_Type_GET_VIN, 0, errorGetVin, strlen(errorGetVin)); + vinCommandInProgress = false; +} + static void relayDiagnosticResponse(DiagnosticsManager* manager, ActiveDiagnosticRequest* request, const DiagnosticResponse* response, Pipeline* pipeline, diff --git a/src/diagnostics.h b/src/diagnostics.h index 9c4eefe1a..f5cd80c61 100644 --- a/src/diagnostics.h +++ b/src/diagnostics.h @@ -396,6 +396,7 @@ unsigned char *getDiagnosticVIN(); void filterForVIN(CanMessage* message); void checkForVinCommand(CanMessage *message); void setVinCommandInProgress(bool vinInProgress); +void sendGetVinError(); } // namespace diagnostics From b232986b94b189a283aed9f54d60553a0935c3ad Mon Sep 17 00:00:00 2001 From: ptreman Date: Thu, 15 Oct 2020 09:34:55 -0400 Subject: [PATCH 24/48] Removed broken messagepack format support --- CHANGELOG.mkd | 2 + docs/compile/example-builds.rst | 2 +- docs/compile/makefile-opts.rst | 2 +- fabfile.py | 4 - src/commands/payload_format_command.cpp | 3 - src/payload/json.cpp | 1 - src/payload/json.h | 1 - src/payload/messagepack.cpp | 1108 ----------------------- src/payload/messagepack.h | 75 -- src/payload/payload.cpp | 5 - src/payload/payload.h | 1 - src/platform/pic32/server_task.cpp | 1 - src/tests/messagepack_payload_tests.cpp | 187 ---- src/tests/tests.mk | 2 - 14 files changed, 4 insertions(+), 1390 deletions(-) delete mode 100644 src/payload/messagepack.cpp delete mode 100644 src/payload/messagepack.h delete mode 100644 src/tests/messagepack_payload_tests.cpp diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd index 22d8808ff..1bc37c254 100644 --- a/CHANGELOG.mkd +++ b/CHANGELOG.mkd @@ -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. diff --git a/docs/compile/example-builds.rst b/docs/compile/example-builds.rst index 1819fd830..4ebc596ba 100644 --- a/docs/compile/example-builds.rst +++ b/docs/compile/example-builds.rst @@ -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 diff --git a/docs/compile/makefile-opts.rst b/docs/compile/makefile-opts.rst index 40f35dbd4..0b4d93712 100644 --- a/docs/compile/makefile-opts.rst +++ b/docs/compile/makefile-opts.rst @@ -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`` diff --git a/fabfile.py b/fabfile.py index 0bcd96bc4..276ba8d41 100644 --- a/fabfile.py +++ b/fabfile.py @@ -346,10 +346,6 @@ def json(): @task def protobuf(): env.payload_format = "PROTOBUF" - -@task -def messagepack(): - env.payload_format = "MESSAGEPACK" @task def clean(): diff --git a/src/commands/payload_format_command.cpp b/src/commands/payload_format_command.cpp index 7779d4a2c..a1df1e262 100644 --- a/src/commands/payload_format_command.cpp +++ b/src/commands/payload_format_command.cpp @@ -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; diff --git a/src/payload/json.cpp b/src/payload/json.cpp index 64965639d..69bc27591 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -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"; diff --git a/src/payload/json.h b/src/payload/json.h index f77fbd4b3..7ea71b3a3 100644 --- a/src/payload/json.h +++ b/src/payload/json.h @@ -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[]; diff --git a/src/payload/messagepack.cpp b/src/payload/messagepack.cpp deleted file mode 100644 index 8fa9d1fdd..000000000 --- a/src/payload/messagepack.cpp +++ /dev/null @@ -1,1108 +0,0 @@ -#include "payload.h" -#include -#include -#include -#include -#include -#include -#include "messagepack.h" -#include "util/strutil.h" -#include "util/log.h" -#include "config.h" -#include "util/log.h" - -#define MESSAGE_PACK_SERIAL_BUF_SZ 128 -#define MESSAGE_PACK_FIXMAP_MARKER 0x80 -#define MESSAGE_PACK_FIXMAP_SIZE 0x0F -#define MESSAGE_PACK_FALSE_MARKER 0xC2 -#define MESSAGE_PACK_TRUE_MARKER 0xC3 -#define MESSAGE_PACK_DOUBLE_MARKER 0xCB -#define MESSAGE_PACK_FIXSTR_MARKER 0xA0 -#define MESSAGE_PACK_FIXMAP_MARKER 0x80 -#define MESSAGE_PACK_MAX_STRLEN 0x1F - -#define MAX_STRLEN 25 -#define MAX_BINLEN 25 - -namespace payload = openxc::payload; -using openxc::util::log::debug; - -const char openxc::payload::messagepack::VERSION_COMMAND_NAME[] = "version"; -const char openxc::payload::messagepack::DEVICE_ID_COMMAND_NAME[] = "device_id"; -const char openxc::payload::messagepack::DEVICE_PLATFORM_COMMAND_NAME[] = "platform"; -const char openxc::payload::messagepack::DIAGNOSTIC_COMMAND_NAME[] = "diagnostic_request"; -const char openxc::payload::messagepack::PASSTHROUGH_COMMAND_NAME[] = "passthrough"; -const char openxc::payload::messagepack::ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME[] = "af_bypass"; -const char openxc::payload::messagepack::PAYLOAD_FORMAT_COMMAND_NAME[] = "payload_format"; -const char openxc::payload::messagepack::PREDEFINED_OBD2_REQUESTS_COMMAND_NAME[] = "predefined_obd2"; -const char openxc::payload::messagepack::MODEM_CONFIGURATION_COMMAND_NAME[] = "modem_configuration"; -const char openxc::payload::messagepack::RTC_CONFIGURATION_COMMAND_NAME[] = "rtc_configuration"; - -const char openxc::payload::messagepack::PAYLOAD_FORMAT_MESSAGEPACK_NAME[] = "messagepack"; -const char openxc::payload::messagepack::PAYLOAD_FORMAT_PROTOBUF_NAME[] = "protobuf"; -const char openxc::payload::messagepack::PAYLOAD_FORMAT_JSON_NAME[] = "json"; - -const char openxc::payload::messagepack::COMMAND_RESPONSE_FIELD_NAME[] = "command_response"; -const char openxc::payload::messagepack::COMMAND_RESPONSE_MESSAGE_FIELD_NAME[] = "message"; -const char openxc::payload::messagepack::COMMAND_RESPONSE_STATUS_FIELD_NAME[] = "status"; - -const char openxc::payload::messagepack::BUS_FIELD_NAME[] = "bus"; -const char openxc::payload::messagepack::ID_FIELD_NAME[] = "id"; -const char openxc::payload::messagepack::DATA_FIELD_NAME[] = "data"; -const char openxc::payload::messagepack::NAME_FIELD_NAME[] = "name"; -const char openxc::payload::messagepack::VALUE_FIELD_NAME[] = "value"; -const char openxc::payload::messagepack::EVENT_FIELD_NAME[] = "event"; -const char openxc::payload::messagepack::FRAME_FORMAT_FIELD_NAME[] = "frame_format"; - -const char openxc::payload::messagepack::FRAME_FORMAT_STANDARD_NAME[] = "standard"; -const char openxc::payload::messagepack::FRAME_FORMAT_EXTENDED_NAME[] = "extended"; - -const char openxc::payload::messagepack::DIAGNOSTIC_MODE_FIELD_NAME[] = "mode"; -const char openxc::payload::messagepack::DIAGNOSTIC_PID_FIELD_NAME[] = "pid"; -const char openxc::payload::messagepack::DIAGNOSTIC_SUCCESS_FIELD_NAME[] = "success"; -const char openxc::payload::messagepack::DIAGNOSTIC_NRC_FIELD_NAME[] = "negative_response_code"; -const char openxc::payload::messagepack::DIAGNOSTIC_PAYLOAD_FIELD_NAME[] = "payload"; -const char openxc::payload::messagepack::DIAGNOSTIC_VALUE_FIELD_NAME[] = "value"; -const char openxc::payload::messagepack::SD_MOUNT_STATUS_COMMAND_NAME[] = "sd_mount_status"; - - -enum msgpack_var_type{TYPE_STRING,TYPE_NUMBER,TYPE_TRUE,TYPE_FALSE,TYPE_BINARY,TYPE_MAP}; - -int32_t dynamic_allocation_bytes = 0; - -typedef struct sMsgPackNode{ - char * string; //points to string header and not the string inorder to derive string - enum msgpack_var_type type; - double valuedouble; - int valueint; - char *valuestring; - uint8_t *bin; - uint8_t binsz; - sMsgPackNode *next,*child; -}sMsgPackNode; - -typedef struct{ - uint8_t MsgPackMapPairCount; -}meta; - -typedef struct{ - uint8_t * end; - uint8_t * start; - uint8_t * rp; - uint8_t * wp; - meta mobj; -}sFile; - -sMsgPackNode* msgPackParse(uint8_t* buf,uint32_t* len); - -static size_t msgPackWriteBuffer(cmp_ctx_t *ctx, const void *data, size_t count) { - - sFile * smsgb = (sFile *)ctx->buf; - - if(ctx->error > 0)return 0; - - if(smsgb->wp + count > (smsgb->end+1)){ - return 0; - } - memcpy(smsgb->wp, data, count); - smsgb->wp += count; - return count; -} - -static bool msgPackReadBuffer(cmp_ctx_t *ctx, void *data, size_t count) { - sFile * smsgb = (sFile *)ctx->buf; - if(smsgb->rp + count > (smsgb->end+1)){ - return 0; - } - memcpy((void*)data, (const void*)smsgb->rp, count); - smsgb->rp += count; - - return count; -} - -static void msgPackInitBuffer(sFile* smsgpackb, uint8_t* buf, uint8_t len){ - - smsgpackb->end = buf + len - 1; - smsgpackb->start = buf; - smsgpackb->rp = buf; - smsgpackb->wp = buf; - -} - -static void msgPackAddObjectString(cmp_ctx_t *ctx, const char* fname ,const char* obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_str(ctx, (const char *)obj, strlen(obj)); - s->mobj.MsgPackMapPairCount++; -} -static void msgPackAddObjectDouble(cmp_ctx_t *ctx, const char* fname ,double obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_double(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -static void msgPackAddObject8bNumeric(cmp_ctx_t *ctx, const char* fname ,uint8_t obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_u8(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -static void msgPackAddObject16bNumeric(cmp_ctx_t *ctx, const char* fname ,uint16_t obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_u16(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -/* -static void msgPackAddObject32bNumeric(cmp_ctx_t *ctx, const char* fname ,uint32_t obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_u32(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -*/ -static void msgPackAddObject64bNumeric(cmp_ctx_t *ctx, const char* fname ,uint32_t obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_u64(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -/* -static void msgPackAddObjectFloat(cmp_ctx_t *ctx, const char* fname ,float obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_float(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -*/ -static void msgPackAddObjectBoolean(cmp_ctx_t *ctx, const char* fname ,bool obj){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - cmp_write_bool(ctx, obj); - s->mobj.MsgPackMapPairCount++; -} -static void msgPackAddObjectBinary(cmp_ctx_t *ctx, const char* fname ,uint8_t* obj, uint8_t len){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - //cmp_write_bin_marker(ctx, len); - cmp_write_bin(ctx,(const void *)obj, len); //writes marker as well - s->mobj.MsgPackMapPairCount++; -} -/* -static void msgPackAddObjectMap(cmp_ctx_t *ctx, const char* fname ,uint8_t* obj,uint8_t len){ - sFile *s = (sFile *)ctx->buf; - cmp_write_str(ctx, (const char *)fname, strlen((const char *)fname)); - msgPackWriteBuffer(ctx, obj, len); - s->mobj.MsgPackMapPairCount++; -} -*/ - - -static void msgPackAddDynamicField(cmp_ctx_t *ctx, openxc_DynamicField* field) { - - if(field->type == openxc_DynamicField_Type_NUM) { - cmp_write_double(ctx, field->numeric_value); - } else if(field->type == openxc_DynamicField_Type_BOOL) { - cmp_write_bool(ctx, field->boolean_value); - } else if(field->type == openxc_DynamicField_Type_STRING) { - cmp_write_str(ctx, field->string_value, strlen(field->string_value)); - } - -} - -static void serializeSimple(openxc_VehicleMessage* message, cmp_ctx_t *ctx) { - - const char* name = message->simple_message.name; - sFile *s = (sFile *)ctx->buf; - msgPackAddObjectString(ctx, payload::messagepack::NAME_FIELD_NAME, name); - - if(message->simple_message.value.type != openxc_DynamicField_Type_UNUSED) { - cmp_write_str(ctx, payload::messagepack::VALUE_FIELD_NAME, strlen(payload::messagepack::VALUE_FIELD_NAME)); - msgPackAddDynamicField(ctx, &message->simple_message.value); - s->mobj.MsgPackMapPairCount++; - } - - if(message->simple_message.event.type != openxc_DynamicField_Type_UNUSED) { - cmp_write_str(ctx, payload::messagepack::EVENT_FIELD_NAME, strlen(payload::messagepack::EVENT_FIELD_NAME)); - msgPackAddDynamicField(ctx, &message->simple_message.event); - s->mobj.MsgPackMapPairCount++; - } -} - -void serializeCan(openxc_VehicleMessage* message, cmp_ctx_t *ctx) { - - msgPackAddObject8bNumeric(ctx, payload::messagepack::BUS_FIELD_NAME, message->can_message.bus); - - msgPackAddObject8bNumeric(ctx, payload::messagepack::ID_FIELD_NAME, message->can_message.bus); - - msgPackAddObjectBinary(ctx, payload::messagepack::DATA_FIELD_NAME, - message->can_message.data.bytes,message->can_message.data.size); - - if(message->can_message.frame_format != openxc_CanMessage_FrameFormat_UNUSED) { - msgPackAddObjectString(ctx, payload::messagepack::FRAME_FORMAT_FIELD_NAME, - message->can_message.frame_format == openxc_CanMessage_FrameFormat_STANDARD ? - payload::messagepack::FRAME_FORMAT_STANDARD_NAME : - payload::messagepack::FRAME_FORMAT_EXTENDED_NAME); - } -} - -static void serializeDiagnostic(openxc_VehicleMessage* message, cmp_ctx_t *ctx) { - - msgPackAddObject8bNumeric(ctx, payload::messagepack::BUS_FIELD_NAME, - message->diagnostic_response.bus); - msgPackAddObject8bNumeric(ctx, payload::messagepack::ID_FIELD_NAME, - message->diagnostic_response.message_id); - msgPackAddObject8bNumeric(ctx, payload::messagepack::DIAGNOSTIC_MODE_FIELD_NAME, - message->diagnostic_response.mode); - msgPackAddObjectBoolean(ctx, payload::messagepack::DIAGNOSTIC_SUCCESS_FIELD_NAME, - message->diagnostic_response.success); - msgPackAddObject16bNumeric(ctx, payload::messagepack::DIAGNOSTIC_PID_FIELD_NAME, - message->diagnostic_response.pid); - - if(message->diagnostic_response.negative_response_code != 0) { - msgPackAddObjectDouble(ctx, payload::messagepack::DIAGNOSTIC_NRC_FIELD_NAME, - message->diagnostic_response.negative_response_code); - } - - if(message->diagnostic_response.value.type != openxc_DynamicField_Type_UNUSED) { - cmp_write_str(ctx, payload::messagepack::VALUE_FIELD_NAME, strlen(payload::messagepack::VALUE_FIELD_NAME)); - msgPackAddDynamicField(ctx, &message->diagnostic_response.value); - - } else if(message->diagnostic_response.payload.size > 0) { - msgPackAddObjectBinary(ctx, payload::messagepack::DIAGNOSTIC_PAYLOAD_FIELD_NAME, - message->diagnostic_response.payload.bytes, message->diagnostic_response.payload.size); - - } - -} - -static bool serializeCommandResponse(openxc_VehicleMessage* message, cmp_ctx_t *ctx) { - - const char* typeString = NULL; - - if(message->command_response.type == openxc_ControlCommand_Type_VERSION) { - typeString = payload::messagepack::VERSION_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_DEVICE_ID) { - typeString = payload::messagepack::DEVICE_ID_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_PLATFORM) { - typeString = payload::messagepack::DEVICE_PLATFORM_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_DIAGNOSTIC) { - typeString = payload::messagepack::DIAGNOSTIC_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_PASSTHROUGH) { - typeString = payload::messagepack::PASSTHROUGH_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_ACCEPTANCE_FILTER_BYPASS) { - typeString = payload::messagepack::ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_PAYLOAD_FORMAT) { - typeString = payload::messagepack::PAYLOAD_FORMAT_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_PREDEFINED_OBD2_REQUESTS) { - typeString = payload::messagepack::PREDEFINED_OBD2_REQUESTS_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_MODEM_CONFIGURATION) { - typeString = payload::messagepack::MODEM_CONFIGURATION_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_RTC_CONFIGURATION) { - typeString = payload::messagepack::RTC_CONFIGURATION_COMMAND_NAME; - } else if(message->command_response.type == openxc_ControlCommand_Type_SD_MOUNT_STATUS) { - typeString = payload::messagepack::SD_MOUNT_STATUS_COMMAND_NAME; - } else { - return false; - } - - msgPackAddObjectString(ctx, payload::messagepack::COMMAND_RESPONSE_FIELD_NAME, - typeString); - - - if(message->command_response.type != openxc_ControlCommand_Type_UNUSED) { - msgPackAddObjectString(ctx, - payload::messagepack::COMMAND_RESPONSE_MESSAGE_FIELD_NAME, - message->command_response.message); - } - - if(message->command_response.type != openxc_ControlCommand_Type_UNUSED) { - msgPackAddObjectBoolean(ctx, - payload::messagepack::COMMAND_RESPONSE_STATUS_FIELD_NAME, - message->command_response.status); - } - return true; -} - - -int openxc::payload::messagepack::serialize(openxc_VehicleMessage* message, uint8_t payload[], size_t length) -{ - - sFile smsgpackb; - - uint8_t MessagePackBuffer[MESSAGE_PACK_SERIAL_BUF_SZ]; - - size_t finalLength = 0; - - cmp_ctx_t cmp; - - memset((void*)&smsgpackb,0,sizeof(smsgpackb)); - - msgPackInitBuffer(&smsgpackb, MessagePackBuffer, MESSAGE_PACK_SERIAL_BUF_SZ); - - cmp_init(&cmp,(void*)&smsgpackb, msgPackReadBuffer, msgPackWriteBuffer); - - cmp_write_map(&cmp,2); - - //"{\"command\": \"diagnostic_request\", \"actio" - //"n\": \"add\", \"request\": {\"bus\": 1, \"id\": 2, \"mode\": 1}}\0"; - - //"{\"command\": \"version\"}\0"; - - //msgPackAddObjectString(&cmp, "command", "device_id"); - //cmp_write_map(&cmp,3); - //msgPackAddObjectString(&cmp, "command", "passthrough"); - //msgPackAddObject8bNumeric(&cmp, "bus", 1); - //msgPackAddObjectBoolean(&cmp, "enabled", 1); - //goto x; - /* - cmp_write_map(&cmp,3); - msgPackAddObjectString(&cmp, "command", "diagnostic_request"); - msgPackAddObjectString(&cmp, "action", "add"); - cmp_write_str(&cmp, "request", 7); - cmp_write_map(&cmp,3); - msgPackAddObject8bNumeric(&cmp, "bus", 1); - msgPackAddObject8bNumeric(&cmp, "id", 2); - msgPackAddObject8bNumeric(&cmp, "mode", 1); - smsgpackb.mobj.MsgPackMapPairCount -=3; - goto x; - */ - if(message->type != openxc_VehicleMessage_Type_UNUSED) { - - msgPackAddObject64bNumeric(&cmp, "timestamp", message->timestamp); - - } - if(message->type == openxc_VehicleMessage_Type_SIMPLE) { - serializeSimple(message, &cmp); - } else if(message->type == openxc_VehicleMessage_Type_CAN) { - serializeCan(message, &cmp); - } else if(message->type == openxc_VehicleMessage_Type_DIAGNOSTIC) { - serializeDiagnostic(message, &cmp); - } else if(message->type == openxc_VehicleMessage_Type_COMMAND_RESPONSE) { - serializeCommandResponse(message, &cmp); - } else { - debug("Unrecognized message type -- not sending"); - } - - if(cmp.error > 0){ - debug("%s\n\n", cmp_strerror(&cmp)); - return 0; - } - if( smsgpackb.mobj.MsgPackMapPairCount > MESSAGE_PACK_FIXMAP_SIZE) - { - debug("Unhandled, excedded fix map limit %d",smsgpackb.mobj.MsgPackMapPairCount); - return 0; - } - - smsgpackb.start[0] = MESSAGE_PACK_FIXMAP_MARKER | smsgpackb.mobj.MsgPackMapPairCount; //todo create a function to add this more gracefully - - - finalLength = smsgpackb.wp - smsgpackb.start; - - memcpy(payload, MessagePackBuffer, finalLength); - - //debug ("parsing %d bytes",finalLength); - //openxc_VehicleMessage m; - //int l = openxc::payload::messagepack::deserialize(payload,finalLength,&m); - //debug ("deserialized %d bytes",l); - //while(1); -/* - for(int i = 0;i < finalLength; i ++) - { - debug("%x", payload[i]); - } - - debug("\n\n"); - - -*/ - return finalLength; -} -sMsgPackNode * msgPackSeekNode(sMsgPackNode* root,const char * name ){ - sMsgPackNode * node = root; - while(node){ - if(strcmp(node->string, name) == 0){ - if(node->child)return node->child; - - return node; - } - node = node->next; - } - //debug("Missing %s",name); - return node; -} - -sMsgPackNode* getnode(cmp_ctx_t * ctx){ - - - char vstr[MAX_STRLEN+1]; - char nstr[MAX_STRLEN+1]; - char binarr[MAX_BINLEN+1]; - uint32_t str_size; - char binsz = 0; - cmp_object_t obj; - enum msgpack_var_type type; - double vd=0.0; - int vi=0; - sMsgPackNode* ch; - - str_size = MAX_STRLEN; - - if (!cmp_read_str(ctx, nstr, &str_size)){ - //debug("Node incomplete %s",cmp_strerror(ctx)); - return NULL; - } - - if (cmp_read_object(ctx, &obj) == true) { //read value - switch (obj.type) { - case CMP_TYPE_FIXARRAY: - case CMP_TYPE_ARRAY16: - case CMP_TYPE_ARRAY32: - case CMP_TYPE_EXT8: - case CMP_TYPE_EXT16: - case CMP_TYPE_EXT32: - case CMP_TYPE_FIXEXT1: - case CMP_TYPE_FIXEXT2: - case CMP_TYPE_FIXEXT4: - case CMP_TYPE_FIXEXT8: - case CMP_TYPE_FIXEXT16: - case CMP_TYPE_NIL: - case CMP_TYPE_UINT64: - case CMP_TYPE_NEGATIVE_FIXNUM: - case CMP_TYPE_SINT8: - case CMP_TYPE_SINT16: - case CMP_TYPE_SINT32: - case CMP_TYPE_SINT64: - { - debug("Unhandled object %d",obj.type); - return NULL; - break; - } - case CMP_TYPE_FIXMAP: - case CMP_TYPE_MAP16: - case CMP_TYPE_MAP32: - { - sFile * s = (sFile *)ctx->buf; - s->rp--; - uint32_t plen = (s->end - s->rp) + 1; - ch = msgPackParse(s->rp,&plen); - if(ch == NULL){ - //debug("Child incomplete %s",cmp_strerror(ctx)); - return NULL; - } - - s->rp += plen + 1; - type = msgpack_var_type::TYPE_MAP; - break; - } - case CMP_TYPE_BIN8: - case CMP_TYPE_BIN16: - case CMP_TYPE_BIN32: - { - if(obj.as.bin_size > MAX_BINLEN) - { - debug("Payload exceeded limit %d bytes",obj.as.bin_size); - return NULL; - } - if (!msgPackReadBuffer(ctx, binarr, obj.as.bin_size)) - { - //debug("Data missing total %d %d %d //%dbytes",obj.as.bin_size,s->rp-s->start,s->end-s->rp,s->end-s->start); - return NULL; - } - binsz = obj.as.bin_size; - type = msgpack_var_type::TYPE_BINARY; - break; - } - - case CMP_TYPE_FIXSTR: - case CMP_TYPE_STR8: - case CMP_TYPE_STR16: - case CMP_TYPE_STR32: - { - if(obj.as.str_size > MAX_STRLEN) - return NULL; - - if (!msgPackReadBuffer(ctx, vstr, obj.as.str_size)) - return NULL; - - vstr[obj.as.str_size] = 0; - type = msgpack_var_type::TYPE_STRING; - break; - } - - case CMP_TYPE_BOOLEAN: - { - if (obj.as.boolean) - type = msgpack_var_type::TYPE_TRUE; - else - type = msgpack_var_type::TYPE_FALSE; - - break; - } - case CMP_TYPE_FLOAT: - { - type = msgpack_var_type::TYPE_NUMBER; - vd = obj.as.flt; - break; - } - - case CMP_TYPE_DOUBLE: - { - type = msgpack_var_type::TYPE_NUMBER; - vd = obj.as.dbl; - break; - } - - case CMP_TYPE_UINT16: - { - type = msgpack_var_type::TYPE_NUMBER; - vi = obj.as.u16; - break; - } - - case CMP_TYPE_UINT32: - { - type = msgpack_var_type::TYPE_NUMBER; - vi = obj.as.u32; - break; - } - - case CMP_TYPE_POSITIVE_FIXNUM: - case CMP_TYPE_UINT8: - { - type = msgpack_var_type::TYPE_NUMBER; - vi = obj.as.u8; - break; - } - - default: - { - debug("Unrecognized object type %u\n", obj.type); - break; - } - - } - } else - { - //debug("Node incomplete %s",cmp_strerror(ctx)); - return NULL; - } - sMsgPackNode* node = (sMsgPackNode*)malloc(sizeof(sMsgPackNode)); - dynamic_allocation_bytes += sizeof(sMsgPackNode); - if(node == NULL){ - debug("Unable to create node in memory"); - return NULL; - } - - str_size = strlen(nstr); - node->string = (char*)malloc(str_size + 1); - dynamic_allocation_bytes += str_size + 1; - memcpy(node->string,nstr,str_size); //copy null terminator as well - node->string[str_size] = '\0'; - node->type = type; - - if(node->type == msgpack_var_type::TYPE_BINARY){ - node->bin = (uint8_t *)malloc(binsz); - dynamic_allocation_bytes += binsz; - if(node->bin ==NULL){ - debug("Unable to allocate mem bin"); - } - memcpy(node->bin,binarr,binsz); - node->binsz = binsz; - //debug("allocated node"); - } - if(node->type == msgpack_var_type::TYPE_STRING){ - str_size = strlen(vstr); - node->valuestring = (char *)malloc(str_size+1); - dynamic_allocation_bytes += str_size + 1; - if(node->valuestring == NULL){ - debug("Unable to allocate mem str"); - } - memcpy(node->valuestring,vstr,str_size); - node->valuestring[str_size] = '\0'; - } - node->child = NULL; - if(type == msgpack_var_type::TYPE_MAP){ - node->child = ch; - } - node->valueint = vi; - node->valuedouble = vd; - node->next = NULL; - return node; -} - -void msgPackListNodes(sMsgPackNode* root) -{ - sMsgPackNode* n = root; - debug("list:"); - while(n) - { - if(n->child){ - debug("child:"); - msgPackListNodes(n->child); - } - - debug("%s",n->string); - n = n->next; - } -} - -void MsgPackDelete(sMsgPackNode* root)//rentrant -{ - sMsgPackNode *pv, *rp; - - rp = root; - while(root->next){ - pv = rp->next; - while(pv->next){ - rp = pv; - pv = pv->next; - if(pv->child){ - MsgPackDelete(pv->child); - pv->child = NULL; - goto x; - } - } - //debug("deleting:%s",pv->string); - dynamic_allocation_bytes -= (strlen(pv->string) + 1); - free(pv->string); - - if(pv->type == msgpack_var_type::TYPE_STRING){ - dynamic_allocation_bytes -= (strlen(pv->valuestring) + 1); - free(pv->valuestring); - - } - if(pv->type == msgpack_var_type::TYPE_BINARY){ - dynamic_allocation_bytes -= (pv->binsz); - free(pv->bin); - } - if(pv->child){ - MsgPackDelete(pv->child); - } - free(pv); - dynamic_allocation_bytes -= sizeof(sMsgPackNode); - rp->next = NULL; -x: - rp = root; - } - //debug("deleting:%s",root->string); - dynamic_allocation_bytes -= (strlen(root->string) + 1); - free(root->string); - if(root->type == msgpack_var_type::TYPE_STRING){ - dynamic_allocation_bytes -= (strlen(root->valuestring) + 1); - free(root->valuestring); - } - if(pv->type == msgpack_var_type::TYPE_BINARY){ - dynamic_allocation_bytes -= (root->binsz); - free(root->bin); - } - free(root); - dynamic_allocation_bytes -= sizeof(sMsgPackNode); -} - -sMsgPackNode* msgPackParse(uint8_t* buf,uint32_t* len){ //reentrant - - sMsgPackNode *node = NULL; - sMsgPackNode *root = NULL; - - sFile smsgpackb; - - cmp_ctx_t cmp; - - if (!(buf[0] > 0x80 && buf[0] < 0x8f)){ - return NULL; - } - - uint32_t map_len; - - msgPackInitBuffer(&smsgpackb, buf, *len); - - cmp_init(&cmp,(void*)&smsgpackb, msgPackReadBuffer, msgPackWriteBuffer); - - - if(cmp_read_map(&cmp, &map_len) == false) - { - return NULL; - } - - //debug("Maplen %d", map_len); - root = getnode(&cmp); //get node creates a node on the heap using malloc - - if( root == NULL) - { - //debug("Root Node missing"); - return NULL; - } - node = root; - map_len--; - while( map_len ){ - - node->next = getnode(&cmp); - - if(node->next == NULL){ - //debug("Message pack contains partial information"); - MsgPackDelete(root); - return NULL; - } - node = node->next; - map_len--; - } - *len = (uint32_t)(smsgpackb.rp - smsgpackb.start); //update bytes read from buffer - return root; -} - - -static void deserializePassthrough(sMsgPackNode* root, openxc_ControlCommand* command) { - - command->type = openxc_ControlCommand_Type_PASSTHROUGH; - - sMsgPackNode* element = msgPackSeekNode(root, "bus"); - - if(element != NULL) { - command->passthrough_mode_request.bus = element->valueint; - } - - element = msgPackSeekNode(root, "enabled"); - if(element != NULL) { - command->passthrough_mode_request.enabled = bool(element->valueint); - } -} - -static void deserializePayloadFormat(sMsgPackNode* root, - openxc_ControlCommand* command) { - - command->type = openxc_ControlCommand_Type_PAYLOAD_FORMAT; - - sMsgPackNode* element = msgPackSeekNode(root, "format"); - if(element != NULL) { - if(!strcmp(element->valuestring, - openxc::payload::messagepack::PAYLOAD_FORMAT_JSON_NAME)) { - command->payload_format_command.format = - openxc_PayloadFormatCommand_PayloadFormat_JSON; - } else if(!strcmp(element->valuestring, - openxc::payload::messagepack::PAYLOAD_FORMAT_PROTOBUF_NAME)) { - command->payload_format_command.format = - openxc_PayloadFormatCommand_PayloadFormat_PROTOBUF; - } else if(!strcmp(element->valuestring, - openxc::payload::messagepack::PAYLOAD_FORMAT_MESSAGEPACK_NAME)) { - command->payload_format_command.format = openxc_PayloadFormatCommand_PayloadFormat_MESSAGEPACK; - } - } -} - -static void deserializePredefinedObd2RequestsCommand(sMsgPackNode* root, - openxc_ControlCommand* command) { - - command->type = openxc_ControlCommand_Type_PREDEFINED_OBD2_REQUESTS; - - sMsgPackNode* element = msgPackSeekNode(root, "enabled"); - if(element != NULL) { - command->predefined_obd2_requests_command.enabled = bool(element->valueint); - } -} - -static void deserializeAfBypass(sMsgPackNode* root, openxc_ControlCommand* command) { - command->type = openxc_ControlCommand_Type_ACCEPTANCE_FILTER_BYPASS; - - sMsgPackNode* element = msgPackSeekNode(root, "bus"); - if(element != NULL) { - command->acceptance_filter_bypass_command.bus = element->valueint; - } - - element = msgPackSeekNode(root, "bypass"); - if(element != NULL) { - command->acceptance_filter_bypass_command.bypass = - bool(element->valueint); - } -} - -static void deserializeDiagnostic(sMsgPackNode* root, openxc_ControlCommand* command) { - command->type = openxc_ControlCommand_Type_DIAGNOSTIC; - - sMsgPackNode* action = msgPackSeekNode(root, "action"); - if(action != NULL && action->type == msgpack_var_type::TYPE_STRING) { - if(!strcmp(action->valuestring, "add")) { - command->diagnostic_request.action = - openxc_DiagnosticControlCommand_Action_ADD; - } else if(!strcmp(action->valuestring, "cancel")) { - command->diagnostic_request.action = - openxc_DiagnosticControlCommand_Action_CANCEL; - } - } - - sMsgPackNode* request = msgPackSeekNode(root, "request"); - if(request != NULL) { - sMsgPackNode * element = msgPackSeekNode(request, "bus"); - if(element != NULL) { - command->diagnostic_request.request.bus = element->valueint; - } - - element = msgPackSeekNode(request, "mode"); - if(element != NULL) { - command->diagnostic_request.request.mode = element->valueint; - } - - element = msgPackSeekNode(request, "id"); - if(element != NULL) { - command->diagnostic_request.request.message_id = element->valueint; - } - - element = msgPackSeekNode(request, "pid"); - if(element != NULL) { - command->diagnostic_request.request.pid = element->valueint; - } - - element = msgPackSeekNode(request, "payload"); - if(element != NULL) { - if(request->type == msgpack_var_type::TYPE_BINARY){ - command->diagnostic_request.request.payload.size = request->binsz; - memcpy(command->diagnostic_request.request.payload.bytes, - request->bin,request->binsz); - } - } - - element = msgPackSeekNode(request, "multiple_responses"); - if(element != NULL) { - command->diagnostic_request.request.multiple_responses = - bool(element->valueint); - } - - element = msgPackSeekNode(request, "frequency"); - if(element != NULL) { - command->diagnostic_request.request.frequency = - element->valuedouble; - } - - element = msgPackSeekNode(request, "decoded_type"); - if(element != NULL) { - if(!strcmp(element->valuestring, "obd2")) { - command->diagnostic_request.request.decoded_type = - openxc_DiagnosticRequest_DecodedType_OBD2; - } else if(!strcmp(element->valuestring, "none")) { - command->diagnostic_request.request.decoded_type = - openxc_DiagnosticRequest_DecodedType_NONE; - } - } - - element = msgPackSeekNode(request, "name"); - if(element != NULL && element->type == msgpack_var_type::TYPE_STRING) { - strcpy(command->diagnostic_request.request.name, - element->valuestring); - } - } -} - -static bool deserializeDynamicField(sMsgPackNode* element, - openxc_DynamicField* field) { - bool status = true; - switch(element->type) { - case msgpack_var_type::TYPE_STRING: - field->type = openxc_DynamicField_Type_STRING; - strcpy(field->string_value, element->valuestring); - break; - case msgpack_var_type::TYPE_FALSE: - case msgpack_var_type::TYPE_TRUE: - field->type = openxc_DynamicField_Type_BOOL; - field->boolean_value = bool(element->valueint); - break; - case msgpack_var_type::TYPE_NUMBER: - field->type = openxc_DynamicField_Type_NUM; - field->numeric_value = element->valuedouble; - break; - default: - debug("Unsupported type in value field: %d", element->type); - status = false; - break; - } - return status; -} - -static void deserializeSimple(sMsgPackNode* root, openxc_VehicleMessage* message) { - message->type = openxc_VehicleMessage_Type_SIMPLE; - openxc_SimpleMessage* simpleMessage = &message->simple_message; - - sMsgPackNode* element = msgPackSeekNode(root, "name"); - if(element != NULL && element->type == msgpack_var_type::TYPE_STRING) { - strcpy(simpleMessage->name, element->valuestring); - } - - element = msgPackSeekNode(root, "value"); - if(element != NULL) { - if(deserializeDynamicField(element, &simpleMessage->value)) { - } - } - - element = msgPackSeekNode(root, "event"); - if(element != NULL) { - if(deserializeDynamicField(element, &simpleMessage->event)) { - } - } -} - -static void deserializeCan(sMsgPackNode* root, openxc_VehicleMessage* message) { - message->type = openxc_VehicleMessage_Type_CAN; - openxc_CanMessage* canMessage = &message->can_message; - - sMsgPackNode* element = msgPackSeekNode(root, "id"); - if(element != NULL) { - canMessage->id = element->valueint; - element = msgPackSeekNode(root, "data"); - if(element != NULL) { - if(element->type == msgpack_var_type::TYPE_BINARY){ - canMessage->data.size = element->binsz; - memcpy(canMessage->data.bytes, - element->bin,element->binsz); - } - } - - element = msgPackSeekNode(root, "bus"); - if(element != NULL) { - canMessage->bus = element->valueint; - } - - element = msgPackSeekNode(root, payload::messagepack::FRAME_FORMAT_FIELD_NAME); - if(element != NULL) { - if(!strcmp(element->valuestring, - payload::messagepack::FRAME_FORMAT_STANDARD_NAME)) { - canMessage->frame_format = openxc_CanMessage_FrameFormat_STANDARD; - } else if(!strcmp(element->valuestring, - payload::messagepack::FRAME_FORMAT_EXTENDED_NAME)) { - canMessage->frame_format = openxc_CanMessage_FrameFormat_EXTENDED; - } - } - } -} - -static void deserializeModemConfiguration(sMsgPackNode* root, openxc_ControlCommand* command) { - // set up the struct for a modem configuration message - command->type = openxc_ControlCommand_Type_MODEM_CONFIGURATION; - openxc_ModemConfigurationCommand* modemConfigurationCommand = &command->modem_configuration_command; - - // parse server command - sMsgPackNode* server = msgPackSeekNode(root, "server"); - if(server != NULL) { - sMsgPackNode* host = msgPackSeekNode(server, "host"); - if(host != NULL) { - strcpy(modemConfigurationCommand->serverConnectSettings.host, host->valuestring); - } - sMsgPackNode* port = msgPackSeekNode(server, "port"); - if(port != NULL) { - modemConfigurationCommand->serverConnectSettings.port = port->valueint; - } - } -} - -static void deserializeRTCConfiguration(sMsgPackNode* root, openxc_ControlCommand* command) { - - command->type = openxc_ControlCommand_Type_RTC_CONFIGURATION; - openxc_RTCConfigurationCommand* rtcConfigurationCommand = &command->rtc_configuration_command; - - sMsgPackNode* time = msgPackSeekNode(root, "time"); - - if(time != NULL) { - rtcConfigurationCommand->unix_time = time->valueint; - } -} - - - - -//Entire data is chunked into a single packet by higher level protocol -//unable to decode partial messages at this moment correctly -size_t openxc::payload::messagepack::deserialize(uint8_t payload[], size_t length, - openxc_VehicleMessage* message){ - - uint32_t Messagelen=0; - uint32_t i = 0; - sMsgPackNode *root; - //debug("Deserialize %d bytes",length); - root = NULL; - //find the start of message by searching for FIXMAPMARKER - while(i < length){ - if(payload[i] > 0x80 && payload[i] < 0x8f){//attempt to parse message if found - uint32_t len = length-i; - root = msgPackParse(&payload[i],&len); - if( root != NULL)//we found a message - { - //debug("Message Pack Data Complete %d bytes", len); - //msgPackListNodes(root); - Messagelen = i + len; //message len to discard on success, discarding previous data - break; - } - } - i++; - } - if(root == NULL) - { - //debug("MessagePackMemUsed:%d bytes", dynamic_allocation_bytes); - return 0; - } - sMsgPackNode* commandNameObject = msgPackSeekNode(root, "command"); - - if(commandNameObject != NULL) { - - message->type = openxc_VehicleMessage_Type_CONTROL_COMMAND; - openxc_ControlCommand* command = &message->control_command; - - if(!strncmp(commandNameObject->valuestring, VERSION_COMMAND_NAME, - strlen(VERSION_COMMAND_NAME))) { - command->type = openxc_ControlCommand_Type_VERSION; - } else if(!strncmp(commandNameObject->valuestring, - DEVICE_ID_COMMAND_NAME, strlen(DEVICE_ID_COMMAND_NAME))) { - command->type = openxc_ControlCommand_Type_DEVICE_ID; - } else if(!strncmp(commandNameObject->valuestring, - DEVICE_PLATFORM_COMMAND_NAME, strlen(DEVICE_PLATFORM_COMMAND_NAME))) { - command->type = openxc_ControlCommand_Type_PLATFORM; - } else if(!strncmp(commandNameObject->valuestring, - DIAGNOSTIC_COMMAND_NAME, strlen(DIAGNOSTIC_COMMAND_NAME))) { - deserializeDiagnostic(root, command); - } else if(!strncmp(commandNameObject->valuestring, - PASSTHROUGH_COMMAND_NAME, strlen(PASSTHROUGH_COMMAND_NAME))) { - deserializePassthrough(root, command); - } else if(!strncmp(commandNameObject->valuestring, - PREDEFINED_OBD2_REQUESTS_COMMAND_NAME, - strlen(PREDEFINED_OBD2_REQUESTS_COMMAND_NAME))) { - deserializePredefinedObd2RequestsCommand(root, command); - } else if(!strncmp(commandNameObject->valuestring, - ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME, - strlen(ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME))) { - deserializeAfBypass(root, command); - } else if(!strncmp(commandNameObject->valuestring, - PAYLOAD_FORMAT_COMMAND_NAME, - strlen(PAYLOAD_FORMAT_COMMAND_NAME))) { - deserializePayloadFormat(root, command); - } - else if(!strncmp(commandNameObject->valuestring, - MODEM_CONFIGURATION_COMMAND_NAME, - strlen(MODEM_CONFIGURATION_COMMAND_NAME))) { - deserializeModemConfiguration(root, command); - } - else if(!strncmp(commandNameObject->valuestring, - RTC_CONFIGURATION_COMMAND_NAME, - strlen(RTC_CONFIGURATION_COMMAND_NAME))) { - deserializeRTCConfiguration(root, command); - } - else if(!strncmp(commandNameObject->valuestring, - SD_MOUNT_STATUS_COMMAND_NAME, - strlen(SD_MOUNT_STATUS_COMMAND_NAME))) { - command->type = openxc_ControlCommand_Type_SD_MOUNT_STATUS; - } - else { - debug("Unrecognized command: %s", commandNameObject->valuestring); - } - } else{ - sMsgPackNode* nameObject = msgPackSeekNode(root, "name"); - if(nameObject == NULL) { - deserializeCan(root, message); - } else { - deserializeSimple(root, message); - } - } - - MsgPackDelete(root); - Messagelen = MIN(Messagelen,length); - //debug("Parsed: %d bytes", Messagelen); - //debug("MessagePackMemUsed:%d bytes", dynamic_allocation_bytes); - return Messagelen; -} - diff --git a/src/payload/messagepack.h b/src/payload/messagepack.h deleted file mode 100644 index 797eaef4f..000000000 --- a/src/payload/messagepack.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef __MESSAGEPACK_H__ -#define __MESSAGEPACK_H__ - -#include "openxc.pb.h" - -namespace openxc { -namespace payload { -namespace messagepack { - -extern const char VERSION_COMMAND_NAME[]; -extern const char DEVICE_ID_COMMAND_NAME[]; -extern const char DEVICE_PLATFORM_COMMAND_NAME[]; -extern const char DIAGNOSTIC_COMMAND_NAME[]; -extern const char PASSTHROUGH_COMMAND_NAME[]; -extern const char ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME[]; -extern const char PAYLOAD_FORMAT_COMMAND_NAME[]; -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[]; -extern const char COMMAND_RESPONSE_STATUS_FIELD_NAME[]; - -extern const char BUS_FIELD_NAME[]; -extern const char ID_FIELD_NAME[]; -extern const char DATA_FIELD_NAME[]; -extern const char NAME_FIELD_NAME[]; -extern const char VALUE_FIELD_NAME[]; -extern const char EVENT_FIELD_NAME[]; -extern const char FRAME_FORMAT_FIELD_NAME[]; - -extern const char FRAME_FORMAT_STANDARD_NAME[]; -extern const char FRAME_FORMAT_EXTENDED_NAME[]; - -extern const char DIAGNOSTIC_MODE_FIELD_NAME[]; -extern const char DIAGNOSTIC_PID_FIELD_NAME[]; -extern const char DIAGNOSTIC_SUCCESS_FIELD_NAME[]; -extern const char DIAGNOSTIC_NRC_FIELD_NAME[]; -extern const char DIAGNOSTIC_PAYLOAD_FIELD_NAME[]; -extern const char DIAGNOSTIC_VALUE_FIELD_NAME[]; - -extern const char MODEM_CONFIGURATION_COMMAND_NAME[]; -extern const char RTC_CONFIGURATION_COMMAND_NAME[]; - -extern const char SD_MOUNT_STATUS_COMMAND_NAME[]; -/* Public: Deserialize an OpenXC message from a payload containing MessagePack. - * - * payload - The bytestream payload to parse a message from. - * length - The length of the payload. - * message - An output parameter, the object to store the deserialized message. - * - * Returns the number of bytes parsed as MessagePack object from the payload, if any - * was found. - */ -size_t deserialize(uint8_t payload[], size_t length, openxc_VehicleMessage* message); - -/* Public: Serialize an OpenXC message as MessagePack and store in the payload. - * - * message - The message to serialize. - * payload - The buffer to store the payload - must be allocated by the caller. - * length - The length of the payload buffer. - * - * Returns the number of bytes written to the payload. If the length is 0, an - * error occurred while serializing. - */ -int serialize(openxc_VehicleMessage* message, uint8_t payload[], size_t length); - -} // namespace messagepack -} // namespace payload -} // namespace openxc - -#endif // __MESSAGEPACK_H__ diff --git a/src/payload/payload.cpp b/src/payload/payload.cpp index 68434e51c..14ab5982b 100644 --- a/src/payload/payload.cpp +++ b/src/payload/payload.cpp @@ -1,7 +1,6 @@ #include "payload.h" #include "payload/json.h" #include "payload/protobuf.h" -#include "payload/messagepack.h" #include "util/log.h" #include @@ -68,8 +67,6 @@ size_t openxc::payload::deserialize(uint8_t payload[], size_t length, debug("deserialize protobuf"); dumpNum(bytesRead); dumpPayload(payload, bytesRead); - } else if(format == PayloadFormat::MESSAGEPACK){ - bytesRead = payload::messagepack::deserialize(payload, length, message); } else { debug("Invalid payload format: %d", format); } @@ -83,8 +80,6 @@ int openxc::payload::serialize(openxc_VehicleMessage* message, serializedLength = payload::json::serialize(message, payload, length); } else if(format == PayloadFormat::PROTOBUF) { serializedLength = payload::protobuf::serialize(message, payload, length); - } else if(format == PayloadFormat::MESSAGEPACK) { - serializedLength = payload::messagepack::serialize(message, payload, length); } else { debug("Invalid payload format: %d", format); } diff --git a/src/payload/payload.h b/src/payload/payload.h index 6edcec633..a645b7dec 100644 --- a/src/payload/payload.h +++ b/src/payload/payload.h @@ -12,7 +12,6 @@ namespace payload { typedef enum { JSON, PROTOBUF, - MESSAGEPACK, } PayloadFormat; /* Public: Deserialize an OpenXC message from the given payload, using the given diff --git a/src/platform/pic32/server_task.cpp b/src/platform/pic32/server_task.cpp index b51ca2799..c4259d779 100644 --- a/src/platform/pic32/server_task.cpp +++ b/src/platform/pic32/server_task.cpp @@ -189,7 +189,6 @@ void openxc::server_task::flushDataBuffer(TelitDevice* device) { break; case PayloadFormat::PROTOBUF: - case PayloadFormat::MESSAGEPACK: // get all bytes from the send buffer (so we have room to fill it again as we POST) byteCount = 0; diff --git a/src/tests/messagepack_payload_tests.cpp b/src/tests/messagepack_payload_tests.cpp deleted file mode 100644 index 1aff7022e..000000000 --- a/src/tests/messagepack_payload_tests.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include -#include -#include - -#include "commands/commands.h" -#include "payload/messagepack.h" - -namespace messagepack = openxc::payload::messagepack; - -using openxc::commands::validate; - -void setup() { -} - -START_TEST (test_passthrough_request) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; - message.command_response.type = openxc_ControlCommand_Type_PASSTHROUGH; - message.command_response.status = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_passthrough_response) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; - message.command_response.type = openxc_ControlCommand_Type_PASSTHROUGH; - message.command_response.status = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - - -START_TEST (test_af_bypass_response) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; - message.command_response.type = openxc_ControlCommand_Type_ACCEPTANCE_FILTER_BYPASS; - message.command_response.status = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_af_bypass_request) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_CONTROL_COMMAND; - message.control_command.type = openxc_ControlCommand_Type_ACCEPTANCE_FILTER_BYPASS; - message.control_command.acceptance_filter_bypass_command.bus = 1; - message.control_command.acceptance_filter_bypass_command.bypass = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_payload_format_response) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; - message.command_response.type = openxc_ControlCommand_Type_PAYLOAD_FORMAT; - message.command_response.status = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_payload_format_request) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_CONTROL_COMMAND; - message.control_command.type = openxc_ControlCommand_Type_PAYLOAD_FORMAT; - message.control_command.payload_format_command.format = openxc_PayloadFormatCommand_PayloadFormat_MESSAGEPACK; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); - message.control_command.payload_format_command.format = openxc_PayloadFormatCommand_PayloadFormat_MESSAGEPACK; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_predefined_obd2_requests_response) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_COMMAND_RESPONSE; - message.command_response.type = openxc_ControlCommand_Type_PREDEFINED_OBD2_REQUESTS; - message.command_response.status = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_predefined_obd2_requests_request) -{ - openxc_VehicleMessage message = openxc_VehicleMessage(); // Zero Fill - message.type = openxc_VehicleMessage_Type_CONTROL_COMMAND; - message.control_command.type = openxc_ControlCommand_Type_PREDEFINED_OBD2_REQUESTS; - message.control_command.predefined_obd2_requests_command.enabled = true; - uint8_t payload[256] = {0}; - ck_assert(messagepack::serialize(&message, payload, sizeof(payload)) > 0); -} -END_TEST - -START_TEST (test_deserialize_can_message_write) -{ - //{"bus": 1,"id": 42,"data":"0x1234"}; - uint8_t rawRequest[21] = { - 0x83, 0xA3, 0x62, 0x75, 0x73, 0xCC, 0x01, 0xA2, - 0x69, 0x64, 0xCC, 0x2A, 0xA4, 0x64, 0x61, 0x74, - 0x61, 0xC4, 0x02, 0x12, 0x34 - }; - openxc_VehicleMessage deserialized = openxc_VehicleMessage(); // Zero Fill - messagepack::deserialize(rawRequest, sizeof(rawRequest), &deserialized); - ck_assert(validate(&deserialized)); -} -END_TEST - -START_TEST (test_deserialize_can_message_write_with_format) -{ - //{"bus": 1,"id": 42,"data":"0x1234","frame_format":"standard"} - uint8_t rawRequest[43] = { - 0x84, 0xA3, 0x62, 0x75, 0x73, 0xCC, 0x01, 0xA2, - 0x69, 0x64, 0xCC, 0x2A, 0xA4, 0x64, 0x61, 0x74, - 0x61, 0xC4, 0x02, 0x12, 0x34, 0xAC, 0x66, 0x72, - 0x61, 0x6D, 0x65, 0x5F, 0x66, 0x6F, 0x72, 0x6D, - 0x61, 0x74, 0xA8, 0x73, 0x74, 0x61, 0x6E, 0x64, - 0x61, 0x72, 0x64 - }; - openxc_VehicleMessage deserialized = openxc_VehicleMessage(); // Zero Fill - messagepack::deserialize(rawRequest, sizeof(rawRequest), &deserialized); - ck_assert(validate(&deserialized)); - ck_assert_int_eq(openxc_CanMessage_FrameFormat_STANDARD, - deserialized.can_message.frame_format); -} -END_TEST - -START_TEST (test_deserialize_message_after_junk) -{ - - //garbagebytes..{"bus": 1,"id": 42,"data":"0x1234"} - uint8_t rawRequest[25] = { - 0x01, 0x02, 0x03, 0x04, 0x83, 0xA3, 0x62, 0x75, 0x73, 0xCC, 0x01, 0xA2, - 0x69, 0x64, 0xCC, 0x2A, 0xA4, 0x64, 0x61, 0x74, - 0x61, 0xC4, 0x02, 0x12, 0x34 - }; - //Message pack payload format will just read the junk bytes ahead of the message and ignore it - openxc_VehicleMessage deserialized = openxc_VehicleMessage(); // Zero Fill - ck_assert_int_eq(25, messagepack::deserialize(rawRequest, sizeof(rawRequest), &deserialized)); - ck_assert(validate(&deserialized)); -} -END_TEST - - -Suite* suite(void) { - Suite* s = suite_create("messagepack_payload"); - TCase *tc_msgpck_payload = tcase_create("messagepack_payload"); - tcase_add_checked_fixture(tc_msgpck_payload, setup, NULL); - tcase_add_test(tc_msgpck_payload, test_passthrough_request); - tcase_add_test(tc_msgpck_payload, test_passthrough_response); - tcase_add_test(tc_msgpck_payload, test_af_bypass_response); - tcase_add_test(tc_msgpck_payload, test_af_bypass_request); - tcase_add_test(tc_msgpck_payload, test_payload_format_response); - tcase_add_test(tc_msgpck_payload, test_payload_format_request); - tcase_add_test(tc_msgpck_payload, test_predefined_obd2_requests_response); - tcase_add_test(tc_msgpck_payload, test_predefined_obd2_requests_request); - tcase_add_test(tc_msgpck_payload, test_deserialize_can_message_write); - tcase_add_test(tc_msgpck_payload, test_deserialize_can_message_write_with_format); - tcase_add_test(tc_msgpck_payload, test_deserialize_message_after_junk); - suite_add_tcase(s, tc_msgpck_payload); - return s; -} - -int main(void) { - - int numberFailed; - Suite* s = suite(); - SRunner *sr = srunner_create(s); - // Don't fork so we can actually use gdb - srunner_set_fork_status(sr, CK_NOFORK); - srunner_run_all(sr, CK_NORMAL); - numberFailed = srunner_ntests_failed(sr); - srunner_free(sr); - return (numberFailed == 0) ? 0 : 1; -} diff --git a/src/tests/tests.mk b/src/tests/tests.mk index aa2ab99d7..4d7a0f56a 100644 --- a/src/tests/tests.mk +++ b/src/tests/tests.mk @@ -65,7 +65,6 @@ test_long: test_short @make usb_raw_write_compile_test @make bluetooth_raw_write_compile_test @make binary_output_compile_test - @make messagepack_output_compile_test @make emulator_compile_test @make msd_emulator_compile_test @make stats_compile_test @@ -139,7 +138,6 @@ $(eval $(call ALL_PLATFORMS_TEST_TEMPLATE, debug_stats_compile_test, DEBUG=1 DEF $(eval $(call ALL_PLATFORMS_TEST_TEMPLATE, usb_raw_write_compile_test, DEBUG=0 DEFAULT_ALLOW_RAW_WRITE_USB=0, code_generation_test)) $(eval $(call ALL_PLATFORMS_TEST_TEMPLATE, bluetooth_raw_write_compile_test, DEBUG=0 DEFAULT_ALLOW_RAW_WRITE_UART=1, code_generation_test)) $(eval $(call ALL_PLATFORMS_TEST_TEMPLATE, binary_output_compile_test, DEBUG=0 DEFAULT_OUTPUT_FORMAT=PROTOBUF, code_generation_test)) -$(eval $(call ALL_PLATFORMS_TEST_TEMPLATE, messagepack_output_compile_test, DEBUG=0 DEFAULT_OUTPUT_FORMAT=MESSAGEPACK, code_generation_test)) copy_passthrough_signals: @echo "Testing example passthrough config in repo for FORDBOARD..." From 3f234e274a7cc32df8ff12bf97682e8756e2c995 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 26 Oct 2020 20:24:22 +0000 Subject: [PATCH 25/48] timestamp unit tests fixed --- src/payload/json.cpp | 2 +- src/tests/canread_tests.cpp | 31 +++++++++++++++---------------- src/tests/diagnostics_tests.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/payload/json.cpp b/src/payload/json.cpp index 69bc27591..1bcba802b 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -623,7 +623,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) { diff --git a/src/tests/canread_tests.cpp b/src/tests/canread_tests.cpp index 6ce8ebb50..8bd1b9627 100644 --- a/src/tests/canread_tests.cpp +++ b/src/tests/canread_tests.cpp @@ -138,7 +138,7 @@ START_TEST (test_send_numerical) uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1]; QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; - ck_assert_str_eq((char*)snapshot, "{\"timestamp\":0,\"name\":\"test\",\"value\":42}\0"); + ck_assert_str_eq((char*)snapshot, "{\"name\":\"test\",\"value\":42}\0"); } END_TEST @@ -153,7 +153,7 @@ START_TEST (test_preserve_float_precision) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":42.500000}\0"); + "{\"name\":\"test\",\"value\":42.500000}\0"); } END_TEST @@ -167,7 +167,7 @@ START_TEST (test_send_boolean) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":false}\0"); + "{\"name\":\"test\",\"value\":false}\0"); } END_TEST @@ -181,7 +181,7 @@ START_TEST (test_send_string) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":\"string\"}\0"); + "{\"name\":\"test\",\"value\":\"string\"}\0"); } END_TEST @@ -204,7 +204,7 @@ START_TEST (test_send_evented_boolean) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":\"value\",\"event\":false}\0"); + "{\"name\":\"test\",\"value\":\"value\",\"event\":false}\0"); } END_TEST @@ -227,7 +227,7 @@ START_TEST (test_send_evented_string) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":\"value\",\"event\":\"event\"}\0"); + "{\"name\":\"test\",\"value\":\"value\",\"event\":\"event\"}\0"); } END_TEST @@ -249,7 +249,7 @@ START_TEST (test_send_evented_float) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"test\",\"value\":\"value\",\"event\":43}\0"); + "{\"name\":\"test\",\"value\":\"value\",\"event\":43}\0"); } END_TEST @@ -315,7 +315,7 @@ START_TEST (test_passthrough_message) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"bus\":1,\"id\":42,\"data\":\"0x123456789abcdef1\"}\0"); + "{\"bus\":1,\"id\":42,\"data\":\"0x123456789abcdef1\"}\0"); } END_TEST @@ -354,7 +354,7 @@ START_TEST (test_default_decoder) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"torque_at_transmission\",\"value\":-19990}\0"); + "{\"name\":\"torque_at_transmission\",\"value\":-19990}\0"); } END_TEST @@ -383,12 +383,11 @@ START_TEST (test_translate_many_signals) } fail_unless(USB_PROCESSED); // 8 signals sent - depends on queue size - //ck_assert_int_eq(11 * 34 + 2, SENT_BYTES); // Protobuff 2 result - ck_assert_int_eq(676, SENT_BYTES); + ck_assert_int_eq(11 * 34 + 2, SENT_BYTES); // 1 in the output queue fail_if(queueEmpty()); //ck_assert_int_eq(1 * 34, QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE)); // Protobuff 2 result - ck_assert_int_eq(96, QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE)); + ck_assert_int_eq(170, QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE)); } END_TEST @@ -406,7 +405,7 @@ START_TEST (test_translate_float) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"torque_at_transmission\",\"value\":42}\0"); + "{\"name\":\"torque_at_transmission\",\"value\":42}\0"); } END_TEST @@ -465,7 +464,7 @@ START_TEST (test_translate_string) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"torque_at_transmission\",\"value\":\"foo\"}\0"); + "{\"name\":\"torque_at_transmission\",\"value\":\"foo\"}\0"); } END_TEST @@ -549,7 +548,7 @@ START_TEST (test_preserve_last_value) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"torque_at_transmission\",\"value\":-19990}\0"); + "{\"name\":\"torque_at_transmission\",\"value\":-19990}\0"); } END_TEST @@ -566,7 +565,7 @@ START_TEST (test_dont_send_same) QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; ck_assert_str_eq((char*)snapshot, - "{\"timestamp\":0,\"name\":\"brake_pedal_status\",\"value\":true}\0"); + "{\"name\":\"brake_pedal_status\",\"value\":true}\0"); QUEUE_INIT(uint8_t, OUTPUT_QUEUE); can::read::translateSignal(testSignal, diff --git a/src/tests/diagnostics_tests.cpp b/src/tests/diagnostics_tests.cpp index 8c33f556a..20d7cf994 100644 --- a/src/tests/diagnostics_tests.cpp +++ b/src/tests/diagnostics_tests.cpp @@ -282,7 +282,7 @@ START_TEST (test_add_basic_request) uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1]; QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; - ck_assert_str_eq((char*)snapshot, "{\"timestamp\":0,\"bus\":1,\"id\":2016,\"mode\":1,\"success\":true,\"pid\":2,\"payload\":\"0x45\"}\0"); + ck_assert_str_eq((char*)snapshot, "{\"bus\":1,\"id\":2016,\"mode\":1,\"success\":true,\"pid\":2,\"payload\":\"0x45\"}\0"); } END_TEST @@ -374,7 +374,7 @@ START_TEST (test_add_request_other_bus) uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1]; QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; - ck_assert_str_eq((char*)snapshot, "{\"timestamp\":0,\"name\":\"mypid\",\"value\":69}\0"); + ck_assert_str_eq((char*)snapshot, "{\"name\":\"mypid\",\"value\":69}\0"); } END_TEST @@ -391,7 +391,7 @@ START_TEST (test_add_request_with_name) uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1]; QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; - ck_assert_str_eq((char*)snapshot, "{\"timestamp\":0,\"name\":\"mypid\",\"value\":69}\0"); + ck_assert_str_eq((char*)snapshot, "{\"name\":\"mypid\",\"value\":69}\0"); } END_TEST @@ -466,7 +466,7 @@ START_TEST (test_add_request_with_name_and_decoder) uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1]; QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot)); snapshot[sizeof(snapshot) - 1] = NULL; - ck_assert_str_eq((char*)snapshot, "{\"timestamp\":0,\"name\":\"mypid\",\"value\":138}\0"); + ck_assert_str_eq((char*)snapshot, "{\"name\":\"mypid\",\"value\":138}\0"); } END_TEST From 07f67b8d8a1c260db8e1ebc0c9c4d1f1ff0525c5 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 10 Nov 2020 17:42:57 +0000 Subject: [PATCH 26/48] Removed commented out lines that were no longer needed --- src/payload/json.cpp | 49 -------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/src/payload/json.cpp b/src/payload/json.cpp index 81987fac4..494b8cb36 100644 --- a/src/payload/json.cpp +++ b/src/payload/json.cpp @@ -106,55 +106,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; From 7d7f1cdeb21b89053920b7d9fa2bdbf9f53ee5cc Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 5 Jan 2021 17:03:47 +0000 Subject: [PATCH 27/48] refactor major code smells defined in sonarqube. --- src/platform/pic32/blueNRG.c | 12 +- src/platform/pic32/telit_he910.cpp | 172 ++++++++--------------------- 2 files changed, 58 insertions(+), 126 deletions(-) diff --git a/src/platform/pic32/blueNRG.c b/src/platform/pic32/blueNRG.c index 45af47d5e..bb4cb1e89 100644 --- a/src/platform/pic32/blueNRG.c +++ b/src/platform/pic32/blueNRG.c @@ -179,8 +179,11 @@ static int16_t SPI_Write(uint8_t* data1, uint8_t* data2, uint16_t Nb_bytes1, uin SPI_SendRecieve(STBTLE_SPICHANNEL, header_master, header_slave, 5); if(header_slave[0] != 0x02){ - result = -1; - goto failed; // BlueNRG not awake. + result = -1; + // Release CS line + SPI_CS_SetHigh(STBTLE_SPICHANNEL); + + return result;// BlueNRG not awake. } rx_bytes = header_slave[1]; @@ -188,7 +191,10 @@ static int16_t SPI_Write(uint8_t* data1, uint8_t* data2, uint16_t Nb_bytes1, uin if(rx_bytes < Nb_bytes1) { result = -2; - goto failed; // underflow + // Release CS line + SPI_CS_SetHigh(STBTLE_SPICHANNEL); + + return result;// underflow. } SPI_SendRecieve(STBTLE_SPICHANNEL, data1, NULL, Nb_bytes1); diff --git a/src/platform/pic32/telit_he910.cpp b/src/platform/pic32/telit_he910.cpp index 2635deaef..33e73108b 100644 --- a/src/platform/pic32/telit_he910.cpp +++ b/src/platform/pic32/telit_he910.cpp @@ -581,11 +581,8 @@ bool openxc::telitHE910::saveSettings() { if(sendCommand(telitDevice, "AT&W0\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -597,11 +594,8 @@ bool openxc::telitHE910::setBaud(unsigned int baudRate) { sprintf(command, "AT+IPR=%u\r\n", baudRate); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -611,15 +605,12 @@ bool openxc::telitHE910::getDeviceFirmwareVersion(char* firmwareVersion) { if(sendCommand(telitDevice, "AT+CGMR\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("AT+CGMR\r\n\r\n", "\r\n\r\nOK\r\n", firmwareVersion, 31) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -630,16 +621,14 @@ bool openxc::telitHE910::getSIMStatus(unsigned int* status) { if(sendCommand(telitDevice, "AT#QSS?\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("#QSS: ", "\r\n\r\n", temp, 7) == false) { rc = false; - goto fcn_exit; + return rc; } *status = atoi(&temp[2]); - - fcn_exit: - return rc; + } @@ -649,15 +638,12 @@ bool openxc::telitHE910::getICCID(char* ICCID) { if(sendCommand(telitDevice, "AT#CCID\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("#CCID: ", "\r\n\r\n", ICCID, 31) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -667,15 +653,12 @@ bool openxc::telitHE910::getDeviceIMEI(char* IMEI) { if(sendCommand(telitDevice, "AT+CGSN\r\n", "\r\n\r\nOK\r\n", 2000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("AT+CGSN\r\n\r\n", "\r\n\r\nOK\r\n", IMEI, 31) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return true; } @@ -724,12 +707,9 @@ bool openxc::telitHE910::setNetworkConnectionMode(OperatorSelectMode mode, Netwo if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - fcn_exit: - return rc; - } bool openxc::telitHE910::getNetworkConnectionStatus(NetworkConnectionStatus* status) { @@ -739,16 +719,13 @@ bool openxc::telitHE910::getNetworkConnectionStatus(NetworkConnectionStatus* sta if(sendCommand(telitDevice, "AT+CREG?\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("+CREG: ", "\r\n\r\nOK\r\n", temp, 7) == false) { rc = false; - goto fcn_exit; + return rc; } *status = (NetworkConnectionStatus)atoi(&temp[2]); - - fcn_exit: - return rc; } @@ -762,11 +739,11 @@ bool openxc::telitHE910::getCurrentNetwork(NetworkDescriptor* network) { if(sendCommand(telitDevice, "AT+COPS?\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("+COPS: ", "\r\n\r\nOK\r\n", temp, 31) == false) { rc = false; - goto fcn_exit; + return rc; } if(p = strchr(temp, ','), p) { p++; @@ -779,9 +756,6 @@ bool openxc::telitHE910::getCurrentNetwork(NetworkDescriptor* network) { } } } - - fcn_exit: - return rc; } @@ -793,11 +767,8 @@ bool openxc::telitHE910::configurePDPContext(NetworkDataSettings dataSettings) { sprintf(command,"AT+CGDCONT=1,\"IP\",\"%s\"\r\n", dataSettings.APN); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -808,18 +779,15 @@ bool openxc::telitHE910::configureSocket(unsigned int socketNumber, SocketConnec if(socketNumber == 0 || socketNumber > 6) { rc = false; - goto fcn_exit; + return rc; } sprintf(command,"AT#SCFG=%u,1,%u,%u,%u,%u\r\n", socketNumber, socketSettings.packetSize, socketSettings.idleTimeout, socketSettings.connectTimeout, socketSettings.txFlushTimer); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -829,11 +797,8 @@ bool openxc::telitHE910::openPDPContext() { if(sendCommand(telitDevice, "AT#SGACT=1,1\r\n", "\r\n\r\nOK\r\n", "ERROR", 30000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -843,11 +808,8 @@ bool openxc::telitHE910::closePDPContext() { if(sendCommand(telitDevice, "AT#SGACT=1,0\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -858,16 +820,13 @@ bool openxc::telitHE910::getPDPContext(bool* connected) { if(sendCommand(telitDevice, "AT#SGACT?\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("#SGACT: 1,", "\r\n\r\nOK\r\n", temp, 31) == false) { rc = false; - goto fcn_exit; + return rc; } *connected = (bool)atoi(temp); - - fcn_exit: - return rc; } @@ -879,12 +838,9 @@ bool openxc::telitHE910::openSocket(unsigned int socketNumber, ServerConnectSett sprintf(command,"AT#SD=%u,0,%u,\"%s\",255,1,1\r\n", socketNumber, serverSettings.port, serverSettings.host); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", "ERROR", 15000) == false) { rc = false; - goto fcn_exit; + return rc; } - fcn_exit: - return rc; - } bool openxc::telitHE910::isSocketOpen(unsigned int socketNumber) { @@ -907,12 +863,9 @@ bool openxc::telitHE910::closeSocket(unsigned int socketNumber) { sprintf(command,"AT#SH=%u\r\n", socketNumber); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", "ERROR", 5000) == false) { rc = false; - goto fcn_exit; + return rc; } - fcn_exit: - return rc; - } bool openxc::telitHE910::getSocketStatus(unsigned int socketNumber, SocketStatus* status) { @@ -924,16 +877,13 @@ bool openxc::telitHE910::getSocketStatus(unsigned int socketNumber, SocketStatus sprintf(command, "AT#SS=%u\r\n", socketNumber); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("#SS: ", "\r\n\r\nOK\r\n", temp, 7) == false) { rc = false; - goto fcn_exit; + return rc; } *status = (SocketStatus)atoi(&temp[2]); - - fcn_exit: - return rc; } @@ -965,7 +915,7 @@ bool openxc::telitHE910::writeSocket(unsigned int socketNumber, char* data, unsi sprintf(command, "AT#SSENDEXT=%u,%u\r\n", socketNumber, maxWrite); if(sendCommand(telitDevice, command, "> ", 5000) == false) { rc = false; - goto fcn_exit; + return rc; } // clear the receive buffer @@ -987,7 +937,7 @@ bool openxc::telitHE910::writeSocket(unsigned int socketNumber, char* data, unsi } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } @@ -1002,15 +952,12 @@ bool openxc::telitHE910::writeSocket(unsigned int socketNumber, char* data, unsi } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } // update write count *len = maxWrite; - - fcn_exit: - return rc; } @@ -1034,7 +981,7 @@ bool openxc::telitHE910::readSocket(unsigned int socketNumber, char* data, unsig sprintf(reply, "#SRECV: %u,", socketNumber); if(sendCommand(telitDevice, command, reply, 1000) == false) { rc = false; - goto fcn_exit; + return rc; } // start the receive timer @@ -1044,7 +991,7 @@ bool openxc::telitHE910::readSocket(unsigned int socketNumber, char* data, unsig pS = recv_data; if(pS = strstr(pS, reply), !pS) { rc = false; - goto fcn_exit; + return rc; } pS += 10; pRx = pS; @@ -1059,7 +1006,7 @@ bool openxc::telitHE910::readSocket(unsigned int socketNumber, char* data, unsig } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } // get the read count @@ -1078,7 +1025,7 @@ bool openxc::telitHE910::readSocket(unsigned int socketNumber, char* data, unsig } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } // put the read data into caller @@ -1096,13 +1043,10 @@ bool openxc::telitHE910::readSocket(unsigned int socketNumber, char* data, unsig } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } - fcn_exit: - return rc; - } bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, unsigned int* len) { @@ -1125,7 +1069,7 @@ bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, un sprintf(reply, "#SRECV: %u,", socketNumber); if(sendCommand(telitDevice, command, reply, 1000) == false) { rc = false; - goto fcn_exit; + return rc; } // start the receive timer @@ -1135,7 +1079,7 @@ bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, un pS = recv_data; if(pS = strstr(pS, reply), !pS) { rc = false; - goto fcn_exit; + return rc; } pS += 10; pRx = pS; @@ -1150,7 +1094,7 @@ bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, un } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } // get the read count @@ -1169,7 +1113,7 @@ bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, un } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } // put the read data into caller @@ -1187,13 +1131,10 @@ bool openxc::telitHE910::readSocketOne(unsigned int socketNumber, char* data, un } if(uptimeMs() >= timer) { rc = false; - goto fcn_exit; + return rc; } } - fcn_exit: - return rc; - } /*SEND/RECEIVE*/ @@ -1300,17 +1241,14 @@ static bool getResponse(const char* startToken, const char* stopToken, char* res if(p1 = strstr(recv_data, startToken), !p1) { rc = false; - goto fcn_exit; + return rc; } if(p2 = strstr(recv_data, stopToken), !p2) { rc = false; - goto fcn_exit; + return rc; } p1 += strlen(startToken); memcpy(response, p1, (maxLen < p2-p1) ? (maxLen) : (p2-p1)); - - fcn_exit: - return rc; } @@ -1371,11 +1309,8 @@ bool openxc::telitHE910::setGPSPowerState(bool enable) { sprintf(command, "AT$GPSP=%u\r\n", (unsigned int)enable); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } - - fcn_exit: - return rc; } @@ -1388,16 +1323,13 @@ bool openxc::telitHE910::getGPSPowerState(bool* enable) { sprintf(command, "AT$GPSP?\r\n"); if(sendCommand(telitDevice, command, "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("$GPSP: ", "\r\n\r\nOK\r\n", temp, 7) == false) { rc = false; - goto fcn_exit; + return rc; } *enable = (bool)atoi(&temp[0]); - - fcn_exit: - return rc; } @@ -1408,26 +1340,23 @@ bool openxc::telitHE910::getGPSLocation() { static unsigned long next_update = 0; if(uptimeMs() < next_update) { - goto fcn_exit; + return rc; } // retrieve the GPS location string from the modem if(sendCommand(telitDevice, "AT$GPSACP\r\n", "\r\n\r\nOK\r\n", 1000) == false) { rc = false; - goto fcn_exit; + return rc; } if(getResponse("$GPSACP: ", "\r\n\r\nOK\r\n", temp, 127) == false) { rc = false; - goto fcn_exit; + return rc; } // now we have the GPS string in 'temp', send to parser to publish signals rc = parseGPSACP(temp); next_update = uptimeMs() + getConfiguration()->telit->config.globalPositioningSettings.gpsInterval; - - fcn_exit: - return rc; } @@ -1479,7 +1408,7 @@ static bool parseGPSACP(const char* GPSACP) { for(i = 0; i < 10; ++i) { if(p2 = strchr(p1, ','), !p2) { rc = false; - goto fcn_exit; + return rc; } memcpy(&splitString[i][0], p1, p2-p1); validString[i] = (p2-p1 > 0) ? true : false; @@ -1560,9 +1489,6 @@ static bool parseGPSACP(const char* GPSACP) { field_value_numerical = atof(&splitString[10][0]); publishGPSSignal("gps_nsat", field_value_numerical, pipeline); } - - fcn_exit: - return rc; } /*PIPELINE*/ From a388e7fb66f46e44912a6b0c09523e7bd10d7ad8 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:18:00 -0500 Subject: [PATCH 28/48] Initial Github Actions testing for vagrant --- .github/workflows/run-tests.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 000000000..00612d976 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,23 @@ +# This is a basic workflow to help you get started with Actions + +name: Run Tests + +# Controls when the action will run. +on: [pull_request] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Vagrant Up + run: | + vagrant up From d1b829f1a113893c7715004033e8cd781bea3455 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:27:44 -0500 Subject: [PATCH 29/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 00612d976..405554fd0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,6 +16,11 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Install vagrant + run: | + sudo apt-get install vagrant # Runs a single command using the runners shell - name: Vagrant Up From 5faed181bf176b37f0035d89b490e87af8a18d04 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:29:59 -0500 Subject: [PATCH 30/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 405554fd0..cf59b34ea 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,7 +20,8 @@ jobs: # Runs a single command using the runners shell - name: Install vagrant run: | - sudo apt-get install vagrant + sudo apt-get update -qq + sudo apt-get install vagrant -qq -y # Runs a single command using the runners shell - name: Vagrant Up From f2fbdb45251f1ffedd6b4de90f81e1a03237fe26 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:40:34 -0500 Subject: [PATCH 31/48] Try manual setup --- .github/workflows/run-tests.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index cf59b34ea..e25539792 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,12 +18,21 @@ jobs: - uses: actions/checkout@v2 # Runs a single command using the runners shell - - name: Install vagrant + - name: Set Up Python 3.6 run: | sudo apt-get update -qq - sudo apt-get install vagrant -qq -y + sudo add-apt-repository ppa:deadsnakes/ppa -y + sudo apt-get update -qq + sudo apt-get install python3.6 -y + sudo rm /usr/bin/python3 + sudo ln -s /usr/bin/python3.6 /usr/bin/python3 + wget https://bootstrap.pypa.io/get-pip.py + sudo python3 get-pip.py + sudo apt-get install -qq -y libsubunit-dev # Runs a single command using the runners shell - - name: Vagrant Up + - name: Bootstrap run: | - vagrant up + script/bootstrap.sh + + From f445f2d5816486834ad29c0d11333d98bcb11d9f Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:45:04 -0500 Subject: [PATCH 32/48] Add tests --- .github/workflows/run-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e25539792..9ccee0175 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -34,5 +34,9 @@ jobs: - name: Bootstrap run: | script/bootstrap.sh + + - name: Build Tests + run: | + PLATFORM=TESTING make test From d1084f036ad2172c09466b2fd795e17b12b8eb0f Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 11:50:14 -0500 Subject: [PATCH 33/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9ccee0175..b5e54de45 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -37,6 +37,7 @@ jobs: - name: Build Tests run: | + cd src PLATFORM=TESTING make test From 73464430d0cc08d04a190ea82ed6ebe9883e5826 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 13:36:47 -0500 Subject: [PATCH 34/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b5e54de45..772edae03 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,6 +20,7 @@ jobs: # Runs a single command using the runners shell - name: Set Up Python 3.6 run: | + tput setab 0; tput clear sudo apt-get update -qq sudo add-apt-repository ppa:deadsnakes/ppa -y sudo apt-get update -qq From 491093dcaecc29b64acb4a4e0faecd16ec55b3e8 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 9 Feb 2021 13:47:25 -0500 Subject: [PATCH 35/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 772edae03..877fbc228 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,7 +20,7 @@ jobs: # Runs a single command using the runners shell - name: Set Up Python 3.6 run: | - tput setab 0; tput clear + TERM=xterm sudo apt-get update -qq sudo add-apt-repository ppa:deadsnakes/ppa -y sudo apt-get update -qq From ce15183e7ff9b55566fdb7c7679dad0ac017c39a Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 23 Feb 2021 12:38:03 -0500 Subject: [PATCH 36/48] Travis Decommission --- .travis.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 53f1e97ef..000000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: c -dist: Bionic -compiler: -- clang -script: PLATFORM=TESTING make test -install: -- gem install coveralls-lcov -before_install: -- sudo apt-get update -qq -- sudo add-apt-repository ppa:deadsnakes/ppa -y -- sudo apt-get update -qq -- sudo apt-get install python3.6 -y -- sudo rm /usr/bin/python3 -- sudo ln -s /usr/bin/python3.6 /usr/bin/python3 -- wget https://bootstrap.pypa.io/get-pip.py -- sudo python3 get-pip.py -- if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq -y libsubunit-dev; fi -- travis_wait script/bootstrap.sh -- cd src -after_success: -- PLATFORM=TESTING make coverage -- coveralls-lcov build/tests/coverage.info -before_deploy: echo "n" | fab release:skip_tests=True -deploy: - provider: releases - api_key: - secure: NOSHkTeRCfYcfW6ft8/5xOsEmn0DFrfvJL0UFsDQ9f0dBPoXPMJpgbXr+0i4wbMvwIgAKmJ2SfgvIBcm8IWXhLSMsZiaaTvrbomNgqI8ZIghBdSe6GARaiF/9V/A5l/8zCVMs65Kpo1BssC0BiESpIgoOR/aeF5J6TmCIbUe03k= - skip_cleanup: true - file_glob: true - file: "./release/openxc-vi-firmware-v*.*.*.zip" - on: - repo: openxc/vi-firmware - tags: true From 89e5c64e18514f40854ad69c22f91f248c2ea48c Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 23 Feb 2021 13:44:40 -0500 Subject: [PATCH 37/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 877fbc228..096ecebb4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -30,6 +30,8 @@ jobs: wget https://bootstrap.pypa.io/get-pip.py sudo python3 get-pip.py sudo apt-get install -qq -y libsubunit-dev + sudo apt-get install python-apt + sudo apt-get install python3-apt # Runs a single command using the runners shell - name: Bootstrap From 58ed8fcc64398ac2c311874aba9205ef722b4ee4 Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Tue, 23 Feb 2021 13:48:23 -0500 Subject: [PATCH 38/48] Update run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 096ecebb4..0e45fe1fd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 # Steps represent a sequence of tasks that will be executed as part of the job steps: From d319780da05bffc1e67f612143dec10864897174 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 1 Mar 2021 22:05:34 +0000 Subject: [PATCH 39/48] Fix for 7DF Broadcast message --- src/diagnostics.cpp | 9 ++++++--- src/libs/uds-c | 2 +- src/platform/lpc17xx/canread.cpp | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/diagnostics.cpp b/src/diagnostics.cpp index f4d586162..96bb66641 100644 --- a/src/diagnostics.cpp +++ b/src/diagnostics.cpp @@ -294,7 +294,9 @@ static openxc_VehicleMessage wrapDiagnosticResponseWithSabot(CanBus* bus, return message; } -static int prevFrame = -1; +void dumpPayload2(unsigned char *, size_t); + +static int prevFrames[] = {-1,-1,-1,-1,-1,-1,-1,-1}; // 7e8-7ef static openxc_VehicleMessage wrapDiagnosticStitchResponseWithSabot(CanBus* bus, const ActiveDiagnosticRequest* request, const DiagnosticResponse* response, openxc_DynamicField value) { @@ -319,13 +321,14 @@ static openxc_VehicleMessage wrapDiagnosticStitchResponseWithSabot(CanBus* bus, message.diagnostic_response.negative_response_code = response->negative_response_code; - message.diagnostic_response.frame = prevFrame + 1; + int frame_offset = (response->arbitration_id - 0x07e8) & 0x7; // Prevent overflow + message.diagnostic_response.frame = prevFrames[frame_offset] + 1; if (response->completed) { message.diagnostic_response.frame = -1; // Marks the last frame in the response } else { message.diagnostic_response.success = true; } - prevFrame = message.diagnostic_response.frame; + prevFrames[frame_offset] = message.diagnostic_response.frame; if(response->payload_length > 0) { if (request->decoder != NULL) { diff --git a/src/libs/uds-c b/src/libs/uds-c index ac44c3702..23755ebc1 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit ac44c370233ce71062d671eb586beb242ac1de6f +Subproject commit 23755ebc12b1e28b779060292f71deea411cce30 diff --git a/src/platform/lpc17xx/canread.cpp b/src/platform/lpc17xx/canread.cpp index 717004c7a..5a381e182 100644 --- a/src/platform/lpc17xx/canread.cpp +++ b/src/platform/lpc17xx/canread.cpp @@ -30,8 +30,8 @@ extern "C" { void CAN_IRQHandler() { for(int i = 0; i < getCanBusCount(); i++) { CanBus* bus = &getCanBuses()[i]; - if((CAN_IntGetStatus(CAN_CONTROLLER(bus)) & 0x01) == 1) { - CanMessage message = receiveCanMessage(bus); + CanMessage message = receiveCanMessage(bus); + if(((CAN_IntGetStatus(CAN_CONTROLLER(bus)) & 0x01) == 1) || (message.format == CanMessageFormat::STANDARD)) { if(shouldAcceptMessage(bus, message.id) && !QUEUE_PUSH(CanMessage, &bus->receiveQueue, message)) { // An exception to the "don't leave commented out code" rule, From 73a0ce2e40d557aa4de1bce2a65cb58e689fa9b1 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 2 Mar 2021 19:40:12 +0000 Subject: [PATCH 40/48] Updated UDS-C lib reference --- src/libs/uds-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/uds-c b/src/libs/uds-c index 23755ebc1..d2790b86f 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit 23755ebc12b1e28b779060292f71deea411cce30 +Subproject commit d2790b86f9a81b08824a9bf19a9c2006dfc6e229 From 53d088c71d4a6a998c69d7c8e8095c9218007605 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 29 Jun 2021 19:41:45 +0000 Subject: [PATCH 41/48] Updated lasted dependencies --- src/libs/openxc-message-format | 2 +- src/libs/uds-c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index 95672efd8..b08ac1c7e 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit 95672efd8ed1c859b0d63c0df971ffba88b39216 +Subproject commit b08ac1c7e20d7c7caac5b86785acb07be301f36f diff --git a/src/libs/uds-c b/src/libs/uds-c index 59618bbae..fbe7b6bd8 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit 59618bbae717b2e814c481e6b70f27ef9dce2713 +Subproject commit fbe7b6bd894adb36174bae73fc3111da4ca5b246 From d2a34b1bd2c44806042da5ca702bb8294b8fcc19 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Thu, 8 Jul 2021 18:58:13 +0000 Subject: [PATCH 42/48] Updaded submodule dependency bitfield-c --- src/libs/uds-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/uds-c b/src/libs/uds-c index fbe7b6bd8..689d5418a 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit fbe7b6bd894adb36174bae73fc3111da4ca5b246 +Subproject commit 689d5418ab6e231d7945560996bc4c590a2f4a24 From c845cb1698abd5dc266869900fb1712ce309aa5d Mon Sep 17 00:00:00 2001 From: pjt0620 Date: Thu, 29 Jul 2021 17:02:28 -0400 Subject: [PATCH 43/48] Fix for bootstrap failure fixed error installing python cryptography that was causing bootstrap to fail. --- script/bootstrap/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/bootstrap/common.sh b/script/bootstrap/common.sh index 727149189..047f7d61b 100644 --- a/script/bootstrap/common.sh +++ b/script/bootstrap/common.sh @@ -234,6 +234,7 @@ pre-configured Vagrant environment. See the docs for more information." if ! command -v pip3 >/dev/null 2>&1; then _install python3-pip $SUDO_CMD ln -s /usr/bin/pip3 /usr/bin/pip + $SUDO_CMD pip install --upgrade pip fi PIP_SUDO_CMD= From b208675155ec10fce24efc3d337fd7e4bdfaf0e6 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Mon, 9 Aug 2021 20:21:40 +0000 Subject: [PATCH 44/48] Updated dependency to master version of release UDS-C library --- src/libs/uds-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/uds-c b/src/libs/uds-c index 689d5418a..e56aeb9c8 160000 --- a/src/libs/uds-c +++ b/src/libs/uds-c @@ -1 +1 @@ -Subproject commit 689d5418ab6e231d7945560996bc4c590a2f4a24 +Subproject commit e56aeb9c884ccbdbe73e1630942f8c0d17e27498 From 043b9d621c1f386862b07af104e7acac14376c48 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Tue, 10 Aug 2021 20:41:28 +0000 Subject: [PATCH 45/48] Fixed fabfile to properly set msd enable --- fabfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fabfile.py b/fabfile.py index 276ba8d41..44b0f5b24 100644 --- a/fabfile.py +++ b/fabfile.py @@ -176,8 +176,8 @@ def compile_firmware(build_name, target_path): env.firmware_release, board['extension'])) for board_name, board in env.msd_boards.items(): - msd_enable() env.board = board_name + msd_enable() build(capture=True, do_clean=True) local("cp build/%s/vi-firmware-%s.%s %s/vi-%s-firmware-%s-msd-ct%s.%s" % (board['name'], board['name'], board['extension'], From 49efdec23e5dff6bffd6295994d4425738a9da3f Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Wed, 11 Aug 2021 15:03:19 +0000 Subject: [PATCH 46/48] Updated 8.2.0 release version numbers and release notes --- CHANGELOG.mkd | 5 +++++ README.rst | 2 +- docs/conf.py | 4 ++-- docs/index.rst | 2 +- script/bootstrap/ci-requirements.txt | 2 +- script/bootstrap/pip-requirements.txt | 2 +- src/config.cpp | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd index 1bc37c254..c2127afa5 100644 --- a/CHANGELOG.mkd +++ b/CHANGELOG.mkd @@ -1,6 +1,11 @@ # OpenXC Vehicle Interface Firmware Changelog ## v8.2.0 * Removed: Removed messagepack format support +* Feature: get_vin command added and is accessible from openxc-control python and from Android and iOS clients +* Update: Improvements to diagnostic response communication +* Update: sonarqube support updates +* Build: build moved from travis to github actions for Travis decommision +* Fix: 7DF Broadcast messaging ## 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. diff --git a/README.rst b/README.rst index e93e1a5a7..dfeaa8e41 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /docs/_static/logo.png -:Version: 8.1.0 +:Version: 8.2.0 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/docs/conf.py b/docs/conf.py index 2a5ea75de..91db5263f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,9 +49,9 @@ # built documents. # # The short X.Y version. -version = '8.1.0' +version = '8.2.0' # The full version, including alpha/beta/rc tags. -release = '8.1.0' +release = '8.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index 8c86c094e..5211635fb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /_static/logo.png -:Version: 8.1.0 +:Version: 8.2.0 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/script/bootstrap/ci-requirements.txt b/script/bootstrap/ci-requirements.txt index 27d3e1c7a..7d69e878c 100644 --- a/script/bootstrap/ci-requirements.txt +++ b/script/bootstrap/ci-requirements.txt @@ -1 +1 @@ -openxc==2.1.0 +openxc==2.2.0 diff --git a/script/bootstrap/pip-requirements.txt b/script/bootstrap/pip-requirements.txt index e0e6c0b44..79a8a16bb 100644 --- a/script/bootstrap/pip-requirements.txt +++ b/script/bootstrap/pip-requirements.txt @@ -2,4 +2,4 @@ Fabric3==1.14.post1 ecdsa==0.13.3 prettyprint==0.1.5 pyparsing==2.2.0 -openxc==2.0.0 +openxc==2.2.0 diff --git a/src/config.cpp b/src/config.cpp index dda541e22..ac13011ce 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -118,7 +118,7 @@ openxc::telitHE910::TelitDevice telitDevice = { openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, - version: "8.1.1", + version: "8.2.0", dummyVin: "Failed to get VIN temporary VIN is :00000000123456789", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, From 123ab3c162b57fffbe2ec7a32f1a52338dae4255 Mon Sep 17 00:00:00 2001 From: GenoJAFord Date: Thu, 12 Aug 2021 16:54:52 +0000 Subject: [PATCH 47/48] Updated version to 8.2.1 --- CHANGELOG.mkd | 3 +++ README.rst | 2 +- docs/conf.py | 4 ++-- docs/index.rst | 2 +- src/config.cpp | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.mkd b/CHANGELOG.mkd index c2127afa5..8714b5e8c 100644 --- a/CHANGELOG.mkd +++ b/CHANGELOG.mkd @@ -1,4 +1,7 @@ # OpenXC Vehicle Interface Firmware Changelog +## v8.2.1 +* Fix: Bootstrap fix + ## v8.2.0 * Removed: Removed messagepack format support * Feature: get_vin command added and is accessible from openxc-control python and from Android and iOS clients diff --git a/README.rst b/README.rst index dfeaa8e41..8bb367973 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /docs/_static/logo.png -:Version: 8.2.0 +:Version: 8.2.1 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/docs/conf.py b/docs/conf.py index 91db5263f..e5bd572b7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,9 +49,9 @@ # built documents. # # The short X.Y version. -version = '8.2.0' +version = '8.2.1' # The full version, including alpha/beta/rc tags. -release = '8.2.0' +release = '8.2.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index 5211635fb..2dcaf395b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ OpenXC Vehicle Interface Firmware .. image:: /_static/logo.png -:Version: 8.2.0 +:Version: 8.2.1 :Web: http://openxcplatform.com :Documentation: http://vi-firmware.openxcplatform.com :Source: http://github.com/openxc/vi-firmware diff --git a/src/config.cpp b/src/config.cpp index ac13011ce..09a59fb3c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -118,7 +118,7 @@ openxc::telitHE910::TelitDevice telitDevice = { openxc::config::Configuration* openxc::config::getConfiguration() { static openxc::config::Configuration CONFIG = { messageSetIndex: 0, - version: "8.2.0", + version: "8.2.1", dummyVin: "Failed to get VIN temporary VIN is :00000000123456789", platform: PLATFORM, environmentMode: ENVIRONMENT_MODE, From 923218a940567060b7eed92b6cf4b607051581ac Mon Sep 17 00:00:00 2001 From: garindae Date: Thu, 19 Aug 2021 13:58:43 -0400 Subject: [PATCH 48/48] Fix submodule link to openxc-message-format lib --- src/libs/openxc-message-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/openxc-message-format b/src/libs/openxc-message-format index b08ac1c7e..34979aa21 160000 --- a/src/libs/openxc-message-format +++ b/src/libs/openxc-message-format @@ -1 +1 @@ -Subproject commit b08ac1c7e20d7c7caac5b86785acb07be301f36f +Subproject commit 34979aa21f2367a5fd92398165ac0480e81a12b7