41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "refframe" 53 ,_mountPos(MOUNTPOS_INVALID)
54 ,_bearing(BEARING_INVALID)
55 ,_calibrationParam(CALIBRATIONPARAM_INVALID)
56 ,_fusionMode(FUSIONMODE_INVALID)
57 ,_valueCallbackRefFrame(NULL)
60 ,_calibStageProgress(0)
88 if(json_val->
has(
"mountPos")) {
91 if(json_val->
has(
"bearing")) {
92 _bearing = floor(json_val->
getDouble(
"bearing") * 1000.0 / 65536.0 + 0.5) / 1000.0;
94 if(json_val->
has(
"calibrationParam")) {
97 if(json_val->
has(
"fusionMode")) {
118 }
catch (std::exception) {
132 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
133 res =
_setAttr(
"mountPos", rest_val);
134 }
catch (std::exception) {
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) {
203 }
catch (std::exception) {
225 }
catch (std::exception) {
240 res =
_setAttr(
"calibrationParam", rest_val);
241 }
catch (std::exception) {
263 }
catch (std::exception) {
277 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
278 res =
_setAttr(
"fusionMode", rest_val);
279 }
catch (std::exception) {
327 }
catch (std::exception) {
349 if (callback != NULL) {
356 if (callback != NULL && this->
isOnline()) {
451 mixedPos = ((position) << (2)) + orientation;
478 caltyp = ((iCalib[0]) / (1000));
482 res = ((iCalib[1]) / (1000));
508 caltyp = ((iCalib[0]) / (1000));
512 res = ((iCalib[2]) / (1000));
526 while (changed > 0) {
530 while (idx < stopidx) {
547 changed = changed + 1;
586 _calibStageHint =
"Set down the device on a steady horizontal surface";
646 _calibStageHint =
"Set down the device on a steady horizontal surface";
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;
653 if (xSq >= 0.04 && xSq < 0.64) {
660 if (ySq >= 0.04 && ySq < 0.64) {
667 if (zSq >= 0.04 && zSq < 0.64) {
673 norm = sqrt(xSq + ySq + zSq);
674 if (norm < 0.8 || norm > 1.2) {
720 _calibStageHint =
"Not yet done, please move back to the previous face";
760 if (orient == 0 || orient == 1) {
763 if (orient == 2 || orient == 3) {
766 if (orient == 4 || orient == 5) {
780 norm = sqrt(xVal * xVal + yVal * yVal + zVal * zVal);
787 this->
_calibSort(intpos, intpos + _calibCount);
798 if (orient == 0 || orient == 1) {
801 if (orient == 2 || orient == 3) {
804 if (orient == 4 || orient == 5) {
838 if (currTick < 1600) {
839 _calibStageHint =
"Set down the device on a steady horizontal surface";
846 calibParam = this->
_download(
"api/refFrame/calibrationParam.txt");
848 cal3 = ((iCalib[1]) / (1000));
849 calAcc = ((cal3) / (100));
850 calMag = ((cal3) / (10)) - 10*calAcc;
851 calGyr = ((cal3) % (10));
853 _calibStageHint =
"Set down the device on a steady horizontal surface";
865 _calibStageHint =
"Slowly turn the device, stopping at each 90 degrees";
968 shiftX = shiftX + 65536;
972 shiftY = shiftY + 65536;
976 shiftZ = shiftZ + 65536;
981 if (scaleX < -2048 || scaleX >= 2048 || scaleY < -2048 || scaleY >= 2048 || scaleZ < -2048 || scaleZ >= 2048) {
984 if (scaleX < -1024 || scaleX >= 1024 || scaleY < -1024 || scaleY >= 1024 || scaleZ < -1024 || scaleZ >= 1024) {
987 if (scaleX < -512 || scaleX >= 512 || scaleY < -512 || scaleY >= 512 || scaleZ < -512 || scaleZ >= 512) {
995 scaleX = ((scaleX) >> (scaleExp));
996 scaleY = ((scaleY) >> (scaleExp));
997 scaleZ = ((scaleZ) >> (scaleExp));
1000 scaleX = scaleX + 1024;
1003 scaleY = scaleY + 1024;
1006 scaleZ = scaleZ + 1024;
1008 scaleLo = ((((scaleY) & (15))) << (12)) + ((scaleX) << (2)) + scaleExp;
1009 scaleHi = ((scaleZ) << (6)) + ((scaleY) >> (4));
1011 newcalib =
YapiWrapper::ysprintf(
"5,%d,%d,%d,%d,%d", shiftX, shiftY, shiftZ, scaleLo,scaleHi);
1048 vector<YFUN_DESCR> v_fundescr;
1050 string serial, funcId, funcName, funcVal, errmsg;
1053 v_fundescr.size() == 0 ||
static const string CALIBRATIONPARAM_INVALID
string _json_get_key(const string &json, const string &data)
double getDouble(const string &key)
yCRITICAL_SECTION _this_cs
virtual int cancel3DCalibration(void)
int set_mountPos(int newval)
static YRefFrame * FirstRefFrame(void)
virtual string get_3DCalibrationHint(void)
YRETCODE _load_unsafe(int msValidity)
static const Y_FUSIONMODE_enum FUSIONMODE_INVALID
vector< double > _calibDataAccY
virtual Y_MOUNTORIENTATION get_mountOrientation(void)
YRefFrame(const string &func)
static const int MOUNTPOS_INVALID
virtual int save3DCalibrationV2(void)
static int DefaultCacheValidity
string getString(const string &key)
virtual int get_3DCalibrationStageProgress(void)
int set_bearing(double newval)
int set_fusionMode(Y_FUSIONMODE_enum newval)
static vector< int > _decodeFloats(string sdat)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
vector< int > _calibOrient
string _download(const string &url)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
vector< double > _calibDataAccZ
virtual int set_mountPosition(Y_MOUNTPOSITION position, Y_MOUNTORIENTATION orientation)
virtual int get_3DCalibrationStage(void)
virtual int get_3DCalibrationProgress(void)
virtual int _parseAttr(YJSONObject *json_val)
#define YAPI_INVALID_STRING
virtual int _parseAttr(YJSONObject *json_val)
virtual int _invokeValueCallback(string value)
int getInt(const string &key)
virtual int save3DCalibrationV1(void)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
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
virtual int save3DCalibration(void)
static YFunction * _FindFromCache(const string &classname, const string &func)
virtual int more3DCalibrationV2(void)
static string ysprintf(const char *fmt,...)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
virtual Y_MOUNTPOSITION get_mountPosition(void)
int set_calibrationParam(const string &newval)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
YRefFrameValueCallback _valueCallbackRefFrame
virtual int registerValueCallback(YRefFrameValueCallback callback)
virtual int get_calibrationState(void)
virtual int get_measureQuality(void)
string get_calibrationParam(void)
virtual int start3DCalibration(void)
Y_FUSIONMODE_enum _fusionMode
virtual int more3DCalibration(void)
static const double BEARING_INVALID
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static YRefFrame * FindRefFrame(string func)
static void _UpdateValueCallbackList(YFunction *func, bool add)
virtual int more3DCalibrationV1(void)
vector< double > _calibDataAcc
bool has(const string &key)
YRefFrame * nextRefFrame(void)
YRETCODE _setAttr(string attrname, string newvalue)
vector< double > _calibDataAccX
virtual int _invokeValueCallback(string value)