This commit is contained in:
Florian Briand 2024-09-11 20:22:47 +02:00
parent 338c6737e9
commit bd9ff39ef0
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B
3 changed files with 43 additions and 4 deletions

View File

@ -8,4 +8,5 @@ edition = "2021"
bitvec = "1.0.1" bitvec = "1.0.1"
deku = "0.17.0" deku = "0.17.0"
libc = "0.2.155" libc = "0.2.155"
num_enum = { version = "0.7.3", features = ["complex-expressions"] }
thiserror = "1.0.63" thiserror = "1.0.63"

View File

@ -1,13 +1,52 @@
use thiserror::Error; use deku::{deku_derive, DekuContainerRead, DekuError, DekuReader};
use std::{ffi::CString, fmt, path::Path, ptr}; use std::{ffi::CString, fmt, path::Path, ptr};
use thiserror::Error;
use crate::{bindings::{SSV_InitLIB2, SSV_TermLIB}, types::{common::read_from_buffer, configuration::Configuration}}; use crate::{
bindings::{SSV_InitLIB2, SSV_LireConfig, SSV_TermLIB},
types::{common::read_from_buffer, configuration::Configuration},
};
use num_enum::FromPrimitive;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub struct SesamVitaleError { pub struct SesamVitaleError {
code: u16, code: u16,
} }
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
#[repr(u16)]
enum SSVIntError {
CPSNotInserted = 61441,
#[num_enum(catch_all)]
NotImplemented(u16),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sesam_vitale_error() {
let int_error = SSVIntError::from(61441);
assert_eq!(int_error, SSVIntError::CPSNotInserted);
let int_error = SSVIntError::from(123);
assert_eq!(int_error, SSVIntError::NotImplemented(123));
println!("{:?}", int_error);
}
}
#[derive(Error, Debug)]
enum SSVError {
#[error("Erreur standard de la librairie SSV")]
SSVStandard,
// #[error("Erreur de parsing")]
// Parsing(#[from] ParsingError),
#[error("Erreur inattendue de la librairie SSV (TMP)")]
SSVUnknownTmp,
}
impl fmt::Display for SesamVitaleError { impl fmt::Display for SesamVitaleError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Got error code {} from SSV_LireConfig", self.code) write!(f, "Got error code {} from SSV_LireConfig", self.code)
@ -63,4 +102,3 @@ pub fn read_config() -> Result<Configuration, SesamVitaleError> {
Ok(configuration) Ok(configuration)
} }

View File

@ -1,3 +1,3 @@
pub mod common; pub mod common;
pub mod configuration; pub mod configuration;
pub mod droits_vitale; // pub mod droits_vitale;