void PrinterPrivate::updateFromJson(Json::Value const & json) { QString const uniqueName(json["uniqueName"].asCString()); QString const displayName(json["displayName"].asCString()); bool const canPrint(json["canPrint"].asBool()); bool const canPrintToFile(json["canPrintToFile"].asBool()); QString const printerType(QString(json["printerType"].asCString())); int const numberOfToolheads(json["numberOfToolheads"].asInt()); const Printer::State state(stateFromString(json["state"].asString())); bool const hasHeatedPlatform(json["hasHeatedPlatform"].asBool()); QStringList machineNames; for(Json::ArrayIndex i = 0; i < json["machineNames"].size(); ++i) { machineNames << QString(json["machineNames"][i].asCString()); } QString const profileName( QString::fromUtf8(json["profile_name"].asCString())); float buildVolumeXmin, buildVolumeYmin, buildVolumeZmin, buildVolumeXmax, buildVolumeYmax, buildVolumeZmax; const std::string buildVolumeKey("build_volume"); if (json.isMember(buildVolumeKey)) { if (json[buildVolumeKey].isArray() && json[buildVolumeKey].size() == 3 && json[buildVolumeKey][0].isNumeric() && json[buildVolumeKey][1].isNumeric() && json[buildVolumeKey][2].isNumeric()) { const float buildVolume[3] = { json[buildVolumeKey][0].asFloat(), json[buildVolumeKey][1].asFloat(), json[buildVolumeKey][2].asFloat() }; buildVolumeXmin = buildVolume[0] / -2.0f; buildVolumeXmax = buildVolume[0] / 2.0f; buildVolumeYmin = buildVolume[1] / -2.0f; buildVolumeYmax = buildVolume[1] / 2.0f; buildVolumeZmin = 0; buildVolumeZmax = buildVolume[2]; } else { LOG_ERROR << "Invalid build_volume: " << json.toStyledString() << std::endl; } } else { LOG_ERROR << "Missing build_volume" << json.toStyledString() << std::endl; } enum { kStateChangeConnected, kStateChangeDisconnected, kStateNotChanged } stateChanged = kStateNotChanged; if ((m_state == Printer::kInvalid || m_state == Printer::kDisconnected) && state != Printer::kInvalid && state != Printer::kDisconnected) { stateChanged = kStateChangeConnected; } if ((m_state != Printer::kInvalid && m_state != Printer::kDisconnected) && (state == Printer::kInvalid || state == Printer::kDisconnected)) { stateChanged = kStateChangeDisconnected; } m_uniqueName = uniqueName; m_displayName = displayName; m_machineNames = machineNames; m_state = state; m_canPrint = canPrint; m_canPrintToFile = canPrintToFile; m_printerType = printerType; m_profileName = profileName; m_numberOfToolheads = numberOfToolheads; m_hasHeatedPlatform = hasHeatedPlatform; m_buildVolumeXmin = buildVolumeXmin; m_buildVolumeYmin = buildVolumeYmin; m_buildVolumeZmin = buildVolumeZmin; m_buildVolumeXmax = buildVolumeXmax; m_buildVolumeYmax = buildVolumeYmax; m_buildVolumeZmax = buildVolumeZmax; // Get firmware version const std::string firmwareVersionKey("firmware_version"); if (json.isMember(firmwareVersionKey)) { if (json[firmwareVersionKey].isInt()) { const int combinedVersion(json[firmwareVersionKey].asInt()); if (combinedVersion < 100) { // At least a three digit number is expected m_firmwareVersion.m_error = kFirmwareVersionTooSmall; } else { m_firmwareVersion.m_major = combinedVersion / 100; m_firmwareVersion.m_minor = (combinedVersion - m_firmwareVersion.m_major * 100); m_firmwareVersion.m_error = kFirmwareVersionOK; } } else { m_firmwareVersion.m_error = kFirmwareVersionNotInteger; } } // Temperature of extruder(s) and platform(s) if (json.isMember("temperature")) { const Json::Value &temperature(json["temperature"]); if (temperature.isMember("tools")) { ToolTemperature::updateFromJson(m_toolTemperature.tools, temperature["tools"]); } if (temperature.isMember("heated_platforms")) { ToolTemperature::updateFromJson(m_toolTemperature.heated_platforms, temperature["heated_platforms"]); } } // Wait to emit signals until all state has been updated switch (stateChanged) { case kStateChangeConnected: m_conveyor->m_private->emitPrinterAdded(m_printer); break; case kStateChangeDisconnected: m_conveyor->m_private->emitPrinterRemoved(m_printer); break; case kStateNotChanged: break; } }
void ofAddon::parseConfig(){ ofFile addonConfig(ofFilePath::join(addonPath,"addon_config.mk")); cout << "parse config " << addonPath << endl; if(!addonConfig.exists()) return; string line, originalLine; int lineNum = 0; while(addonConfig.good()){ lineNum++; getline(addonConfig,originalLine); line = originalLine; ofStringReplace(line,"\r",""); ofStringReplace(line,"\n",""); Poco::trimInPlace(line); // discard comments if(line[0]=='#' || line == ""){ continue; } // found section? if(line[line.size()-1]==':'){ ofStringReplace(line,":",""); currentParseState = stateFromString(line); if(currentParseState == Unknown){ ofLogError() << "Error parsing " << name << " addon_config.mk" << "\n\t\t" << "line " << lineNum << ": " << originalLine << "\n\t\t" << "sectionName " << stateName(currentParseState) << " not recognized"; } continue; } // found Variable if(line.find("=")!=string::npos){ bool addToValue = false; string variable, value; vector<string> varValue; if(line.find("+=")!=string::npos){ addToValue = true; varValue = ofSplitString(line,"+="); }else{ addToValue = false; varValue = ofSplitString(line,"="); } variable = Poco::trim(varValue[0]); value = Poco::trim(varValue[1]); if(!checkCorrectPlatform(currentParseState)){ continue; } if(!checkCorrectVariable(variable,currentParseState)){ ofLogError() << "Error parsing " << name << " addon_config.mk" << "\n\t\t" << "line " << lineNum << ": " << originalLine << "\n\t\t" << "variable " << variable << " not recognized for section " << stateName(currentParseState); continue; } parseVariableValue(variable, value, addToValue, originalLine, lineNum); } } exclude(includePaths,excludeIncludes); exclude(srcFiles,excludeSources); exclude(libs,excludeLibs); }