예제 #1
0
int
ulValidateConfig (json_object* bcfg, ulboard* ulcfg)
{
  int retCode = 0;

  if (bcfg && ulcfg)
  {
    retCode = ulGetProdAndVersion (bcfg, ulcfg);

    if (retCode == 0)
    {
      if (isIPACConfig (bcfg, ulcfg)
          || isIPACUltimateConfig (bcfg, ulcfg)
          || isPACDriveConfig (bcfg, ulcfg)
          || isPACLED64Config (bcfg, ulcfg)
          || isUltistikConfig (bcfg, ulcfg)
          || isUSBButtonConfig(bcfg, ulcfg)
          || isServoStikConfig(bcfg, ulcfg))
      {
        log_info("Configuration is %s. [Validated]", ulBoardTypeToString(ulcfg->type));
      }
      else
      {
        retCode = -1;
        log_err("Configuration is '%s'. [Not validated].", ulBoardTypeToString(ulcfg->type));
      }
    }
    else
    {
      retCode = -1;
      log_err("Configuration is '%s'. [Not validated].", ulBoardTypeToString(ulcfg->type));
    }
  }
  else
  {
    retCode = -1;
    log_err("JSON format invalid");
  }

  return retCode;
}
예제 #2
0
bool updateUltimarcBoard (json_object* jobj)
{
  bool ret = false;

  const char* prodstr = NULL;
  int version = 0;

  json_object* prodobj = NULL;
  json_object* verobj = NULL;

  if (json_object_object_get_ex(jobj, "product", &prodobj) &&
      json_object_get_type(prodobj) == json_type_string)
  {
    if (json_object_object_get_ex(jobj, "version", &verobj) &&
        json_object_get_type(verobj) == json_type_int)
    {
      prodstr = json_object_get_string(prodobj);
      version = json_object_get_int(verobj);

      if (isIPACConfig(prodstr, version, jobj))
      {
        log_info ("Updating IPAC2/MinIPAC board...");
        ret = updateBoardIPAC(jobj);
      }
      else if (isIPAC4Config(prodstr, version, jobj))
      {
        log_info ("Updating IPAC4 board...");
        ret = updateBoardIPAC4(jobj);
      }
      else if (isIPACUltimateConfig(prodstr, version, jobj))
      {
        log_info ("Updating IPAC Ultimate board...");
        ret = updateBoardIPacUltimate(jobj);
      }
      else if (isPACDriveConfig(prodstr, version, jobj))
      {
        log_info ("Updating PAC Drive board...");
        ret = updateBoardPacDrive(jobj);
      }
      else if (isPACLED64Config(prodstr, version, jobj))
      {
        log_info ("Updating PAC LED 64 board...");
        ret = updateBoardPacLED(jobj);
      }
      else if (isUltistikConfig(prodstr, version, jobj))
      {
        log_info ("Updating Ultistik board...");
        ret = updateBoardULTISTIK(jobj);
      }
    }
    else
    {
      if (json_object_object_get_ex(jobj, "version", &verobj))
      {
        log_err ("'version' is not defined as a integer");
      }
      else
      {
        log_err ("'version' is not defined in the configuration file");
      }
    }
  }
  else
  {
    if (json_object_object_get_ex(jobj, "product", &prodobj))
    {
      log_err ("'product' is not defined as a string");
    }
    else
    {
      log_err ("'product' is not defined in the configuration file");
    }
  }

  if (ret)
  {
    log_info ("Update done.\n");
  }
  else
  {
    log_info ("Update failed!\n");
  }

  json_object_put(jobj);
  return ret;
}