Ejemplo n.º 1
0
    $plug_regul_value[$nb] = get_plug_conf("PLUG_REGUL_VALUE", $nb, $main_error);
    $plug_power_max[$nb] = get_plug_conf("PLUG_POWER_MAX", $nb, $main_error);
    $plug_tolerance[$nb] = get_plug_conf("PLUG_TOLERANCE", $nb, $main_error);
    $plug_second_tolerance[$nb] = get_plug_conf("PLUG_SECOND_TOLERANCE", $nb, $main_error);
    $plug_compute_method[$nb] = get_plug_conf("PLUG_COMPUTE_METHOD", $nb, $main_error);
    $plug_regul_sensor[$nb] = get_plug_conf("PLUG_REGUL_SENSOR", $nb, $main_error);
    $plug_module[$nb] = get_plug_conf("PLUG_MODULE", $nb, $main_error);
    if ($plug_module[$nb] == "") {
        $plug_num_module[$nb] = "wireless";
    }
    $plug_num_module[$nb] = get_plug_conf("PLUG_NUM_MODULE", $nb, $main_error);
    if ($plug_num_module[$nb] == "") {
        $plug_num_module[$nb] = 1;
    }
    $plug_module_options[$nb] = get_plug_conf("PLUG_MODULE_OPTIONS", $nb, $main_error);
    $plug_module_output[$nb] = get_plug_conf("PLUG_MODULE_OUTPUT", $nb, $main_error);
    if ($plug_module_output[$nb] == "") {
        $plug_module_output[$nb] = 1;
    }
    $plug_sensor[$nb] = get_plug_regul_sensor($nb, $main_error);
    $plug_count_sensor[$nb] = count(explode("-", $plug_regul_sensor[$nb]));
}
// Write file plug01 plug02...
if (isset($sd_card) && !empty($sd_card)) {
    if (isset($submit_plugs) && !empty($submit_plugs)) {
        // build conf plug array
        $plugconf = create_plugconf_from_database($GLOBALS['NB_MAX_PLUG'], $main_error);
        if (count($plugconf) > 0) {
            if (!check_sd_card($sd_card)) {
                $main_error[] = __('ERROR_WRITE_SD_PLUGCONF');
            } else {
Ejemplo n.º 2
0
function write_pluga($sd_card, &$out)
{
    $file = $sd_card . "/serverPlugUpdate/plg/pluga";
    if ($f = @fopen($file, "w+")) {
        $pluga = "";
        $nb_plug = get_configuration("NB_PLUGS", $out);
        while (strlen("{$nb_plug}") < 2) {
            $nb_plug = "0{$nb_plug}";
        }
        $pluga = $nb_plug . "\r\n";
        for ($i = 0; $i < $nb_plug; $i++) {
            // Get power of the plug
            $tmp_power_max = get_plug_conf("PLUG_POWER_MAX", $i + 1, $out);
            // Get module of the plug
            $tmp_MODULE = get_plug_conf("PLUG_MODULE", $i + 1, $out);
            if ($tmp_MODULE == "") {
                $tmp_MODULE = "wireless";
            }
            // Get module number of the plug
            $tmp_NUM_MODULE = get_plug_conf("PLUG_NUM_MODULE", $i + 1, $out);
            if ($tmp_NUM_MODULE == "") {
                $tmp_NUM_MODULE = 1;
            }
            // Get module options of the plug
            $tmp_MODULE_OPTIONS = get_plug_conf("PLUG_MODULE_OPTIONS", $i + 1, $out);
            // Get module output used
            $tmp_MODULE_OUTPUT = get_plug_conf("PLUG_MODULE_OUTPUT", $i + 1, $out);
            if ($tmp_MODULE_OUTPUT == "") {
                $tmp_MODULE_OUTPUT = 1;
            }
            // Create adress for this plug
            $tmp_pluga = 0;
            switch ($tmp_MODULE) {
                case "wireless":
                    if ($tmp_power_max == "3500") {
                        $tmp_pluga = $GLOBALS['PLUGA_DEFAULT_3500W'][$i];
                    } else {
                        $tmp_pluga = $GLOBALS['PLUGA_DEFAULT'][$i];
                    }
                    break;
                case "direct":
                    // Direct plug case (Adresse 50 --> 58)
                    $tmp_pluga = $tmp_MODULE_OUTPUT + 49;
                    break;
                case "mcp230xx":
                    // MCP plug case
                    // Module 1 : (Adresse 60 --> 67)
                    // Module 2 : (Adresse 70 --> 77)
                    // Module 3 : (Adresse 80 --> 87)
                    $tmp_pluga = 60 + 10 * ($tmp_NUM_MODULE - 1) + $tmp_MODULE_OUTPUT - 1;
                    break;
                case "dimmer":
                    // Dimmer plug case
                    // Module 1 : (Adresse 90 --> 93)
                    // Module 2 : (Adresse 95 --> 98)
                    // Module 3 : (Adresse 100 --> 103)
                    $tmp_pluga = 90 + 5 * ($tmp_NUM_MODULE - 1) + $tmp_MODULE_OUTPUT - 1;
                    break;
                case "network":
                    // 1000 ...
                    $tmp_pluga = 1000 + 16 * ($tmp_NUM_MODULE - 1) + $tmp_MODULE_OUTPUT - 1;
                    break;
                case "xmax":
                    // xmax plug case
                    // Module 1 : (Adresse 105 --> 108)
                    $tmp_pluga = 105 + $tmp_MODULE_OUTPUT - 1;
                    break;
                case "pwm":
                    // pwm plug case
                    // Module 1 : (Adresse 31 --> 38)
                    // Module 2 : (Adresse 39 --> 44)
                    // Module 3 : (Adresse 45 --> 49)
                    $base = 31;
                    if ($tmp_NUM_MODULE == 2) {
                        $base = 39;
                    }
                    if ($tmp_NUM_MODULE == 3) {
                        $base = 45;
                    }
                    $tmp_pluga = $base + $tmp_MODULE_OUTPUT - 1;
                    break;
                case "bulcky":
                    // bulcky plug case
                    // Module 1 : (Adresse 2000 --> 2004)
                    // Module 2 : (Adresse 2010 --> 2014)
                    // Module 3 : (Adresse 2020 --> 2024)
                    //$tmp_pluga = 2000 + 10 * ($tmp_NUM_MODULE - 1) + $tmp_MODULE_OUTPUT - 1;
                    $tmp_pluga = 2000 + $tmp_MODULE_OUTPUT - 1;
                    break;
            }
            while (strlen($tmp_pluga) < 3) {
                $tmp_pluga = "0{$tmp_pluga}";
            }
            $pluga = $pluga . $tmp_pluga . "\r\n";
        }
        if (!@fwrite($f, "{$pluga}")) {
            fclose($f);
            return false;
        }
    } else {
        return false;
    }
    fclose($f);
    return true;
}