AtClient

Struct AtClient 

Source
pub struct AtClient<P> { /* private fields */ }
Expand description

AT 指令客户端。P 是字节流:串口,或任何实现了 Read + Write 的类型。

对 P 的要求:read 在没有数据时应在较短时间(例如 100 ms)内返回 Ok(0) 或 TimedOut / WouldBlock 错误,而不是无限阻塞,否则指令超时不起作用。

Implementations§

Source§

impl AtClient<Box<dyn SerialPort>>

Source

pub fn open(path: &str) -> Result<Self>

打开串口(115200 8N1)并同步。path 如 /dev/ttyACM0、COM5。

Linux 上板子的串口可以用 /dev/serial/by-id/usb-1a86_USB_Single_Serial_* 找到。

Source§

impl<P: Read + Write> AtClient<P>

Source

pub fn new(port: P) -> Self

用现成的字节流构造(不发送任何东西)。

Source

pub fn set_timeout(&mut self, timeout: Duration)

一条指令等待 OK / ERROR 的时间,默认 8 s。自检和 ADC 上电另有更长的固定超时。

Source

pub fn into_inner(self) -> P

取回底层的字节流。

Source

pub fn sync(&mut self) -> Result<()>

同步:发一个空行结束设备行缓冲里可能残留的字符,丢弃 0.3 s 内收到的全部输出。

Source

pub fn command(&mut self, cmd: &str) -> Result<Vec<String>>

发送一条指令(不带行尾),返回 OK 之前设备输出的行。设备回答 ERROR 时返回 Error::At。

Source

pub fn command_timeout( &mut self, cmd: &str, timeout: Duration, ) -> Result<Vec<String>>

同 command,指定超时。

Source

pub fn wait_for(&mut self, text: &str, timeout: Duration) -> Result<Vec<String>>

等待设备输出一行包含 text 的内容,返回这之前(含该行)收到的全部行。

用于捕获上电自检报告:板子上电后调用 wait_for("ready, AT+HELP", 60 s)。

Source

pub fn ping(&mut self) -> Result<()>

AT:握手,检查管理程序在响应。

Source

pub fn version(&mut self) -> Result<VersionInfo>

ATI:固件版本。

Source

pub fn help(&mut self) -> Result<Vec<String>>

AT+HELP:指令列表(原文)。

Source

pub fn status(&mut self) -> Result<SystemStatus>

AT+STATUS?:系统状态。

Source

pub fn selftest_result(&mut self) -> Result<SelfTestResult>

AT+SELFTEST?:上一次自检的结果。

Source

pub fn run_selftest(&mut self) -> Result<SelfTestReport>

AT+SELFTEST:重新自检并返回报告,约需 10 s(超时 90 s)。

自检期间 ADC 会重新上电和训练,数据面有短暂中断;不要在采集过程中执行。

Source

pub fn filter(&mut self) -> Result<FilterSetting>

AT+FILT?:采集路径滤波器的档位。

Source

pub fn set_filter(&mut self, f: FilterSetting) -> Result<()>

AT+FILT=<FIR 档>,<log2 平均长度>。

Source

pub fn fir_coefficients(&mut self, gear: u8) -> Result<[i16; 8]>

AT+FIRCOEF?<档>:读出一组 FIR 系数(档 1..=7)。15 抽头对称 FIR 的 8 个系数, c0 最外侧 … c7 中心,Q1.15。

Source

pub fn set_fir_coefficients(&mut self, gear: u8, coef: &[i16; 8]) -> Result<()>

AT+FIRCOEF=<档>,<c0>,…,<c7>:写入一组 FIR 系数。档 4..=7 留给用户;直流增益 = (2 × (c0+…+c6) + c7) / 32768。

Source

pub fn statistics(&mut self, window: Option<Window>) -> Result<Vec<StatTable>>

AT+STAT?:window 为 None 时返回三个窗口的统计表,否则只返回指定窗口。

Source

pub fn set_stat_source(&mut self, filtered: bool) -> Result<()>

AT+STATSRC=<0|1>:统计取自原始样点(false)或采集路径滤波器的输出(true)。

