Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Static Private Attributes | List of all members
YAPI Class Reference

#include <yocto_api.h>

Static Public Member Functions

static string _bin2HexStr (const string &data)
 
static string _checkFirmware (const string &serial, const string &rev, const string &path)
 
static double _decimalToDouble (s16 val)
 
static vector< int > _decodeFloats (string sdat)
 
static vector< int > _decodeWords (string s)
 
static s16 _doubleToDecimal (double val)
 
static string _flattenJsonStruct (string jsonbuffer)
 
static yCalibrationHandler _getCalibrationHandler (int calibType)
 
static string _hexStr2Bin (const string &str)
 
static void _yapiFunctionUpdateCallbackFwd (YFUN_DESCR fundesc, const char *value)
 
static bool CheckLogicalName (const string &name)
 
static void DisableExceptions (void)
 
static void EnableExceptions (void)
 
static void FreeAPI (void)
 
static string GetAPIVersion (void)
 
static u64 GetTickCount (void)
 
static YRETCODE HandleEvents (string &errmsg)
 
static YRETCODE InitAPI (int mode, string &errmsg)
 
static double LinearCalibrationHandler (double rawValue, int calibType, intArr params, floatArr rawValues, floatArr refValues)
 
static YRETCODE PreregisterHub (const string &url, string &errmsg)
 
static void RegisterCalibrationHandler (int calibrationType, yCalibrationHandler calibrationHandler)
 
static void RegisterDeviceArrivalCallback (yDeviceUpdateCallback arrivalCallback)
 
static void RegisterDeviceChangeCallback (yDeviceUpdateCallback changeCallback)
 
static void RegisterDeviceRemovalCallback (yDeviceUpdateCallback removalCallback)
 
static YRETCODE RegisterHub (const string &url, string &errmsg)
 
static void RegisterHubDiscoveryCallback (YHubDiscoveryCallback hubDiscoveryCallback)
 
static void RegisterLogFunction (yLogFunction logfun)
 
static YRETCODE Sleep (unsigned ms_duration, string &errmsg)
 
static YRETCODE TestHub (const string &url, int mstimeout, string &errmsg)
 
static YRETCODE TriggerHubDiscovery (string &errmsg)
 
static void UnregisterHub (const string &url)
 
static YRETCODE UpdateDeviceList (string &errmsg)
 

Static Public Attributes

static bool _apiInitialized = false
 
static yCRITICAL_SECTION _global_cs
 
static int DefaultCacheValidity = 5
 
static const u32 DETECT_ALL = (Y_DETECT_USB | Y_DETECT_NET)
 
static const u32 DETECT_NET = 2
 
static const u32 DETECT_NONE = 0
 
static const u32 DETECT_USB = 1
 
static const int DEVICE_BUSY = -6
 
static const int DEVICE_NOT_FOUND = -4
 
static yDeviceUpdateCallback DeviceArrivalCallback = NULL
 
static yDeviceUpdateCallback DeviceChangeCallback = NULL
 
static yDeviceUpdateCallback DeviceRemovalCallback = NULL
 
static const int DOUBLE_ACCES = -11
 
static bool ExceptionsDisabled = false
 
static const int EXHAUSTED = -10
 
static const int FILE_NOT_FOUND = -14
 
static const int INVALID_ARGUMENT = -2
 
static const double INVALID_DOUBLE = (-DBL_MAX)
 
static const int INVALID_INT = YAPI_INVALID_INT
 
static const s64 INVALID_LONG = YAPI_INVALID_LONG
 
static const string INVALID_STRING = YAPI_INVALID_STRING
 
static const int INVALID_UINT = YAPI_INVALID_UINT
 
static const int IO_ERROR = -8
 
static yLogFunction LogFunction = NULL
 
static const int NO_MORE_DATA = -9
 
static const int NOT_INITIALIZED = -1
 
static const int NOT_SUPPORTED = -3
 
static const u32 RESEND_MISSING_PKT = 4
 
static const int RTC_NOT_READY = -13
 
static const int SUCCESS = 0
 
static const int TIMEOUT = -7
 
static const int UNAUTHORIZED = -12
 
static const int VERSION_MISMATCH = -5
 

Static Private Member Functions

static void _yapiDeviceArrivalCallbackFwd (YDEV_DESCR devdesc)
 
static void _yapiDeviceChangeCallbackFwd (YDEV_DESCR devdesc)
 
static void _yapiDeviceLogCallbackFwd (YDEV_DESCR devdesc, const char *line)
 
