Skip to content

Commit

Permalink
Merge branch 'next' into devicePlatformCommand
Browse files Browse the repository at this point in the history
Conflicts:
	src/config.cpp
	src/config.h
	src/libs/openxc-message-format
  • Loading branch information
rwoberholzer committed Sep 21, 2016
2 parents 5cd96be + 503645d commit 02f4f5b
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 28 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

* BREAKING: Removed fine_odometer_since_restart from emulator.
* Feature: Added sending evented messages from emulator.
Evented messages will come at a slower rate then other messages to simulate real world frequency
Evented messages will come at a slower rate then other messages to simulate real world frequency
* Fix: When building emualtor, obd2, or translated_obd2 firmware, those designations will now be
indicated in the version number instead of the type number in signals.cpp.
* Feature: Add support for multi-frame diagnostic responses (currently just for
receiving, not sending)
* Feature: VIs running emulator firmware will now respond to basic diagnostic requests from enabler
and the command line. The response will mimic the request's bus, message ID, mode, and PID (if sent).
The response will also include a randomly generated value between 0 and 100.
Recurring diagnostic messages when running emulator firmware are currently not supported.

## v7.2.0

Expand Down
Binary file modified docs/_static/OpenXC-CrossChasm-Flash.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def build_options():
DEFAULT_COMPILER_OPTIONS = {
'DEBUG': env.debug,
'MSD_ENABLE' : env.msd_enable,
'ENVIRONMENT_MODE' : 'default_mode',
'DEFAULT_FILE_GENERATE_SECS' : env.default_file_generate_secs,
'BOOTLOADER': env.bootloader,
'TEST_MODE_ONLY': env.test_mode_only,
Expand All @@ -151,11 +152,14 @@ def build_options():
if env.mode == 'emulator':
options['DEFAULT_EMULATED_DATA_STATUS'] = True
options['DEFAULT_POWER_MANAGEMENT'] = "ALWAYS_ON"
options['ENVIRONMENT_MODE'] = env.mode
elif env.mode == 'translated_obd2':
options['DEFAULT_POWER_MANAGEMENT'] = "OBD2_IGNITION_CHECK"
options['DEFAULT_RECURRING_OBD2_REQUESTS_STATUS'] = True
options['ENVIRONMENT_MODE'] = env.mode
elif env.mode == 'obd2':
options['DEFAULT_POWER_MANAGEMENT'] = "OBD2_IGNITION_CHECK"
options['ENVIRONMENT_MODE'] = env.mode
return " ".join((build_option(key, value)
for key, value in options.iteritems()))

Expand Down
4 changes: 4 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ SYMBOLS += DEFAULT_USB_PRODUCT_ID=$(DEFAULT_USB_PRODUCT_ID)
DEFAULT_CAN_ACK_STATUS ?= 0
SYMBOLS += DEFAULT_CAN_ACK_STATUS=$(DEFAULT_CAN_ACK_STATUS)

ENVIRONMENT_MODE ?= "default_mode"
SYMBOLS += ENVIRONMENT_MODE="\"$(ENVIRONMENT_MODE)\""

# TODO see https://github.com/openxc/vi-firmware/issues/189
# ifeq ($(NETWORK), 1)
# SYMBOLS += __USE_NETWORK__
Expand Down Expand Up @@ -216,6 +219,7 @@ endif
define show_options
$(call show_vi_config_variable,PLATFORM)
$(call show_vi_config_variable,BOOTLOADER)
$(call show_vi_config_variable,ENVIRONMENT_MODE)
$(call show_vi_config_variable,TEST_MODE_ONLY)
$(call show_vi_config_variable,DEBUG)
$(call show_vi_config_variable,MSD_ENABLE)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/device_id_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ bool openxc::commands::handleDeviceIdCommmand() {
ble::BleDevice* ble = getConfiguration()->ble;

sprintf(ids,"%02X:%02X:%02X:%02X:%02X:%02X",
ble->blesettings.bdaddr[0],ble->blesettings.bdaddr[1],ble->blesettings.bdaddr[2],
ble->blesettings.bdaddr[3],ble->blesettings.bdaddr[4],ble->blesettings.bdaddr[5]
ble->blesettings.bdaddr[5],ble->blesettings.bdaddr[4],ble->blesettings.bdaddr[3],
ble->blesettings.bdaddr[2],ble->blesettings.bdaddr[1],ble->blesettings.bdaddr[0]
);
sendCommandResponse(openxc_ControlCommand_Type_DEVICE_ID, true,
(char *)ids, strlen(ids));
Expand Down
12 changes: 10 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ble::BleDevice bleDevice = {
allowRawWrites: DEFAULT_ALLOW_RAW_WRITE_BLE
},
blesettings: {
"OpenXC_C5_BTLE",
"OPENXC-VI-XXXX",
adv_min_ms: 100,
adv_max_ms: 100,
slave_min_ms : 8, //range 0x0006 to 0x0C80
Expand Down Expand Up @@ -120,6 +120,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() {
messageSetIndex: 0,
version: "7.2.1-dev",
platform: PLATFORM,
environmentMode: ENVIRONMENT_MODE,
payloadFormat: PayloadFormat::DEFAULT_OUTPUT_FORMAT,
recurringObd2Requests: DEFAULT_RECURRING_OBD2_REQUESTS_STATUS,
obd2BusAddress: DEFAULT_OBD2_BUS,
Expand Down Expand Up @@ -185,9 +186,16 @@ openxc::config::Configuration* openxc::config::getConfiguration() {
}

void openxc::config::getFirmwareDescriptor(char* buffer, size_t length) {
snprintf(buffer, length, "%s (%s)", getConfiguration()->version,
const char* envMode = getConfiguration()->environmentMode;
if(strcmp(envMode, "default_mode") != 0)
{
snprintf(buffer, length, "%s (%s)", getConfiguration()->version, getConfiguration()->environmentMode);
}
else {
snprintf(buffer, length, "%s (%s)", getConfiguration()->version,
signals::getActiveMessageSet() != NULL ?
signals::getActiveMessageSet()->name : "default");
}
}

#ifdef TELIT_HE910_SUPPORT
Expand Down
4 changes: 4 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ typedef enum {
* messageSetIndex - The index of the currently active message set from the
* signals module.
* version - A string describing the firmware version.
* environmentMode - A string describing the what type of firmware it is.
* Modes: default_mode, emulator, obd2, translated_obd2
* "default_mode" is when there is no modifier present (ie: emulator, obd2, etc)
* payloadFormat - The currently active payload format, from the payload module.
* This is used for both input and output.
* recurringObd2Requests - True if the VI should automatically query for
Expand Down Expand Up @@ -108,6 +111,7 @@ typedef struct {
int messageSetIndex;
const char* version;
const char* platform;
const char* environmentMode;
openxc::payload::PayloadFormat payloadFormat;
bool recurringObd2Requests;
uint8_t obd2BusAddress;
Expand Down
64 changes: 56 additions & 8 deletions src/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "obd2.h"
#include <bitfield/bitfield.h>
#include <limits.h>
#include "config.h"

#define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10
#define DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET 0x8
Expand All @@ -24,6 +25,7 @@ using openxc::can::read::publishNumericalMessage;
using openxc::pipeline::Pipeline;
using openxc::signals::getCanBuses;
using openxc::signals::getCanBusCount;
using openxc::config::getConfiguration;

namespace time = openxc::util::time;
namespace pipeline = openxc::pipeline;
Expand Down Expand Up @@ -341,6 +343,9 @@ static void receiveCanMessage(DiagnosticsManager* manager,
} else {
debug("Fatal error sending or receiving diagnostic request");
}
} else if(!response.completed && response.multi_frame) {
// Reset the timeout clock while completing the multi-frame receive
time::tick(&entry->timeoutClock);
}
}
}
Expand Down Expand Up @@ -642,14 +647,57 @@ bool openxc::diagnostics::handleDiagnosticCommand(
"using first active: %d", bus->address);
}

if(bus == NULL) {
debug("No active bus to send diagnostic request");
status = false;
} else if(bus->rawWritable) {
status = handleAuthorizedCommand(manager, bus, command);
} else {
debug("Raw CAN writes not allowed for bus %d", bus->address);
status = false;
if(getConfiguration()->emulatedData){
//Checking to see if the message ID is in the "standard" OBD range (7DF or 7E0->7E7)
//See: https://en.wikipedia.org/wiki/OBD-II_PIDs#CAN_.2811-bit.29_bus_format
if(commandRequest->message_id >= 0x7DF && commandRequest->message_id <= 0x7E7)
{
openxc_VehicleMessage message = {0};
message.has_type = true;
message.type = openxc_VehicleMessage_Type_DIAGNOSTIC;
message.has_diagnostic_response = true;
message.diagnostic_response = {0};
message.diagnostic_response.has_bus = true;
message.diagnostic_response.bus = bus->address;
message.diagnostic_response.has_message_id = true;
//7DF should respond with a random message id between 7e8 and 7ef
//7E0 through 7E7 should respond with a id that is 8 higher (7E0->7E8)
if(commandRequest->message_id == 0x7DF)
{
message.diagnostic_response.message_id = rand()%(0x7EF-0x7E8 + 1) + 0x7E8;
}
else if(commandRequest->message_id >= 0x7E0 && commandRequest->message_id <= 0x7E7)
{
message.diagnostic_response.message_id = commandRequest->message_id + 8;
}
message.diagnostic_response.has_mode = true;
message.diagnostic_response.mode = commandRequest->mode;
if(commandRequest->has_pid)
{
message.diagnostic_response.has_pid = true;
message.diagnostic_response.pid = commandRequest->pid;
}
message.diagnostic_response.has_value = true;
message.diagnostic_response.value = rand() % 100;
pipeline::publish(&message, &getConfiguration()->pipeline);
}
else //If it's outside the range, the command_request will return false
{
debug("Sent message ID is outside the valid range for emulator (7DF to 7E7)");
status=false;
}
}
else
{
if(bus == NULL) {
debug("No active bus to send diagnostic request");
status = false;
} else if(bus->rawWritable) {
status = handleAuthorizedCommand(manager, bus, command);
} else {
debug("Raw CAN writes not allowed for bus %d", bus->address);
status = false;
}
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/isotp-c
2 changes: 1 addition & 1 deletion src/libs/uds-c
18 changes: 11 additions & 7 deletions src/platform/pic32/ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>proce
#include <stddef.h>
#include <plib.h>
#include <stdbool.h>
#include <ctype.h>
Expand Down Expand Up @@ -104,7 +104,7 @@ static const uint8_t device_gap_name[] = "CrossChasm";
uint16_t vtServHandle, appComCharHandle, appRSPCharHandle;
static uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
static uint16_t conn_handle=0;

static char device_adv_name[16];


#ifdef BLE_NO_ACT_TIMEOUT_ENABLE
Expand Down Expand Up @@ -444,7 +444,6 @@ static tBleStatus ST_BLE_Set_Connectable(BleDevice* device)
{
return ret;//failed
}

adv[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
ret = strlen(device->blesettings.advname);

Expand Down Expand Up @@ -589,12 +588,17 @@ bool openxc::interface::ble::initialize(BleDevice* device)

if(ret = hci_read_bd_addr(device->blesettings.bdaddr), ret != BLE_STATUS_SUCCESS){
debug("Ble mac add read failed");
memset(&device->blesettings.bdaddr[0],0xFF,6);
}

debug("Mac address %x:%x:%x:%x:%x:%x", device->blesettings.bdaddr[0], device->blesettings.bdaddr[1], device->blesettings.bdaddr[2],
device->blesettings.bdaddr[3], device->blesettings.bdaddr[4], device->blesettings.bdaddr[5]);


//debug("Mac address %x:%x:%x:%x:%x:%x", device->blesettings.bdaddr[0], device->blesettings.bdaddr[1], device->blesettings.bdaddr[2],
// device->blesettings.bdaddr[3], device->blesettings.bdaddr[4], device->blesettings.bdaddr[5]);

sprintf(device_adv_name,"OPENXC-VI-%02X%02X",device->blesettings.bdaddr[1],device->blesettings.bdaddr[0]);


device->blesettings.advname = (const char*)device_adv_name;

//Initialize device name charactertistic
ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, strlen((const char*)device_gap_name), (uint8_t *)device_gap_name);

Expand Down
14 changes: 8 additions & 6 deletions src/platform/pic32/hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "WProgram.h" //for arduino millis reference
#include "hci.h"
#include "libs/STBTLE/list.h"

#define OCF_HAL_READ_CONFIG_DATA 0x000D

#if BLE_CONFIG_DBG_ENABLE
#define PRINTF(...) printf(__VA_ARGS__)
Expand Down Expand Up @@ -718,24 +718,26 @@ int hci_le_set_random_address(tBDAddr bdaddr)
if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;

return status;
return 0;
}

int hci_read_bd_addr(tBDAddr bdaddr)
{
struct hci_request rq;
read_bd_addr_rp resp;
uint8_t offset = 0x80;

Osal_MemSet(&resp, 0, sizeof(resp));

Osal_MemSet(&rq, 0, sizeof(rq));
rq.ogf = OGF_INFO_PARAM;
rq.ocf = OCF_READ_BD_ADDR;
rq.cparam = NULL;
rq.clen = 0;
rq.ogf = OGF_VENDOR_CMD;;
rq.ocf = 0x0D;//read config data;
rq.cparam = &offset;//offset address for mac address
rq.clen = 1;
rq.rparam = &resp;
rq.rlen = READ_BD_ADDR_RP_SIZE;


if (hci_send_req(&rq, FALSE) < 0)
return BLE_STATUS_TIMEOUT;

Expand Down

0 comments on commit 02f4f5b

Please sign in to comment.