void DisplayInternal::doHandleMsgModePost(const StringMap& postValues) {
  initModeMessageData(0 /*currX*/, 5 /*currY*/, true /*incrementX*/, false /*incrementY*/,
		      0 /*confetti*/, false /*blink*/, font5x4 /*font*/, 60 /*timeout*/);

  for (auto& kvp : postValues) {
    const std::string& k = kvp.first;
    const std::string& v = kvp.second;
    const char* const key = k.c_str();
    const char* const value = v.c_str(); 

    if (strncasecmp(key, "msg", strlen(key)) == 0) {
      if (strncasecmp(value, "#cookie", 7) == 0) {
	if (value[7] == 0) {
	  modeMessageData.modeMsgsIndex = (ModeMsgsIndex) getRandomNumber(modeMsgsIndexLast);
	} else {
	  modeMessageData.modeMsgsIndex = (ModeMsgsIndex) strtoul(&value[7], NULL, 10);
	}
	// nitpick: skip 0
	if (modeMessageData.modeMsgsIndex == modeMsgsIndexBoot) modeMessageData.modeMsgsIndex = modeMsgsIndexFortunate1;
      } else {
	strncpy(modeMessageData.msg, value, sizeof(modeMessageData.msg));
      }
    } else if (strncasecmp(key, "x", strlen(key)) == 0) {
      modeMessageData.currX = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "y", strlen(key)) == 0) {
      modeMessageData.currYFactor = strtoul(value, NULL, 10) * INCREMENT_Y_SCALE;
    } else if (strncasecmp(key, "font", strlen(key)) == 0) {
      modeMessageData.font = (Font) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "alternateFont", strlen(key)) == 0) {
      modeMessageData.alternateFont = parseBooleanValue(value);
    } else if (strncasecmp(key, "confetti", strlen(key)) == 0) {
      modeMessageData.confetti = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "bounce", strlen(key)) == 0) {
      modeMessageData.incrementY = parseBooleanValue(value) ? INCREMENT_Y_VALUE : 0;
    } else if (strncasecmp(key, "noScroll", strlen(key)) == 0) {
      modeMessageData.incrementX = parseBooleanValue(value) ? false : true;
    } else if (strncasecmp(key, "blink", strlen(key)) == 0) {
      modeMessageData.blink = parseBooleanValue(value);
    } else if (strncasecmp(key, "color", strlen(key)) == 0) {
      modeMessageData.displayColor = (DisplayColor) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "repeats", strlen(key)) == 0) {
	modeMessageData.repeats = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "timeout", strlen(key)) == 0) {
      modeMessageData.timeout = strtoul(value, NULL, 10);
    }
  } // for
  changeDisplayMode(displayModeMessage, *info);
}
void DisplayInternal::doHandleImgBackgroundPost(const StringMap& postValues) {
  int backgroundImgIndex = 0;
  BackgroundImg img;

  memset(&img, 0, sizeof(img));
  for (auto& kvp : postValues) {
    const std::string& k = kvp.first;
    const std::string& v = kvp.second;
    const char* const key = k.c_str();
    const char* const value = v.c_str(); 

    if (strncasecmp(key, "index", strlen(key)) == 0) {
      backgroundImgIndex = strtoul(value, NULL, 10);
      if (backgroundImgIndex < 0 || backgroundImgIndex >= BACKGROUND_IMG_COUNT) {
	backgroundImgIndex = 0;
      }
    } else if (strncasecmp(key, "enabled", strlen(key)) == 0) {
      img.enabled = parseBooleanValue(value);
    } else if (strncasecmp(key, "clearAll", strlen(key)) == 0) {
      if (parseBooleanValue(value)) {
	for (int i=0; i < BACKGROUND_IMG_COUNT; ++i) initBackgroundImg(i);
      }
    } else if (strncasecmp(key, "imgArt", strlen(key)) == 0) {
      img.imgArt = (ImgArt) strtoul(value, NULL, 10);
      if (img.imgArt < 0 || img.imgArt >= imgArtLast) {
	img.imgArt = (ImgArt) 0;
      }
    } else if (strncasecmp(key, "x", strlen(key)) == 0) {
      img.x = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "y", strlen(key)) == 0) {
      img.y = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "color", strlen(key)) == 0) {
      img.displayColor = (DisplayColor) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationStep", strlen(key)) == 0) {
      img.animation.animationStep = (AnimationStep) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationPhase", strlen(key)) == 0) {
      img.animation.animationStepPhase = (uint8_t) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationPhaseValue", strlen(key)) == 0) {
      img.animation.animationStepPhaseValue = (uint8_t) strtoul(value, NULL, 10);
    }
  } // for

  backgroundImg[backgroundImgIndex] = img;
}
void DisplayInternal::doHandleMsgBackgroundPost(const StringMap& postValues) {
  int msgIndex = 0;
  BackgroundMessage msg;

  memset(&msg, 0, sizeof(msg));
  for (auto& kvp : postValues) {
    const std::string& k = kvp.first;
    const std::string& v = kvp.second;
    const char* const key = k.c_str();
    const char* const value = v.c_str(); 

    if (strncasecmp(key, "index", strlen(key)) == 0) {
      msgIndex = strtoul(value, NULL, 10);
      if (msgIndex < 0 || msgIndex >= BACKGROUND_MESSAGE_COUNT) {
	msgIndex = 0;
      }
    } else if (strncasecmp(key, "msg", strlen(key)) == 0) {
      strncpy(msg.msg, value, sizeof(msg.msg));
    } else if (strncasecmp(key, "enabled", strlen(key)) == 0) {
      msg.enabled = parseBooleanValue(value);
    } else if (strncasecmp(key, "clearAll", strlen(key)) == 0) {
      if (parseBooleanValue(value)) {
	for (int i=0; i < BACKGROUND_MESSAGE_COUNT; ++i) initBackgroundMessage(i);
      }
    } else if (strncasecmp(key, "font", strlen(key)) == 0) {
      msg.font = (Font) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "x", strlen(key)) == 0) {
      msg.x = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "y", strlen(key)) == 0) {
      msg.y = strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "color", strlen(key)) == 0) {
      msg.displayColor = (DisplayColor) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationStep", strlen(key)) == 0) {
      msg.animation.animationStep = (AnimationStep) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationPhase", strlen(key)) == 0) {
      msg.animation.animationStepPhase = (uint8_t) strtoul(value, NULL, 10);
    } else if (strncasecmp(key, "animationPhaseValue", strlen(key)) == 0) {
      msg.animation.animationStepPhaseValue = (uint8_t) strtoul(value, NULL, 10);
    }
  } // for

  backgroundMessage[msgIndex] = msg;
}
static IoT_Error_t UpdateValueIfNoObject(const char *pJsonString, jsonStruct_t *pDataStruct, jsmntok_t token) {
	IoT_Error_t ret_val = NONE_ERROR;
	if (pDataStruct->type == SHADOW_JSON_BOOL) {
		ret_val = parseBooleanValue(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_INT32) {
		ret_val = parseInteger32Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_INT16) {
		ret_val = parseInteger16Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_INT8) {
		ret_val = parseInteger8Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_UINT32) {
		ret_val = parseUnsignedInteger32Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_UINT16) {
		ret_val = parseUnsignedInteger16Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_UINT8) {
		ret_val = parseUnsignedInteger8Value(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_FLOAT) {
		ret_val = parseFloatValue(pDataStruct->pData, pJsonString, &token);
	} else if (pDataStruct->type == SHADOW_JSON_DOUBLE) {
		ret_val = parseDoubleValue(pDataStruct->pData, pJsonString, &token);
	}

	return ret_val;
}
Exemple #5
0
void RepoParams::readInfoFile(const std::string& fileName)
{
  File f;
  logMsg(LOG_DEBUG, "Opening \'%s\' info file in read-only mode", fileName.c_str());
  f.openReadOnly(fileName);
  std::string content;
  f.readTextFile(content);
  InfoFileReader reader;
  StringToStringMap params;
  reader.read(content, params);
  for(StringToStringMap::const_iterator it = params.begin();it != params.end();it++)
    {
      const std::string& name = it->first;
      const std::string& value = it->second;
      logMsg(LOG_DEBUG, "%s:parsing \'%s\' = \'%s\'", fileName.c_str(), name.c_str(), value.c_str());
      //Format type;
      if (trim(name) == INFO_FILE_FORMAT_TYPE)
	{
	  if (trim(value) == INFO_FILE_FORMAT_TYPE_TEXT)
	    formatType = FormatTypeText; else
	    if (trim(value) == INFO_FILE_FORMAT_TYPE_BINARY)
	      formatType = FormatTypeBinary; else
	      throw InfoFileValueException(InfoFileValueException::InvalidFormatType, trim(value));
	  continue;
	} //Format type;
      //Compression type;
      if (trim(name) == INFO_FILE_COMPRESSION_TYPE)
	{
	  if (trim(value) == INFO_FILE_COMPRESSION_TYPE_NONE)
	    compressionType = CompressionTypeNone; else
	    if (trim(value) == INFO_FILE_COMPRESSION_TYPE_GZIP)
	      compressionType = CompressionTypeGzip; else
	      throw InfoFileValueException(InfoFileValueException::InvalidCompressionType, trim(value));
	  continue;
	} //Compression type;
      //Version;
      if (trim(name) == INFO_FILE_VERSION)
	{
	  version = trim(value);
	  continue;
	} //Version;
      //Md5sum;
      if (trim(name) == INFO_FILE_MD5SUM)
	{
	md5sumFileName = trim(value);
	continue;
	} //Md5sum;
      // Change log binary;
      if (trim(name) == INFO_FILE_CHANGELOG_BINARY)
	{
	  changeLogBinary = parseBooleanValue(trim(value), trim(name));
	  continue;
	} //Change log binary;
      //Change log sources;
      if (trim(name) == INFO_FILE_CHANGELOG_SOURCES)
	{
	  changeLogSources = parseBooleanValue(trim(value), trim(name));
	  continue;
	} //Change log sources;
      //Filter provides by references;
      if (trim(name) == INFO_FILE_FILTER_PROVIDES_BY_REFS)
	{
	  filterProvidesByRefs = parseBooleanValue(trim(value), trim(name));
	  continue;
	}
      //Filter provides by dirs;
      if (trim(name) == INFO_FILE_FILTER_PROVIDES_BY_DIRS)
	{
	  parseStringVector(trim(value), filterProvidesByDirs);
	  continue;
	} //Filter provides by dirs;
      //Exclude requires;
      if (trim(name) == INFO_FILE_EXCLUDE_REQUIRES)
	{
	  parseStringVector(trim(value), excludeRequiresRegExp);
	  continue;
	}
      userParams.insert(StringToStringMap::value_type(trim(name), trim(value)));
    } //for(values);
}