41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "watchdog" 53 ,_state(STATE_INVALID)
54 ,_stateAtPowerOn(STATEATPOWERON_INVALID)
55 ,_maxTimeOnStateA(MAXTIMEONSTATEA_INVALID)
56 ,_maxTimeOnStateB(MAXTIMEONSTATEB_INVALID)
57 ,_output(OUTPUT_INVALID)
58 ,_pulseTimer(PULSETIMER_INVALID)
59 ,_delayedPulseTimer(DELAYEDPULSETIMER_INVALID)
60 ,_countdown(COUNTDOWN_INVALID)
61 ,_autoStart(AUTOSTART_INVALID)
62 ,_running(RUNNING_INVALID)
63 ,_triggerDelay(TRIGGERDELAY_INVALID)
64 ,_triggerDuration(TRIGGERDURATION_INVALID)
65 ,_valueCallbackWatchdog(NULL)
82 if(json_val->
has(
"state")) {
85 if(json_val->
has(
"stateAtPowerOn")) {
88 if(json_val->
has(
"maxTimeOnStateA")) {
91 if(json_val->
has(
"maxTimeOnStateB")) {
94 if(json_val->
has(
"output")) {
97 if(json_val->
has(
"pulseTimer")) {
100 if(json_val->
has(
"delayedPulseTimer")) {
102 if (subjson->
has(
"moving")) {
105 if (subjson->
has(
"target")) {
108 if (subjson->
has(
"ms")) {
112 if(json_val->
has(
"countdown")) {
115 if(json_val->
has(
"autoStart")) {
118 if(json_val->
has(
"running")) {
121 if(json_val->
has(
"triggerDelay")) {
124 if(json_val->
has(
"triggerDuration")) {
153 }
catch (std::exception) {
177 rest_val = (newval>0 ?
"1" :
"0");
179 }
catch (std::exception) {
211 }
catch (std::exception) {
236 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
237 res =
_setAttr(
"stateAtPowerOn", rest_val);
238 }
catch (std::exception) {
268 }
catch (std::exception) {
292 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
293 res =
_setAttr(
"maxTimeOnStateA", rest_val);
294 }
catch (std::exception) {
324 }
catch (std::exception) {
348 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
349 res =
_setAttr(
"maxTimeOnStateB", rest_val);
350 }
catch (std::exception) {
380 }
catch (std::exception) {
404 rest_val = (newval>0 ?
"1" :
"0");
406 }
catch (std::exception) {
438 }
catch (std::exception) {
452 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
453 res =
_setAttr(
"pulseTimer", rest_val);
454 }
catch (std::exception) {
475 char buf[32]; sprintf(buf,
"%u", (u32)ms_duration); rest_val = string(buf);
476 return _setAttr(
"pulseTimer", rest_val);
493 }
catch (std::exception) {
507 char buff[64]; sprintf(buff,
"%d:%d",newval.
target,newval.
ms); rest_val = string(buff);
508 res =
_setAttr(
"delayedPulseTimer", rest_val);
509 }
catch (std::exception) {
530 char buff[64]; sprintf(buff,
"%d:%d",ms_delay,ms_duration); rest_val = string(buff);
531 return _setAttr(
"delayedPulseTimer", rest_val);
557 }
catch (std::exception) {
586 }
catch (std::exception) {
611 rest_val = (newval>0 ?
"1" :
"0");
612 res =
_setAttr(
"autoStart", rest_val);
613 }
catch (std::exception) {
642 }
catch (std::exception) {
665 rest_val = (newval>0 ?
"1" :
"0");
666 res =
_setAttr(
"running", rest_val);
667 }
catch (std::exception) {
688 return _setAttr(
"running", rest_val);
713 }
catch (std::exception) {
737 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
738 res =
_setAttr(
"triggerDelay", rest_val);
739 }
catch (std::exception) {
768 }
catch (std::exception) {
791 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
792 res =
_setAttr(
"triggerDuration", rest_val);
793 }
catch (std::exception) {
841 }
catch (std::exception) {
863 if (callback != NULL) {
870 if (callback != NULL && this->
isOnline()) {
901 vector<YFUN_DESCR> v_fundescr;
903 string serial, funcId, funcName, funcVal, errmsg;
906 v_fundescr.size() == 0 ||
int set_maxTimeOnStateB(s64 newval)
int set_output(Y_OUTPUT_enum newval)
yCRITICAL_SECTION _this_cs
static const s64 TRIGGERDELAY_INVALID
static YWatchdog * FindWatchdog(string func)
s64 get_triggerDelay(void)
YRETCODE _load_unsafe(int msValidity)
virtual int _invokeValueCallback(string value)
Y_OUTPUT_enum get_output(void)
static YWatchdog * FirstWatchdog(void)
Y_AUTOSTART_enum _autoStart
virtual int _parseAttr(YJSONObject *json_val)
static const Y_AUTOSTART_enum AUTOSTART_INVALID
static const s64 TRIGGERDURATION_INVALID
int set_pulseTimer(s64 newval)
YWatchdogValueCallback _valueCallbackWatchdog
static int DefaultCacheValidity
int set_state(Y_STATE_enum newval)
YJSONObject * getYJSONObject(const string &key)
static const Y_STATE_enum STATE_INVALID
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
YDelayedPulse _delayedPulseTimer
static const Y_RUNNING_enum RUNNING_INVALID
s64 get_maxTimeOnStateB(void)
YDelayedPulse get_delayedPulseTimer(void)
static const s64 PULSETIMER_INVALID
virtual int _parseAttr(YJSONObject *json_val)
int set_triggerDelay(s64 newval)
int set_stateAtPowerOn(Y_STATEATPOWERON_enum newval)
static const Y_STATEATPOWERON_enum STATEATPOWERON_INVALID
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
static const Y_OUTPUT_enum OUTPUT_INVALID
YWatchdog * nextWatchdog(void)
int set_autoStart(Y_AUTOSTART_enum newval)
static YFunction * _FindFromCache(const string &classname, const string &func)
static const s64 COUNTDOWN_INVALID
int set_running(Y_RUNNING_enum newval)
Y_STATEATPOWERON_enum _stateAtPowerOn
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
Y_STATEATPOWERON_enum get_stateAtPowerOn(void)
int set_delayedPulseTimer(YDelayedPulse newval)
Y_AUTOSTART_enum get_autoStart(void)
int set_maxTimeOnStateA(s64 newval)
virtual int registerValueCallback(YWatchdogValueCallback callback)
YWatchdog(const string &func)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
static const s64 MAXTIMEONSTATEB_INVALID
s64 get_maxTimeOnStateA(void)
s64 getLong(const string &key)
static const s64 MAXTIMEONSTATEA_INVALID
int delayedPulse(int ms_delay, int ms_duration)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static const YDelayedPulse DELAYEDPULSETIMER_INVALID
s64 get_triggerDuration(void)
static void _UpdateValueCallbackList(YFunction *func, bool add)
int set_triggerDuration(s64 newval)
Y_RUNNING_enum get_running(void)
int pulse(int ms_duration)
bool has(const string &key)
void(* YWatchdogValueCallback)(YWatchdog *func, const string &functionValue)
YRETCODE _setAttr(string attrname, string newvalue)
virtual int _invokeValueCallback(string value)
Y_STATE_enum get_state(void)