Пример #1
0
int set_rgb()
{
  unsigned char color;
  unsigned char i;
  color = uart_string[2];
  if(color == 'R')
    match[0] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else if(color == 'G')
    match[1] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else if(color == 'B')
    match[2] = (uart_string[3] - 0x30) * 100 + (uart_string[4] - 0x30) * 10 + (uart_string[5] - 0x30);
  else
  {
    uart_send_string("Fehler\n\r");
    return -1;
  }
  i = 6;
  uart_send_char(uart_string[i]);
  uart_send_char(uart_string[i+1]);
  uart_send_char(uart_string[i+2]);
  uart_send_char(uart_string[i+3]);
  uart_send_var((uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30));
  if(uart_string[i] == 'R' || uart_string[i] == 'G' || uart_string[i] == 'B')
  {
    uart_send_char('r');
    if(uart_string[i] == 'R')
    {
      match[0] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
      uart_send_var((uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30));
    }
    else if(uart_string[i] == 'G')
      match[1] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
    else
      match[2] = (uart_string[i+1] - 0x30) * 100 + (uart_string[i+2] - 0x30) * 10 + (uart_string[i+3] - 0x30);
  i=i+4;
  }
  sort_matches();
}
Пример #2
0
char *read_custom_category(char *name, struct custom_data *data)
{
    int i;

    readname = name;

    memset(&matches, 0, sizeof(matches));
    memset(&match_list, 0, sizeof(match_list));
    memset(&positions, 0, sizeof(positions));
    memset(&round_robin_pools, 0, sizeof(round_robin_pools));
    memset(&symbols, 0, sizeof(symbols));
    memset(&match_order, 0, sizeof(match_order));
    memset(&best_of_three_pairs, 0, sizeof(best_of_three_pairs));
    num_round_robin_pools = 0;
    num_symbols = 0;
    num_matches = 0;
    num_best_of_three_pairs = 0;
    num_groups = 0;
    group_set = 0;
    groups_type = 0;
    linenum = 1;
    stop = 0;
    max_comp = 0;
    num_ord = 0;
    competitors_min = competitors_max = 0;
    value = numvalue = ordernum = n = max_comp = stop = 0;
    pagenum = linenum = 1;

    for (i = 0; i < NUM_CUSTOM_MATCHES; i++)
        match_list[i] = i;

    f = fopen(name, "r");
    if (!f) {
        snprintf(message, sizeof(message), "Cannot read %s", name);
        return message;
    }

    program();

    fclose(f);

    if (stop)
        return message;

    for (i = 1; i < NUM_CUST_POS ; i++) {
        if (!positions[i].match)
            continue;
        
        solve(positions[i].match, 1, i);
    }

    sort_matches();

    data->num_round_robin_pools = 0;
    data->num_matches = 0;
    data->num_positions = 0;

    // round robin
    for (i = 0; i < num_round_robin_pools; i++) {
        int j;
        for (j = 0; j < round_robin_pools[i].num_rr_matches; j++) {
            data->round_robin_pools[i].rr_matches[j] = 
                get_match_num(round_robin_pools[i].rr_matches[j]->name);
            checkval2((data->round_robin_pools[i].rr_matches[j]), "Pool %s: match %s doesn't exist", 
                     round_robin_pools[i].name->name,
                     round_robin_pools[i].rr_matches[j]->name);
        } // for
        for (j = 0; j < round_robin_pools[i].num_competitors; j++) {
            data->round_robin_pools[i].competitors[j] = 
                get_palyer_bare(&round_robin_pools[i].competitors[j]);
        }

        data->round_robin_pools[i].num_rr_matches = round_robin_pools[i].num_rr_matches;
        data->round_robin_pools[i].num_competitors = round_robin_pools[i].num_competitors;
        snprintf(data->round_robin_pools[i].name, 16, "%s", round_robin_pools[i].name->name);
    }
    data->num_round_robin_pools = num_round_robin_pools;

    // best of three
    for (i = 0; i < num_best_of_three_pairs; i++) {
        int j;
        for (j = 0; j < 3; j++) {
            data->best_of_three_pairs[i].matches[j] = 
                get_match_num(best_of_three_pairs[i].matches[j]->name);
            checkval2((data->best_of_three_pairs[i].matches[j]), "Best of three %s: match %s doesn't exist", 
                     best_of_three_pairs[i].name->name,
                     best_of_three_pairs[i].matches[j]->name);
        }
        snprintf(data->best_of_three_pairs[i].name, 16, "%s", best_of_three_pairs[i].name->name);
    }
    data->num_best_of_three_pairs = num_best_of_three_pairs;

    // matches
    for (i = 0; i < num_matches; i++) {
        match_t *m = &matches[match_list[i]];
        data->matches[i].c1 = get_palyer_bare(&m->c1);
        data->matches[i].c2 = get_palyer_bare(&m->c2);
    }
    data->num_matches = num_matches;

    // positions
    for (i = 0; positions[i].match; i++) {
        if (get_rr_num(positions[i].match->name)) {
            data->positions[i].type = COMP_TYPE_ROUND_ROBIN;
            data->positions[i].match = get_rr_num(positions[i].match->name);
        } else if (get_b3_num(positions[i].match->name)) {
            data->positions[i].type = COMP_TYPE_BEST_OF_3;
            data->positions[i].match = get_b3_num(positions[i].match->name);
        } else {
            data->positions[i].type = COMP_TYPE_MATCH;
            data->positions[i].match = get_match_num(positions[i].match->name);
        }
        checkval2((data->positions[i].match > 0), "Wrong match name \"%s\" in pos%d", 
                  positions[i].match->name, positions[i].pos);
        data->positions[i].pos = positions[i].pos;
        data->positions[i].real_contest_pos = positions[i].real_contest_pos;
    }
    data->num_positions = i;

    // groups
    if (num_groups == 0) {
        // create default groups
            
        // find best of 3
        for (i = 0; i < data->num_best_of_three_pairs && num_groups < NUM_GROUPS; i++) {
            int n = data->best_of_three_pairs[i].matches[0];
            if (data->matches[n].c1.type == COMP_TYPE_COMPETITOR) {
                groups[num_groups].competitors[0] = data->matches[n].c1.num;
                groups[num_groups].competitors[1] = data->matches[n].c2.num;
                groups[num_groups].num_competitors = 2;
                num_groups++;
            }
        }

        // round robin
        for (i = 0; i < data->num_round_robin_pools && num_groups < NUM_GROUPS; i++) {
            if (data->round_robin_pools[i].competitors[0].type == COMP_TYPE_COMPETITOR) {
                int j;
                for (j = 0; j < data->round_robin_pools[i].num_competitors; j++)
                    groups[num_groups].competitors[j] = data->round_robin_pools[i].competitors[j].num;
                num_groups++;
                groups_type = 1;
            }
        }

        // matches
        if (num_groups == 0) {
            // assume we have a knock out system
            int n = competitors_max/4;
            for (i = 0; i < 4; i++) {
                int j;
                for (j = 0; j < n; j++) {
                    groups[i].competitors[j] = i*n + j + 1;
                }
                groups[i].num_competitors = n;
            }
        }
    }

    for (i = 0; i < num_groups; i++) {
        int j;
        for (j = 0; j < groups[i].num_competitors; j++)
            data->groups[i].competitors[j] = groups[i].competitors[j];
        data->groups[i].num_competitors = groups[i].num_competitors;
    }
    data->num_groups = num_groups;

    // info
    checkval2((competitors_min >= 1 && competitors_min <= competitors_max &&
               name_long[0] && name_short[0]), "Wrong info");
    data->competitors_min = competitors_min;
    data->competitors_max = competitors_max;
    strncpy(data->name_long, name_long, sizeof(data->name_long)-1);
    strncpy(data->name_short, name_short, sizeof(data->name_short)-1);

    return 0;
}