1#[cfg(test)]
2mod tests;
3
4use core::fmt;
5
6pub const PROJECT_VERSION: &str = "/etc/quectel-project-version";
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum Model {
12 Eva,
14 Evd,
16}
17
18#[derive(Clone, Debug, PartialEq, Eq)]
20pub struct Revision {
21 pub revision: String,
23 pub model: Option<Model>,
25}
26
27impl Model {
28 const fn as_str(self) -> &'static str {
29 match self {
30 Self::Eva => "AG35EVA",
31 Self::Evd => "AG35EVD",
32 }
33 }
34
35 fn from_revision(revision: &str) -> Option<Self> {
36 [Self::Eva, Self::Evd]
37 .into_iter()
38 .find(|model| revision.contains(model.as_str()))
39 }
40}
41
42impl fmt::Display for Model {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 f.write_str(self.as_str())
45 }
46}
47
48impl Revision {
49 #[must_use]
52 pub fn parse(content: &str) -> Option<Self> {
53 content.lines().find_map(|line| {
54 let (key, value) = line.split_once(':')?;
55 key.trim().ends_with("Rev").then(|| {
56 let revision = value.trim().to_owned();
57 Self {
58 model: Model::from_revision(&revision),
59 revision,
60 }
61 })
62 })
63 }
64}