串口服务校验返回的发送函数逻辑优化, 工作类添加写、检查IMEI/SN函数
This commit is contained in:
parent
bc1f8d4eaa
commit
3ab2c5aeca
@ -43,8 +43,14 @@ impl SerialService {
|
|||||||
|
|
||||||
pub fn send_command_with_target<T: for<'a> AsRef<str>>(&mut self, command: T, timeout: Option<u64>, target: T) -> Result<bool, String> {
|
pub fn send_command_with_target<T: for<'a> AsRef<str>>(&mut self, command: T, timeout: Option<u64>, target: T) -> Result<bool, String> {
|
||||||
let target_str = target.as_ref();
|
let target_str = target.as_ref();
|
||||||
_ = return match self.send_command(command, timeout) {
|
return match self.send_command(command, timeout) {
|
||||||
Ok(resp) => { Ok(resp.contains(target_str)) },
|
Ok(resp) => {
|
||||||
|
if resp.contains(target_str){
|
||||||
|
return Ok(true);
|
||||||
|
}else{
|
||||||
|
return Err(resp)
|
||||||
|
}
|
||||||
|
},
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::models::work_model::WorkModel;
|
||||||
use crate::services::{serial_service::SerialService, sqlite_service::SqliteService, excel_service::ExcelService};
|
use crate::services::{serial_service::SerialService, sqlite_service::SqliteService, excel_service::ExcelService};
|
||||||
|
|
||||||
|
|
||||||
@ -9,10 +10,27 @@ pub struct WorkService {
|
|||||||
|
|
||||||
impl Default for WorkService {
|
impl Default for WorkService {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
WorkService {
|
todo!()
|
||||||
serial_service: *SerialService::new("COM3").unwrap(),
|
|
||||||
sqlite_service: SqliteService::default(),
|
|
||||||
excel_service: ExcelService::new("a").unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WorkService {
|
||||||
|
fn write_imei(&mut self, imei: String) -> Result<bool, String> {
|
||||||
|
let write_imei_command = format!("AT+ECCGSN=\"IMEI\",\"{}\"", imei);
|
||||||
|
return self.serial_service.send_command_with_target(write_imei_command, None, "OK".to_string());
|
||||||
|
}
|
||||||
|
fn write_sn(&mut self, sn: String) -> Result<bool, String> {
|
||||||
|
let write_sn_command = format!("AT+ECCGSN=\"SN\",\"{}\"", sn);
|
||||||
|
return self.serial_service.send_command_with_target(write_sn_command, None, "OK".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_imei(&mut self, imei: &str) -> Result<bool, String> {
|
||||||
|
let check_imei_command = "AT+CGSN=1".to_string();
|
||||||
|
return self.serial_service.send_command_with_target(check_imei_command, None, imei.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_sn(&mut self, sn: &str) -> Result<bool, String> {
|
||||||
|
let check_sn_command = "AT+CGSN=0".to_string();
|
||||||
|
return self.serial_service.send_command_with_target(check_sn_command, None, sn.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user