Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to set bluetooth pin #425

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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