opendaq 0.1.1

Safe Rust bindings for openDAQ, the open-source data acquisition SDK
Documentation
// Generated by tools/generate_bindings.py -- do not edit by hand.

// Mechanical output: lint findings here are the generator's business.
#![allow(clippy::all, unused_imports, rustdoc::bare_urls)]

use crate::error::{check, Error, Result};
use crate::object::{BaseObject, Interface, Ref};
use crate::sys;
use crate::value::{Complex, Ratio, Value};
use crate::generated::*;
use std::ffi::c_char;

/// Channels represent physical sensors of openDAQ devices. Internally they are standard function blocks with an additional option to provide a list of tags.
/// Wrapper over the openDAQ `daqChannel` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct Channel(pub(crate) FunctionBlock);

impl std::ops::Deref for Channel {
    type Target = FunctionBlock;
    fn deref(&self) -> &FunctionBlock { &self.0 }
}
impl crate::sealed::Sealed for Channel {}
unsafe impl Interface for Channel {
    const NAME: &'static str = "daqChannel";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqChannel_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl Channel {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { Channel(FunctionBlock::__from_ref(r)) }
}
impl std::fmt::Display for Channel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&Channel> for Value {
    fn from(value: &Channel) -> Value { Value::Object(value.to_base_object()) }
}
impl From<Channel> for Value {
    fn from(value: Channel) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for Channel {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

/// Provides information about the function block.
/// Wrapper over the openDAQ `daqFunctionBlockType` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct FunctionBlockType(pub(crate) ComponentType);

impl std::ops::Deref for FunctionBlockType {
    type Target = ComponentType;
    fn deref(&self) -> &ComponentType { &self.0 }
}
impl crate::sealed::Sealed for FunctionBlockType {}
unsafe impl Interface for FunctionBlockType {
    const NAME: &'static str = "daqFunctionBlockType";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqFunctionBlockType_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl FunctionBlockType {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { FunctionBlockType(ComponentType::__from_ref(r)) }
}
impl std::fmt::Display for FunctionBlockType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&FunctionBlockType> for Value {
    fn from(value: &FunctionBlockType) -> Value { Value::Object(value.to_base_object()) }
}
impl From<FunctionBlockType> for Value {
    fn from(value: FunctionBlockType) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for FunctionBlockType {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

/// Recorders represent objects which record input data to a persistent storage medium such as a file, database, or cloud storage bucket. Recorders implement the `IRecorder` interface and may expose additional properties for configuring the storage (such as file type, storage location, etc.). tags.
/// Wrapper over the openDAQ `daqRecorder` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct Recorder(pub(crate) BaseObject);

impl std::ops::Deref for Recorder {
    type Target = BaseObject;
    fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for Recorder {}
unsafe impl Interface for Recorder {
    const NAME: &'static str = "daqRecorder";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqRecorder_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl Recorder {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { Recorder(BaseObject(r)) }
}
impl std::fmt::Display for Recorder {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&Recorder> for Value {
    fn from(value: &Recorder) -> Value { Value::Object(value.to_base_object()) }
}
impl From<Recorder> for Value {
    fn from(value: Recorder) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for Recorder {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

impl FunctionBlockType {
    /// Creates a Function block type object, with the id, name, description and optional defaultConfig.
    ///
    /// # Parameters
    /// - `id`: The unique type ID of the function block.
    /// - `name`: The name of the function block. Eg. FFT.
    /// - `description`: A short description of the function block and its behaviour.
    /// - `default_config`: The property object, to be cloned and returned, each time user creates default configuration object. This way each instance of the function block has its own configuration object.
    ///
    /// Calls the openDAQ C function `daqFunctionBlockType_createFunctionBlockType()`.
    pub fn new(id: &str, name: &str, description: &str, default_config: &PropertyObject) -> Result<FunctionBlockType> {
        let __id = crate::marshal::make_string(id)?;
        let __name = crate::marshal::make_string(name)?;
        let __description = crate::marshal::make_string(description)?;
        let mut __obj: *mut sys::daqFunctionBlockType = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqFunctionBlockType_createFunctionBlockType)(&mut __obj, __id.as_ptr() as *mut _, __name.as_ptr() as *mut _, __description.as_ptr() as *mut _, default_config.as_raw() as *mut _) };
        check(__code, "daqFunctionBlockType_createFunctionBlockType")?;
        Ok(unsafe { crate::marshal::require_object::<FunctionBlockType>(__obj as *mut _, "daqFunctionBlockType_createFunctionBlockType") }?)
    }

}

impl Recorder {
    /// Checks whether data from connected signals is currently being recorded to the persistent storage medium.
    ///
    /// # Parameters
    /// - `is_recording`: A pointer to a boolean which is populated with the recording state.
    ///
    /// # Errors
    /// - `OPENDAQ_SUCCESS`: if the recording status was successfully returned.
    ///
    /// Calls the openDAQ C function `daqRecorder_getIsRecording()`.
    pub fn is_recording(&self) -> Result<bool> {
        let mut __is_recording: u8 = 0;
        let __code = unsafe { (crate::sys::api().daqRecorder_getIsRecording)(self.as_raw() as *mut _, &mut __is_recording) };
        check(__code, "daqRecorder_getIsRecording")?;
        Ok(__is_recording != 0)
    }

    /// Starts recording data from connected signals to the persistent storage medium.
    ///
    /// # Errors
    /// - `OPENDAQ_SUCCESS`: if the recording successfully started.
    /// - `OPENDAQ_ERR_INVALIDSTATE`: if the recording has already been started and the implementation chooses to treat this scenario as an error.
    ///
    /// Calls the openDAQ C function `daqRecorder_startRecording()`.
    pub fn start_recording(&self) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqRecorder_startRecording)(self.as_raw() as *mut _) };
        check(__code, "daqRecorder_startRecording")?;
        Ok(())
    }

    /// Stops recording data from connected signals to the persistent storage medium.
    ///
    /// # Errors
    /// - `OPENDAQ_SUCCESS`: if the recording successfully stopped.
    /// - `OPENDAQ_ERR_INVALIDSTATE`: if the recording is not started and the implementation chooses to treat this scenario as an error.
    ///
    /// Calls the openDAQ C function `daqRecorder_stopRecording()`.
    pub fn stop_recording(&self) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqRecorder_stopRecording)(self.as_raw() as *mut _) };
        check(__code, "daqRecorder_stopRecording")?;
        Ok(())
    }

}