Exemple #1
0
int
serialParseStopBits (unsigned int *bits, const char *string) {
  if (isUnsignedInteger(bits, string)) return 1;

  logMessage(LOG_WARNING, "invalid serial stop bit count: %s", string);
  return 0;
}
Exemple #2
0
int
serialParseBaud (unsigned int *baud, const char *string) {
  if (isUnsignedInteger(baud, string)) return 1;

  logMessage(LOG_WARNING, "invalid serial baud: %s", string);
  return 0;
}
Exemple #3
0
int
usbParseProductIdentifier (uint16_t *identifier, const char *string) {
  if (string && *string) {
    unsigned int value;

    if (isUnsignedInteger(&value, string)) {
      if ((value > 0) && (value <= UINT16_MAX)) {
        *identifier = value;
        return 1;
      }
    }

    logMessage(LOG_WARNING, "invalid USB product identifier: %s", string);
    return 0;
  }

  *identifier = 0;
  return 1;
}
Exemple #4
0
int
serialValidateBaud (unsigned int *baud, const char *description, const char *word, const unsigned int *choices) {
  if (!*word || isUnsignedInteger(baud, word)) {
    const SerialBaudEntry *entry = serialGetBaudEntry(*baud);

    if (entry) {
      if (!choices) return 1;

      while (*choices) {
        if (*baud == *choices) return 1;
        choices += 1;
      }

      logMessage(LOG_ERR, "unsupported %s: %u", description, *baud);
    } else {
      logMessage(LOG_ERR, "undefined %s: %u", description, *baud);
    }
  } else {
    logMessage(LOG_ERR, "invalid %s: %u", description, *baud);
  }

  return 0;
}
Exemple #5
0
//------------------------------------------------------------------------------
///
/// Parsing the buffer back to the lines
///
/// @param buf_to_parse Contains the whole config file
/// @param nr_gravity   Is the default value to be changed if necessary
/// @param res_width    Is the default value to be changed if necessary
/// @param res_height   Is the default value to be changed if necessary
/// @param nr_pps       Is the default value to be changed if necessary
/// @param wind_angle   Is the default value to be changed if necessary
/// @param wind_force   Is the default value to be changed if necessary
///
/// @return void no Error checking needed
//
void parseBuffer(char *buf_to_parse, float *nr_gravity, unsigned int *res_width, 
  unsigned int *res_height, unsigned int *nr_pps, float *wind_angle, 
  float *wind_force)
{
  char *mark_end = NULL;
  int count_max_config_params = COUNT_MAX_CONFIG_PARAMS; 
  int been_set = 0; // incorrect = 0;

  while((mark_end = strchr(buf_to_parse, '\n')) != NULL)
  {
    char *temp = NULL;
    *mark_end = '\0';
    temp = buf_to_parse;
    buf_to_parse = ++mark_end;
    char *pch;

    if (strlen(temp) == 0)
      continue;

    if((pch = strstr(temp, STRING_GRAVITATION)) != NULL)
    {
      if((sscanf(temp, "%*s %f", nr_gravity) == COUNT_NUMBERS_GRAVITY) &&
        (been_set & MASK_GRAVITATION) == 0)
      {
		    been_set |= MASK_GRAVITATION;
        printf("gravitation set to %.2f\n", *nr_gravity);
        count_max_config_params--;
      }
      else
      {
        //incorrect++;
        *nr_gravity = DEFAULT_GRAVITY;
      }
    }
    else if((pch = strstr(temp, STRING_WIND)) != NULL)
    {
      if(sscanf(temp, "%*s %f %f", wind_angle, wind_force) ==
        COUNT_NUMBERS_WIND && (been_set & MASK_WIND) == 0)
      {
        been_set |= MASK_WIND;
        printf("wind set to %.2f degrees with force %.2fm/s^2\n", *wind_angle, 
          *wind_force);
        count_max_config_params--;
      }
      else
      {
        *wind_angle = DEFAULT_WIND;
        *wind_force = DEFAULT_WIND;
        //incorrect++;        
      }
    }
    else if((pch = strstr(temp, STRING_RESOLUTION)) != NULL)
    {
      if(sscanf(temp, "%*s %u %u", res_width, res_height) == 
        COUNT_NUMBERS_RESOLUTION && isUnsignedInteger(temp) &&
        *res_width % 1 == 0 && *res_height % 1 == 0 && 
        (been_set & MASK_RESOLUTION) == 0)
      {
        been_set |= MASK_RESOLUTION;
        printf("resolution set to %u:%u\n", *res_width, *res_height);
        count_max_config_params--;
      }
      else
      {
        *res_width = DEFAULT_RESOLUTION;
        *res_height = DEFAULT_RESOLUTION;
        //incorrect++;
      }
    }
    else if((pch = strstr(temp, STRING_PPS)) != NULL)
    {      
      if (sscanf(temp, "%*s %u", nr_pps) == COUNT_NUMBERS_PPS &&
        isUnsignedInteger(temp) && (been_set & MASK_PPS) == 0)
      {
        been_set |= MASK_PPS;
        printf("pps set to %u\n", *nr_pps);
        count_max_config_params--;
      }
      else
      {
        *nr_pps = DEFAULT_PPS;
        //incorrect++;
      }
    }
    //else
    //  incorrect++;
  }
  if (/*incorrect +*/ count_max_config_params != 0)
    printf("%d " ERROR_MSG_CONFIG_FILE, /*incorrect +*/ count_max_config_params);
}