-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use core::str::Split; | ||
|
||
use crate::{ | ||
command_buffer::CommandBuffer, coordinate::PolarCoordinate, coordinate_queue, | ||
transmission_channel, | ||
}; | ||
|
||
const MOVE: &str = "MOVE"; | ||
|
||
pub async fn execute(command_buf: CommandBuffer) { | ||
let mut args = command_buf.to_str().unwrap().split(' '); | ||
let method = args.next().unwrap(); | ||
|
||
match method { | ||
MOVE => execute_move(args).await, | ||
_ => {} | ||
}; | ||
} | ||
|
||
async fn execute_move(mut args: Split<'_, char>) { | ||
transmission_channel::send("MOVE ACK\r\n").await; | ||
let theta_str = args.next().unwrap(); | ||
let rho_str = args.next().unwrap(); | ||
coordinate_queue::queue(PolarCoordinate { | ||
theta: theta_str.parse::<f64>().unwrap(), | ||
rho: rho_str.parse::<f64>().unwrap(), | ||
}) | ||
.await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,20 @@ | ||
use defmt::info; | ||
use embassy_rp::{peripherals::UART0, uart::{Async, UartRx}}; | ||
|
||
use crate::{control_buffer::ControlBuffer, coordinate::PolarCoordinate, coordinate_queue, transmission_channel}; | ||
|
||
static MOVE: &str = "MOVE"; | ||
use crate::{command_buffer::CommandBuffer, command_executor}; | ||
|
||
#[embassy_executor::task] | ||
pub async fn reader_task(mut rx: UartRx<'static, UART0, Async>) { | ||
loop { | ||
let mut control_buffer = ControlBuffer::new(); | ||
let mut command_buffer = CommandBuffer::new(); | ||
loop { | ||
let mut char_buf = [0u8]; | ||
let _rr = rx.read(&mut char_buf).await; | ||
let _br = control_buffer.add_char_buf(&char_buf); | ||
if control_buffer.is_complete() { | ||
let _br = command_buffer.add_char_buf(&char_buf); | ||
if command_buffer.is_complete() { | ||
break; | ||
} | ||
} | ||
|
||
let input = control_buffer.to_str().unwrap(); | ||
let mut args = input.split(' '); | ||
let command = args.next().unwrap(); | ||
|
||
if command == MOVE { | ||
transmission_channel::send("MOVE ACK\r\n").await; | ||
let theta_str = args.next().unwrap(); | ||
let rho_str = args.next().unwrap(); | ||
// TODO: parse rho | ||
coordinate_queue::queue(PolarCoordinate { | ||
theta: theta_str.parse::<f64>().unwrap(), | ||
rho: 0.0, | ||
}).await; | ||
info!("Move to {}, {}", theta_str, rho_str); | ||
} | ||
command_executor::execute(command_buffer).await; | ||
} | ||
} |