diff --git a/src/api/class/include/class/class.hpp b/src/api/class/include/class/class.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7aeeea98830a559adac864a6314a75050cbe1f45 --- /dev/null +++ b/src/api/class/include/class/class.hpp @@ -0,0 +1,539 @@ +/** + * @file class.hpp + * @author Alfonso Dominguez <alfonso.dominguez@tecnalia.com> and Leire Querejeta Lomas <leire.querejeta@tecnalia.com> + * @date 2020 + * + * Copyright 2020 Tecnalia Research & Innovation. + * Distributed under the GNU GPL v3. + * For full terms see https://www.gnu.org/licenses/gpl.txt + * + * @brief Header with the API methods + */ + +#pragma once + +#include <string> +#include <vector> + +#include "class_structures.hpp" +#include "class_error.hpp" +#include "class_cb.hpp" + +#include <class/class_Export.h> + +// forward declaration +class ClassCore; + +//! default server port to connect to +const int DEFAULT_SERVER_PORT = 50000; +//! default server ip to connect to +const std::string DEFAULT_SERVER_IP = "127.0.0.1"; +//! default port on which class_server messages are listened to +const int DEFAULT_LOCAL_PORT = 50001; +//! default ip on which class_server messages are listened to +const std::string DEFAULT_LOCAL_IP = "127.0.0.1"; + +//! API main class +class CLASS_EXPORT Class +{ +public: + + //! Allowed acquisition rates + enum AcqFreq { + FREQ_250, ///< 250Hz + FREQ_500, ///< 500Hz + FREQ_1000, ///< 1000Hz + FREQ_2000, ///< 2000Hz + FREQ_4000, ///< 4000Hz + FREQ_8000 ///< 8000Hz + }; + + //! Mode for initialization + enum InitMode { + TACTILITY, ///< Tactility: low amplitude stimulators, and includes a special fw version, such as the command of "selected 0/1" + PAIN, ///< Pain: low amplitude stimulators, including small steps (0.1 steps) + DESKTOP, ///< Desktop: high amplitudes, with bigger steps (0.1 are not allowed, only 1 steps) + NEURORESEARCH, + ICARE, + TIB_ACQ, + TIB_STIM + }; + + //! Allowed channel numbers for acquisition + enum AcqCh { + CH_1, ///< 1 channel + CH_2, ///< 2 channels + CH_3, ///< 3 channels + CH_4, ///< 4 channels + CH_5, ///< 5 channels + CH_6, ///< 6 channels + CH_7, ///< 7 channels + CH_8, ///< 8 channels + CH_9, ///< 9 channels + CH_10, ///< 10 channels + CH_11, ///< 11 channels + CH_12, ///< 12 channels + CH_13, ///< 13 channels + CH_14, ///< 14 channels + CH_15, ///< 15 channels + CH_16 ///< 16 channels + }; + + //! Acquisition types + enum AcqImpedancePolarity { + TYPE_UNIPOLAR, ///< Unipolar + TYPE_BIPOLAR ///< Bipolar + }; + + //! Impedance acquisition sign + enum AcqImpedanceSign { + TYPE_POSITIVE, ///< Positives + TYPE_NEGATIVE ///< Negatives + }; + + //! Acquisition gain + enum AcqGain { + GAIN_1, ///< 1.0 + GAIN_2, ///< 2.0 + GAIN_4, ///< 4.0 + GAIN_8, ///< 8.0 + GAIN_12, ///< 12.0 + GAIN_24 ///< 24.0 + }; + + //! Acquisition Input + enum AcqInput { + NORMAL, ///< Normal + TEST ///< Test + }; + + //! Basic constructor + Class(); + //! Basic destructor + ~Class(); + + /*! + \brief Connect to the CLASS server + \return Integer indicating the success of the connection (0-success, <0 error) + */ + ClassError::Error connect(); + + /*! + \brief Connect to the CLASS server + \param server_ip IP to connect with. + \param server_port Port to connect with. + \return Integer indicating the success of the connection (0-success, <0 error) + */ + ClassError::Error connect(const std::string & server_ip, const int & server_port); + + /*! + \brief Connect to the CLASS server + \param server_ip IP to connect with. + \param server_port Port to connect with. + \param local_port Port which listens for msgs coming from CLASS server. + \return Integer indicating the success of the connection (0-success, <0 error) + */ + ClassError::Error connect(const std::string & server_ip, const int & server_port, const int & local_port); + + /*! + \brief Connect to the CLASS server + \param server_ip IP to connect with. + \param server_port Port to connect with. + \param local_ip IP which listens for msgs coming from CLASS server. + \param local_port Port which listens for msgs coming from CLASS server. + \return Integer indicating the success of the connection (0-success, <0 error) + */ + ClassError::Error connect(const std::string & server_ip, const int & server_port, const std::string & local_ip, const int & local_port); + + /*! + \brief Disconnect from CLASS server + \return Integer indicating the success of the disconnection (0-success, <0 error) + */ + ClassError::Error disconnect(); + + /*! + \brief get acquisition frames + \return Vector with acquisition frames + */ + std::vector<AcqFrame> getAcqFrames(); + + /*! + \brief get the level of the battery + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getBattery(); + + /*! + \brief get buzzer + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getBuzzer(); + + /*! + \brief get device name + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getDeviceName(); + + /*! + \brief get the firmware version + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getFirmware(); + + /*! + \brief get frequency + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getFrequency(); + + /*! + \brief get the hardware version + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getHardware(); + + /*! + \brief get high voltage + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getHv(); + + /*! + \brief get interval + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getInterval(); + + /*! + \brief get logevents + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getLogevents(); + + /*! + \brief get pattern + \param number number of pattern + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getPatternStatus(const int& number); + + + /*! + \brief get rtc + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getRTC(); + + /*! + \brief get sd function + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getSDFunction(); + + /*! + \brief get sd user name + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getSDUName(); + + /*! + \brief get the tic + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getTic(); + + /*! + \brief get virtual electrode + \param number of virtual electrode + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error getVelecStatus(const int& number); + + /*! + \brief Init communication + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error initCommunication(); + + /*! + \brief Init communication sending iam mode + \param mode Initialization mode. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error initCommunication(const InitMode& mode); + + /*! + \brief Clear pattern + \param id pattern to delete + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error patternDelete(const int& id); + + /*! + \brief Sends custom command to CLASS device + \param cmd Command. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error sendCustomCmd(const std::string& cmd); + + /*! + \brief Sets class acq configurations + \param frequency Frequency of acquisition. + \param channel_numbers Channel numbers. + \param gain Gain for the acquisition. + \param input Acq input type, normal or test. + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setAcqConfig(const AcqFreq& frequency, const std::vector<int>& channel_numbers, const AcqGain& gain, const AcqInput& input); + + /*! + \brief Sets the config for impedance acquisition + \param type Impedance acquisition type. + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setAcqImpedanceConfig(const AcqImpedanceSign& type); + + /*! + \brief Sets the polarity for impedance acquisition + \param type Polarity acquisition type. + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setAcqImpedancePolarity(const AcqImpedancePolarity& polarity); + + /*! + \brief Sets class acq input to normal (bio signal captured from channels) + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setAcqInputNormal(); + + /*! + \brief Sets class acq input to test. The class will provide a quadratic signal. It is useful for testing and not getting saturated signal all the time. + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setAcqInputTest(); + + /*! + \brief Sets the order of the filter used for impedance calculation + \param order Filter order (>0). + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setImpedanceFilterOrder(const int& order); + + /*! + \brief Sets the duration of the buffer (ms*frequency//1000.0) + \param ms Time in ms. + \return Integer indicating the success of the setting process (0-success, <0 error) + */ + ClassError::Error setBufferDuration(const double& ms); + + /*! + \brief Sets buzzer on + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setbuzzerPlay(); + + /*! + \brief Sets ms of buzzer song + \param tempo time in ms + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setbuzzerTempo(const std::string& tempo); + + /*! + \brief set the callback + \param callback Callback + \param language Language which has defined the callback + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setCallback(ClassCallback * callback, std::string language); + + /*! + \brief Sets name of device + \param name name of the device. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setDevName(const std::string& devicename); + + /*! + \brief Sets electrode pads number + \param id Electrode number/ID. + \param pads_number Number of pads of the electrode. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setElecPads(const int& id, const int& pads_number); + + /*! + \brief Sets high voltage to off + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error sethvOff(); + + /*! + \brief Sets name of device + \param hvvalue name of the device. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error sethvValue(const std::string& hvvalue); + + /*! + \brief Sets high voltage to on + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error sethvOn(); + + /*! + \brief Sets interval value + \param interval value of stimulation interl pulses interval + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setintervalValue(const std::string& interval); + /*! + \brief Sets logevents to off + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setlogeventsOff(); + /*! + \brief Sets logevents to on + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setlogeventsOn(); + + /*! + \brief set pattern + \param id pattern number + \param pat vector of patterns + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setPattern(const int& id, const std::vector<Pattern>& pat); + + /*! + \brief set name of sd card folder where the pattern are saved + \param sdfunctionname name of the folder + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setSDFunctionName(const std::string& sdfunctionname); + + /*! + \brief set name of sdcard folder where the folder containing the patterns is saved + \param sduname name of the folder + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setSDUName(const std::string& sduname); + + /*! + \brief Shutdown + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setShutdown(); + /*! + \brief Sets electrode pads number + \param frequency Frequency of the stimulation. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setStimFreq(const double& frequency); + + /*! + \brief Sets rtc date + \param date mm/dd/yyyy format + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setrtcDate(const std::string& rtcDate); + + /*! + \brief Sets rtc time + \param date hh:mm:ss format + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setrtcTime(const std::string& rtcTime); + + /*! + \brief Sets virtual electrode + \param id Virtual electrode number/ID. + \param name Name of the virtual electrode. + \param electrode_id Electrode ID/number. + \param cathodes List of integers with the IDs of the pads acting as cathodes + \param anodes List of integers with the IDs of the pads acting as cathodes + \param amp List of doubles with the amplitude (in mA) associated to each of the cathodes. Must have the same length as cathodes + \param width List of integers with the pulse width (in uS) associated to each of the cathodes. Must have the same length as cathodes + \param selected Defines if the velec is selected (‘true’ value) or deselected (‘false’ value). Only selected velecs will be executed with a “stim on” command + \param sync Defines if the velec is synchronous (‘rtue’ value) or asynchronous (‘false’ value). + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setVelec(const int& id, const std::string& name, const int& electrode_id, const std::vector<int>& cathodes, const std::vector<int>& anodes, const std::vector<double>& amp, const std::vector<int>& width, const bool& selected, const bool& sync); + + /*! + \brief Sets whether the virtual electrode is selected or not + \param id Virtual electrode number/ID. + \param selected Defines if the velec is selected (‘true’ value) or deselected (‘false’ value). Only selected velecs will be executed with a “stim on” command. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setVelecSelected(const int& id, const bool& selected); + + /*! + \brief Sets whether the virtual electrodes are selected or not + \param id Vector with virtual electrode numbers/IDs. + \param selected Vector with bool indicating whether the velecs are selected (‘true’ value) or deselected (‘false’ value). Only selected velecs will be executed with a “stim on” command. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error setVelecsSelected(const std::vector<int>& id, const std::vector<bool>& selected); + + /*! + \brief Starts acquisition + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error startAcq(); + + /*! + \brief Starts acquisition stream + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error startAcqStream(); + + /*! + \brief Starts impedance acquisition + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error startImpedanceAcq(); + + /*! + \brief Starts stimulation + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error startStim(); + + /*! + \brief Start stimulation of the virtual electrode which name is passed as parameter + \param name Name of the virtual electrode. + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error stimVelec(const std::string& name); + + /*! + \brief Stops acquisition + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error stopAcq(); + + /*! + \brief Stops acquisition stream + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error stopAcqStream(); + + /*! + \brief Stops impedance acquisition + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error stopImpedanceAcq(); + + /*! + \brief Stops stimulation + \return Integer indicating the success of the process (0-success, <0 error) + */ + ClassError::Error stopStim(); + +private: + //! Core internal component + ClassCore * core_; +};