41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "relay" 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 ,_valueCallbackRelay(NULL)
78 if(json_val->
has(
"state")) {
81 if(json_val->
has(
"stateAtPowerOn")) {
84 if(json_val->
has(
"maxTimeOnStateA")) {
87 if(json_val->
has(
"maxTimeOnStateB")) {
90 if(json_val->
has(
"output")) {
93 if(json_val->
has(
"pulseTimer")) {
96 if(json_val->
has(
"delayedPulseTimer")) {
98 if (subjson->
has(
"moving")) {
101 if (subjson->
has(
"target")) {
104 if (subjson->
has(
"ms")) {
108 if(json_val->
has(
"countdown")) {
137 }
catch (std::exception) {
161 rest_val = (newval>0 ?
"1" :
"0");
163 }
catch (std::exception) {
195 }
catch (std::exception) {
220 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
221 res =
_setAttr(
"stateAtPowerOn", rest_val);
222 }
catch (std::exception) {
252 }
catch (std::exception) {
276 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
277 res =
_setAttr(
"maxTimeOnStateA", rest_val);
278 }
catch (std::exception) {
308 }
catch (std::exception) {
332 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
333 res =
_setAttr(
"maxTimeOnStateB", rest_val);
334 }
catch (std::exception) {
364 }
catch (std::exception) {
388 rest_val = (newval>0 ?
"1" :
"0");
390 }
catch (std::exception) {
422 }
catch (std::exception) {
436 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
437 res =
_setAttr(
"pulseTimer", rest_val);
438 }
catch (std::exception) {
459 char buf[32]; sprintf(buf,
"%u", (u32)ms_duration); rest_val = string(buf);
460 return _setAttr(
"pulseTimer", rest_val);
477 }
catch (std::exception) {
491 char buff[64]; sprintf(buff,
"%d:%d",newval.
target,newval.
ms); rest_val = string(buff);
492 res =
_setAttr(
"delayedPulseTimer", rest_val);
493 }
catch (std::exception) {
514 char buff[64]; sprintf(buff,
"%d:%d",ms_delay,ms_duration); rest_val = string(buff);
515 return _setAttr(
"delayedPulseTimer", rest_val);
541 }
catch (std::exception) {
589 }
catch (std::exception) {
611 if (callback != NULL) {
618 if (callback != NULL && this->
isOnline()) {
649 vector<YFUN_DESCR> v_fundescr;
651 string serial, funcId, funcName, funcVal, errmsg;
654 v_fundescr.size() == 0 ||
int pulse(int ms_duration)
yCRITICAL_SECTION _this_cs
int set_output(Y_OUTPUT_enum newval)
s64 get_maxTimeOnStateA(void)
void(* YRelayValueCallback)(YRelay *func, const string &functionValue)
static YRelay * FirstRelay(void)
Y_STATEATPOWERON_enum get_stateAtPowerOn(void)
static const s64 MAXTIMEONSTATEB_INVALID
static const s64 COUNTDOWN_INVALID
YRETCODE _load_unsafe(int msValidity)
Y_STATEATPOWERON_enum _stateAtPowerOn
int set_maxTimeOnStateA(s64 newval)
int set_state(Y_STATE_enum newval)
static int DefaultCacheValidity
YJSONObject * getYJSONObject(const string &key)
static YRelay * FindRelay(string func)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
int set_delayedPulseTimer(YDelayedPulse newval)
virtual int _invokeValueCallback(string value)
virtual int _parseAttr(YJSONObject *json_val)
virtual int _parseAttr(YJSONObject *json_val)
int getInt(const string &key)
static const s64 PULSETIMER_INVALID
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
static const s64 MAXTIMEONSTATEA_INVALID
YRelayValueCallback _valueCallbackRelay
Y_OUTPUT_enum get_output(void)
static const Y_STATEATPOWERON_enum STATEATPOWERON_INVALID
static const YDelayedPulse DELAYEDPULSETIMER_INVALID
static YFunction * _FindFromCache(const string &classname, const string &func)
int set_maxTimeOnStateB(s64 newval)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
static const Y_STATE_enum STATE_INVALID
Y_STATE_enum get_state(void)
YDelayedPulse _delayedPulseTimer
YRelay(const string &func)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
static const Y_OUTPUT_enum OUTPUT_INVALID
s64 getLong(const string &key)
s64 get_maxTimeOnStateB(void)
int set_stateAtPowerOn(Y_STATEATPOWERON_enum newval)
static bool _apiInitialized
YDelayedPulse get_delayedPulseTimer(void)
YRETCODE _nextFunction(string &hwId)
static void _UpdateValueCallbackList(YFunction *func, bool add)
int delayedPulse(int ms_delay, int ms_duration)
virtual int registerValueCallback(YRelayValueCallback callback)
bool has(const string &key)
YRETCODE _setAttr(string attrname, string newvalue)
virtual int _invokeValueCallback(string value)
int set_pulseTimer(s64 newval)