add tactile_a codec

This commit is contained in:
lenn
2026-04-01 18:35:22 +08:00
parent a754656ea4
commit 380394b93a
17 changed files with 564 additions and 31 deletions

View File

@@ -1,13 +1,15 @@
use std::io::Read;
use std::time::Instant;
use crate::serial_core::frame::{crc8, usize_to_u16_be_bytes, FrameHandler};
use crate::serial_core::frame::{FrameHandler};
use crate::serial_core::utils::*;
use crate::serial_core::{codec::Codec, error::CodecError, frame::TestFrame};
use anyhow::anyhow;
use async_trait::async_trait;
use chrono::Local;
use csv::StringRecord;
use crate::serial_core::record::{write_csv, CsvExporter, CsvImporter, RecordedFrame, Recording};
use crc::{Crc, CRC_8_SMBUS};
use crate::serial_core::utils::*;
pub struct TestCodec {
buffer: Vec<u8>,
}
@@ -52,7 +54,9 @@ impl Codec<TestFrame> for TestCodec {
break;
}
let payload = self.buffer[5..5 + length].to_vec();
let checksum = crc8(payload.as_slice());
// let checksum = crc8(payload.as_slice());
let crc8_alg = crc::Crc::<u8>::new(&crc::CRC_8_SMBUS);
let checksum = crc8_alg.checksum(payload.as_slice());
if self.buffer[frame_length - 1] != checksum {
self.buffer.drain(0..1);
continue;
@@ -112,10 +116,6 @@ fn parse_data_frame(data: &[u8]) -> Result<Vec<i32>, CodecError> {
Ok(vals)
}
fn elapsed_millis(start_at: Instant) -> u64 {
start_at.elapsed().as_millis() as u64
}
pub struct TestCsvExporter;
pub struct TestCsvImporter {
channels: usize,