示例#1
0
		void LogInfoReporter::CreateReportMsg(int iLogType, const char* szTypeName, const char* szLogContent, int64_t date, bool pd)
		{
			JSON* joMsg = JSON::CreateObject();

			joMsg->AddNumberItem("date", date);
			joMsg->AddNumberItem("eid", iLogType);
			joMsg->AddStringItem("tname", szTypeName);
			joMsg->AddStringItem("content", szLogContent);
			joMsg->AddBoolItem("pd", pd);
			char *pJsonValue = joMsg->PrintValue(0, false);
			SetReportMsg(pJsonValue);
			MJ_FREE(pJsonValue);

			SetReportType(5);
		}
示例#2
0
// Writes the current calibration for a particular device to a device profile file
// sensor - the sensor that was calibrated
// cal_name - an optional name for the calibration or default if cal_name == NULL
bool SensorFusion::SaveMagCalibration(const char* calibrationName) const
{
    if (CachedSensorInfo.SerialNumber[0] == 0 || !HasMagCalibration())
        return false;
    
    // A named calibration may be specified for calibration in different
    // environments, otherwise the default calibration is used
    if (calibrationName == NULL)
        calibrationName = "default";

    // Generate a mag calibration event
    JSON* calibration = JSON::CreateObject();
    // (hardcoded for now) the measurement and representation method 
    calibration->AddStringItem("Version", "2.0");   
    calibration->AddStringItem("Name", "default");

    // time stamp the calibration
    char time_str[64];
   
#if defined(OVR_OS_WIN32) and !defined(__MINGW32__)
    struct tm caltime;
    localtime_s(&caltime, &MagCalibrationTime);
    strftime(time_str, 64, "%Y-%m-%d %H:%M:%S", &caltime);
#else
    struct tm* caltime;
    caltime = localtime(&MagCalibrationTime);
    strftime(time_str, 64, "%Y-%m-%d %H:%M:%S", caltime);
#endif
   
    calibration->AddStringItem("Time", time_str);

    // write the full calibration matrix
    char matrix[256];
    Matrix4f calmat = GetMagCalibration();
    calmat.ToString(matrix, 256);
    calibration->AddStringItem("CalibrationMatrix", matrix);
    // save just the offset, for backwards compatibility
    // this can be removed when we don't want to support 0.2.4 anymore
    Vector3f center(calmat.M[0][3], calmat.M[1][3], calmat.M[2][3]);
    Matrix4f tmp = calmat; tmp.M[0][3] = tmp.M[1][3] = tmp.M[2][3] = 0; tmp.M[3][3] = 1;
    center = tmp.Inverted().Transform(center);
    Matrix4f oldcalmat; oldcalmat.M[0][3] = center.x; oldcalmat.M[1][3] = center.y; oldcalmat.M[2][3] = center.z; 
    oldcalmat.ToString(matrix, 256);
    calibration->AddStringItem("Calibration", matrix);
    

    String path = GetBaseOVRPath(true);
    path += "/Devices.json";

    // Look for a prexisting device file to edit
    Ptr<JSON> root = *JSON::Load(path);
    if (root)
    {   // Quick sanity check of the file type and format before we parse it
        JSON* version = root->GetFirstItem();
        if (version && version->Name == "Oculus Device Profile Version")
        {   
            int major = atoi(version->Value.ToCStr());
            if (major > MAX_DEVICE_PROFILE_MAJOR_VERSION)
            {
                // don't use the file on unsupported major version number
                root->Release();
                root = NULL;
            }
        }
        else
        {
            root->Release();
            root = NULL;
        }
    }

    JSON* device = NULL;
    if (root)
    {
        device = root->GetFirstItem();   // skip the header
        device = root->GetNextItem(device);
        while (device)
        {   // Search for a previous calibration with the same name for this device
            // and remove it before adding the new one
            if (device->Name == "Device")
            {   
                JSON* item = device->GetItemByName("Serial");
                if (item && item->Value == CachedSensorInfo.SerialNumber)
                {   // found an entry for this device
                    item = device->GetNextItem(item);
                    while (item)
                    {
                        if (item->Name == "MagCalibration")
                        {   
                            JSON* name = item->GetItemByName("Name");
                            if (name && name->Value == calibrationName)
                            {   // found a calibration of the same name
                                item->RemoveNode();
                                item->Release();
                                break;
                            } 
                        }
                        item = device->GetNextItem(item);
                    }

                    // update the auto-mag flag
                    item = device->GetItemByName("EnableYawCorrection");
                    if (item)
                        item->dValue = (double)EnableYawCorrection;
                    else
                        device->AddBoolItem("EnableYawCorrection", EnableYawCorrection);

                    break;
                }
            }

            device = root->GetNextItem(device);
        }
    }
    else
    {   // Create a new device root
        root = *JSON::CreateObject();
        root->AddStringItem("Oculus Device Profile Version", "1.0");
    }

    if (device == NULL)
    {
        device = JSON::CreateObject();
        device->AddStringItem("Product", CachedSensorInfo.ProductName);
        device->AddNumberItem("ProductID", CachedSensorInfo.ProductId);
        device->AddStringItem("Serial", CachedSensorInfo.SerialNumber);
        device->AddBoolItem("EnableYawCorrection", EnableYawCorrection);

        root->AddItem("Device", device);
    }

    // Create and the add the new calibration event to the device
    device->AddItem("MagCalibration", calibration);

    return root->Save(path);
}
示例#3
0
//-----------------------------------------------------------------------------
bool ProfileManager::SetTaggedProfile(const char** tag_names, const char** tags, int num_tags, Profile* profile)
{
    Lock::Locker lockScope(&ProfileLock);

    if (ProfileCache == NULL)
    {   // Load the cache
        LoadCache(true);
        if (ProfileCache == NULL)
            return false;  // TODO: Generate a new profile DB
    }

    JSON* tagged_data = ProfileCache->GetItemByName("TaggedData");
    OVR_ASSERT(tagged_data);
    if (tagged_data == NULL)
        return false;

    // Get the cached tagged data section
    JSON* vals = FindTaggedData(tagged_data, tag_names, tags, num_tags);
    if (vals == NULL)
    {  
        JSON* tagged_item = JSON::CreateObject();
        JSON* taglist = JSON::CreateArray();
        for (int i=0; i<num_tags; i++)
        {
            JSON* k = JSON::CreateObject();
            k->AddStringItem(tag_names[i], tags[i]);
            taglist->AddArrayElement(k);
        }

        vals = JSON::CreateObject();
        
        tagged_item->AddItem("tags", taglist);
        tagged_item->AddItem("vals", vals);
        tagged_data->AddArrayElement(tagged_item);
    }

    // Now add or update each profile setting in cache
    for (unsigned int i=0; i<profile->Values.GetSize(); i++)
    {
        JSON* value = profile->Values[i];
        
        bool found = false;
        JSON* item = vals->GetFirstItem();
        while (item)
        {
            if (value->Name == item->Name)
            {
                // Don't allow a pre-existing type to be overridden
                OVR_ASSERT(value->Type == item->Type);

                if (value->Type == item->Type)
                {   // Check for the same value
                    if (value->Type == JSON_Array)
                    {   // Update each array item
                        if (item->GetArraySize() == value->GetArraySize())
                        {   // Update each value (assumed to be basic types and not array of objects)
                            JSON* value_element = value->GetFirstItem();
                            JSON* item_element = item->GetFirstItem();
                            while (item_element && value_element)
                            {
                                if (value_element->Type == JSON_String)
                                {
                                    if (item_element->Value != value_element->Value)
                                    {   // Overwrite the changed value and mark for file update
                                        item_element->Value = value_element->Value;
                                        Changed = true;
                                    }
                                }
                                else {
                                    if (item_element->dValue != value_element->dValue)
                                    {   // Overwrite the changed value and mark for file update
                                        item_element->dValue = value_element->dValue;
                                        Changed = true;
                                    }
                                }
                                
                                value_element = value->GetNextItem(value_element);
                                item_element = item->GetNextItem(item_element);
                            }
                        }
                        else
                        {   // if the array size changed, simply create a new one                            
// TODO: Create the new array
                        }
                    }
                    else if (value->Type == JSON_String)
                    {
                        if (item->Value != value->Value)
                        {   // Overwrite the changed value and mark for file update
                            item->Value = value->Value;
                            Changed = true;
                        }
                    }
                    else {
                        if (item->dValue != value->dValue)
                        {   // Overwrite the changed value and mark for file update
                            item->dValue = value->dValue;
                            Changed = true;
                        }
                    }
                }
                else
                {
                    return false;
                }

                found = true;
                break;
            }
            
            item = vals->GetNextItem(item);
        }

        if (!found)
        {   // Add the new value
            Changed = true;

            if (value->Type == JSON_String)
                vals->AddStringItem(value->Name, value->Value);
            else if (value->Type == JSON_Bool)
                vals->AddBoolItem(value->Name, ((int)value->dValue != 0));
            else if (value->Type == JSON_Number)
                vals->AddNumberItem(value->Name, value->dValue);
            else if (value->Type == JSON_Array)
                vals->AddItem(value->Name, value->Copy());
            else
            {
                OVR_ASSERT(false);
                Changed = false;
            }
        }
    }

    return true;
}