39 #define __FILE_ID__ "yocto_api" 40 #define _CRT_SECURE_NO_DEPRECATE 46 #define yySleep(ms) Sleep(ms) 49 #define yySleep(ms) usleep(ms*1000) 75 int _ystrpos(
const string& haystack,
const string& needle)
77 size_t pos = haystack.find(needle);
78 if(pos == string::npos) {
85 vector<string>
_strsplit(
const string& str,
char delimiter)
92 found = str.find(delimiter, pos);
93 if (found != std::string::npos) {
94 res.push_back(str.substr(pos, found - pos));
97 }
while (found != std::string::npos);
98 res.push_back(str.substr(pos));
108 if (data[cur_pos] ==
'[') {
110 }
else if (data[cur_pos] ==
'{') {
112 }
else if (data[cur_pos] ==
'"') {
156 if (data.length() <= (unsigned) start) {
159 char sti = data[start];
160 while (start < stop && (sti ==
'\n' || sti ==
'\r' || sti ==
' ')) {
168 int ststart = cur_pos - 10;
169 int stend = cur_pos + 10;
177 return errmsg +
" near " +
_data.substr(ststart, cur_pos - ststart) +
_data.substr(cur_pos, stend - cur_pos);
191 for (
unsigned i = 0; i < ref->
_arrayValue.size(); i++) {
225 for (
unsigned i = 0; i <
_arrayValue.size(); i++) {
240 if (
_data[cur_pos] !=
'[') {
247 char sti =
_data[cur_pos];
252 int len = jobj->
parse();
258 }
else if (sti ==
'[') {
260 int len = jobj->
parse();
266 }
else if (sti ==
'"') {
268 int len = jobj->
parse();
274 }
else if (sti ==
'-' || (sti >=
'0' && sti <=
'9')) {
276 int len = jobj->
parse();
282 }
else if (sti ==
']') {
285 }
else if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
292 }
else if (sti ==
']') {
296 if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
355 string subres = yjsonContent->
toJSON();
371 string subres = yjsonContent->
toString();
398 if (
_data[cur_pos] !=
'"') {
402 int str_start = cur_pos;
406 unsigned char sti =
_data[cur_pos];
410 value +=
_data.substr(str_start, cur_pos - str_start);
413 }
else if (sti ==
'"') {
414 value +=
_data.substr(str_start, cur_pos - str_start);
418 }
else if (sti < 32) {
425 str_start = cur_pos + 1;
510 sti =
_data[cur_pos];
517 sti =
_data[cur_pos];
518 if (sti ==
'.' &&
_isFloat ==
false) {
519 string int_part =
_data.substr(start, cur_pos - start);
522 }
else if (sti < '0' || sti >
'9') {
523 string numberpart =
_data.substr(start, cur_pos - start);
594 for (
unsigned i = 0; i < ref->
_keys.size(); i++) {
595 string key = ref->
_keys[i];
596 _keys.push_back(key);
618 for (
unsigned i = 0; i <
_keys.size(); i++) {
627 string current_name =
"";
631 if (
_data.length() <= (unsigned)cur_pos ||
_data[cur_pos] !=
'{') {
638 char sti =
_data[cur_pos];
643 name_start = cur_pos + 1;
644 }
else if (sti ==
'}') {
648 if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
655 current_name =
_data.substr(name_start, cur_pos - name_start);
668 if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
676 int len = jobj->
parse();
679 _keys.push_back(current_name);
683 }
else if (sti ==
'[') {
685 int len = jobj->
parse();
688 _keys.push_back(current_name);
692 }
else if (sti ==
'"') {
694 int len = jobj->
parse();
697 _keys.push_back(current_name);
701 }
else if (sti ==
'-' || (sti >=
'0' && sti <=
'9')) {
703 int len = jobj->
parse();
706 _keys.push_back(current_name);
710 }
else if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
717 name_start = cur_pos + 1;
718 }
else if (sti ==
'}') {
722 if (sti !=
' ' && sti !=
'\n' && sti !=
'\r') {
762 for (map<string, YJSONContent*>::iterator it =
_parsed.begin(); it !=
_parsed.end(); ++it) {
763 v.push_back(it->first);
807 for (i = 0; i <
_keys.size(); i++) {
808 string key =
_keys[i];
810 string subres = subContent->
toJSON();
827 for (i = 0; i <
_keys.size(); i++) {
828 string key =
_keys[i];
830 string subres = subContent->
toString();
846 if (reference != NULL) {
853 }
catch (std::exception) {
862 int length = newArray->
length();
863 for (
int i = 0; i < length; i++) {
883 _keys.push_back(key);
888 _keys.push_back(key);
1005 double summaryMinVal=DBL_MAX;
1006 double summaryMaxVal=-DBL_MAX;
1007 double summaryTotalTime=0;
1008 double summaryTotalAvg=0;
1012 j.
src = json.c_str();
1019 if (!strcmp(j.
token,
"id")) {
1024 }
else if (!strcmp(j.
token,
"unit")) {
1029 }
else if (!strcmp(j.
token,
"calib")) {
1034 _calib[0] = _calib[0] / 1000;
1035 }
else if (!strcmp(j.
token,
"cal")) {
1042 }
else if (!strcmp(j.
token,
"streams")) {
1044 s64 streamEndTime, endTime = 0;
1045 s64 streamStartTime, startTime = 0x7fffffff;
1063 if(startTime > streamStartTime) {
1064 startTime = streamStartTime;
1066 if(endTime < streamEndTime) {
1067 endTime = streamEndTime;
1073 if (summaryMaxVal < stream->get_maxValue())
1079 (double)streamEndTime,
1083 _preview.push_back(rec);
1087 if((
_streams.size() > 0) && (summaryTotalTime>0)) {
1153 string firmwarepath;
1166 res =
yapiUpdateFirmwareEx(serial.c_str(), firmwarepath.c_str(), settings.c_str(), force, newupdate, errmsg);
1189 if (prod_prefix ==
"YoctoHub") {
1190 {
string ignore_error;
YAPI::Sleep(1000, ignore_error);};
1227 char smallbuff[1024];
1232 string bootloader_list;
1233 vector<string> bootladers;
1239 if (fullsize <= 1024) {
1240 bootloader_list = string(smallbuff, yapi_res);
1242 buffsize = fullsize;
1243 bigbuff = (
char *)malloc(buffsize);
1249 bootloader_list = string(bigbuff, yapi_res);
1253 if (!(bootloader_list ==
"")) {
1254 bootladers =
_strsplit(bootloader_list,
',');
1275 char smallbuff[1024];
1280 string firmware_path;
1284 res =
yapiCheckFirmware(serial.c_str(), release.c_str(), path.c_str(), smallbuff, 1024, &fullsize, errmsg);
1286 firmware_path =
"error:" + string(errmsg);
1287 return "error:" + string(errmsg);
1289 if (fullsize <= 1024) {
1290 firmware_path = string(smallbuff, fullsize);
1292 buffsize = fullsize;
1293 bigbuff = (
char *)malloc(buffsize);
1294 res =
yapiCheckFirmware(serial.c_str(), release.c_str(), path.c_str(), bigbuff, buffsize, &fullsize, errmsg);
1296 firmware_path =
"error:" + string(errmsg);
1298 firmware_path = string(bigbuff, fullsize);
1302 return firmware_path;
1349 leng = (int)(err).length();
1350 if (( leng >= 6) && (
"error:" == (err).substr(0, 6))) {
1376 double duration_float = 0.0;
1379 _runNo = encoded[0] + (((encoded[1]) << (16)));
1380 _utcStamp = encoded[2] + (((encoded[3]) << (16)));
1382 _isAvg = (((val) & (0x100)) == 0);
1383 _samplesPerHour = ((val) & (0xff));
1384 if (((val) & (0x100)) != 0) {
1385 _samplesPerHour = _samplesPerHour * 3600;
1387 if (((val) & (0x200)) != 0) {
1388 _samplesPerHour = _samplesPerHour * 60;
1397 _scale = encoded[6];
1398 _isScal = (_scale != 0);
1399 _isScal32 = ((int)encoded.size() >= 14);
1401 _isClosed = (val != 0xffff);
1402 if (val == 0xffff) {
1406 duration_float = _nRows * 3600 / _samplesPerHour;
1407 _duration = (int) floor(duration_float+0.5);
1412 while (i < _decimals) {
1413 _decexp = _decexp * 10.0;
1418 _caltyp = iCalib[0];
1421 maxpos = (int)iCalib.size();
1427 while (i < maxpos) {
1428 _calpar.push_back(iCalib[i]);
1432 while (i + 1 < maxpos) {
1434 fRaw = fRaw / 1000.0;
1435 fRef = iCalib[i + 1];
1436 fRef = fRef / 1000.0;
1437 _calraw.push_back(fRaw);
1438 _calref.push_back(fRef);
1443 while (i + 1 < maxpos) {
1445 iRef = iCalib[i + 1];
1446 _calpar.push_back(iRaw);
1447 _calpar.push_back(iRef);
1450 fRaw = (fRaw - _offset) / _scale;
1452 fRef = (fRef - _offset) / _scale;
1453 _calraw.push_back(fRaw);
1454 _calref.push_back(fRef);
1466 _columnNames.clear();
1472 _columnNames.clear();
1473 _columnNames.push_back(_functionId);
1479 _avgVal = this->_decodeAvg(encoded[8] + (((((encoded[9]) ^ (0x8000))) << (16))), 1);
1480 _minVal = this->_decodeVal(encoded[10] + (((encoded[11]) << (16))));
1481 _maxVal = this->_decodeVal(encoded[12] + (((encoded[13]) << (16))));
1483 _minVal = this->_decodeVal(encoded[8]);
1484 _maxVal = this->_decodeVal(encoded[9]);
1485 _avgVal = this->_decodeAvg(encoded[10] + (((encoded[11]) << (16))), _nRows);
1496 if ((
int)(sdata).size() == 0) {
1505 while (idx + 3 < (
int)udat.size()) {
1508 dat.push_back(this->_decodeVal(udat[idx + 2] + (((udat[idx + 3]) << (16)))));
1509 dat.push_back(this->_decodeAvg(udat[idx] + (((((udat[idx + 1]) ^ (0x8000))) << (16))), 1));
1510 dat.push_back(this->_decodeVal(udat[idx + 4] + (((udat[idx + 5]) << (16)))));
1513 dat.push_back(this->_decodeVal(udat[idx]));
1514 dat.push_back(this->_decodeAvg(udat[idx + 2] + (((udat[idx + 3]) << (16))), 1));
1515 dat.push_back(this->_decodeVal(udat[idx + 1]));
1518 _values.push_back(dat);
1521 if (_isScal && !(_isScal32)) {
1522 while (idx < (
int)udat.size()) {
1524 dat.push_back(this->_decodeVal(udat[idx]));
1525 _values.push_back(dat);
1529 while (idx + 1 < (
int)udat.size()) {
1531 dat.push_back(this->_decodeAvg(udat[idx] + (((((udat[idx + 1]) ^ (0x8000))) << (16))), 1));
1532 _values.push_back(dat);
1538 _nRows = (int)_values.size();
1546 _functionId.c_str(),_runNo,_utcStamp);
1552 return this->_parseStream(_parent->_download(this->_get_url()));
1563 val = (val - _offset) / _scale;
1569 if (_calhdl != NULL) {
1570 val = _calhdl(val, _caltyp, _calpar, _calraw, _calref);
1584 val = (val / (100 * count) - _offset) / _scale;
1586 val = val / (count * _decexp);
1590 if (_calhdl != NULL) {
1591 val = _calhdl(val, _caltyp, _calpar, _calraw, _calref);
1628 return (
int)(_utcStamp - ((unsigned)time(NULL)));
1655 return ((3600000) / (_samplesPerHour));
1660 return 3600.0 / _samplesPerHour;
1676 if ((_nRows != 0) && _isClosed) {
1724 if ((
int)_columnNames.size() != 0) {
1725 return _columnNames;
1728 return _columnNames;
1788 return (
int)(((unsigned)time(NULL)) - _utcStamp);
1808 if (((
int)_values.size() == 0) || !(_isClosed)) {
1832 if (((
int)_values.size() == 0) || !(_isClosed)) {
1835 if (row >= (
int)_values.size()) {
1838 if (col >= (
int)_values[row].size()) {
1841 return _values[row][col];
1974 vector< vector<double> > dataRows;
1983 if (progress != _progress) {
1986 if (_progress < 0) {
1988 if (strdata ==
"{}") {
1992 return this->_parse(strdata);
1994 stream = _streams[_progress];
1997 _progress = _progress + 1;
1998 if ((
int)dataRows.size() == 0) {
1999 return this->get_progress();
2006 nCols = (int)dataRows[0].size();
2019 for (
unsigned ii = 0; ii < dataRows.size(); ii++) {
2020 if ((tim >= _startTime) && ((_endTime == 0) || (tim <= _endTime))) {
2021 _measures.push_back(
YMeasure(tim - itv, tim,
2022 dataRows[ii][minCol],
2023 dataRows[ii][avgCol],dataRows[ii][maxCol]));
2026 tim = floor(tim * 1000+0.5) / 1000.0;
2028 return this->get_progress();
2049 if (!(_hardwareId ==
"")) {
2124 if (_progress < 0) {
2128 if (_progress >= (
int)_streams.size()) {
2131 return ((1 + (1 + _progress) * 98) / ((1 + (int)_streams.size())));
2147 if (_progress < 0) {
2149 if (_startTime != 0) {
2152 if (_endTime != 0) {
2156 if (_progress >= (
int)_streams.size()) {
2159 stream = _streams[_progress];
2163 return this->processMore(_progress, _parent->_download(url));
2225 vector< vector<double> > dataRows;
2226 vector<YMeasure> measures;
2236 for (
unsigned ii = 0; ii < _streams.size(); ii++) {
2238 stream = _streams[ii];
2241 if (stream == NULL) {
2245 if ((
int)dataRows.size() == 0) {
2253 nCols = (int)dataRows[0].size();
2266 for (
unsigned ii = 0; ii < dataRows.size(); ii++) {
2267 if ((tim >= _startTime) && ((_endTime == 0) || (tim <= _endTime))) {
2268 measures.push_back(
YMeasure(tim - itv, tim,
2269 dataRows[ii][minCol],
2270 dataRows[ii][avgCol],dataRows[ii][maxCol]));
2314 _className(
"Function"),_func(func),
2319 ,_logicalName(LOGICALNAME_INVALID)
2320 ,_advertisedValue(ADVERTISEDVALUE_INVALID)
2321 ,_valueCallbackFunction(NULL)
2322 ,_cacheExpiration(0)
2340 if(
_cache.find(classname +
"_" + func) !=
_cache.end())
2341 return _cache[classname +
"_" + func];
2347 _cache[classname +
"_" + func] = obj;
2352 for (std::map<string, YFunction*>::iterator cache_iterator =
_cache.begin();
2353 cache_iterator !=
_cache.end(); ++cache_iterator){
2354 delete cache_iterator->second;
2357 _cache = std::map<string, YFunction*>();
2369 if(json_val->
has(
"logicalName")) {
2372 if(json_val->
has(
"advertisedValue")) {
2400 }
catch (std::exception) {
2431 res =
_setAttr(
"logicalName", rest_val);
2432 }
catch (std::exception) {
2461 }
catch (std::exception) {
2476 res =
_setAttr(
"advertisedValue", rest_val);
2477 }
catch (std::exception) {
2525 }
catch (std::exception) {
2547 if (callback != NULL) {
2554 if (callback != NULL && this->
isOnline()) {
2639 vector<YFUN_DESCR> v_fundescr;
2641 string serial, funcId, funcName, funcVal, errmsg;
2644 v_fundescr.size() == 0 ||
2673 if(
YISERR(tmp_fundescr)) {
2679 if(
YISERR(tmp_fundescr)) {
2696 if(
YISERR(res))
return res;
2711 vector<YFUN_DESCR> v_fundescr;
2714 string serial, funcId, funcName, funcVal, errmsg;
2727 if(v_fundescr.size() == 0) {
2736 hwid = serial+
"."+funcId;
2755 unsigned char c = *s++;
2760 *pt++ = 0xc2 + (c>0xbf ? 1 : 0);
2761 *pt++ = (c & 0x3f) + 0x80;
2777 j.
src = json.c_str();
2785 if (!strcmp(j.
token, key.c_str())) {
2801 j.
src = json.c_str();
2815 const char *json_cstr,*last;
2816 string backup = json;
2817 j.
src = json_cstr = json.c_str();
2824 int depth = j.
depth;
2838 if (j.
depth == depth) {
2839 long location, length;
2840 while (*last ==
',' || *last ==
'\n'){
2843 location = (long)(last - json_cstr);
2844 length = (long)(j.
src - last);
2845 string item = json.substr(location, length);
2846 res.push_back(item);
2854 const char *json_data = json.c_str();
2855 int len = (int)(json.length() & 0x0fffffff);
2862 string result = string(p, res);
2873 int len = (int)(json.length() & 0x0fffffff);
2879 p = (
char*) malloc(len + 1);
2883 string result = string(p, decoded_len);
2895 unsigned char esc[3];
2896 string escaped =
"";
2898 for (p = changeval.c_str(); (c = *p) != 0; p++) {
2899 if (c <=
' ' || (c >
'z' && c !=
'~') || c ==
'"' || c ==
'%' || c ==
'&' ||
2900 c ==
'+' || c ==
'<' || c ==
'=' || c ==
'>' || c ==
'\\' || c ==
'^' || c ==
'`') {
2901 if ((c==0xc2 || c==0xc3) && (p[1] & 0xc0)==0x80) {
2907 esc[1] = (c >= 0xa0 ? (c >> 4) - 10 +
'A' : (c >> 4) +
'0');
2909 esc[2] = (c >= 0xa ? c - 10 +
'A' : c +
'0');
2910 escaped.append((
char*)esc, 3);
2912 escaped.append((
char*)&c, 1);
2938 request =
"GET /api/";
2939 request.append(funcid);
2940 request.append(
"/");
2943 if(changeattr!=
"") {
2944 request.append(changeattr);
2946 request.append(
"?");
2947 request.append(changeattr);
2948 request.append(
"=");
2954 request.append(
"&. \r\n\r\n");
2970 string errmsg, request;
3013 string errmsg, buffer;
3023 res = dev->
HTTPRequest(channel, request, buffer, callback, context, errmsg);
3031 res = dev->
HTTPRequest(channel, request, buffer, callback, context, errmsg);
3037 if (0 != buffer.find(
"OK\r\n")) {
3038 if (0 != buffer.find(
"HTTP/1.1 200 OK\r\n")) {
3055 string request,buffer;
3058 request =
"GET /"+url+
" HTTP/1.1\r\n\r\n";
3060 found = buffer.find(
"\r\n\r\n");
3061 if(string::npos == found){
3066 return buffer.substr(found+4);
3074 string request, buffer;
3078 request =
"POST /upload.html HTTP/1.1\r\n";
3079 string body =
"Content-Disposition: form-data; name=\"" + path +
"\"; filename=\"api\"\r\n" +
3080 "Content-Type: application/octet-stream\r\n" +
3081 "Content-Transfer-Encoding: binary\r\n\r\n" + content;
3084 }
while (body.find(boundary) != string::npos);
3085 request +=
"Content-Type: multipart/form-data; boundary=" + boundary +
"\r\n";
3086 request +=
"\r\n--" + boundary +
"\r\n" + body +
"\r\n--" + boundary +
"--\r\n";
3087 buffer = this->
_requestEx(0, request, callback, context);
3088 found = buffer.find(
"\r\n\r\n");
3089 if (string::npos == found) {
3113 return newDataStream;
3119 std::map<string, YDataStream*>::iterator it;
3135 string errmsg, serial, funcId, funcName, funcValue;
3136 string descr =
_func;
3156 string errmsg, serial, funcId, funcName, funcValue;
3157 string mod_serial, mod_funcId,mod_funcname;
3169 if(mod_funcname!=
"") {
3171 return mod_funcname+
"."+funcId;
3175 return serial+
"."+funcId;
3218 return string(snum)+string(
".")+string(funcid);
3252 return string(funcid);
3319 }
catch (std::exception) {
3368 }
catch (std::exception ex) {
3397 }
catch (std::exception) {
3415 string errmsg, apires;
3444 string errmsg, serial, funcId, funcName, funcValue;
3513 vector<YFunction*>::iterator it;
3520 vector<YFunction*>::iterator it;
3535 vector<YFunction*>::iterator it;
3542 vector<YFunction*>::iterator it;
3605 if(
YISERR(res))
return res;
3608 if(
YISERR(res))
return res;
3610 pos = request.find_first_of(
'/');
3611 fullrequest = request.substr(0,pos) + (string)
_subpath + request.substr(pos+1);
3628 errmsg = (string)errbuff;
3632 errmsg = (string)errbuff;
3635 if (replysize > 0 && reply != NULL) {
3636 buffer = string(reply, replysize);
3641 errmsg = (string)errbuff;
3658 errmsg = (string)errbuff;
3671 for (i = 0; !locked && i < 5 ; i++) {
3689 string rootdev, buffer;
3690 string request =
"GET /api.json \r\n\r\n";
3703 request =
"GET /api.json \r\n\r\n";
3726 j.
src = buffer.data();
3727 j.
end = j.
src + buffer.size();
3730 errmsg =
"Failed to parse HTTP header";
3734 if(
string(j.
token) !=
"200") {
3735 errmsg = string(
"Unexpected HTTP return code: ")+j.
token;
3740 errmsg =
"Unexpected HTTP header format";
3745 errmsg =
"Unexpected JSON reply format";
3750 do j.
src--;
while(j.
src[0] !=
'{' && j.
src[0] !=
'[');
3751 json_str = string(j.
src);
3753 apires =
new YJSONObject(json_str, 0, (
int)json_str.length());
3755 }
catch (std::exception ex) {
3756 errmsg =
"unexpected JSON structure: " + string(ex.what());
3858 callback(module,
string(line));
3869 vector<YFunction*>::iterator it;
3877 _data_events.push(dataEv);
3886 _plug_events.push(ev);
3900 _plug_events.push(ev);
3915 _plug_events.push(ev);
3932 _data_events.push(ev);
3949 ev.
report[p++] = *bytes++;
3951 _data_events.push(ev);
3962 strcpy(ev.
serial, serial);
3963 strcpy(ev.
url, url);
3964 _plug_events.push(ev);
3972 1.0e-6, 1.0e-5, 1.0e-4, 1.0e-3, 1.0e-2, 1.0e-1, 1.0,
3973 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9 };
3980 int mantis = val & 2047;
3983 if(mantis == 0)
return 0.0;
3988 res = (double)(mantis) *
decExp[val >> 11];
3990 return (negate ? -res : res);
4009 comp = val / 1999.0;
4011 while(comp >
decExp[decpow] && decpow < 15) {
4014 mant = val /
decExp[decpow];
4015 if(decpow == 15 && mant > 2047.0) {
4016 res = (15 << 11) + 2047;
4018 res = (decpow << 11) + (
int)floor(mant+.5);
4020 return (negate ? -res : res);
4037 for(
unsigned p = 0; p < sdat.size();) {
4039 unsigned c = sdat[p++];
4042 }
else if(c ==
'X') {
4044 }
else if(c ==
'Y') {
4046 }
else if(c >=
'a') {
4047 int srcpos = (int)udat.size()-1-(c-
'a');
4053 if(p+2 > sdat.size())
return udat;
4056 val += (c -
'0') << 5;
4058 if(c ==
'z') c =
'\\';
4059 val += (c -
'0') << 10;
4061 udat.push_back((
int)val);
4071 for(
unsigned p = 0; p < sdat.size();) {
4076 unsigned c = sdat[p++];
4077 while(c !=
'-' && (c < '0' || c >
'9')) {
4078 if(p >= sdat.size()) {
4084 if(p >= sdat.size()) {
4090 while((c >=
'0' && c <=
'9') || c ==
'.') {
4093 }
else if(dec < 3) {
4094 val = val * 10 + (c -
'0');
4097 if(p < sdat.size()) {
4104 if(dec == 0) val *= 1000;
4105 else if(dec == 1) val *= 100;
4108 idat.push_back(sign*val);
4118 const u8 *ptr = (u8*) data.data();
4119 size_t len = data.length();
4120 string res = string(len * 2, 0);
4121 for (
size_t j = 0; j < len; j++, ptr++) {
4124 res[j * 2 + 1] =
hexArray[v & 0x0F];
4132 size_t len = hex_str.length() / 2;
4133 const char *p = hex_str.c_str();
4134 string res = string(len, 0);
4135 for (
size_t i = 0; i < len; i++) {
4138 for(j = 0; j < 2; j++) {
4140 if(*p >=
'a' && *p <=
'f'){
4142 }
else if(*p >=
'A' && *p <=
'F'){
4144 }
else if(*p >=
'0' && *p <=
'9'){
4159 bool neg = *p ==
'-';
4160 if (*p ==
'+' || neg) {
4163 while (*p >=
'0' && *p <=
'9') {
4245 for(i = 0; i <= 20; i++) {
4272 while (!_plug_events.empty()) {
4275 while (!_data_events.empty()) {
4278 _calibHandlers.clear();
4324 if(arrivalCallback) {
4387 if (
YISERR(res))
return res;
4410 double x = rawValues[0];
4411 double adj = refValues[0] - x;
4417 npt = calibType % 10;
4418 if(npt > (
int)rawValues.size()) npt = (
int)rawValues.size();
4419 if(npt > (
int)refValues.size()) npt = (
int)refValues.size();
4421 npt = (int)refValues.size();
4423 while(rawValue > rawValues[i] && ++i < npt) {
4428 adj = refValues[i] - x;
4430 if(rawValue < x && x > x2) {
4431 adj = adj2 + (adj - adj2) * (rawValue - x2) / (x - x2);
4434 return rawValue + adj;
4457 res =
yapiTestHub(url.c_str(), mstimeout, errbuf);
4515 if(
YISERR(res))
return res;
4545 if(
YISERR(res))
return res;
4588 if(
YISERR(res))
return res;
4606 while(!_plug_events.empty()){
4609 if(_plug_events.empty()){
4613 ev = _plug_events.front();
4671 while (!_data_events.empty()) {
4677 if (_data_events.empty()) {
4681 ev = _data_events.front();
4778 const char *_ver, *_date;
4802 int neededsize, res;
4811 if(neededsize > initsize) {
4823 buffer = vector<YDEV_DESCR>(ptr, ptr+res);
4866 if(neededsize > initsize) {
4878 buffer = vector<YFUN_DESCR>(ptr, ptr+res);
4898 if(neededsize > initsize) {
4910 buffer = vector<YFUN_DESCR>(ptr, ptr+res);
5000 char on_stack_buffer[1024];
5002 char *buffer = on_stack_buffer;
5005 for (
int i = 0; i < 13; i++) {
5006 va_start(args, fmt);
5007 n = vsnprintf(buffer, size, fmt, args);
5009 if (n > -1 && n < size) {
5010 res = string(buffer);
5019 if (buffer != on_stack_buffer) {
5022 buffer = (
char*)malloc(size);
5024 if (buffer != on_stack_buffer) {
5039 ,_productName(PRODUCTNAME_INVALID)
5040 ,_serialNumber(SERIALNUMBER_INVALID)
5041 ,_productId(PRODUCTID_INVALID)
5042 ,_productRelease(PRODUCTRELEASE_INVALID)
5043 ,_firmwareRelease(FIRMWARERELEASE_INVALID)
5044 ,_persistentSettings(PERSISTENTSETTINGS_INVALID)
5045 ,_luminosity(LUMINOSITY_INVALID)
5046 ,_beacon(BEACON_INVALID)
5047 ,_upTime(UPTIME_INVALID)
5048 ,_usbCurrent(USBCURRENT_INVALID)
5049 ,_rebootCountdown(REBOOTCOUNTDOWN_INVALID)
5050 ,_userVar(USERVAR_INVALID)
5051 ,_valueCallbackModule(NULL)
5075 if(json_val->
has(
"productName")) {
5078 if(json_val->
has(
"serialNumber")) {
5081 if(json_val->
has(
"productId")) {
5084 if(json_val->
has(
"productRelease")) {
5087 if(json_val->
has(
"firmwareRelease")) {
5090 if(json_val->
has(
"persistentSettings")) {
5093 if(json_val->
has(
"luminosity")) {
5096 if(json_val->
has(
"beacon")) {
5099 if(json_val->
has(
"upTime")) {
5102 if(json_val->
has(
"usbCurrent")) {
5105 if(json_val->
has(
"rebootCountdown")) {
5108 if(json_val->
has(
"userVar")) {
5136 }
catch (std::exception) {
5165 }
catch (std::exception) {
5194 }
catch (std::exception) {
5223 }
catch (std::exception) {
5252 }
catch (std::exception) {
5282 }
catch (std::exception) {
5296 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
5297 res =
_setAttr(
"persistentSettings", rest_val);
5298 }
catch (std::exception) {
5327 }
catch (std::exception) {
5353 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
5354 res =
_setAttr(
"luminosity", rest_val);
5355 }
catch (std::exception) {
5384 }
catch (std::exception) {
5407 rest_val = (newval>0 ?
"1" :
"0");
5408 res =
_setAttr(
"beacon", rest_val);
5409 }
catch (std::exception) {
5438 }
catch (std::exception) {
5467 }
catch (std::exception) {
5498 }
catch (std::exception) {
5512 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
5513 res =
_setAttr(
"rebootCountdown", rest_val);
5514 }
catch (std::exception) {
5544 }
catch (std::exception) {
5569 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
5570 res =
_setAttr(
"userVar", rest_val);
5571 }
catch (std::exception) {
5613 }
catch (std::exception) {
5635 if (callback != NULL) {
5642 if (callback != NULL && this->
isOnline()) {
5744 if (
_ystrpos(tmp_res,
"error:") == 0) {
5766 if ((
int)(settings).size() == 0) {
5768 settings =
"error:Unable to get device settings";
5806 string file_data_bin;
5807 string temp_data_bin;
5808 string ext_settings;
5809 vector<string> filelist;
5810 vector<string> templist;
5813 if ((
int)(settings).size() == 0) {
5816 ext_settings =
", \"extras\":[";
5819 for (
unsigned ii = 0; ii < templist.size(); ii++) {
5823 if (t_type ==
"RES_NTC") {
5824 id = ( templist[ii]).substr( 11, (
int)( templist[ii]).length() - 11);
5826 if ((
int)(temp_data_bin).size() == 0) {
5827 return temp_data_bin;
5829 item =
YapiWrapper::ysprintf(
"%s{\"fid\":\"%s\", \"json\":%s}\n", sep.c_str(), templist[ii].c_str(),temp_data_bin.c_str());
5830 ext_settings = ext_settings + item;
5835 ext_settings = ext_settings +
"],\n\"files\":[";
5837 json = this->
_download(
"files.json?a=dir&f=");
5838 if ((
int)(json).size() == 0) {
5843 for (
unsigned ii = 0; ii < filelist.size(); ii++) {
5845 if (((
int)(name).length() > 0) && !(name ==
"startupConf.json")) {
5848 item =
YapiWrapper::ysprintf(
"%s{\"name\":\"%s\", \"data\":\"%s\"}\n", sep.c_str(), name.c_str(),file_data.c_str());
5849 ext_settings = ext_settings + item;
5854 res =
"{ \"api\":" + settings + ext_settings +
"]}";
5860 vector<string> values;
5866 url =
"api/" + funcId +
".json?command=Z";
5872 size = (int)values.size();
5873 while (ofs + 1 < size) {
5875 currTemp = values[ofs + 1];
5876 url =
YapiWrapper::ysprintf(
"api/%s/.json?command=m%s:%s", funcId.c_str(), curr.c_str(),currTemp.c_str());
5885 vector<string> extras;
5889 for (
unsigned ii = 0; ii < extras.size(); ii++) {
5922 if (json_api ==
"") {
5926 if (!(json_extra ==
"")) {
5931 vector<string> files;
5935 down = this->
_download(
"files.json?a=format");
5938 if (!(res ==
"ok")) {
5944 for (
unsigned ii = 0; ii < files.size(); ii++) {
5973 if (fid == funcId) {
5999 if (ftype == funType) {
6003 if (ftype == funType) {
6015 char smallbuff[1024];
6021 string jsoncomplexstr;
6023 jsoncomplexstr = jsoncomplex;
6024 res =
yapiGetAllJsonKeys(jsoncomplexstr.c_str(), smallbuff, 1024, &fullsize, errmsg);
6027 jsonflat =
"error:" + string(errmsg);
6030 if (fullsize <= 1024) {
6031 jsonflat = string(smallbuff, fullsize);
6033 fullsize = fullsize * 2;
6034 buffsize = fullsize;
6035 bigbuff = (
char *)malloc(buffsize);
6036 res =
yapiGetAllJsonKeys(jsoncomplexstr.c_str(), bigbuff, buffsize, &fullsize, errmsg);
6039 jsonflat =
"error:" + string(errmsg);
6041 jsonflat = string(bigbuff, fullsize);
6050 if (cparams ==
"0,") {
6060 if (cparams ==
"" || cparams ==
"0") {
6063 if (((
int)(cparams).length() < 2) || (
_ystrpos(cparams,
".") >= 0)) {
6072 if (unit_name ==
"g" || unit_name ==
"gauss" || unit_name ==
"W") {
6075 if (unit_name ==
"C") {
6076 if (sensorType ==
"") {
6079 if (atoi((sensorType).c_str()) < 8) {
6085 if (unit_name ==
"m" || unit_name ==
"deg") {
6093 if (unit_name ==
"% RH" || unit_name ==
"mbar" || unit_name ==
"lx") {
6106 int paramOffset = 0;
6108 vector<string> words_str;
6109 vector<double> calibData;
6116 double wordVal = 0.0;
6120 funScale = this->
calibScale(unit_name, sensorType);
6122 paramScale = funScale;
6123 paramOffset = funOffset;
6128 if ((words[0] == 1366) && (words[1] == 12500)) {
6133 funScale = words[1];
6134 funOffset = words[0];
6138 if (currentFuncValue ==
"" || (atoi((currentFuncValue).c_str()) > 10)) {
6148 if (paramVer == 2) {
6150 if ((words[0] == 1366) && (words[1] == 12500)) {
6155 paramScale = words[1];
6156 paramOffset = words[0];
6158 if (((
int)words.size() >= 3) && (words[2] > 0)) {
6159 maxSize = 3 + 2 * ((words[2]) % (10));
6160 if (maxSize > (
int)words.size()) {
6161 maxSize = (int)words.size();
6164 while (i < maxSize) {
6165 calibData.push_back((
double) words[i]);
6170 if (paramVer == 1) {
6172 for (
unsigned ii = 0; ii < words_str.size(); ii++) {
6173 words.push_back(atoi((words_str[ii]).c_str()));
6175 if (param ==
"" || (words[0] > 10)) {
6178 if (((
int)words.size() > 0) && (words[0] > 0)) {
6179 maxSize = 1 + 2 * ((words[0]) % (10));
6180 if (maxSize > (
int)words.size()) {
6181 maxSize = (int)words.size();
6184 while (i < maxSize) {
6185 calibData.push_back((
double) words[i]);
6190 if (paramVer == 0) {
6191 ratio = atof((param).c_str());
6193 calibData.push_back(0.0);
6194 calibData.push_back(0.0);
6195 calibData.push_back(floor(65535 / ratio+0.5));
6196 calibData.push_back(65535.0);
6202 while (i < (
int)calibData.size()) {
6203 if (paramScale > 0) {
6205 calibData[i] = (calibData[i] - paramOffset) / paramScale;
6215 calibType = (int) floor(iCalib[0] / 1000.0+0.5);
6216 if (calibType >= 30) {
6217 calibType = calibType - 30;
6220 while (i < (
int)iCalib.size()) {
6221 calibData.push_back(iCalib[i] / 1000.0);
6227 if ((
int)calibData.size() == 0) {
6232 while (i < (
int)calibData.size()) {
6233 if (((i) & (1)) > 0) {
6234 param = param +
":";
6236 param = param +
" ";
6241 param = param +
",";
6246 nPoints = (((int)calibData.size()) / (2));
6249 while (i < 2 * nPoints) {
6250 if (funScale == 0) {
6253 wordVal = calibData[i] * funScale + funOffset;
6260 if ((
int)calibData.size() == 4) {
6261 param =
YapiWrapper::ysprintf(
"%f",floor(1000 * (calibData[3] - calibData[1]) / calibData[2] - calibData[0]+0.5));
6281 vector<string> restoreLast;
6282 string old_json_flat;
6283 vector<string> old_dslist;
6284 vector<string> old_jpath;
6285 vector<int> old_jpath_len;
6286 vector<string> old_val_arr;
6287 string actualSettings;
6288 vector<string> new_dslist;
6289 vector<string> new_jpath;
6290 vector<int> new_jpath_len;
6291 vector<string> new_val_arr;
6322 for (
unsigned ii = 0; ii < old_dslist.size(); ii++) {
6325 leng = (int)(each_str).length();
6327 if ((eqpos < 0) || (leng == 0)) {
6331 jpath = (each_str).substr( 0, eqpos);
6333 value = (each_str).substr( eqpos, leng - eqpos);
6334 old_jpath.push_back(jpath);
6335 old_jpath_len.push_back((
int)(jpath).length());
6336 old_val_arr.push_back(value);
6339 actualSettings = this->
_download(
"api.json");
6342 for (
unsigned ii = 0; ii < new_dslist.size(); ii++) {
6346 leng = (int)(each_str).length();
6348 if ((eqpos < 0) || (leng == 0)) {
6352 jpath = (each_str).substr( 0, eqpos);
6354 value = (each_str).substr( eqpos, leng - eqpos);
6355 new_jpath.push_back(jpath);
6356 new_jpath_len.push_back((
int)(jpath).length());
6357 new_val_arr.push_back(value);
6360 while (i < (
int)new_jpath.size()) {
6361 njpath = new_jpath[i];
6362 leng = (int)(njpath).length();
6364 if ((cpos < 0) || (leng == 0)) {
6367 fun = (njpath).substr( 0, cpos);
6369 attr = (njpath).substr( cpos, leng - cpos);
6371 if (fun ==
"services") {
6374 if ((do_update) && (attr ==
"firmwareRelease")) {
6377 if ((do_update) && (attr ==
"usbCurrent")) {
6380 if ((do_update) && (attr ==
"upTime")) {
6383 if ((do_update) && (attr ==
"persistentSettings")) {
6386 if ((do_update) && (attr ==
"adminPassword")) {
6389 if ((do_update) && (attr ==
"userPassword")) {
6392 if ((do_update) && (attr ==
"rebootCountdown")) {
6395 if ((do_update) && (attr ==
"advertisedValue")) {
6398 if ((do_update) && (attr ==
"poeCurrent")) {
6401 if ((do_update) && (attr ==
"readiness")) {
6404 if ((do_update) && (attr ==
"ipAddress")) {
6407 if ((do_update) && (attr ==
"subnetMask")) {
6410 if ((do_update) && (attr ==
"router")) {
6413 if ((do_update) && (attr ==
"linkQuality")) {
6416 if ((do_update) && (attr ==
"ssid")) {
6419 if ((do_update) && (attr ==
"channel")) {
6422 if ((do_update) && (attr ==
"security")) {
6425 if ((do_update) && (attr ==
"message")) {
6428 if ((do_update) && (attr ==
"currentValue")) {
6431 if ((do_update) && (attr ==
"currentRawValue")) {
6434 if ((do_update) && (attr ==
"currentRunIndex")) {
6437 if ((do_update) && (attr ==
"pulseTimer")) {
6440 if ((do_update) && (attr ==
"lastTimePressed")) {
6443 if ((do_update) && (attr ==
"lastTimeReleased")) {
6446 if ((do_update) && (attr ==
"filesCount")) {
6449 if ((do_update) && (attr ==
"freeSpace")) {
6452 if ((do_update) && (attr ==
"timeUTC")) {
6455 if ((do_update) && (attr ==
"rtcTime")) {
6458 if ((do_update) && (attr ==
"unixTime")) {
6461 if ((do_update) && (attr ==
"dateTime")) {
6464 if ((do_update) && (attr ==
"rawValue")) {
6467 if ((do_update) && (attr ==
"lastMsg")) {
6470 if ((do_update) && (attr ==
"delayedPulseTimer")) {
6473 if ((do_update) && (attr ==
"rxCount")) {
6476 if ((do_update) && (attr ==
"txCount")) {
6479 if ((do_update) && (attr ==
"msgCount")) {
6484 newval = new_val_arr[i];
6487 while ((j < (
int)old_jpath.size()) && !(found)) {
6488 if ((new_jpath_len[i] == old_jpath_len[j]) && (new_jpath[i] == old_jpath[j])) {
6490 oldval = old_val_arr[j];
6491 if (!(newval == oldval)) {
6499 if (attr ==
"calibrationParam") {
6506 while ((j < (
int)old_jpath.size()) && !(found)) {
6507 if ((new_jpath_len[i] == old_jpath_len[j]) && (new_jpath[i] == old_jpath[j])) {
6509 old_calib = old_val_arr[j];
6513 tmp = fun +
"/unit";
6516 while ((j < (
int)new_jpath.size()) && !(found)) {
6517 if (tmp == new_jpath[j]) {
6519 unit_name = new_val_arr[j];
6523 tmp = fun +
"/sensorType";
6526 while ((j < (
int)new_jpath.size()) && !(found)) {
6527 if (tmp == new_jpath[j]) {
6529 sensorType = new_val_arr[j];
6533 newval = this->
calibConvert(old_calib, new_val_arr[i], unit_name, sensorType);
6534 url =
"api/" + fun +
".json?" + attr +
"=" + this->
_escapeAttr(newval);
6537 url =
"api/" + fun +
".json?" + attr +
"=" + this->
_escapeAttr(oldval);
6538 if (attr ==
"resolution") {
6539 restoreLast.push_back(url);
6547 for (
unsigned ii = 0; ii < restoreLast.size(); ii++) {
6608 return this->
_upload(
"logs.txt", text);
6621 char smallbuff[1024];
6626 string subdevice_list;
6627 vector<string> subdevices;
6632 yapi_res =
yapiGetSubdevices(serial.c_str(), smallbuff, 1024, &fullsize, errmsg);
6636 if (fullsize <= 1024) {
6637 subdevice_list = string(smallbuff, yapi_res);
6639 buffsize = fullsize;
6640 bigbuff = (
char *)malloc(buffsize);
6641 yapi_res =
yapiGetSubdevices(serial.c_str(), bigbuff, buffsize, &fullsize, errmsg);
6646 subdevice_list = string(bigbuff, yapi_res);
6650 if (!(subdevice_list ==
"")) {
6651 subdevices =
_strsplit(subdevice_list,
',');
6678 return string(hubserial);
6702 return string(path);
6717 vector<YFUN_DESCR> v_fundescr;
6719 string serial, funcId, funcName, funcVal, errmsg;
6722 v_fundescr.size() == 0 ||
6736 string errmsg, serial, funcId, funcName, funcValue;
6737 string mod_serial, mod_funcId,mod_funcname;
6744 if(mod_funcname!=
"") {
6746 return mod_funcname;
6772 vector<YFUN_DESCR> *functions;
6790 fundescr = functions->at(idx);
6800 vector<YFUN_DESCR> *functions;
6819 return (
int)functions->size();
6825 string serial, funcId, funcName, basetype, funcVal, errmsg;
6830 res =
_getFunction(functionIndex, serial, funcId, basetype, funcName, funcVal, errmsg);
6831 }
catch (std::exception) {
6846 string serial, funcId, basetype, funcName, funcVal, errmsg;
6850 res =
_getFunction(functionIndex, serial, funcId, basetype, funcName, funcVal, errmsg);
6851 }
catch (std::exception) {
6867 string serial, funcId, basetype, funcName, funcVal, errmsg;
6871 res =
_getFunction(functionIndex, serial, funcId, basetype, funcName, funcVal, errmsg);
6872 }
catch (std::exception) {
6889 string serial, funcId, basetype, funcName, funcVal, errmsg;
6895 res =
_getFunction(functionIndex, serial, funcId, basetype, funcName, funcVal, errmsg);
6896 }
catch (std::exception) {
6907 while (*p && (*p <'0' || *p >
'9')) {
6911 return string(buffer);
6917 string serial, funcId, basetype, funcName, funcVal, errmsg;
6921 res =
_getFunction(functionIndex, serial, funcId, basetype, funcName, funcVal, errmsg);
6922 }
catch (std::exception) {
6970 ,_unit(UNIT_INVALID)
6971 ,_currentValue(CURRENTVALUE_INVALID)
6972 ,_lowestValue(LOWESTVALUE_INVALID)
6973 ,_highestValue(HIGHESTVALUE_INVALID)
6974 ,_currentRawValue(CURRENTRAWVALUE_INVALID)
6975 ,_logFrequency(LOGFREQUENCY_INVALID)
6976 ,_reportFrequency(REPORTFREQUENCY_INVALID)
6977 ,_advMode(ADVMODE_INVALID)
6978 ,_calibrationParam(CALIBRATIONPARAM_INVALID)
6979 ,_resolution(RESOLUTION_INVALID)
6980 ,_sensorState(SENSORSTATE_INVALID)
6981 ,_valueCallbackSensor(NULL)
6982 ,_timedReportCallbackSensor(NULL)
6983 ,_prevTimedReport(0.0)
7017 if(json_val->
has(
"unit")) {
7020 if(json_val->
has(
"currentValue")) {
7023 if(json_val->
has(
"lowestValue")) {
7026 if(json_val->
has(
"highestValue")) {
7029 if(json_val->
has(
"currentRawValue")) {
7032 if(json_val->
has(
"logFrequency")) {
7035 if(json_val->
has(
"reportFrequency")) {
7038 if(json_val->
has(
"advMode")) {
7041 if(json_val->
has(
"calibrationParam")) {
7044 if(json_val->
has(
"resolution")) {
7047 if(json_val->
has(
"sensorState")) {
7075 }
catch (std::exception) {
7109 res = floor(res+0.5) /
_iresol;
7110 }
catch (std::exception) {
7134 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
7135 res =
_setAttr(
"lowestValue", rest_val);
7136 }
catch (std::exception) {
7167 res = floor(res+0.5) /
_iresol;
7168 }
catch (std::exception) {
7192 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
7193 res =
_setAttr(
"highestValue", rest_val);
7194 }
catch (std::exception) {
7225 res = floor(res+0.5) /
_iresol;
7226 }
catch (std::exception) {
7257 }
catch (std::exception) {
7288 }
catch (std::exception) {
7316 res =
_setAttr(
"logFrequency", rest_val);
7317 }
catch (std::exception) {
7348 }
catch (std::exception) {
7376 res =
_setAttr(
"reportFrequency", rest_val);
7377 }
catch (std::exception) {
7407 }
catch (std::exception) {
7431 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
7432 res =
_setAttr(
"advMode", rest_val);
7433 }
catch (std::exception) {
7455 }
catch (std::exception) {
7470 res =
_setAttr(
"calibrationParam", rest_val);
7471 }
catch (std::exception) {
7495 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
7496 res =
_setAttr(
"resolution", rest_val);
7497 }
catch (std::exception) {
7527 }
catch (std::exception) {
7559 }
catch (std::exception) {
7607 }
catch (std::exception) {
7629 if (callback != NULL) {
7636 if (callback != NULL && this->
isOnline()) {
7685 _caltyp = ((iCalib[0]) / (1000));
7704 maxpos = (int)iCalib.size();
7707 while (position < maxpos) {
7708 _calpar.push_back(iCalib[position]);
7709 position = position + 1;
7714 while (position + 1 < maxpos) {
7715 fRaw = iCalib[position];
7716 fRaw = fRaw / 1000.0;
7717 fRef = iCalib[position + 1];
7718 fRef = fRef / 1000.0;
7721 position = position + 2;
7727 if ((
int)iCalib.size() < 2) {
7744 position = iCalib[0];
7745 while (position > 0) {
7747 position = position - 1;
7751 if ((
int)iCalib.size() == 2) {
7767 maxpos = 3 + 2 * maxpos;
7768 if (maxpos > (
int)iCalib.size()) {
7769 maxpos = (int)iCalib.size();
7775 while (position + 1 < maxpos) {
7776 iRaw = iCalib[position];
7777 iRef = iCalib[position + 1];
7791 position = position + 2;
7835 hwid = serial +
".dataLogger";
7851 res = this->
_download(
"api/dataLogger/recording?recording=1");
7852 if (!((
int)(res).size()>0)) {
7868 res = this->
_download(
"api/dataLogger/recording?recording=0");
7869 if (!((
int)(res).size()>0)) {
7909 return YDataSet(
this,funcid,funit,startTime,endTime);
7927 if (callback != NULL) {
7974 res = this->
_setAttr(
"calibrationParam", rest_val);
7975 }
catch (std::exception) {
8012 this->
_throw(
YAPI_NOT_SUPPORTED,
"Calibration parameters format mismatch. Please upgrade your library or firmware.");
8020 for (
unsigned ii = 0; ii <
_calraw.size(); ii++) {
8021 rawValues.push_back(
_calraw[ii]);
8023 for (
unsigned ii = 0; ii <
_calref.size(); ii++) {
8024 refValues.push_back(
_calref[ii]);
8026 }
catch (std::exception) {
8041 npt = (int)rawValues.size();
8042 if (npt != (
int)refValues.size()) {
8058 this->
_throw(
YAPI_NOT_SUPPORTED,
"Calibration parameters format mismatch. Please upgrade your library or firmware.");
8122 double startTime = 0.0;
8123 double endTime = 0.0;
8124 double minVal = 0.0;
8125 double avgVal = 0.0;
8126 double maxVal = 0.0;
8128 endTime = timestamp;
8130 if (startTime == 0) {
8131 startTime = endTime;
8133 if (report[0] == 2) {
8135 if ((
int)report.size() <= 5) {
8141 while (i < (
int)report.size()) {
8142 byteVal = report[i];
8143 avgRaw = avgRaw + poww * byteVal;
8144 poww = poww * 0x100;
8147 if (((byteVal) & (0x80)) != 0) {
8148 avgRaw = avgRaw - poww;
8150 avgVal = avgRaw / 1000.0;
8160 sublen = 1 + ((report[1]) & (3));
8165 while ((sublen > 0) && (i < (int)report.size())) {
8166 byteVal = report[i];
8167 avgRaw = avgRaw + poww * byteVal;
8168 poww = poww * 0x100;
8170 sublen = sublen - 1;
8172 if (((byteVal) & (0x80)) != 0) {
8173 avgRaw = avgRaw - poww;
8175 sublen = 1 + ((((report[1]) >> (2))) & (3));
8178 while ((sublen > 0) && (i < (int)report.size())) {
8179 byteVal = report[i];
8180 difRaw = difRaw + poww * byteVal;
8181 poww = poww * 0x100;
8183 sublen = sublen - 1;
8185 minRaw = avgRaw - difRaw;
8186 sublen = 1 + ((((report[1]) >> (4))) & (3));
8189 while ((sublen > 0) && (i < (int)report.size())) {
8190 byteVal = report[i];
8191 difRaw = difRaw + poww * byteVal;
8192 poww = poww * 0x100;
8194 sublen = sublen - 1;
8196 maxRaw = avgRaw + difRaw;
8197 avgVal = avgRaw / 1000.0;
8198 minVal = minRaw / 1000.0;
8199 maxVal = maxRaw / 1000.0;
8210 if (report[0] == 0) {
8216 while (i < (
int)report.size()) {
8217 byteVal = report[i];
8218 avgRaw = avgRaw + poww * byteVal;
8219 poww = poww * 0x100;
8225 if (((byteVal) & (0x80)) != 0) {
8226 avgRaw = avgRaw - poww;
8234 minRaw = report[1] + 0x100 * report[2];
8235 maxRaw = report[3] + 0x100 * report[4];
8236 avgRaw = report[5] + 0x100 * report[6] + 0x10000 * report[7];
8237 byteVal = report[8];
8238 if (((byteVal) & (0x80)) == 0) {
8239 avgRaw = avgRaw + 0x1000000 * byteVal;
8241 avgRaw = avgRaw - 0x1000000 * (0x100 - byteVal);
8248 return YMeasure( startTime, endTime, minVal, avgVal,maxVal);
8297 vector<YFUN_DESCR> v_fundescr;
8299 string serial, funcId, funcName, funcVal, errmsg;
8302 v_fundescr.size() == 0 ||
8317 unsigned stamp,
unsigned utc,
unsigned itv)
8340 vector<int> coldiv, coltyp;
8341 vector<double> colscl;
8343 vector<yCalibrationHandler> calhdl;
8345 vector<intArr> calpar;
8346 vector<floatArr> calraw;
8347 vector<floatArr> calref;
8364 if(!strcmp(j.
token,
"time")) {
8367 }
else if(!strcmp(j.
token,
"UTC")) {
8370 }
else if(!strcmp(j.
token,
"interval")) {
8373 }
else if(!strcmp(j.
token,
"nRows")) {
8376 }
else if(!strcmp(j.
token,
"keys")) {
8381 if(j.
token[0] !=
']')
goto fail;
8388 }
else if(!strcmp(j.
token,
"div")) {
8391 coldiv.push_back(atoi(j.
token));
8393 if(j.
token[0] !=
']')
goto fail;
8395 _nCols = (int)coldiv.size();
8396 }
else if(
_nCols != (
int)coldiv.size()) {
8400 }
else if(!strcmp(j.
token,
"type")) {
8403 coltyp.push_back(atoi(j.
token));
8405 if(j.
token[0] !=
']')
goto fail;
8407 _nCols = (int)coltyp.size();
8408 }
else if(
_nCols != (
int)coltyp.size()) {
8412 }
else if(!strcmp(j.
token,
"scal")) {
8416 colscl.push_back((
double)atoi(j.
token) / 65536.0);
8417 colofs.push_back(coltyp[c++] != 0 ? -32767 : 0);
8419 if(j.
token[0] !=
']')
goto fail;
8421 _nCols = (int)colscl.size();
8422 }
else if(
_nCols != (
int)colscl.size()) {
8426 }
else if(!strcmp(j.
token,
"cal")) {
8430 int calibType = (*p ? atoi(p) : 0);
8436 caltyp[c] = calibType;
8437 while(*p && *p !=
',') p++;
8441 if(calibType <= 10) {
8442 fval = (double)(ival + colofs[c]) / coldiv[c];
8446 calpar[c].push_back(ival);
8447 while(*p && *p !=
',') p++;
8448 if(calpar[c].size() & 1) {
8449 calraw[c].push_back(fval);
8451 calref[c].push_back(fval);
8456 if(j.
token[0] !=
']')
goto fail;
8457 }
else if(!strcmp(j.
token,
"data")) {
8458 if(colscl.size() == 0) {
8459 for(p = 0; p < coldiv.size(); p++) {
8460 colscl.push_back(1.0 / (
double)coldiv[p]);
8461 colofs.push_back(coltyp[p] != 0 ? -32767 : 0);
8470 udat.push_back(atoi(j.
token));
8472 if(j.
token[0] !=
']' )
goto fail;
8478 for(p = 0; p < udat.size(); p++) {
8481 val = (udat[p] + colofs[c]) * colscl[c];
8485 if(caltyp[c] > 0 && calhdl.size() >= c && calhdl[c]) {
8486 if(caltyp[c] <= 10) {
8488 val = calhdl[c]((udat[p] + colofs[c]) / coldiv[c], caltyp[c], calpar[c], calraw[c], calref[c]);
8489 }
else if(caltyp[c] > 20) {
8491 val = calhdl[c](val, caltyp[c], calpar[c], calraw[c], calref[c]);
8502 if(dat.size() > 0)
goto fail;
8553 if(this->dataLoggerURL ==
"") this->dataLoggerURL =
"/logger.json";
8556 res = _getDevice(dev, errmsg);
8563 sprintf(query,
"GET %s?run=%u&time=%u \r\n\r\n", this->dataLoggerURL.c_str(), runIdx, timeIdx);
8565 sprintf(query,
"GET %s \r\n\r\n", this->dataLoggerURL.c_str());
8567 res = dev->
HTTPRequest(0, query, buffer, NULL, NULL, errmsg);
8575 res = dev->
HTTPRequest(0, query, buffer, NULL, NULL, errmsg);
8583 j.
src = buffer.data();
8584 j.
end = j.
src + buffer.size();
8590 if(
string(j.
token) !=
"200") {
8591 if(
string(j.
token) ==
"404" && this->dataLoggerURL !=
"/dataLogger.json") {
8593 this->dataLoggerURL =
"/dataLogger.json";
8594 return this->getData(runIdx, timeIdx, buffer, j);
8629 unsigned i, si, arr[4];
8642 if(j.
token[0] ==
'[') {
8644 for(i = 0; i < 4; i++) {
8646 arr[i] = atoi(j.
token);
8655 }
else if(j.
token[0] ==
'{') {
8657 size_t pos = buffer.find(
"\r\n\r\n", 0);
8658 buffer = buffer.substr(pos+4);
8659 vector<YDataSet> sets = this->parse_dataSets(buffer);
8660 for (i=0; i < sets.size(); i++) {
8661 vector<YDataStream*> ds = sets[i].get_privateDataStreams();
8662 for (si=0; si < ds.size(); si++) {
8679 ,_currentRunIndex(CURRENTRUNINDEX_INVALID)
8680 ,_timeUTC(TIMEUTC_INVALID)
8681 ,_recording(RECORDING_INVALID)
8682 ,_autoStart(AUTOSTART_INVALID)
8683 ,_beaconDriven(BEACONDRIVEN_INVALID)
8684 ,_clearHistory(CLEARHISTORY_INVALID)
8685 ,_valueCallbackDataLogger(NULL)
8703 if(json_val->
has(
"currentRunIndex")) {
8706 if(json_val->
has(
"timeUTC")) {
8709 if(json_val->
has(
"recording")) {
8712 if(json_val->
has(
"autoStart")) {
8715 if(json_val->
has(
"beaconDriven")) {
8718 if(json_val->
has(
"clearHistory")) {
8748 }
catch (std::exception) {
8777 }
catch (std::exception) {
8800 char buf[32]; sprintf(buf,
"%u", (u32)newval); rest_val = string(buf);
8801 res =
_setAttr(
"timeUTC", rest_val);
8802 }
catch (std::exception) {
8832 }
catch (std::exception) {
8856 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
8857 res =
_setAttr(
"recording", rest_val);
8858 }
catch (std::exception) {
8888 }
catch (std::exception) {
8914 rest_val = (newval>0 ?
"1" :
"0");
8915 res =
_setAttr(
"autoStart", rest_val);
8916 }
catch (std::exception) {
8946 }
catch (std::exception) {
8972 rest_val = (newval>0 ?
"1" :
"0");
8973 res =
_setAttr(
"beaconDriven", rest_val);
8974 }
catch (std::exception) {
8996 }
catch (std::exception) {
9010 rest_val = (newval>0 ?
"1" :
"0");
9011 res =
_setAttr(
"clearHistory", rest_val);
9012 }
catch (std::exception) {
9060 }
catch (std::exception) {
9082 if (callback != NULL) {
9089 if (callback != NULL && this->
isOnline()) {
9140 vector<string> dslist;
9142 vector<YDataSet> res;
9146 for (
unsigned ii = 0; ii < dslist.size(); ii++) {
9148 dataset->
_parse(dslist[ii]);
9149 res.push_back(*dataset);
9166 vector<YFUN_DESCR> v_fundescr;
9168 string serial, funcId, funcName, funcVal, errmsg;
9171 v_fundescr.size() == 0 ||
virtual int get_progress(void)
virtual s64 get_endTimeUTC(void)
virtual int get_runIndex(void)
string _json_get_key(const string &json, const string &data)
static vector< int > _decodeWords(string s)
static const int USERVAR_INVALID
virtual double _decodeVal(int w)
virtual string toString()
virtual string get_functionId(void)
void(* YHubDiscoveryCallback)(const string &serial, const string &url)
prototype of the Hub discoverycallback
string get_logicalName(void)
static YHubDiscoveryCallback _HubDiscoveryCallback
static std::vector< YFunction * > _FunctionCallbacks
YAPI_FUNCTION YAPI_FUNCTION_EXPORT yapiGetFunction(const char *class_str, const char *function_str, char *errmsg)
string get_productName(void)
string FormatError(const string &errmsg, int cur_pos)
double getDouble(const string &key)
static void FreeAPI(void)
yCRITICAL_SECTION _this_cs
YDataLogger * nextDataLogger(void)
virtual int get_duration(void)
YJSONObject(const string &data)
YDataLoggerValueCallback _valueCallbackDataLogger
int set_luminosity(int newval)
static YJSONContent * ParseJson(const string &data, int start, int stop)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetFunctionInfo(YAPI_FUNCTION fundesc, YAPI_DEVICE *devdesc, char *serial, char *funcId, char *funcName, char *funcVal, char *errmsg)
YRETCODE YAPI_FUNCTION_EXPORT yapiTestHub(const char *url, int mstimeout, char *errmsg)
vector< YDataStream * > _streams
virtual int set_allSettingsAndFiles(string settings)
static YDEV_DESCR getDevice(const string &device_str, string &errmsg)
static std::vector< YFunction * > _TimedReportCallbackList
static YSensor * FindSensor(string func)
virtual int get_columnCount(void)
virtual int _parserHelper(void)
static const double DATA_INVALID
static const double LOWESTVALUE_INVALID
int set_rebootCountdown(int newval)
static const int PRODUCTRELEASE_INVALID
Y_PERSISTENTSETTINGS_enum get_persistentSettings(void)
virtual string get_allSettings(void)
static void RegisterHubDiscoveryCallback(YHubDiscoveryCallback hubDiscoveryCallback)
static void _UpdateTimedReportCallbackList(YFunction *func, bool add)
YRETCODE HTTPRequest_unsafe(int channel, const string &request, string &buffer, yapiRequestProgressCallback progress_cb, void *progress_ctx, string &errmsg)
virtual vector< YDataStream * > get_privateDataStreams(void)
virtual string get_friendlyName(void)
virtual string get_icon2d(void)
static YDevice * getDevice(YDEV_DESCR devdescr)
string _json_get_string(const string &json)
int set_autoStart(Y_AUTOSTART_enum newval)
char serial[YOCTO_SERIAL_LEN]
int set_calibrationParam(const string &newval)
static YFUN_DESCR getFunction(const string &class_str, const string &function_str, string &errmsg)
YRETCODE _load_unsafe(int msValidity)
void yInitializeCriticalSection(yCRITICAL_SECTION *cs)
virtual int startUpdate(void)
static const int REBOOTCOUNTDOWN_INVALID
static int getFunctionsByDevice(YDEV_DESCR devdesc, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
virtual string checkFirmware(string path, bool onlynew)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetBootloaders(char *buffer, int buffersize, int *fullsize, char *errmsg)
static yCRITICAL_SECTION _updateDeviceList_CS
YJSONString * getYJSONString(const string &key)
void YAPI_FUNCTION_EXPORT yapiRegisterDeviceLogCallback(yapiDeviceLogCallback logCallback)
virtual int get_startTime(void)
string get_firmwareRelease(void)
string functionBaseType(int functionIndex)
YModule(const string &func)
void convert(YJSONObject *reference, YJSONArray *newArray)
static const string ADVERTISEDVALUE_INVALID
double get_currentRawValue(void)
#define Y_CURRENTVALUE_INVALID
YRETCODE YAPI_FUNCTION_EXPORT yapiGetDevicePath(YAPI_DEVICE devdesc, char *rootdevice, char *request, int requestsize, int *neededsize, char *errmsg)
virtual bool isSensorReady(void)
int set_lowestValue(double newval)
virtual int _parserHelper(void)
virtual vector< int > _get_calibration(void)
virtual int _initFromDataSet(YDataSet *dataset, vector< int > encoded)
string get_hardwareId(void)
virtual string toJSON()=0
virtual bool isClosed(void)
char _rootdevice[YOCTO_SERIAL_LEN]
virtual string get_url(void)
std::map< string, YDataStream * > _dataStreams
time_t * get_startTimeUTC_asTime_t(time_t *time)
static vector< string > GetAllBootLoaders(void)
static const string REPORTFREQUENCY_INVALID
void YAPI_FUNCTION_EXPORT yapiRegisterTimedReportCallback(yapiTimedReportCallback timedReportCallback)
virtual int _parseAttr(YJSONObject *json_val)
YRETCODE HTTPRequestAsync(int channel, const string &request, HTTPRequestCallback callback, void *context, string &errmsg)
static void UnregisterHub(const string &url)
vector< YFUN_DESCR > _functions
static YModule * FindModule(string func)
YModule * get_module(void)
static YDEV_DESCR getDeviceByFunction(YFUN_DESCR fundesc, string &errmsg)
virtual string toString()
static const string FRIENDLYNAME_INVALID
YJSONArray * getYJSONArray(int i)
YJSONNumber(const string &data, int start, int stop)
static string _bin2HexStr(const string &data)
static void EnableExceptions(void)
virtual string toString()
static const string CALIBRATIONPARAM_INVALID
static const string LOGFREQUENCY_INVALID
static YRETCODE PreregisterHub(const string &url, string &errmsg)
int getData(unsigned runIdx, unsigned timeIdx, string &buffer, yJsonStateMachine &j)
virtual double get_maxValue(void)
double get_dataSamplesInterval(void)
string functionName(int functionIndex)
YRETCODE _upload(const string &path, const string &content)
static void _yapiDeviceArrivalCallbackFwd(YDEV_DESCR devdesc)
virtual int revertFromFlash(void)
void(* yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes)
virtual string toString()=0
static int DefaultCacheValidity
void(* YSensorValueCallback)(YSensor *func, const string &functionValue)
YRETCODE HTTPRequestPrepare(const string &request, string &fullrequest, char *errbuff)
static std::map< string, YFunction * > _cache
string getString(const string &key)
YJSONObject * getYJSONObject(const string &key)
time_t * get_endTimeUTC_asTime_t(time_t *time)
static const string HARDWAREID_INVALID
void(* HTTPRequestCallback)(YDevice *device, void *context, YRETCODE returnval, const string &result, string &errmsg)
YJSONContent(const string &data, int start, int stop, YJSONType type)
int YAPI_FUNCTION_EXPORT yapiJsonDecodeString(const char *json_string, char *output)
virtual string _get_url(void)
virtual double get_minValue(void)
YRETCODE get_errorType(void)
YJSONContent * get(int i)
virtual YFirmwareUpdate updateFirmwareEx(string path, bool force)
string _escapeAttr(const string &changeval)
vector< double > floatArr
prototype of the value calibration handlers
virtual int get_progress(void)
double get_resolution(void)
virtual double get_averageValue(void)
Y_AUTOSTART_enum get_autoStart(void)
static const string LOGICALNAME_INVALID
Y_CLEARHISTORY_enum get_clearHistory(void)
YFunction * nextFunction(void)
virtual int loadCalibrationPoints(vector< double > &rawValues, vector< double > &refValues)
static const string FIRMWARERELEASE_INVALID
static const int DEVICE_NOT_FOUND
string get_advertisedValue(void)
virtual int get_dataSamplesIntervalMs(void)
void set_userData(void *data)
int _ystrpos(const string &haystack, const string &needle)
void _throw(YRETCODE errType, string errMsg)
static const Y_BEACONDRIVEN_enum BEACONDRIVEN_INVALID
static u16 getAPIVersion(string &version, string &date)
virtual string get_friendlyName(void)
yJsonRetCode yJsonParse(yJsonStateMachine *j)
static vector< int > _decodeFloats(string sdat)
Y_ADVMODE_enum get_advMode(void)
static const string FUNCTIONID_INVALID
static const int PRODUCTID_INVALID
static void RegisterDeviceArrivalCallback(yDeviceUpdateCallback arrivalCallback)
YJSONContent * get(const string &key)
YRETCODE load(int msValidity)
static YRETCODE getDeviceInfo(YDEV_DESCR devdesc, yDeviceSt &infos, string &errmsg)
string _request(const string &request)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static string GetAPIVersion(void)
void YAPI_FUNCTION_EXPORT yapiFreeAPI(void)
virtual vector< YMeasure > get_preview(void)
YSensor * nextSensor(void)
YRETCODE YAPI_FUNCTION_EXPORT yapiLockFunctionCallBack(char *errmsg)
virtual string download(string pathname)
void setImmutableAttributes(yDeviceSt *infos)
YRETCODE getFunctions(vector< YFUN_DESCR > **functions, string &errmsg)
YRETCODE _getDevice(YDevice *&dev, string &errMsg)
virtual string _encodeCalibrationPoints(vector< double > rawValues, vector< double > refValues)
Y_BEACONDRIVEN_enum get_beaconDriven(void)
virtual s64 get_startTimeUTC(void)
string _download(const string &url)
static YRETCODE RegisterHub(const string &url, string &errmsg)
static yDeviceUpdateCallback DeviceRemovalCallback
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
static YRETCODE updateDeviceList(bool forceupdate, string &errmsg)
static YRETCODE TestHub(const string &url, int mstimeout, string &errmsg)
string _get_json_path(const string &json, const string &path)
YDataLogger * _dataLogger
static const double INVALID_DOUBLE
virtual vector< YDataSet > parse_dataSets(string json)
Y_RECORDING_enum get_recording(void)
static queue< yapiGlobalEvent > _plug_events
virtual string toString()
int YAPI_FUNCTION_EXPORT yapiGetAllDevices(YAPI_DEVICE *buffer, int maxsize, int *neededsize, char *errmsg)
YModuleLogCallback get_logCallback()
virtual int set_allSettings(string settings)
static const int CURRENTRUNINDEX_INVALID
YRETCODE _buildSetRequest(const string &changeattr, const string *changeval, string &request, string &errmsg)
virtual int loadMore(void)
void yJsonSkip(yJsonStateMachine *j, int nitems)
string functionType(int functionIndex)
YDevice(YDEV_DESCR devdesc)
char value[YOCTO_PUBVAL_LEN]
static double _decimalToDouble(s16 val)
double get_currentValue(void)
virtual int _parseStream(string sdata)
static void RegisterDeviceChangeCallback(yDeviceUpdateCallback changeCallback)
virtual vector< string > get_subDevices(void)
void * get_userData(void)
virtual string get_hardwareId(void)
YFUN_DESCR functionDescriptor(void)
#define YAPI_INVALID_STRING
YFUN_DESCR get_functionDescriptor(void)
virtual int _parseAttr(YJSONObject *json_val)
YRETCODE _getDescriptor(YFUN_DESCR &fundescr, string &errMsg)
string get_functionId(void)
int _parse(YJSONObject *j)
virtual int _parseAttr(YJSONObject *json_val)
static void RegisterDeviceRemovalCallback(yDeviceUpdateCallback removalCallback)
double get_lowestValue(void)
YAPI_DEVICE YAPI_FUNCTION_EXPORT yapiGetDevice(const char *device_str, char *errmsg)
virtual int loadThermistorExtra(string funcId, string jsonExtra)
int YAPI_FUNCTION_EXPORT yapiCheckLogicalName(const char *name)
virtual int reboot(int secBeforeReboot)
static const int LUMINOSITY_INVALID
void YAPI_FUNCTION_EXPORT yapiRegisterLogFunction(yapiLogFunction logfun)
int set_highestValue(double newval)
YDataStream * _findDataStream(YDataSet &dataset, const string &def)
#define yApproximateSleep(ms)
static double LinearCalibrationHandler(double rawValue, int calibType, intArr params, floatArr rawValues, floatArr refValues)
virtual int saveToFlash(void)
static const s64 UPTIME_INVALID
virtual YMeasure _decodeTimedReport(double timestamp, vector< int > report)
static void _yapiDeviceLogCallbackFwd(YDEV_DESCR devdesc, const char *line)
virtual int registerTimedReportCallback(YSensorTimedReportCallback callback)
int getInt(const string &key)
virtual YFirmwareUpdate updateFirmware(string path)
virtual int registerValueCallback(YModuleValueCallback callback)
int set_advertisedValue(const string &newval)
virtual double get_dataSamplesInterval(void)
static u64 GetTickCount(void)
virtual vector< vector< double > > get_dataRows(void)
int YAPI_FUNCTION_EXPORT yapiGetFunctionsByClass(const char *class_str, YAPI_FUNCTION prevfundesc, YAPI_FUNCTION *buffer, int maxsize, int *neededsize, char *errmsg)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
virtual double get_startTimeUTC(void)
YModule * nextModule(void)
static void DisableExceptions(void)
static const Y_RECORDING_enum RECORDING_INVALID
string get_logFrequency(void)
virtual int registerValueCallback(YDataLoggerValueCallback callback)
void YAPI_FUNCTION_EXPORT yapiRegisterHubDiscoveryCallback(yapiHubDiscoveryCallback hubDiscoveryCallback)
Y_BEACON_enum get_beacon(void)
vector< string > _strsplit(const string &str, char delimiter)
#define YAPI_INVALID_DOUBLE
virtual double get_averageValue(void)
virtual int _invokeValueCallback(string value)
string get_calibrationParam(void)
int YAPI_FUNCTION_EXPORT yapiGetFunctionsByDevice(YAPI_DEVICE devdesc, YAPI_FUNCTION prevfundesc, YAPI_FUNCTION *buffer, int maxsize, int *neededsize, char *errmsg)
#define YOCTO_CALIB_TYPE_OFS
virtual string loadAttribute(string attrName)
virtual int _invokeTimedReportCallback(YMeasure value)
int set_reportFrequency(const string &newval)
YAPI_FUNCTION_EXPORT void yapiFreeMem(void *ptr)
string getKeyFromIdx(int i)
virtual int _invokeValueCallback(string value)
virtual double _applyCalibration(double rawValue)
#define YOCTO_FUNCTION_LEN
virtual string get_parentHub(void)
vector< YJSONContent * > _arrayValue
static const int SENSORSTATE_INVALID
int YAPI_FUNCTION_EXPORT yapiJsonGetPath(const char *path, const char *json_data, int json_size, const char **result, char *errmsg)
int set_persistentSettings(Y_PERSISTENTSETTINGS_enum newval)
Y_AUTOSTART_enum _autoStart
virtual int forgetAllDataStreams(void)
static void RegisterLogFunction(yLogFunction logfun)
YJSONNumber * getYJSONNumber(const string &key)
static YFunction * _FindFromCache(const string &classname, const string &func)
static const string SERIALNUMBER_INVALID
int get_productRelease(void)
virtual int calibVersion(string cparams)
vector< vector< double > > _values
static YModule * FirstModule(void)
vector< YMeasure > _preview
YRETCODE YAPI_FUNCTION_EXPORT yapiHTTPRequestSyncDone(YIOHDL *iohdl, char *errmsg)
YRETCODE YAPI_FUNCTION_EXPORT yapiHTTPRequestSyncStartOutOfBand(YIOHDL *iohdl, int channel, const char *device, const char *request, int requestsize, char **reply, int *replysize, yapiRequestProgressCallback progress_cb, void *progress_ctx, char *errmsg)
vector< string > _json_get_array(const string &json)
virtual vector< YDataSet > get_dataSets(void)
void _clearDataStreamCache()
string get_errorMessage(void)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetAllJsonKeys(const char *json_buffer, char *buffer, int buffersize, int *fullsize, char *errmsg)
static string ysprintf(const char *fmt,...)
int get_dataStreams(vector< YDataStream * > &v)
static void RegisterCalibrationHandler(int calibrationType, yCalibrationHandler calibrationHandler)
virtual string get_lastLogs(void)
static const string PRODUCTNAME_INVALID
u16 YAPI_FUNCTION_EXPORT yapiGetAPIVersion(const char **version, const char **apidate)
virtual vector< YMeasure > get_measuresAt(YMeasure measure)
void(* YFunctionValueCallback)(YFunction *func, const string &functionValue)
static string CheckFirmware(string serial, string path, int minrelease)
virtual string _flattenJsonStruct(string jsoncomplex)
static void _ClearCache(void)
virtual int get_rowCount(void)
YRETCODE YAPI_FUNCTION_EXPORT yapiInitAPI(int detect_type, char *errmsg)
int set_clearHistory(Y_CLEARHISTORY_enum newval)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetFunctionInfoEx(YAPI_FUNCTION fundesc, YAPI_DEVICE *devdesc, char *serial, char *funcId, char *baseType, char *funcName, char *funcVal, char *errmsg)
void YAPI_FUNCTION_EXPORT yapiRegisterDeviceChangeCallback(yapiDeviceUpdateCallback changeCallback)
static yCalibrationHandler _getCalibrationHandler(int calibType)
YSensorTimedReportCallback _timedReportCallbackSensor
void put(const string &flatAttr)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static void _yapiHubDiscoveryCallbackFwd(const char *serial, const char *url)
static yCRITICAL_SECTION _global_cs
static yDeviceUpdateCallback DeviceChangeCallback
virtual double _decodeVal(int w)
int set_logicalName(const string &newval)
string _decode_json_string(const string &json)
static const Y_AUTOSTART_enum AUTOSTART_INVALID
void(* YModuleValueCallback)(YModule *func, const string &functionValue)
virtual int calibScale(string unit_name, string sensorType)
static const string UNIT_INVALID
string _parseString(yJsonStateMachine &j)
int set_beaconDriven(Y_BEACONDRIVEN_enum newval)
virtual int _processMore(int newupdate)
static queue< yapiDataEvent > _data_events
void(* YDataLoggerValueCallback)(YDataLogger *func, const string &functionValue)
virtual int calibOffset(string unit_name)
static YRETCODE Sleep(unsigned ms_duration, string &errmsg)
static string _hexStr2Bin(const string &str)
static YRETCODE InitAPI(int mode, string &errmsg)
int set_userVar(int newval)
virtual int registerValueCallback(YFunctionValueCallback callback)
static bool ExceptionsDisabled
void YAPI_FUNCTION_EXPORT yapiStartStopDeviceLogCallback(const char *serial, int start)
virtual vector< string > get_functionIds(string funType)
virtual int triggerFirmwareUpdate(int secBeforeReboot)
YFunctionValueCallback _valueCallbackFunction
Y_PERSISTENTSETTINGS_enum
static YRETCODE getFunctionInfoEx(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &baseType, string &funcName, string &funcVal, string &errmsg)
YRETCODE _uploadWithProgress(const string &path, const string &content, yapiRequestProgressCallback callback, void *context)
virtual YDataLogger * get_dataLogger(void)
virtual int _parseAttr(YJSONObject *json_val)
virtual string calibConvert(string param, string currentFuncValue, string unit_name, string sensorType)
int set_recording(Y_RECORDING_enum newval)
#define Y_FRIENDLYNAME_INVALID
virtual int registerValueCallback(YSensorValueCallback callback)
void yDeleteCriticalSection(yCRITICAL_SECTION *cs)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
virtual string get_unit(void)
int yTryEnterCriticalSection(yCRITICAL_SECTION *cs)
static YDataLogger * FirstDataLogger(void)
virtual int unmuteValueCallbacks(void)
static YDataLogger * FindDataLogger(string func)
virtual double get_maxValue(void)
static const double CURRENTVALUE_INVALID
static const Y_ADVMODE_enum ADVMODE_INVALID
virtual vector< string > get_columnNames(void)
int set_resolution(double newval)
YRETCODE _getFunction(int idx, string &serial, string &funcId, string &baseType, string &funcName, string &funcVal, string &errMsg)
virtual int _invokeValueCallback(string value)
static void _yapiDeviceRemovalCallbackFwd(YDEV_DESCR devdesc)
virtual string get_progressMessage(void)
static const s64 TIMEUTC_INVALID
Y_BEACONDRIVEN_enum _beaconDriven
YRETCODE YAPI_FUNCTION_EXPORT yapiTriggerHubDiscovery(char *errmsg)
static YSensor * FirstSensor(void)
void(* yLogFunction)(const string &msg)
prototype of the log callback
s64 getLong(const string &key)
static yDeviceUpdateCallback DeviceArrivalCallback
void setContent(const string &value)
int _parse(const string &json)
virtual s64 get_startTimeUTC(void)
u64 YAPI_FUNCTION_EXPORT yapiGetTickCount(void)
YRETCODE YAPI_FUNCTION_EXPORT yapiSleep(int ms_duration, char *errmsg)
void YAPI_FUNCTION_EXPORT yapiRegisterFunctionUpdateCallback(yapiFunctionUpdateCallback updateCallback)
void registerLogCallback(YModuleLogCallback callback)
static void _yapiLogFunctionFwd(const char *log, u32 loglen)
static void _yapiDeviceChangeCallbackFwd(YDEV_DESCR devdesc)
Y_RECORDING_enum _recording
static YRETCODE HandleEvents(string &errmsg)
YFunction(const string &func)
static s16 _doubleToDecimal(double val)
void(* YSensorTimedReportCallback)(YSensor *func, YMeasure measure)
#define Y_FUNCTIONDESCRIPTOR_INVALID
virtual bool hasFunction(string funcId)
static const int USBCURRENT_INVALID
char serial[YOCTO_SERIAL_LEN]
YRETCODE YAPI_FUNCTION_EXPORT yapiPreregisterHub(const char *url, char *errmsg)
YJSONArray * getYJSONArray(const string &key)
virtual int processMore(int progress, string data)
yCalibrationHandler _calhdl
static const double RESOLUTION_INVALID
int set_logFrequency(const string &newval)
YRETCODE YAPI_FUNCTION_EXPORT yapiUnlockDeviceCallBack(char *errmsg)
static const Y_PERSISTENTSETTINGS_enum PERSISTENTSETTINGS_INVALID
vector< YMeasure > _measures
void YAPI_FUNCTION_EXPORT yapiRegisterDeviceRemovalCallback(yapiDeviceUpdateCallback removalCallback)
virtual double get_endTimeUTC(void)
static const string INVALID_STRING
static vector< YDevice * > _devCache
YDataLogger(const string &func)
int set_advMode(Y_ADVMODE_enum newval)
YRETCODE YAPI_FUNCTION_EXPORT yapiLockDeviceCallBack(char *errmsg)
void YAPI_FUNCTION_EXPORT yapiUnregisterHub(const char *url)
static const char * hexArray
static void _yapiFunctionTimedReportCallbackFwd(YAPI_FUNCTION fundesc, double timestamp, const u8 *bytes, u32 len)
static bool _apiInitialized
string functionId(int functionIndex)
YRETCODE _nextFunction(string &hwId)
static const double CURRENTRAWVALUE_INVALID
string functionValue(int functionIndex)
virtual int log(string text)
void parseWithRef(YJSONObject *reference)
static void _yapiFunctionUpdateCallbackFwd(YFUN_DESCR fundesc, const char *value)
YRETCODE YAPI_FUNCTION_EXPORT yapiUnlockFunctionCallBack(char *errmsg)
static const double HIGHESTVALUE_INVALID
YModuleValueCallback _valueCallbackModule
string get_reportFrequency(void)
YOldDataStream(YDataLogger *parent, unsigned run, unsigned stamp, unsigned utc, unsigned itv)
virtual int stopDataLogger(void)
YRETCODE HTTPRequest(int channel, const string &request, string &buffer, yapiRequestProgressCallback progress_cb, void *progress_ctx, string &errmsg)
static yCRITICAL_SECTION _handleEvent_CS
static void _UpdateValueCallbackList(YFunction *func, bool add)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetSubdevices(const char *serial, char *buffer, int buffersize, int *fullsize, char *errmsg)
Y_PERSISTENTSETTINGS_enum _persistentSettings
void(* YModuleLogCallback)(YModule *module, const string &logline)
char productname[YOCTO_PRODUCTNAME_LEN]
void clearCache(bool clearSubpath)
void(* yDeviceUpdateCallback)(YModule *module)
prototype of the device arrival/update/removal callback
static bool CheckLogicalName(const string &name)
vector< string > _columnNames
static YFunction * FirstFunction(void)
map< string, YJSONContent * > _parsed
virtual YDataSet get_recordedData(s64 startTime, s64 endTime)
virtual double _decodeAvg(int dw)
YSensor(const string &func)
double get_highestValue(void)
YDataStream(YFunction *parent)
YModuleLogCallback _logCallback
virtual int startDataLogger(void)
virtual int loadStream(void)
YModule * yFindModule(const string &func)
static YRETCODE TriggerHubDiscovery(string &errmsg)
static yLogFunction LogFunction
virtual YMeasure get_summary(void)
bool has(const string &key)
YRETCODE YAPI_FUNCTION_EXPORT yapiHTTPRequestAsyncOutOfBand(int channel, const char *device, const char *request, int requestsize, yapiRequestAsyncCallback callback, void *context, char *errmsg)
string get_serialNumber(void)
int set_beacon(Y_BEACON_enum newval)
static int SkipGarbage(const string &data, int start, int stop)
void YAPI_FUNCTION_EXPORT yapiRegisterDeviceArrivalCallback(yapiDeviceUpdateCallback arrivalCallback)
string _requestEx(int tcpchan, const string &request, yapiRequestProgressCallback callback, void *context)
YRETCODE _setAttr(string attrname, string newvalue)
virtual double _decodeAvg(int dw, int count)
YSensorValueCallback _valueCallbackSensor
int set_timeUTC(s64 newval)
int get_sensorState(void)
int get_currentRunIndex(void)
virtual double get_data(int row, int col)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetDeviceInfo(YAPI_DEVICE devdesc, yDeviceSt *infos, char *errmsg)
static YRETCODE handleEvents(string &errmsg)
int get_rebootCountdown(void)
double(* yCalibrationHandler)(double rawValue, int calibType, vector< int > params, vector< double > rawValues, vector< double > refValues)
static const Y_BEACON_enum BEACON_INVALID
YRETCODE YAPI_FUNCTION_EXPORT yapiUpdateDeviceList(u32 forceupdate, char *errmsg)
virtual int muteValueCallbacks(void)
Y_CLEARHISTORY_enum _clearHistory
YRETCODE YAPI_FUNCTION_EXPORT yapiCheckFirmware(const char *serial, const char *rev, const char *path, char *buffer, int buffersize, int *fullsize, char *errmsg)
virtual int set_extraSettings(string jsonExtra)
static YFunction * FindFunction(string func)
virtual vector< YMeasure > get_measures(void)
virtual int _invokeValueCallback(string value)
YJSONObject * getYJSONObject(int i)
static const Y_CLEARHISTORY_enum CLEARHISTORY_INVALID
#define YOCTO_LOGICAL_LEN
virtual double get_minValue(void)
static int getAllDevices(vector< YDEV_DESCR > &buffer, string &errmsg)
YRETCODE requestAPI(YJSONObject *&apires, string &errmsg)
static map< int, yCalibrationHandler > _calibHandlers
YRETCODE YAPI_FUNCTION_EXPORT yapiRegisterHub(const char *url, char *errmsg)
static YRETCODE UpdateDeviceList(string &errmsg)
YRETCODE YAPI_FUNCTION_EXPORT yapiHandleEvents(char *errmsg)
virtual int calibrateFromPoints(vector< double > rawValues, vector< double > refValues)
YRETCODE YAPI_FUNCTION_EXPORT yapiUpdateFirmwareEx(const char *serial, const char *firmwarePath, const char *settings, int force, int startUpdate, char *msg)
YRETCODE YAPI_FUNCTION_EXPORT yapiGetDevicePathEx(const char *serial, char *rootdevice, char *request, int requestsize, int *neededsize, char *errmsg)
YDataSet(YFunction *parent, const string &functionId, const string &unit, s64 startTime, s64 endTime)