Skip to content

Commit

Permalink
Merge pull request #368 from openxc/devicePlatformCommand
Browse files Browse the repository at this point in the history
Added command to retrieve the device's platform
  • Loading branch information
rwoberholzer committed Sep 21, 2016
2 parents 503645d + 02f4f5b commit 89da2f5
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ OBJDIR = $(OBJDIR_ROOT)
# 0 or 1
BOOTLOADER ?= 1

PLATFORM ?= "NONE"
SYMBOLS += PLATFORM="\"$(PLATFORM)\""

DEFAULT_ALLOW_RAW_WRITE_USB ?= 1
SYMBOLS += DEFAULT_ALLOW_RAW_WRITE_USB=$(DEFAULT_ALLOW_RAW_WRITE_USB)

Expand Down
5 changes: 5 additions & 0 deletions src/commands/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "commands/diagnostic_request_command.h"
#include "commands/version_command.h"
#include "commands/device_id_command.h"
#include "commands/device_platform_command.h"
#include "commands/can_message_write_command.h"
#include "commands/simple_write_command.h"
#include "commands/af_bypass_command.h"
Expand Down Expand Up @@ -39,6 +40,9 @@ static bool handleComplexCommand(openxc_VehicleMessage* message) {
case openxc_ControlCommand_Type_DEVICE_ID:
status = openxc::commands::handleDeviceIdCommmand();
break;
case openxc_ControlCommand_Type_PLATFORM:
status = openxc::commands::handleDevicePlatformCommmand();
break;
case openxc_ControlCommand_Type_PASSTHROUGH:
status = openxc::commands::handlePassthroughModeCommand(command);
break;
Expand Down Expand Up @@ -138,6 +142,7 @@ static bool validateControlCommand(openxc_VehicleMessage* message) {
break;
case openxc_ControlCommand_Type_VERSION:
case openxc_ControlCommand_Type_DEVICE_ID:
case openxc_ControlCommand_Type_PLATFORM:
case openxc_ControlCommand_Type_SD_MOUNT_STATUS:
valid = true;
break;
Expand Down
40 changes: 40 additions & 0 deletions src/commands/device_platform_command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "device_platform_command.h"
#include "config.h"
#include "diagnostics.h"
#include "interface/usb.h"
#include "util/log.h"
#include "config.h"
#include "pb_decode.h"
#include <payload/payload.h>
#include "signals.h"
#include <can/canutil.h>
#include <bitfield/bitfield.h>
#include <limits.h>

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::handleDevicePlatformCommmand() {
char* platform_name;
platform_name = strdup(config::getConfiguration()->platform);
sendCommandResponse(openxc_ControlCommand_Type_PLATFORM, true,
platform_name, strlen(platform_name));
return true;
}
12 changes: 12 additions & 0 deletions src/commands/device_platform_command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __DEVICE_PLATFORM_COMMAND_H__
#define __DEVICE_PLATFORM_COMMAND_H__

namespace openxc {
namespace commands {

bool handleDevicePlatformCommmand();

} // namespace commands
} // namespace openxc

#endif // __DEVICE_PLATFORM_COMMAND_H__
1 change: 1 addition & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() {
static openxc::config::Configuration CONFIG = {
messageSetIndex: 0,
version: "7.2.1-dev",
platform: PLATFORM,
environmentMode: ENVIRONMENT_MODE,
payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT,
recurringObd2Requests: DEFAULT_RECURRING_OBD2_REQUESTS_STATUS,
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef enum {
typedef struct {
int messageSetIndex;
const char* version;
const char* platform;
const char* environmentMode;
openxc::payload::PayloadFormat payloadFormat;
bool recurringObd2Requests;
Expand Down
7 changes: 7 additions & 0 deletions src/payload/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using openxc::util::log::debug;

const char openxc::payload::json::VERSION_COMMAND_NAME[] = "version";
const char openxc::payload::json::DEVICE_ID_COMMAND_NAME[] = "device_id";
const char openxc::payload::json::DEVICE_PLATFORM_COMMAND_NAME[] = "platform";
const char openxc::payload::json::DIAGNOSTIC_COMMAND_NAME[] = "diagnostic_request";
const char openxc::payload::json::PASSTHROUGH_COMMAND_NAME[] = "passthrough";
const char openxc::payload::json::ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME[] = "af_bypass";
Expand Down Expand Up @@ -99,6 +100,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_PLATFORM) {
typeString = payload::json::DEVICE_PLATFORM_COMMAND_NAME;
} else if(message->command_response.type == openxc_ControlCommand_Type_DIAGNOSTIC) {
typeString = payload::json::DIAGNOSTIC_COMMAND_NAME;
} else if(message->command_response.type == openxc_ControlCommand_Type_PASSTHROUGH) {
Expand Down Expand Up @@ -571,6 +574,10 @@ size_t openxc::payload::json::deserialize(uint8_t payload[], size_t length,
DEVICE_ID_COMMAND_NAME, strlen(DEVICE_ID_COMMAND_NAME))) {
command->has_type = true;
command->type = openxc_ControlCommand_Type_DEVICE_ID;
} else if(!strncmp(commandNameObject->valuestring,
DEVICE_PLATFORM_COMMAND_NAME, strlen(DEVICE_PLATFORM_COMMAND_NAME))) {
command->has_type = true;
command->type = openxc_ControlCommand_Type_PLATFORM;
} else if(!strncmp(commandNameObject->valuestring,
DIAGNOSTIC_COMMAND_NAME, strlen(DIAGNOSTIC_COMMAND_NAME))) {
deserializeDiagnostic(root, command);
Expand Down
1 change: 1 addition & 0 deletions src/payload/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 DIAGNOSTIC_COMMAND_NAME[];
extern const char PASSTHROUGH_COMMAND_NAME[];
extern const char ACCEPTANCE_FILTER_BYPASS_COMMAND_NAME[];
Expand Down
7 changes: 7 additions & 0 deletions src/payload/messagepack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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";
Expand Down Expand Up @@ -288,6 +289,8 @@ static bool serializeCommandResponse(openxc_VehicleMessage* message, cmp_ctx_t *
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) {
Expand Down Expand Up @@ -1116,6 +1119,10 @@ size_t openxc::payload::messagepack::deserialize(uint8_t payload[], size_t lengt
DEVICE_ID_COMMAND_NAME, strlen(DEVICE_ID_COMMAND_NAME))) {
command->has_type = true;
command->type = openxc_ControlCommand_Type_DEVICE_ID;
} else if(!strncmp(commandNameObject->valuestring,
DEVICE_PLATFORM_COMMAND_NAME, strlen(DEVICE_PLATFORM_COMMAND_NAME))) {
command->has_type = true;
command->type = openxc_ControlCommand_Type_PLATFORM;
} else if(!strncmp(commandNameObject->valuestring,
DIAGNOSTIC_COMMAND_NAME, strlen(DIAGNOSTIC_COMMAND_NAME))) {
deserializeDiagnostic(root, command);
Expand Down
1 change: 1 addition & 0 deletions src/payload/messagepack.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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[];
Expand Down
8 changes: 8 additions & 0 deletions src/tests/command_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@ START_TEST (test_validate_version_command)
}
END_TEST

START_TEST (test_validate_device_platform_command)
{
CONTROL_COMMAND.control_command.type = openxc_ControlCommand_Type_PLATFORM;
ck_assert(validate(&CONTROL_COMMAND));
}
END_TEST

START_TEST (test_validate_device_id_command)
{
CONTROL_COMMAND.control_command.type = openxc_ControlCommand_Type_DEVICE_ID;
Expand Down Expand Up @@ -957,6 +964,7 @@ Suite* suite(void) {
tcase_add_test(tc_validation,
test_validate_diagnostic_no_multiple_responses);
tcase_add_test(tc_validation, test_validate_version_command);
tcase_add_test(tc_validation, test_validate_device_platform_command);
tcase_add_test(tc_validation, test_validate_device_id_command);
tcase_add_test(tc_validation, test_validate_passthrough_commmand);
tcase_add_test(tc_validation, test_validate_bypass_command);
Expand Down

0 comments on commit 89da2f5

Please sign in to comment.