Source

pub fn set_stream_period(&mut self, seconds: u32) -> Result<()>

AT+STREAM=<秒>:让管理程序每隔这么多秒自行打印一次 1 s 窗口的统计表,0 关闭(最大 3600)。

打开后,这些自发输出会混进后续指令的应答行里,解析类的方法可能因此出错; 需要周期读数时建议改为定时调用 read。

Source

pub fn set_adc_power(&mut self, on: bool) -> Result<()>

AT+ADC=<0|1>:ADC 模块断电 / 上电并训练 LVDS 接收(上电约需数秒,超时 60 s)。

Source

pub fn set_lasers(&mut self, sfp0: bool, sfp1: bool) -> Result<()>

AT+SFP=<掩码>:两个光口的激光开关。上电时都是关的;数据走 SFP0。

Source

pub fn uptime(&mut self) -> Result<Duration>

AT+UPTIME?:开机时间(自 PL 配置完成起,49.7 天回绕)。

Source

pub fn host_ip(&mut self) -> Result<Ipv4Addr>

AT+HOSTIP?:上位机 IP(数据和心跳的目的地址)。

Source

pub fn set_host_ip(&mut self, ip: Ipv4Addr) -> Result<()>

AT+HOSTIP=<a.b.c.d>:设置上位机 IP,立即生效,不掉电保存。

Source

pub fn read(&mut self, target: Target, window: Window) -> Result<Vec<Reading>>

AT+READ=<对象>,<窗口>:当前读数——最近一个已完成统计窗口的均值、rms、最小、最大(ADC 码)。

Source

pub fn ranges(&mut self) -> Result<[Range; 12]>

AT+RANGE?:12 路输入各自的量程。

Source

pub fn set_range(&mut self, target: Target, range: Range) -> Result<()>

AT+RANGE=<对象>,<10|5|2>:设置输入量程。上电默认 ±10 V,不掉电保存。

Source

pub fn conv_sources(&mut self) -> Result<Vec<ConvSource>>

AT+CONV?:当前用作 CONV 来源的输入。

Source

pub fn set_conv_sources(&mut self, channels: &[Channel]) -> Result<()>

AT+CONV=<输入>[,<输入>…] / AT+CONV=NONE:整体替换 CONV 来源列表(最多 4 路)。 列表里的输入都进组 0、上升沿、阈值 1400 码、迟滞 200 码;空列表清除全部来源。

Source

pub fn add_conv_source(&mut self, s: &ConvSource) -> Result<()>

AT+CONVADD=<输入>,<组>,<沿>,<阈值>,<迟滞>:增加一路 CONV 来源;该输入已在列表里则就地修改。 4 个边沿检测器用完时设备返回 ERROR。

Source

pub fn remove_conv_source(&mut self, channel: Channel) -> Result<()>

AT+CONVDEL=<输入>:删除一路 CONV 来源;不在列表里时设备返回 ERROR。

Trait Implementations§

Source§

impl<P: Read + Write> RegIo for AtClient<P>

经 AT+REG 读写寄存器。每个寄存器一条指令,115200 波特率下每秒约一百多次。

Source§

fn read_regs(&mut self, addr: u16, n: usize) -> Result<Vec<u32>>

从 addr 起连续读 n 个寄存器(地址每次加 4)。
Source§

fn write_regs(&mut self, pairs: &[(u16, u32)]) -> Result<Vec<u32>>

按顺序写一组 (地址, 值),返回每个寄存器写后读回的值。
Source§

fn read_reg(&mut self, addr: u16) -> Result<u32>

读一个寄存器。
Source§

fn write_reg(&mut self, addr: u16, value: u32) -> Result<u32>

写一个寄存器,返回写后读回的值。

Auto Trait Implementations§

§

impl<P> Freeze for AtClient<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for AtClient<P>
where P: RefUnwindSafe,

§

impl<P> Send for AtClient<P>
where P: Send,

§

impl<P> Sync for AtClient<P>
where P: Sync,

§

impl<P> Unpin for AtClient<P>
where P: Unpin,

§

impl<P> UnwindSafe for AtClient<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.