yocto_longitude.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_longitude.cpp 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Implements yFindLongitude(), the high-level API for Longitude functions
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 
41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt
42 #include "yocto_longitude.h"
43 #include "yapi/yjson.h"
44 #include "yapi/yapi.h"
45 #include <string.h>
46 #include <stdio.h>
47 #include <math.h>
48 #include <stdlib.h>
49 #define __FILE_ID__ "longitude"
50 
51 YLongitude::YLongitude(const string& func): YSensor(func)
52 //--- (YLongitude initialization)
53  ,_valueCallbackLongitude(NULL)
54  ,_timedReportCallbackLongitude(NULL)
55 //--- (end of YLongitude initialization)
56 {
57  _className="Longitude";
58 }
59 
61 {
62 //--- (YLongitude cleanup)
63 //--- (end of YLongitude cleanup)
64 }
65 //--- (YLongitude implementation)
66 // static attributes
67 
68 
97 {
98  YLongitude* obj = NULL;
99  int taken = 0;
100  if (YAPI::_apiInitialized) {
102  taken = 1;
103  }try {
104  obj = (YLongitude*) YFunction::_FindFromCache("Longitude", func);
105  if (obj == NULL) {
106  obj = new YLongitude(func);
107  YFunction::_AddToCache("Longitude", func, obj);
108  }
109  } catch (std::exception) {
111  throw;
112  }
114  return obj;
115 }
116 
129 {
130  string val;
131  if (callback != NULL) {
133  } else {
135  }
136  _valueCallbackLongitude = callback;
137  // Immediately invoke value callback with current value
138  if (callback != NULL && this->isOnline()) {
139  val = _advertisedValue;
140  if (!(val == "")) {
141  this->_invokeValueCallback(val);
142  }
143  }
144  return 0;
145 }
146 
148 {
149  if (_valueCallbackLongitude != NULL) {
150  _valueCallbackLongitude(this, value);
151  } else {
153  }
154  return 0;
155 }
156 
169 {
170  YSensor* sensor = NULL;
171  sensor = this;
172  if (callback != NULL) {
174  } else {
176  }
178  return 0;
179 }
180 
182 {
183  if (_timedReportCallbackLongitude != NULL) {
184  _timedReportCallbackLongitude(this, value);
185  } else {
187  }
188  return 0;
189 }
190 
192 {
193  string hwid;
194 
195  if(YISERR(_nextFunction(hwid)) || hwid=="") {
196  return NULL;
197  }
198  return YLongitude::FindLongitude(hwid);
199 }
200 
202 {
203  vector<YFUN_DESCR> v_fundescr;
204  YDEV_DESCR ydevice;
205  string serial, funcId, funcName, funcVal, errmsg;
206 
207  if(YISERR(YapiWrapper::getFunctionsByClass("Longitude", 0, v_fundescr, sizeof(YFUN_DESCR), errmsg)) ||
208  v_fundescr.size() == 0 ||
209  YISERR(YapiWrapper::getFunctionInfo(v_fundescr[0], ydevice, serial, funcId, funcName, funcVal, errmsg))) {
210  return NULL;
211  }
212  return YLongitude::FindLongitude(serial+"."+funcId);
213 }
214 
215 //--- (end of YLongitude implementation)
216 
217 //--- (YLongitude functions)
218 //--- (end of YLongitude functions)
string _advertisedValue
Definition: yocto_api.h:1569
static void _UpdateTimedReportCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3531
virtual int registerTimedReportCallback(YLongitudeTimedReportCallback callback)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:672
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
Definition: yocto_api.cpp:4930
void(* YLongitudeTimedReportCallback)(YLongitude *func, YMeasure measure)
YAPI_FUNCTION YFUN_DESCR
Definition: yocto_api.h:230
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Definition: yocto_api.cpp:2345
YLongitudeTimedReportCallback _timedReportCallbackLongitude
YLongitude(const string &func)
virtual int _invokeTimedReportCallback(YMeasure value)
Definition: yocto_api.cpp:7936
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:7645
YAPI_DEVICE YDEV_DESCR
Definition: yocto_api.h:229
static YFunction * _FindFromCache(const string &classname, const string &func)
Definition: yocto_api.cpp:2338
YLongitudeValueCallback _valueCallbackLongitude
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:647
static yCRITICAL_SECTION _global_cs
Definition: yocto_api.h:476
bool isOnline(void)
Definition: yocto_api.cpp:3291
virtual int registerValueCallback(YLongitudeValueCallback callback)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
Definition: yocto_api.cpp:4852
string _className
Definition: yocto_api.h:1558
static YLongitude * FirstLongitude(void)
virtual int _invokeTimedReportCallback(YMeasure value)
YLongitude * nextLongitude(void)
void(* YLongitudeValueCallback)(YLongitude *func, const string &functionValue)
static bool _apiInitialized
Definition: yocto_api.h:475
YRETCODE _nextFunction(string &hwId)
Definition: yocto_api.cpp:2709
static void _UpdateValueCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3509
#define YISERR(retcode)
Definition: ydef.h:394
virtual int _invokeValueCallback(string value)
static YLongitude * FindLongitude(string func)


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