Skip to content

Commit

Permalink
Merge pull request #425 from openxc/BluetoothPin
Browse files Browse the repository at this point in the history
Added code to set bluetooth pin
  • Loading branch information
pjt0620 committed Dec 19, 2019
2 parents c41c393 + 32adb62 commit dff571b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ SYMBOLS += DEFAULT_ALLOW_RAW_WRITE_NETWORK=$(DEFAULT_ALLOW_RAW_WRITE_NETWORK)
DEFAULT_ALLOW_RAW_WRITE_BLE ?= 0
SYMBOLS += DEFAULT_ALLOW_RAW_WRITE_BLE=$(DEFAULT_ALLOW_RAW_WRITE_BLE)

DEFAULT_BLUETOOTH_PIN ?= "\"1234\""
SYMBOLS += DEFAULT_BLUETOOTH_PIN=$(DEFAULT_BLUETOOTH_PIN)

DEFAULT_METRICS_STATUS ?= 0
SYMBOLS += DEFAULT_METRICS_STATUS=$(DEFAULT_METRICS_STATUS)

Expand Down
14 changes: 14 additions & 0 deletions src/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "atcommander.h"
#include "util/timer.h"
#include "gpio.h"
#include "config.h"
#include <string.h>

#define BLUETOOTH_DEVICE_NAME "OpenXC-VI"
Expand All @@ -21,6 +22,7 @@ using openxc::gpio::GPIO_DIRECTION_OUTPUT;
using openxc::gpio::GPIO_DIRECTION_INPUT;
using openxc::gpio::GPIO_VALUE_HIGH;
using openxc::gpio::GPIO_VALUE_LOW;
using openxc::config::getConfiguration;
using openxc::util::time::delayMs;
using openxc::util::log::debug;

Expand Down Expand Up @@ -80,6 +82,18 @@ void openxc::bluetooth::configureExternalModule(UartDevice* device) {
debug("Unable to disable remote Bluetooth configuration");
}

AtCommand pinCommand = {
request_format: "SP,%s\r",
expected_response: "AOK",
error_response: "ERR"
};

if(at_commander_set(&config, &pinCommand, getConfiguration()->bluetoothPin)) {
debug("Changed Bluetooth Pairing Pin to %s.", getConfiguration()->bluetoothPin);
} else {
debug("Unable to change Bluetooth Pairing Pin.");
}

AtCommand inquiryCommand = {
request_format: "SI,%s\r",
expected_response: "AOK",
Expand Down
1 change: 1 addition & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() {
desiredRunLevel: RunLevel::CAN_ONLY,
initialized: false,
runLevel: RunLevel::NOT_RUNNING,
bluetoothPin: DEFAULT_BLUETOOTH_PIN,
uart: {
descriptor: {
allowRawWrites: DEFAULT_ALLOW_RAW_WRITE_UART
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ typedef struct {
RunLevel desiredRunLevel;
bool initialized;
RunLevel runLevel;
const char* bluetoothPin;
openxc::interface::uart::UartDevice uart;
openxc::interface::network::NetworkDevice network;
openxc::interface::usb::UsbDevice usb;
Expand Down

0 comments on commit dff571b

Please sign in to comment.