41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "power" 53 ,_cosPhi(COSPHI_INVALID)
54 ,_meter(METER_INVALID)
55 ,_meterTimer(METERTIMER_INVALID)
56 ,_valueCallbackPower(NULL)
57 ,_timedReportCallbackPower(NULL)
75 if(json_val->
has(
"cosPhi")) {
76 _cosPhi = floor(json_val->
getDouble(
"cosPhi") * 1000.0 / 65536.0 + 0.5) / 1000.0;
78 if(json_val->
has(
"meter")) {
79 _meter = floor(json_val->
getDouble(
"meter") * 1000.0 / 65536.0 + 0.5) / 1000.0;
81 if(json_val->
has(
"meterTimer")) {
111 }
catch (std::exception) {
125 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
127 }
catch (std::exception) {
158 }
catch (std::exception) {
187 }
catch (std::exception) {
235 }
catch (std::exception) {
257 if (callback != NULL) {
264 if (callback != NULL && this->
isOnline()) {
298 if (callback != NULL) {
341 vector<YFUN_DESCR> v_fundescr;
343 string serial, funcId, funcName, funcVal, errmsg;
346 v_fundescr.size() == 0 ||
static const double COSPHI_INVALID
static YPower * FindPower(string func)
double getDouble(const string &key)
yCRITICAL_SECTION _this_cs
virtual int registerValueCallback(YPowerValueCallback callback)
YPower(const string &func)
static void _UpdateTimedReportCallbackList(YFunction *func, bool add)
YRETCODE _load_unsafe(int msValidity)
static const double METER_INVALID
static int DefaultCacheValidity
YPowerValueCallback _valueCallbackPower
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
virtual int _invokeValueCallback(string value)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
static const int METERTIMER_INVALID
static YPower * FirstPower(void)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
#define YAPI_INVALID_DOUBLE
virtual int _invokeTimedReportCallback(YMeasure value)
virtual int _invokeValueCallback(string value)
static YFunction * _FindFromCache(const string &classname, const string &func)
virtual int _invokeTimedReportCallback(YMeasure value)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
virtual int _parseAttr(YJSONObject *json_val)
void(* YPowerTimedReportCallback)(YPower *func, YMeasure measure)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
virtual int registerTimedReportCallback(YPowerTimedReportCallback callback)
void(* YPowerValueCallback)(YPower *func, const string &functionValue)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
virtual int _parseAttr(YJSONObject *json_val)
static void _UpdateValueCallbackList(YFunction *func, bool add)
int set_meter(double newval)
bool has(const string &key)
YPowerTimedReportCallback _timedReportCallbackPower
YRETCODE _setAttr(string attrname, string newvalue)