static void _yapiDeviceRemovalCallbackFwd (YDEV_DESCR devdesc)
 
static void _yapiFunctionTimedReportCallbackFwd (YAPI_FUNCTION fundesc, double timestamp, const u8 *bytes, u32 len)
 
static void _yapiHubDiscoveryCallbackFwd (const char *serial, const char *url)
 
static void _yapiLogFunctionFwd (const char *log, u32 loglen)
 

Static Private Attributes

static map< int, yCalibrationHandler_calibHandlers
 
static queue< yapiDataEvent_data_events
 
static YHubDiscoveryCallback _HubDiscoveryCallback = NULL
 
static u64 _nextEnum = 0
 
static queue< yapiGlobalEvent_plug_events
 

Detailed Description

Definition at line 440 of file yocto_api.h.

Member Function Documentation

string YAPI::_bin2HexStr ( const string &  data)
static

Definition at line 4116 of file yocto_api.cpp.

static string YAPI::_checkFirmware ( const string &  serial,
const string &  rev,
const string &  path 
)
static
double YAPI::_decimalToDouble ( s16  val)
static

Definition at line 3977 of file yocto_api.cpp.

vector< int > YAPI::_decodeFloats ( string  sdat)
static

Definition at line 4067 of file yocto_api.cpp.

vector< int > YAPI::_decodeWords ( string  s)
static

Definition at line 4033 of file yocto_api.cpp.

s16 YAPI::_doubleToDecimal ( double  val)
static

Definition at line 3995 of file yocto_api.cpp.

static string YAPI::_flattenJsonStruct ( string  jsonbuffer)
static
yCalibrationHandler YAPI::_getCalibrationHandler ( int  calibType)
static

Definition at line 4023 of file yocto_api.cpp.

string YAPI::_hexStr2Bin ( const string &  str)
static

Definition at line 4130 of file yocto_api.cpp.

void YAPI::_yapiDeviceArrivalCallbackFwd ( YDEV_DESCR  devdesc)
staticprivate

Definition at line 3863 of file yocto_api.cpp.

void YAPI::_yapiDeviceChangeCallbackFwd ( YDEV_DESCR  devdesc)
staticprivate

Definition at line 3903 of file yocto_api.cpp.

void YAPI::_yapiDeviceLogCallbackFwd ( YDEV_DESCR  devdesc,
const char *  line 
)
staticprivate

Definition at line 3847 of file yocto_api.cpp.

void YAPI::_yapiDeviceRemovalCallbackFwd ( YDEV_DESCR  devdesc)
staticprivate

Definition at line 3889 of file yocto_api.cpp.

void YAPI::_yapiFunctionTimedReportCallbackFwd ( YAPI_FUNCTION  fundesc,
double  timestamp,
const u8 *  bytes,
u32  len 
)
staticprivate

Definition at line 3937 of file yocto_api.cpp.

void YAPI::_yapiFunctionUpdateCallbackFwd ( YFUN_DESCR  fundesc,
const char *  value 
)
static

Definition at line 3918 of file yocto_api.cpp.

void YAPI::_yapiHubDiscoveryCallbackFwd ( const char *  serial,
const char *  url 
)
staticprivate

Definition at line 3956 of file yocto_api.cpp.

void YAPI::_yapiLogFunctionFwd ( const char *  log,
u32  loglen 
)
staticprivate

Definition at line 3840 of file yocto_api.cpp.

bool YAPI::CheckLogicalName ( const string &  name)
static

Checks if a given string is valid as logical name for a module or a function. A valid logical name has a maximum of 19 characters, all among A..Z, a..z, 0..9, _, and -. If you try to configure a logical name with an incorrect string, the invalid characters are ignored.

Parameters
name: a string containing the name to check.
Returns
true if the name is valid, false otherwise.

Definition at line 4771 of file yocto_api.cpp.

void YAPI::DisableExceptions ( void  )
static

Disables the use of exceptions to report runtime errors. When exceptions are disabled, every function returns a specific error value which depends on its type and which is documented in this reference manual.

Definition at line 4288 of file yocto_api.cpp.

void YAPI::EnableExceptions ( void  )
static

Re-enables the use of exceptions for runtime error handling. Be aware than when exceptions are enabled, every function that fails triggers an exception. If the exception is not caught by the user code, it either fires the debugger or aborts (i.e. crash) the program. On failure, throws an exception or returns a negative error code.

Definition at line 4298 of file yocto_api.cpp.

void YAPI::FreeAPI ( void  )
static

