Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Jul 21, 2024
1 parent be44cca commit 4474bc3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
48 changes: 42 additions & 6 deletions src/app_dio.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,65 @@
// Print debug support
use crate::print_debug_message;
use crate::{api_dio::PicohaDioRequest, print_debug_message};
use core::fmt::Write;

// USB Communications Class Device support
use usbd_serial::SerialPort;

// Size of internal buffers
const BUFFER_CAPACITY: usize = 64;

/// Application Digital I/O
pub struct AppDio {
// ...
// Accumulated incoming data buffer
in_buf: [u8; BUFFER_CAPACITY],
// Keep track of number of data in the buffer
in_buf_size: usize,
// Decode buffer
decode_buffer: [u8; BUFFER_CAPACITY],
}

impl AppDio {
pub fn new() -> Self {
AppDio {
// ...
in_buf: [0u8; 64],
in_buf_size: 0,
decode_buffer: [0u8; 64],
}
}

/// Accumulate new data
fn accumulate_new_data(&mut self, data: &[u8]) {
// Compute indexes
let data_len = data.len();
let i_from = self.in_buf_size;
let i_to = self.in_buf_size + data_len;

// Copy data to the buffer
self.in_buf[i_from..i_to].clone_from_slice(&data);

// Update the buffer size
self.in_buf_size += data_len;
}

/// Try to decode a request from the incoming data buffer
///
fn try_to_decode_request(&self) -> Option<PicohaDioRequest> {
let mut slip_decoder = serial_line_ip::Decoder::new();

// match slip_decoder.decode(&cmd_buf[..cmd_buf_size], &mut decoded_buffer) {
// Ok((input_bytes_processed, output_slice, is_end_of_packet)) => {

None
}

/// Process incoming data
///
pub fn process_incoming_data(
&mut self,
serial: &mut SerialPort<rp2040_hal::usb::UsbBus>,
data: &[u8],
) {
print_debug_message!("Received data: {:?}", data);

// ...
print_debug_message!("+ recieved data: {:?}", data);
self.accumulate_new_data(data);
}
}
38 changes: 0 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,44 +216,6 @@ unsafe fn main() -> ! {
}
Ok(count) => {
app.process_incoming_data(&mut serial, &buf[..count]);
// command_buffer[..count].iter().for_each(|b| {

// });

// cmd_buf[cmd_buf_size..count].clone_from_slice(&buf);

// Usage:
print_debug_message!("Received {} bytes, {}", count, cmd_buf.len());

let oooo = &buf[..count];
// writeln!(&mut message, "Received {:?}", oooo).unwrap();
// DEBUG_UART
// .as_ref()
// .unwrap()
// .write_full_blocking(message.as_bytes());

{
let (left, right) = cmd_buf.split_at_mut(cmd_buf_size);

// writeln!(&mut message, "left {}, right {}", left.len(), right.len())
// .unwrap();
// DEBUG_UART
// .as_ref()
// .unwrap()
// .write_full_blocking(message.as_bytes());

right[..count].clone_from_slice(&buf[..count]);

cmd_buf_size += count;
}

// writeln!(&mut message, "total {:?}", cmd_buf).unwrap();
// DEBUG_UART
// .as_ref()
// .unwrap()
// .write_full_blocking(message.as_bytes());

// cmd_buf_size += count;

//
let mut slip_decoder = serial_line_ip::Decoder::new();
Expand Down

0 comments on commit 4474bc3

Please sign in to comment.