yocto_wakeupschedule.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_wakeupschedule.cpp 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Implements yFindWakeUpSchedule(), the high-level API for WakeUpSchedule 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_wakeupschedule.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__ "wakeupschedule"
50 
51 YWakeUpSchedule::YWakeUpSchedule(const string& func): YFunction(func)
52 //--- (YWakeUpSchedule initialization)
53  ,_minutesA(MINUTESA_INVALID)
54  ,_minutesB(MINUTESB_INVALID)
55  ,_hours(HOURS_INVALID)
56  ,_weekDays(WEEKDAYS_INVALID)
57  ,_monthDays(MONTHDAYS_INVALID)
58  ,_months(MONTHS_INVALID)
59  ,_nextOccurence(NEXTOCCURENCE_INVALID)
60  ,_valueCallbackWakeUpSchedule(NULL)
61 //--- (end of YWakeUpSchedule initialization)
62 {
63  _className="WakeUpSchedule";
64 }
65 
67 {
68 //--- (YWakeUpSchedule cleanup)
69 //--- (end of YWakeUpSchedule cleanup)
70 }
71 //--- (YWakeUpSchedule implementation)
72 // static attributes
73 
75 {
76  if(json_val->has("minutesA")) {
77  _minutesA = json_val->getInt("minutesA");
78  }
79  if(json_val->has("minutesB")) {
80  _minutesB = json_val->getInt("minutesB");
81  }
82  if(json_val->has("hours")) {
83  _hours = json_val->getInt("hours");
84  }
85  if(json_val->has("weekDays")) {
86  _weekDays = json_val->getInt("weekDays");
87  }
88  if(json_val->has("monthDays")) {
89  _monthDays = json_val->getInt("monthDays");
90  }
91  if(json_val->has("months")) {
92  _months = json_val->getInt("months");
93  }
94  if(json_val->has("nextOccurence")) {
95  _nextOccurence = json_val->getLong("nextOccurence");
96  }
97  return YFunction::_parseAttr(json_val);
98 }
99 
100 
109 {
110  int res = 0;
112  try {
115  {
118  }
119  }
120  }
121  res = _minutesA;
122  } catch (std::exception) {
124  throw;
125  }
127  return res;
128 }
129 
140 {
141  string rest_val;
142  int res;
144  try {
145  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
146  res = _setAttr("minutesA", rest_val);
147  } catch (std::exception) {
149  throw;
150  }
152  return res;
153 }
154 
163 {
164  int res = 0;
166  try {
169  {
172  }
173  }
174  }
175  res = _minutesB;
176  } catch (std::exception) {
178  throw;
179  }
181  return res;
182 }
183 
194 {
195  string rest_val;
196  int res;
198  try {
199  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
200  res = _setAttr("minutesB", rest_val);
201  } catch (std::exception) {
203  throw;
204  }
206  return res;
207 }
208 
217 {
218  int res = 0;
220  try {
223  {
226  }
227  }
228  }
229  res = _hours;
230  } catch (std::exception) {
232  throw;
233  }
235  return res;
236 }
237 
248 {
249  string rest_val;
250  int res;
252  try {
253  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
254  res = _setAttr("hours", rest_val);
255  } catch (std::exception) {
257  throw;
258  }
260  return res;
261 }
262 
271 {
272  int res = 0;
274  try {
277  {
280  }
281  }
282  }
283  res = _weekDays;
284  } catch (std::exception) {
286  throw;
287  }
289  return res;
290 }
291 
302 {
303  string rest_val;
304  int res;
306  try {
307  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
308  res = _setAttr("weekDays", rest_val);
309  } catch (std::exception) {
311  throw;
312  }
314  return res;
315 }
316 
325 {
326  int res = 0;
328  try {
331  {
334  }
335  }
336  }
337  res = _monthDays;
338  } catch (std::exception) {
340  throw;
341  }
343  return res;
344 }
345 
356 {
357  string rest_val;
358  int res;
360  try {
361  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
362  res = _setAttr("monthDays", rest_val);
363  } catch (std::exception) {
365  throw;
366  }
368  return res;
369 }
370 
379 {
380  int res = 0;
382  try {
385  {
388  }
389  }
390  }
391  res = _months;
392  } catch (std::exception) {
394  throw;
395  }
397  return res;
398 }
399 
410 {
411  string rest_val;
412  int res;
414  try {
415  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
416  res = _setAttr("months", rest_val);
417  } catch (std::exception) {
419  throw;
420  }
422  return res;
423 }
424 
433 {
434  s64 res = 0;
436  try {
439  {
442  }
443  }
444  }
445  res = _nextOccurence;
446  } catch (std::exception) {
448  throw;
449  }
451  return res;
452 }
453 
482 {
483  YWakeUpSchedule* obj = NULL;
484  int taken = 0;
485  if (YAPI::_apiInitialized) {
487  taken = 1;
488  }try {
489  obj = (YWakeUpSchedule*) YFunction::_FindFromCache("WakeUpSchedule", func);
490  if (obj == NULL) {
491  obj = new YWakeUpSchedule(func);
492  YFunction::_AddToCache("WakeUpSchedule", func, obj);
493  }
494  } catch (std::exception) {
496  throw;
497  }
499  return obj;
500 }
501 
514 {
515  string val;
516  if (callback != NULL) {
518  } else {
520  }
521  _valueCallbackWakeUpSchedule = callback;
522  // Immediately invoke value callback with current value
523  if (callback != NULL && this->isOnline()) {
524  val = _advertisedValue;
525  if (!(val == "")) {
526  this->_invokeValueCallback(val);
527  }
528  }
529  return 0;
530 }
531 
533 {
534  if (_valueCallbackWakeUpSchedule != NULL) {
535  _valueCallbackWakeUpSchedule(this, value);
536  } else {
538  }
539  return 0;
540 }
541 
546 {
547  s64 res = 0;
548 
549  res = this->get_minutesB();
550  res = ((res) << (30));
551  res = res + this->get_minutesA();
552  return res;
553 }
554 
565 {
566  this->set_minutesA((int)(((bitmap) & (0x3fffffff))));
567  bitmap = ((bitmap) >> (30));
568  return this->set_minutesB((int)(((bitmap) & (0x3fffffff))));
569 }
570 
572 {
573  string hwid;
574 
575  if(YISERR(_nextFunction(hwid)) || hwid=="") {
576  return NULL;
577  }
579 }
580 
582 {
583  vector<YFUN_DESCR> v_fundescr;
584  YDEV_DESCR ydevice;
585  string serial, funcId, funcName, funcVal, errmsg;
586 
587  if(YISERR(YapiWrapper::getFunctionsByClass("WakeUpSchedule", 0, v_fundescr, sizeof(YFUN_DESCR), errmsg)) ||
588  v_fundescr.size() == 0 ||
589  YISERR(YapiWrapper::getFunctionInfo(v_fundescr[0], ydevice, serial, funcId, funcName, funcVal, errmsg))) {
590  return NULL;
591  }
592  return YWakeUpSchedule::FindWakeUpSchedule(serial+"."+funcId);
593 }
594 
595 //--- (end of YWakeUpSchedule implementation)
596 
597 //--- (YWakeUpSchedule functions)
598 //--- (end of YWakeUpSchedule functions)
string _advertisedValue
Definition: yocto_api.h:1569
static YWakeUpSchedule * FindWakeUpSchedule(string func)
yCRITICAL_SECTION _this_cs
Definition: yocto_api.h:1563
virtual int _invokeValueCallback(string value)
YRETCODE _load_unsafe(int msValidity)
Definition: yocto_api.cpp:3327
virtual s64 get_minutes(void)
YWakeUpScheduleValueCallback _valueCallbackWakeUpSchedule
static int DefaultCacheValidity
Definition: yocto_api.h:468
int set_minutesB(int newval)
u64 _cacheExpiration
Definition: yocto_api.h:1571
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:672
static const s64 NEXTOCCURENCE_INVALID
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
Definition: yocto_api.cpp:4930
static const int MINUTESB_INVALID
virtual int _parseAttr(YJSONObject *json_val)
Definition: yocto_api.cpp:2367
virtual int registerValueCallback(YWakeUpScheduleValueCallback callback)
YWakeUpSchedule * nextWakeUpSchedule(void)
YAPI_FUNCTION YFUN_DESCR
Definition: yocto_api.h:230
int getInt(const string &key)
Definition: yocto_api.cpp:779
static u64 GetTickCount(void)
Definition: yocto_api.cpp:4755
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Definition: yocto_api.cpp:2345
void(* YWakeUpScheduleValueCallback)(YWakeUpSchedule *func, const string &functionValue)
YAPI_DEVICE YDEV_DESCR
Definition: yocto_api.h:229
static YFunction * _FindFromCache(const string &classname, const string &func)
Definition: yocto_api.cpp:2338
static const int MONTHS_INVALID
int set_minutesA(int newval)
int set_months(int newval)
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
int set_weekDays(int newval)
static const int HOURS_INVALID
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
int set_hours(int newval)
s64 getLong(const string &key)
Definition: yocto_api.cpp:790
YWakeUpSchedule(const string &func)
static const int WEEKDAYS_INVALID
int set_monthDays(int newval)
static YWakeUpSchedule * FirstWakeUpSchedule(void)
static bool _apiInitialized
Definition: yocto_api.h:475
YRETCODE _nextFunction(string &hwId)
Definition: yocto_api.cpp:2709
virtual int _parseAttr(YJSONObject *json_val)
virtual int set_minutes(s64 bitmap)
static void _UpdateValueCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3509
#define YISERR(retcode)
Definition: ydef.h:394
static const int MINUTESA_INVALID
bool has(const string &key)
Definition: yocto_api.cpp:735
YRETCODE _setAttr(string attrname, string newvalue)
Definition: yocto_api.cpp:2968
static const int MONTHDAYS_INVALID
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:2563


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