yocto_refframe.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_refframe.cpp 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Implements yFindRefFrame(), the high-level API for RefFrame 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_refframe.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__ "refframe"
50 
51 YRefFrame::YRefFrame(const string& func): YFunction(func)
52 //--- (YRefFrame initialization)
53  ,_mountPos(MOUNTPOS_INVALID)
54  ,_bearing(BEARING_INVALID)
55  ,_calibrationParam(CALIBRATIONPARAM_INVALID)
56  ,_fusionMode(FUSIONMODE_INVALID)
57  ,_valueCallbackRefFrame(NULL)
58  ,_calibV2(0)
59  ,_calibStage(0)
60  ,_calibStageProgress(0)
61  ,_calibProgress(0)
62  ,_calibCount(0)
63  ,_calibInternalPos(0)
64  ,_calibPrevTick(0)
65  ,_calibAccXOfs(0.0)
66  ,_calibAccYOfs(0.0)
67  ,_calibAccZOfs(0.0)
68  ,_calibAccXScale(0.0)
69  ,_calibAccYScale(0.0)
70  ,_calibAccZScale(0.0)
71 //--- (end of YRefFrame initialization)
72 {
73  _className="RefFrame";
74 }
75 
77 {
78 //--- (YRefFrame cleanup)
79 //--- (end of YRefFrame cleanup)
80 }
81 //--- (YRefFrame implementation)
82 // static attributes
85 
87 {
88  if(json_val->has("mountPos")) {
89  _mountPos = json_val->getInt("mountPos");
90  }
91  if(json_val->has("bearing")) {
92  _bearing = floor(json_val->getDouble("bearing") * 1000.0 / 65536.0 + 0.5) / 1000.0;
93  }
94  if(json_val->has("calibrationParam")) {
95  _calibrationParam = json_val->getString("calibrationParam");
96  }
97  if(json_val->has("fusionMode")) {
98  _fusionMode = (Y_FUSIONMODE_enum)json_val->getInt("fusionMode");
99  }
100  return YFunction::_parseAttr(json_val);
101 }
102 
103 
105 {
106  int res = 0;
108  try {
111  {
114  }
115  }
116  }
117  res = _mountPos;
118  } catch (std::exception) {
120  throw;
121  }
123  return res;
124 }
125 
126 int YRefFrame::set_mountPos(int newval)
127 {
128  string rest_val;
129  int res;
131  try {
132  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
133  res = _setAttr("mountPos", rest_val);
134  } catch (std::exception) {
136  throw;
137  }
139  return res;
140 }
141 
164 int YRefFrame::set_bearing(double newval)
165 {
166  string rest_val;
167  int res;
169  try {
170  char buf[32]; sprintf(buf,"%d", (int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
171  res = _setAttr("bearing", rest_val);
172  } catch (std::exception) {
174  throw;
175  }
177  return res;
178 }
179 
190 {
191  double res = 0.0;
193  try {
196  {
199  }
200  }
201  }
202  res = _bearing;
203  } catch (std::exception) {
205  throw;
206  }
208  return res;
209 }
210 
212 {
213  string res;
215  try {
218  {
221  }
222  }
223  }
224  res = _calibrationParam;
225  } catch (std::exception) {
227  throw;
228  }
230  return res;
231 }
232 
233 int YRefFrame::set_calibrationParam(const string& newval)
234 {
235  string rest_val;
236  int res;
238  try {
239  rest_val = newval;
240  res = _setAttr("calibrationParam", rest_val);
241  } catch (std::exception) {
243  throw;
244  }
246  return res;
247 }
248 
250 {
251  Y_FUSIONMODE_enum res;
253  try {
256  {
259  }
260  }
261  }
262  res = _fusionMode;
263  } catch (std::exception) {
265  throw;
266  }
268  return res;
269 }
270 
272 {
273  string rest_val;
274  int res;
276  try {
277  char buf[32]; sprintf(buf, "%d", newval); rest_val = string(buf);
278  res = _setAttr("fusionMode", rest_val);
279  } catch (std::exception) {
281  throw;
282  }
284  return res;
285 }
286 
315 {
316  YRefFrame* obj = NULL;
317  int taken = 0;
318  if (YAPI::_apiInitialized) {
320  taken = 1;
321  }try {
322  obj = (YRefFrame*) YFunction::_FindFromCache("RefFrame", func);
323  if (obj == NULL) {
324  obj = new YRefFrame(func);
325  YFunction::_AddToCache("RefFrame", func, obj);
326  }
327  } catch (std::exception) {
329  throw;
330  }
332  return obj;
333 }
334 
347 {
348  string val;
349  if (callback != NULL) {
351  } else {
353  }
354  _valueCallbackRefFrame = callback;
355  // Immediately invoke value callback with current value
356  if (callback != NULL && this->isOnline()) {
357  val = _advertisedValue;
358  if (!(val == "")) {
359  this->_invokeValueCallback(val);
360  }
361  }
362  return 0;
363 }
364 
366 {
367  if (_valueCallbackRefFrame != NULL) {
368  _valueCallbackRefFrame(this, value);
369  } else {
371  }
372  return 0;
373 }
374 
389 {
390  int position = 0;
391  position = this->get_mountPos();
392  if (position < 0) {
394  }
395  return (Y_MOUNTPOSITION) ((position) >> (2));
396 }
397 
414 {
415  int position = 0;
416  position = this->get_mountPos();
417  if (position < 0) {
419  }
420  return (Y_MOUNTORIENTATION) ((position) & (3));
421 }
422 
449 {
450  int mixedPos = 0;
451  mixedPos = ((position) << (2)) + orientation;
452  return this->set_mountPos(mixedPos);
453 }
454 
470 {
471  string calibParam;
472  vector<int> iCalib;
473  int caltyp = 0;
474  int res = 0;
475 
476  calibParam = this->get_calibrationParam();
477  iCalib = YAPI::_decodeFloats(calibParam);
478  caltyp = ((iCalib[0]) / (1000));
479  if (caltyp != 33) {
480  return YAPI_NOT_SUPPORTED;
481  }
482  res = ((iCalib[1]) / (1000));
483  return res;
484 }
485 
500 {
501  string calibParam;
502  vector<int> iCalib;
503  int caltyp = 0;
504  int res = 0;
505 
506  calibParam = this->get_calibrationParam();
507  iCalib = YAPI::_decodeFloats(calibParam);
508  caltyp = ((iCalib[0]) / (1000));
509  if (caltyp != 33) {
510  return YAPI_NOT_SUPPORTED;
511  }
512  res = ((iCalib[2]) / (1000));
513  return res;
514 }
515 
516 int YRefFrame::_calibSort(int start,int stopidx)
517 {
518  int idx = 0;
519  int changed = 0;
520  double a = 0.0;
521  double b = 0.0;
522  double xa = 0.0;
523  double xb = 0.0;
524  // bubble sort is good since we will re-sort again after offset adjustment
525  changed = 1;
526  while (changed > 0) {
527  changed = 0;
528  a = _calibDataAcc[start];
529  idx = start + 1;
530  while (idx < stopidx) {
531  b = _calibDataAcc[idx];
532  if (a > b) {
533  _calibDataAcc[idx-1] = b;
534  _calibDataAcc[idx] = a;
535  xa = _calibDataAccX[idx-1];
536  xb = _calibDataAccX[idx];
537  _calibDataAccX[idx-1] = xb;
538  _calibDataAccX[idx] = xa;
539  xa = _calibDataAccY[idx-1];
540  xb = _calibDataAccY[idx];
541  _calibDataAccY[idx-1] = xb;
542  _calibDataAccY[idx] = xa;
543  xa = _calibDataAccZ[idx-1];
544  xb = _calibDataAccZ[idx];
545  _calibDataAccZ[idx-1] = xb;
546  _calibDataAccZ[idx] = xa;
547  changed = changed + 1;
548  } else {
549  a = b;
550  }
551  idx = idx + 1;
552  }
553  }
554  return 0;
555 }
556 
574 {
575  if (!(this->isOnline())) {
576  return YAPI_DEVICE_NOT_FOUND;
577  }
578  if (_calibStage != 0) {
579  this->cancel3DCalibration();
580  }
582  _calibV2 = (atoi((_calibSavedParams).c_str()) == 33);
583  this->set_calibrationParam("0");
584  _calibCount = 50;
585  _calibStage = 1;
586  _calibStageHint = "Set down the device on a steady horizontal surface";
588  _calibProgress = 1;
589  _calibInternalPos = 0;
590  _calibPrevTick = (int) ((YAPI::GetTickCount()) & (0x7FFFFFFF));
591  _calibOrient.clear();
592  _calibDataAccX.clear();
593  _calibDataAccY.clear();
594  _calibDataAccZ.clear();
595  _calibDataAcc.clear();
596  return YAPI_SUCCESS;
597 }
598 
610 {
611  if (_calibV2) {
612  return this->more3DCalibrationV2();
613  }
614  return this->more3DCalibrationV1();
615 }
616 
618 {
619  int currTick = 0;
620  string jsonData;
621  double xVal = 0.0;
622  double yVal = 0.0;
623  double zVal = 0.0;
624  double xSq = 0.0;
625  double ySq = 0.0;
626  double zSq = 0.0;
627  double norm = 0.0;
628  int orient = 0;
629  int idx = 0;
630  int intpos = 0;
631  int err = 0;
632  // make sure calibration has been started
633  if (_calibStage == 0) {
634  return YAPI_INVALID_ARGUMENT;
635  }
636  if (_calibProgress == 100) {
637  return YAPI_SUCCESS;
638  }
639  // make sure we leave at least 160ms between samples
640  currTick = (int) ((YAPI::GetTickCount()) & (0x7FFFFFFF));
641  if (((currTick - _calibPrevTick) & (0x7FFFFFFF)) < 160) {
642  return YAPI_SUCCESS;
643  }
644  // load current accelerometer values, make sure we are on a straight angle
645  // (default timeout to 0,5 sec without reading measure when out of range)
646  _calibStageHint = "Set down the device on a steady horizontal surface";
647  _calibPrevTick = ((currTick + 500) & (0x7FFFFFFF));
648  jsonData = this->_download("api/accelerometer.json");
649  xVal = atoi((this->_json_get_key(jsonData, "xValue")).c_str()) / 65536.0;
650  yVal = atoi((this->_json_get_key(jsonData, "yValue")).c_str()) / 65536.0;
651  zVal = atoi((this->_json_get_key(jsonData, "zValue")).c_str()) / 65536.0;
652  xSq = xVal * xVal;
653  if (xSq >= 0.04 && xSq < 0.64) {
654  return YAPI_SUCCESS;
655  }
656  if (xSq >= 1.44) {
657  return YAPI_SUCCESS;
658  }
659  ySq = yVal * yVal;
660  if (ySq >= 0.04 && ySq < 0.64) {
661  return YAPI_SUCCESS;
662  }
663  if (ySq >= 1.44) {
664  return YAPI_SUCCESS;
665  }
666  zSq = zVal * zVal;
667  if (zSq >= 0.04 && zSq < 0.64) {
668  return YAPI_SUCCESS;
669  }
670  if (zSq >= 1.44) {
671  return YAPI_SUCCESS;
672  }
673  norm = sqrt(xSq + ySq + zSq);
674  if (norm < 0.8 || norm > 1.2) {
675  return YAPI_SUCCESS;
676  }
677  _calibPrevTick = currTick;
678  // Determine the device orientation index
679  orient = 0;
680  if (zSq > 0.5) {
681  if (zVal > 0) {
682  orient = 0;
683  } else {
684  orient = 1;
685  }
686  }
687  if (xSq > 0.5) {
688  if (xVal > 0) {
689  orient = 2;
690  } else {
691  orient = 3;
692  }
693  }
694  if (ySq > 0.5) {
695  if (yVal > 0) {
696  orient = 4;
697  } else {
698  orient = 5;
699  }
700  }
701  // Discard measures that are not in the proper orientation
702  if (_calibStageProgress == 0) {
703  // New stage, check that this orientation is not yet done
704  idx = 0;
705  err = 0;
706  while (idx + 1 < _calibStage) {
707  if (_calibOrient[idx] == orient) {
708  err = 1;
709  }
710  idx = idx + 1;
711  }
712  if (err != 0) {
713  _calibStageHint = "Turn the device on another face";
714  return YAPI_SUCCESS;
715  }
716  _calibOrient.push_back(orient);
717  } else {
718  // Make sure device is not turned before stage is completed
719  if (orient != _calibOrient[_calibStage-1]) {
720  _calibStageHint = "Not yet done, please move back to the previous face";
721  return YAPI_SUCCESS;
722  }
723  }
724  // Save measure
725  _calibStageHint = "calibrating...";
726  _calibDataAccX.push_back(xVal);
727  _calibDataAccY.push_back(yVal);
728  _calibDataAccZ.push_back(zVal);
729  _calibDataAcc.push_back(norm);
731  _calibProgress = 1 + 16 * (_calibStage - 1) + ((16 * _calibInternalPos) / (_calibCount));
734  return YAPI_SUCCESS;
735  }
736  // Stage done, compute preliminary result
737  intpos = (_calibStage - 1) * _calibCount;
738  this->_calibSort(intpos, intpos + _calibCount);
739  intpos = intpos + ((_calibCount) / (2));
740  _calibLogMsg = YapiWrapper::ysprintf("Stage %d: median is %d,%d,%d", _calibStage,
741  (int) floor(1000*_calibDataAccX[intpos]+0.5),
742  (int) floor(1000*_calibDataAccY[intpos]+0.5),(int) floor(1000*_calibDataAccZ[intpos]+0.5));
743  // move to next stage
744  _calibStage = _calibStage + 1;
745  if (_calibStage < 7) {
746  _calibStageHint = "Turn the device on another face";
747  _calibPrevTick = ((currTick + 500) & (0x7FFFFFFF));
749  _calibInternalPos = 0;
750  return YAPI_SUCCESS;
751  }
752  // Data collection completed, compute accelerometer shift
753  xVal = 0;
754  yVal = 0;
755  zVal = 0;
756  idx = 0;
757  while (idx < 6) {
758  intpos = idx * _calibCount + ((_calibCount) / (2));
759  orient = _calibOrient[idx];
760  if (orient == 0 || orient == 1) {
761  zVal = zVal + _calibDataAccZ[intpos];
762  }
763  if (orient == 2 || orient == 3) {
764  xVal = xVal + _calibDataAccX[intpos];
765  }
766  if (orient == 4 || orient == 5) {
767  yVal = yVal + _calibDataAccY[intpos];
768  }
769  idx = idx + 1;
770  }
771  _calibAccXOfs = xVal / 2.0;
772  _calibAccYOfs = yVal / 2.0;
773  _calibAccZOfs = zVal / 2.0;
774  // Recompute all norms, taking into account the computed shift, and re-sort
775  intpos = 0;
776  while (intpos < (int)_calibDataAcc.size()) {
777  xVal = _calibDataAccX[intpos] - _calibAccXOfs;
778  yVal = _calibDataAccY[intpos] - _calibAccYOfs;
779  zVal = _calibDataAccZ[intpos] - _calibAccZOfs;
780  norm = sqrt(xVal * xVal + yVal * yVal + zVal * zVal);
781  _calibDataAcc[intpos] = norm;
782  intpos = intpos + 1;
783  }
784  idx = 0;
785  while (idx < 6) {
786  intpos = idx * _calibCount;
787  this->_calibSort(intpos, intpos + _calibCount);
788  idx = idx + 1;
789  }
790  // Compute the scaling factor for each axis
791  xVal = 0;
792  yVal = 0;
793  zVal = 0;
794  idx = 0;
795  while (idx < 6) {
796  intpos = idx * _calibCount + ((_calibCount) / (2));
797  orient = _calibOrient[idx];
798  if (orient == 0 || orient == 1) {
799  zVal = zVal + _calibDataAcc[intpos];
800  }
801  if (orient == 2 || orient == 3) {
802  xVal = xVal + _calibDataAcc[intpos];
803  }
804  if (orient == 4 || orient == 5) {
805  yVal = yVal + _calibDataAcc[intpos];
806  }
807  idx = idx + 1;
808  }
809  _calibAccXScale = xVal / 2.0;
810  _calibAccYScale = yVal / 2.0;
811  _calibAccZScale = zVal / 2.0;
812  // Report completion
813  _calibProgress = 100;
814  _calibStageHint = "Calibration data ready for saving";
815  return YAPI_SUCCESS;
816 }
817 
819 {
820  int currTick = 0;
821  string calibParam;
822  vector<int> iCalib;
823  int cal3 = 0;
824  int calAcc = 0;
825  int calMag = 0;
826  int calGyr = 0;
827  // make sure calibration has been started
828  if (_calibStage == 0) {
829  return YAPI_INVALID_ARGUMENT;
830  }
831  if (_calibProgress == 100) {
832  return YAPI_SUCCESS;
833  }
834  // make sure we don't start before previous calibration is cleared
835  if (_calibStage == 1) {
836  currTick = (int) ((YAPI::GetTickCount()) & (0x7FFFFFFF));
837  currTick = ((currTick - _calibPrevTick) & (0x7FFFFFFF));
838  if (currTick < 1600) {
839  _calibStageHint = "Set down the device on a steady horizontal surface";
840  _calibStageProgress = ((currTick) / (40));
841  _calibProgress = 1;
842  return YAPI_SUCCESS;
843  }
844  }
845 
846  calibParam = this->_download("api/refFrame/calibrationParam.txt");
847  iCalib = YAPI::_decodeFloats(calibParam);
848  cal3 = ((iCalib[1]) / (1000));
849  calAcc = ((cal3) / (100));
850  calMag = ((cal3) / (10)) - 10*calAcc;
851  calGyr = ((cal3) % (10));
852  if (calGyr < 3) {
853  _calibStageHint = "Set down the device on a steady horizontal surface";
854  _calibStageProgress = 40 + calGyr*20;
855  _calibProgress = 4 + calGyr*2;
856  } else {
857  _calibStage = 2;
858  if (calMag < 3) {
859  _calibStageHint = "Slowly draw '8' shapes along the 3 axis";
860  _calibStageProgress = 1 + calMag*33;
861  _calibProgress = 10 + calMag*5;
862  } else {
863  _calibStage = 3;
864  if (calAcc < 3) {
865  _calibStageHint = "Slowly turn the device, stopping at each 90 degrees";
866  _calibStageProgress = 1 + calAcc*33;
867  _calibProgress = 25 + calAcc*25;
868  } else {
869  _calibStageProgress = 99;
870  _calibProgress = 100;
871  }
872  }
873  }
874  return YAPI_SUCCESS;
875 }
876 
884 {
885  return _calibStageHint;
886 }
887 
895 {
896  return _calibProgress;
897 }
898 
906 {
907  return _calibStage;
908 }
909 
917 {
918  return _calibStageProgress;
919 }
920 
928 {
929  string msg;
930  msg = _calibLogMsg;
931  _calibLogMsg = "";
932  return msg;
933 }
934 
943 {
944  if (_calibV2) {
945  return this->save3DCalibrationV2();
946  }
947  return this->save3DCalibrationV1();
948 }
949 
951 {
952  int shiftX = 0;
953  int shiftY = 0;
954  int shiftZ = 0;
955  int scaleExp = 0;
956  int scaleX = 0;
957  int scaleY = 0;
958  int scaleZ = 0;
959  int scaleLo = 0;
960  int scaleHi = 0;
961  string newcalib;
962  if (_calibProgress != 100) {
963  return YAPI_INVALID_ARGUMENT;
964  }
965  // Compute integer values (correction unit is 732ug/count)
966  shiftX = -(int) floor(_calibAccXOfs / 0.000732+0.5);
967  if (shiftX < 0) {
968  shiftX = shiftX + 65536;
969  }
970  shiftY = -(int) floor(_calibAccYOfs / 0.000732+0.5);
971  if (shiftY < 0) {
972  shiftY = shiftY + 65536;
973  }
974  shiftZ = -(int) floor(_calibAccZOfs / 0.000732+0.5);
975  if (shiftZ < 0) {
976  shiftZ = shiftZ + 65536;
977  }
978  scaleX = (int) floor(2048.0 / _calibAccXScale+0.5) - 2048;
979  scaleY = (int) floor(2048.0 / _calibAccYScale+0.5) - 2048;
980  scaleZ = (int) floor(2048.0 / _calibAccZScale+0.5) - 2048;
981  if (scaleX < -2048 || scaleX >= 2048 || scaleY < -2048 || scaleY >= 2048 || scaleZ < -2048 || scaleZ >= 2048) {
982  scaleExp = 3;
983  } else {
984  if (scaleX < -1024 || scaleX >= 1024 || scaleY < -1024 || scaleY >= 1024 || scaleZ < -1024 || scaleZ >= 1024) {
985  scaleExp = 2;
986  } else {
987  if (scaleX < -512 || scaleX >= 512 || scaleY < -512 || scaleY >= 512 || scaleZ < -512 || scaleZ >= 512) {
988  scaleExp = 1;
989  } else {
990  scaleExp = 0;
991  }
992  }
993  }
994  if (scaleExp > 0) {
995  scaleX = ((scaleX) >> (scaleExp));
996  scaleY = ((scaleY) >> (scaleExp));
997  scaleZ = ((scaleZ) >> (scaleExp));
998  }
999  if (scaleX < 0) {
1000  scaleX = scaleX + 1024;
1001  }
1002  if (scaleY < 0) {
1003  scaleY = scaleY + 1024;
1004  }
1005  if (scaleZ < 0) {
1006  scaleZ = scaleZ + 1024;
1007  }
1008  scaleLo = ((((scaleY) & (15))) << (12)) + ((scaleX) << (2)) + scaleExp;
1009  scaleHi = ((scaleZ) << (6)) + ((scaleY) >> (4));
1010  // Save calibration parameters
1011  newcalib = YapiWrapper::ysprintf("5,%d,%d,%d,%d,%d", shiftX, shiftY, shiftZ, scaleLo,scaleHi);
1012  _calibStage = 0;
1013  return this->set_calibrationParam(newcalib);
1014 }
1015 
1017 {
1018  return this->set_calibrationParam("5,5,5,5,5,5");
1019 }
1020 
1027 {
1028  if (_calibStage == 0) {
1029  return YAPI_SUCCESS;
1030  }
1031 
1032  _calibStage = 0;
1034 }
1035 
1037 {
1038  string hwid;
1039 
1040  if(YISERR(_nextFunction(hwid)) || hwid=="") {
1041  return NULL;
1042  }
1043  return YRefFrame::FindRefFrame(hwid);
1044 }
1045 
1047 {
1048  vector<YFUN_DESCR> v_fundescr;
1049  YDEV_DESCR ydevice;
1050  string serial, funcId, funcName, funcVal, errmsg;
1051 
1052  if(YISERR(YapiWrapper::getFunctionsByClass("RefFrame", 0, v_fundescr, sizeof(YFUN_DESCR), errmsg)) ||
1053  v_fundescr.size() == 0 ||
1054  YISERR(YapiWrapper::getFunctionInfo(v_fundescr[0], ydevice, serial, funcId, funcName, funcVal, errmsg))) {
1055  return NULL;
1056  }
1057  return YRefFrame::FindRefFrame(serial+"."+funcId);
1058 }
1059 
1060 //--- (end of YRefFrame implementation)
1061 
1062 //--- (YRefFrame functions)
1063 //--- (end of YRefFrame functions)
static const string CALIBRATIONPARAM_INVALID
string _json_get_key(const string &json, const string &data)
Definition: yocto_api.cpp:2772
string _advertisedValue
Definition: yocto_api.h:1569
Y_FUSIONMODE_enum
double getDouble(const string &key)
Definition: yocto_api.cpp:796
yCRITICAL_SECTION _this_cs
Definition: yocto_api.h:1563
virtual int cancel3DCalibration(void)
double _calibAccXScale
int set_mountPos(int newval)
static YRefFrame * FirstRefFrame(void)
string _calibStageHint
double _calibAccZOfs
virtual string get_3DCalibrationHint(void)
double _bearing
YRETCODE _load_unsafe(int msValidity)
Definition: yocto_api.cpp:3327
static const Y_FUSIONMODE_enum FUSIONMODE_INVALID
double get_bearing(void)
vector< double > _calibDataAccY
virtual Y_MOUNTORIENTATION get_mountOrientation(void)
int _calibInternalPos
YRefFrame(const string &func)
double _calibAccZScale
static const int MOUNTPOS_INVALID
virtual int save3DCalibrationV2(void)
static int DefaultCacheValidity
Definition: yocto_api.h:468
string getString(const string &key)
Definition: yocto_api.cpp:773
double _calibAccXOfs
virtual int get_3DCalibrationStageProgress(void)
int set_bearing(double newval)
string _calibLogMsg
u64 _cacheExpiration
Definition: yocto_api.h:1571
int set_fusionMode(Y_FUSIONMODE_enum newval)
static vector< int > _decodeFloats(string sdat)
Definition: yocto_api.cpp:4067
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:672
vector< int > _calibOrient
string _download(const string &url)
Definition: yocto_api.cpp:3053
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
Definition: yocto_api.cpp:4930
vector< double > _calibDataAccZ
virtual int set_mountPosition(Y_MOUNTPOSITION position, Y_MOUNTORIENTATION orientation)
int _calibStageProgress
virtual int get_3DCalibrationStage(void)
double _calibAccYScale
virtual int get_3DCalibrationProgress(void)
virtual int _parseAttr(YJSONObject *json_val)
#define YAPI_INVALID_STRING
Definition: yocto_api.h:69
virtual int _parseAttr(YJSONObject *json_val)
Definition: yocto_api.cpp:2367
YAPI_FUNCTION YFUN_DESCR
Definition: yocto_api.h:230
virtual int _invokeValueCallback(string value)
int getInt(const string &key)
Definition: yocto_api.cpp:779
virtual int save3DCalibrationV1(void)
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
virtual string get_3DCalibrationLogMsg(void)
virtual int _calibSort(int start, int stopidx)
void(* YRefFrameValueCallback)(YRefFrame *func, const string &functionValue)
Y_FUSIONMODE_enum get_fusionMode(void)
#define YAPI_INVALID_DOUBLE
Definition: yocto_api.h:73
int get_mountPos(void)
virtual int save3DCalibration(void)
YAPI_DEVICE YDEV_DESCR
Definition: yocto_api.h:229
static YFunction * _FindFromCache(const string &classname, const string &func)
Definition: yocto_api.cpp:2338
virtual int more3DCalibrationV2(void)
static string ysprintf(const char *fmt,...)
Definition: yocto_api.cpp:4997
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
virtual Y_MOUNTPOSITION get_mountPosition(void)
int _calibPrevTick
int set_calibrationParam(const string &newval)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
Definition: yocto_api.cpp:4852
YRefFrameValueCallback _valueCallbackRefFrame
virtual int registerValueCallback(YRefFrameValueCallback callback)
virtual int get_calibrationState(void)
virtual int get_measureQuality(void)
Y_MOUNTORIENTATION
string _className
Definition: yocto_api.h:1558
string get_calibrationParam(void)
virtual int start3DCalibration(void)
Y_FUSIONMODE_enum _fusionMode
virtual int more3DCalibration(void)
static const double BEARING_INVALID
int _calibProgress
static bool _apiInitialized
Definition: yocto_api.h:475
YRETCODE _nextFunction(string &hwId)
Definition: yocto_api.cpp:2709
static YRefFrame * FindRefFrame(string func)
static void _UpdateValueCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3509
#define YISERR(retcode)
Definition: ydef.h:394
Y_MOUNTPOSITION
double _calibAccYOfs
virtual int more3DCalibrationV1(void)
vector< double > _calibDataAcc
bool has(const string &key)
Definition: yocto_api.cpp:735
YRefFrame * nextRefFrame(void)
string _calibSavedParams
YRETCODE _setAttr(string attrname, string newvalue)
Definition: yocto_api.cpp:2968
vector< double > _calibDataAccX
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:2563
string _calibrationParam


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