Skip to content

Commit

Permalink
Merge pull request #361 from openxc/ble-fixes
Browse files Browse the repository at this point in the history
Ble fixes
  • Loading branch information
rwoberholzer committed Sep 16, 2016
2 parents 9b01ac8 + 2727753 commit 503645d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
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
2 changes: 1 addition & 1 deletion 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
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 503645d

Please sign in to comment.