Frees dynamically allocated memory blocks used by the Yoctopuce library. It is generally not required to call this function, unless you want to free all dynamically allocated memory blocks in order to track a memory leak for instance. You should not call any other library function after calling yFreeAPI(), or your program will crash.

Definition at line 4262 of file yocto_api.cpp.

string YAPI::GetAPIVersion ( void  )
static

Returns the version identifier for the Yoctopuce library in use. The version is a string in the form "Major.Minor.Build", for instance "1.01.5535". For languages using an external DLL (for instance C#, VisualBasic or Delphi), the character string includes as well the DLL version, for instance "1.01.5535 (1.01.5439)".

If you want to verify in your code that the library version is compatible with the version that you have used during development, verify that the major number is strictly equal and that the minor number is greater or equal. The build number is not relevant with respect to the library compatibility.

Returns
a character string describing the library version.

Definition at line 4192 of file yocto_api.cpp.

u64 YAPI::GetTickCount ( void  )
static

Returns the current value of a monotone millisecond-based time counter. This counter can be used to compute delays in relation with Yoctopuce devices, which also uses the millisecond as timebase.

Returns
a long integer corresponding to the millisecond counter.

Definition at line 4755 of file yocto_api.cpp.

YRETCODE YAPI::HandleEvents ( string &  errmsg)
static

Maintains the device-to-library communication channel. If your program includes significant loops, you may want to include a call to this function to make sure that the library takes care of the information pushed by the modules on the communication channels. This is not strictly necessary, but it may improve the reactivity of the library for the following commands.

This function may signal an error in case there is a communication problem while contacting a module.

Parameters
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4658 of file yocto_api.cpp.

YRETCODE YAPI::InitAPI ( int  mode,
string &  errmsg 
)
static

Initializes the Yoctopuce programming library explicitly. It is not strictly needed to call yInitAPI(), as the library is automatically initialized when calling yRegisterHub() for the first time.

When Y_DETECT_NONE is used as detection mode, you must explicitly use yRegisterHub() to point the API to the VirtualHub on which your devices are connected before trying to access them.

Parameters
mode: an integer corresponding to the type of automatic device detection to use. Possible values are Y_DETECT_NONE, Y_DETECT_USB, Y_DETECT_NET, and Y_DETECT_ALL.
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4221 of file yocto_api.cpp.

double YAPI::LinearCalibrationHandler ( double  rawValue,
int  calibType,
intArr  params,
floatArr  rawValues,
floatArr  refValues 
)
static

Definition at line 4408 of file yocto_api.cpp.

YRETCODE YAPI::PreregisterHub ( const string &  url,
string &  errmsg 
)
static

Fault-tolerant alternative to RegisterHub(). This function has the same purpose and same arguments as RegisterHub(), but does not trigger an error when the selected hub is not available at the time of the function call. This makes it possible to register a network hub independently of the current connectivity, and to try to contact it only when a device is actively needed.

Parameters
url: a string containing either "usb","callback" or the root URL of the hub to monitor
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4539 of file yocto_api.cpp.

void YAPI::RegisterCalibrationHandler ( int  calibrationType,
yCalibrationHandler  calibrationHandler 
)
static

Definition at line 4401 of file yocto_api.cpp.

void YAPI::RegisterDeviceArrivalCallback ( yDeviceUpdateCallback  arrivalCallback)
static

Register a callback function, to be called each time a device is plugged. This callback will be invoked while yUpdateDeviceList is running. You will have to call this function on a regular basis.

Parameters
arrivalCallback: a procedure taking a YModule parameter, or NULL to unregister a previously registered callback.

Definition at line 4321 of file yocto_api.cpp.

void YAPI::RegisterDeviceChangeCallback ( yDeviceUpdateCallback  changeCallback)
static

Definition at line 4350 of file yocto_api.cpp.

void YAPI::RegisterDeviceRemovalCallback ( yDeviceUpdateCallback  removalCallback)
static

Register a callback function, to be called each time a device is unplugged. This callback will be invoked while yUpdateDeviceList is running. You will have to call this function on a regular basis.

Parameters
removalCallback: a procedure taking a YModule parameter, or NULL to unregister a previously registered callback.

Definition at line 4345 of file yocto_api.cpp.

YRETCODE YAPI::RegisterHub ( const string &  url,
string &  errmsg 
)
static

Setup the Yoctopuce library to use modules connected on a given machine. The parameter will determine how the API will work. Use the following values:

usb: When the usb keyword is used, the API will work with devices connected directly to the USB bus. Some programming languages such a Javascript, PHP, and Java don't provide direct access to USB hardware, so usb will not work with these. In this case, use a VirtualHub or a networked YoctoHub (see below).

x.x.x.x or hostname: The API will use the devices connected to the host with the given IP address or hostname. That host can be a regular computer running a VirtualHub, or a networked YoctoHub such as YoctoHub-Ethernet or YoctoHub-Wireless. If you want to use the VirtualHub running on you local computer, use the IP address 127.0.0.1.

callback: that keyword make the API run in "<i>HTTP Callback</i>" mode. This a special mode allowing to take control of Yoctopuce devices through a NAT filter when using a VirtualHub or a networked YoctoHub. You only need to configure your hub to call your server script on a regular basis. This mode is currently available for PHP and Node.JS only.

Be aware that only one application can use direct USB access at a given time on a machine. Multiple access would cause conflicts while trying to access the USB modules. In particular, this means that you must stop the VirtualHub software before starting an application that uses direct USB access. The workaround for this limitation is to setup the library to use the VirtualHub rather than direct USB access.

If access control has been activated on the hub, virtual or not, you want to reach, the URL parameter should look like:

http://username:password@address:port

You can call RegisterHub several times to connect to several machines.

Parameters
url: a string containing either "usb","callback" or the root URL of the hub to monitor
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4509 of file yocto_api.cpp.

void YAPI::RegisterHubDiscoveryCallback ( YHubDiscoveryCallback  hubDiscoveryCallback)
static

Register a callback function, to be called each time an Network Hub send an SSDP message. The callback has two string parameter, the first one contain the serial number of the hub and the second contain the URL of the network hub (this URL can be passed to RegisterHub). This callback will be invoked while yUpdateDeviceList is running. You will have to call this function on a regular basis.

Parameters
hubDiscoveryCallback: a procedure taking two string parameter, the serial number and the hub URL. Use NULL to unregister a previously registered callback.

Definition at line 4365 of file yocto_api.cpp.

void YAPI::RegisterLogFunction ( yLogFunction  logfun)
static

Registers a log callback function. This callback will be called each time the API have something to say. Quite useful to debug the API.

Parameters
logfun: a procedure taking a string parameter, or NULL to unregister a previously registered callback.

Definition at line 4308 of file yocto_api.cpp.

YRETCODE YAPI::Sleep ( unsigned  ms_duration,
string &  errmsg 
)
static

Pauses the execution flow for a specified duration. This function implements a passive waiting loop, meaning that it does not consume CPU cycles significantly. The processor is left available for other threads and processes. During the pause, the library nevertheless reads from time to time information from the Yoctopuce modules by calling yHandleEvents(), in order to stay up-to-date.

This function may signal an error in case there is a communication problem while contacting a module.

Parameters
ms_duration: an integer corresponding to the duration of the pause, in milliseconds.
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4725 of file yocto_api.cpp.

YRETCODE YAPI::TestHub ( const string &  url,
int  mstimeout,
string &  errmsg 
)
static

Test if the hub is reachable. This method do not register the hub, it only test if the hub is usable. The url parameter follow the same convention as the RegisterHub method. This method is useful to verify the authentication parameters for a hub. It is possible to force this method to return after mstimeout milliseconds.

Parameters
url: a string containing either "usb","callback" or the root URL of the hub to monitor
mstimeout: the number of millisecond available to test the connection.
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure returns a negative error code.

Definition at line 4453 of file yocto_api.cpp.

YRETCODE YAPI::TriggerHubDiscovery ( string &  errmsg)
static

Force a hub discovery, if a callback as been registered with yRegisterHubDiscoveryCallback it will be called for each net work hub that will respond to the discovery.

Parameters
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds. On failure, throws an exception or returns a negative error code.

Definition at line 4381 of file yocto_api.cpp.

void YAPI::UnregisterHub ( const string &  url)
static

Setup the Yoctopuce library to no more use modules connected on a previously registered machine with RegisterHub.

Parameters
url: a string containing either "usb" or the root URL of the hub to monitor

Definition at line 4560 of file yocto_api.cpp.

YRETCODE YAPI::UpdateDeviceList ( string &  errmsg)
static

Triggers a (re)detection of connected Yoctopuce modules. The library searches the machines or USB ports previously registered using yRegisterHub(), and invokes any user-defined callback function in case a change in the list of connected devices is detected.

This function can be called as frequently as desired to refresh the device list and to make the application aware of hot-plug events.

Parameters
errmsg: a string passed by reference to receive any error message.
Returns
YAPI_SUCCESS when the call succeeds.

On failure, throws an exception or returns a negative error code.

Definition at line 4584 of file yocto_api.cpp.

Member Data Documentation

bool YAPI::_apiInitialized = false
static

Definition at line 475 of file yocto_api.h.

std::map< int, yCalibrationHandler > YAPI::_calibHandlers
staticprivate

Definition at line 447 of file yocto_api.h.

queue< yapiDataEvent > YAPI::_data_events
staticprivate

Definition at line 443 of file yocto_api.h.

yCRITICAL_SECTION YAPI::_global_cs
static

Definition at line 476 of file yocto_api.h.

YHubDiscoveryCallback YAPI::_HubDiscoveryCallback = NULL
staticprivate

Definition at line 444 of file yocto_api.h.

u64 YAPI::_nextEnum = 0
staticprivate

Definition at line 445 of file yocto_api.h.

queue< yapiGlobalEvent > YAPI::_plug_events
staticprivate

Definition at line 442 of file yocto_api.h.

int YAPI::DefaultCacheValidity = 5
static

Definition at line 468 of file yocto_api.h.

const u32 YAPI::DETECT_ALL = (Y_DETECT_USB | Y_DETECT_NET)
static

Definition at line 488 of file yocto_api.h.

const u32 YAPI::DETECT_NET = 2
static

Definition at line 486 of file yocto_api.h.

const u32 YAPI::DETECT_NONE = 0
static

Definition at line 484 of file yocto_api.h.

const u32 YAPI::DETECT_USB = 1
static

Definition at line 485 of file yocto_api.h.

const int YAPI::DEVICE_BUSY = -6
static

Definition at line 497 of file yocto_api.h.

const int YAPI::DEVICE_NOT_FOUND = -4
static

Definition at line 495 of file yocto_api.h.

yDeviceUpdateCallback YAPI::DeviceArrivalCallback = NULL
static

Definition at line 480 of file yocto_api.h.

yDeviceUpdateCallback YAPI::DeviceChangeCallback = NULL
static

Definition at line 482 of file yocto_api.h.

yDeviceUpdateCallback YAPI::DeviceRemovalCallback = NULL
static

Definition at line 481 of file yocto_api.h.

const int YAPI::DOUBLE_ACCES = -11
static

Definition at line 502 of file yocto_api.h.

bool YAPI::ExceptionsDisabled = false
static

Definition at line 469 of file yocto_api.h.

const int YAPI::EXHAUSTED = -10
static

Definition at line 501 of file yocto_api.h.

const int YAPI::FILE_NOT_FOUND = -14
static

Definition at line 505 of file yocto_api.h.

const int YAPI::INVALID_ARGUMENT = -2
static

Definition at line 493 of file yocto_api.h.

const double YAPI::INVALID_DOUBLE = (-DBL_MAX)
static

Definition at line 473 of file yocto_api.h.

const int YAPI::INVALID_INT = YAPI_INVALID_INT
static

Definition at line 471 of file yocto_api.h.

const s64 YAPI::INVALID_LONG = YAPI_INVALID_LONG
static

Definition at line 474 of file yocto_api.h.

const string YAPI::INVALID_STRING = YAPI_INVALID_STRING
static

Definition at line 470 of file yocto_api.h.

const int YAPI::INVALID_UINT = YAPI_INVALID_UINT
static

Definition at line 472 of file yocto_api.h.

const int YAPI::IO_ERROR = -8
static

Definition at line 499 of file yocto_api.h.

yLogFunction YAPI::LogFunction = NULL
static

Definition at line 479 of file yocto_api.h.

const int YAPI::NO_MORE_DATA = -9
static

Definition at line 500 of file yocto_api.h.

const int YAPI::NOT_INITIALIZED = -1
static

Definition at line 492 of file yocto_api.h.

const int YAPI::NOT_SUPPORTED = -3
static

Definition at line 494 of file yocto_api.h.

const u32 YAPI::RESEND_MISSING_PKT = 4
static

Definition at line 487 of file yocto_api.h.

const int YAPI::RTC_NOT_READY = -13
static

Definition at line 504 of file yocto_api.h.

const int YAPI::SUCCESS = 0
static

Definition at line 491 of file yocto_api.h.

const int YAPI::TIMEOUT = -7
static

Definition at line 498 of file yocto_api.h.

const int YAPI::UNAUTHORIZED = -12
static

Definition at line 503 of file yocto_api.h.

const int YAPI::VERSION_MISMATCH = -5
static

Definition at line 496 of file yocto_api.h.


The documentation for this class was generated from the following files:


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:13