Skip to content

Commit

Permalink
Prepare sending System Id for App pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
ah- committed Mar 1, 2018
1 parent 2abc87f commit 8df1309
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cortex_m_semihosting::hio;
use nb;
use rtfm::Threshold;
use super::hidreport::HidReport;
use super::protocol::{Message, MsgType, BleOp, KeyboardOp};
use super::protocol::{Message, MsgType, BleOp, KeyboardOp, SystemOp};
use super::serial::Serial;
use super::serial::bluetooth_usart::BluetoothUsart;

Expand Down Expand Up @@ -64,13 +64,27 @@ impl<'a> Bluetooth<'a> {

pub fn receive(message: &Message) {
match message.msg_type {
//(2, 1) => {
// SYSTEM Get ID
//let data = &[4, 1, 0, 1, 2, 3, 4][..];
//self.send(MsgType::System, 129, &data, gpioa);
//}
MsgType::System => {
debug!("msg: System {} {:?}", message.operation, message.data).ok();
match SystemOp::from(message.operation) {
SystemOp::GetId => {
const DEVICE_MODEL_ANNE_PRO: u8 = 2;
const DEVICE_TYPE_KEYBOARD: u8 = 1;
//const DEVICE_ID = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

// send two packets
// nblock = 2
// [datalen, nblock, iblock = 0, data...]
// [datalen, nblock, iblock = 1, data...]

let data1 = [10, 2, 0, DEVICE_TYPE_KEYBOARD, DEVICE_MODEL_ANNE_PRO, 1, 2, 3, 4, 5, 6];
let data2 = [8, 2, 1, 7, 8, 9, 10, 11, 12];
self.send(MsgType::System, SystemOp::AckGetId as u8, &data1);
self.send(MsgType::System, SystemOp::AckGetId as u8, &data2);
}
_ => {
debug!("msg: System {} {:?}", message.operation, message.data).ok();
}
}
}
MsgType::Ble => {
match BleOp::from(message.operation) {
Expand Down
2 changes: 2 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ impl From<u8> for LedOp {
#[derive(Debug,Copy,Clone)]
pub enum SystemOp {
Reserved = 0,
GetId = 1,
IsSyncCode = 8,
SetSyncCode = 9,
AckReserved = 128,
AckGetId = 129,
}

impl From<u8> for SystemOp {
Expand Down

0 comments on commit 8df1309

Please sign in to comment.