diff options
Diffstat (limited to 'lib/electricity_meter.cpp')
-rw-r--r-- | lib/electricity_meter.cpp | 346 |
1 files changed, 0 insertions, 346 deletions
diff --git a/lib/electricity_meter.cpp b/lib/electricity_meter.cpp deleted file mode 100644 index 01f5b76..0000000 --- a/lib/electricity_meter.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* **************************************************************************** - * electricity_meter.cpp -- méthodes de la classe `electricity_meter`. - * Copyright (C) 2018 Thomas Touhey <thomas@touhey.fr> - * - * This project is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/or redistribute the software under the terms of the - * CeCILL license as circulated by CEA, CNRS and INRIA at the - * following URL: "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the project's author, the holder of the - * economic rights, and the successive licensors have only limited liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also therefore - * means that it is reserved for developers and experienced professionals - * having in-depth computer knowledge. Users are therefore encouraged to load - * and test the software's suitability as regards their requirements in - * conditions enabling the security of their systems and/or data to be - * ensured and, more generally, to use and operate it in the same conditions - * as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * ************************************************************************* */ -#include "internals.hpp" - -using namespace wesh; - -/* --- - * Affichages des énumérations. - * --- */ - -std::ostream& operator<<(std::ostream& os, - electricity_meter_mode md) -{ - switch (md) { - case emm_conso: - os << "CONSO"; - break; - case emm_prod: - os << "PROD"; - break; - default: - os << "(unknown)"; - break; - } - - return (os); -} - -std::ostream& operator<<(std::ostream& os, - electricity_meter_subscription_type st) -{ - switch (st) { - case emst_base: - os << "BASE"; - break; - case emst_hchp: - os << "HCHP"; - break; - case emst_ejp: - os << "EJP"; - break; - case emst_tempo: - os << "TEMPO"; - break; - default: - os << "(unknown)"; - break; - } - - return (os); -} - -std::ostream& operator<<(std::ostream& os, - electricity_meter_subscription_period pd) -{ - switch (pd) { - case emsp_hn: - os << "HN/TH"; - break; - case emsp_hc: - os << "HC(JB)"; - break; - case emsp_hp: - os << "HP(JB)"; - break; - case emsp_pm: - os << "PM"; - break; - case emsp_hcjw: - os << "HCJW"; - break; - case emsp_hpjw: - os << "HPJW"; - break; - case emsp_hcjr: - os << "HCJR"; - break; - case emsp_hpjr: - os << "HPJR"; - break; - default: - os << "(unknown)"; - break; - } - - return (os); -} - -std::ostream& operator<<(std::ostream& os, - wesh::electricity_meter_subscription sb) -{ - switch (sb.type) { - case emst_base: switch (sb.period) { - case emsp_hn: - os << "BASE"; - break; - default: - os << "(unknown)"; - } break; - case emst_hchp: switch (sb.period) { - case emsp_hc: - os << "HCHC"; - break; - case emsp_hp: - os << "HCHP"; - break; - default: - os << "(unknown)"; - } break; - case emst_ejp: switch (sb.period) { - case emsp_hn: - os << "EJPHN"; - break; - case emsp_pm: - os << "EJPPM"; - break; - default: - os << "(unknown)"; - } break; - case emst_tempo: switch (sb.period) { - case emsp_hcjb: - os << "HCJB"; - break; - case emsp_hpjb: - os << "HPJB"; - break; - case emsp_hcjw: - os << "HCJW"; - break; - case emsp_hpjw: - os << "HPJW"; - break; - case emsp_hcjr: - os << "HCJR"; - break; - case emsp_hpjr: - os << "HPJR"; - break; - default: - os << "(unknown)"; - } break; - default: - os << "(unknown)"; - } - - return (os); -} - -std::ostream& operator<<(std::ostream& os, - electricity_meter_phase_mode pm) -{ - switch (pm) { - case empm_none: - os << "(none)"; - break; - case empm_mono: - os << "MONO"; - break; - case empm_tri: - os << "TRI"; - break; - default: - os << "(unknown)"; - break; - } - - return (os); -} - -/* --- - * Constructeur, destructeur. - * --- */ - -electricity_meter::electricity_meter(void) -{ - this->parent = nullptr; - this->num = -1; -} - -electricity_meter::electricity_meter(wes_base *parent_to_use, int num_to_use) -{ - /* FIXME: Vérifier si les arguments sont valides. */ - - this->parent = parent_to_use; - this->num = num_to_use; - - this->gather(); -} - -/* --- - * Récupération de l'objet. - * --- */ - -/* Remarque : l'absence de `default` dans les switch est volontaire. */ - -void electricity_meter::gather(void) -{ - wespid_with_tic_id_t args = { - static_cast<wespid_t>(this->parent->get_id()), - this->num}; - wespret_with_tic_t *resp; - - if (this->num < 0) - throw not_loaded_exception(); - - /* Requête au démon. */ - - resp = get_tic_1(&args, clnt(this->parent)); - if (!resp) - throw connexion_exception(); - - if (resp->ret != WESPRET_OK) - throw_exception_using_ret(resp->ret); - - this->is_read = resp->cfg.read; - this->name = std::string(resp->cfg.name); - - switch (resp->cfg.mode) { - case WESPTICMODE_CONSO: - this->mode = emm_conso; - break; - case WESPTICMODE_PROD: - this->mode = emm_prod; - break; - default: - throw daemon_exception(); - } - - switch (resp->data.tarif) { - case WESPTICTARIF_BASE: - this->subscription.type = emst_base; - this->subscription.period = emsp_hn; - break; - case WESPTICTARIF_HCHP: - this->subscription.type = emst_hchp; - switch (resp->data.period & ~(WESPTICPERIOD_JB | WESPTICPERIOD_JR)) { - case WESPTICPERIOD_HC: - this->subscription.period = emsp_hc; - break; - case WESPTICPERIOD_HP: - this->subscription.period = emsp_hp; - break; - default: - throw daemon_exception(); - } - break; - case WESPTICTARIF_EJP: - this->subscription.type = emst_ejp; - switch (resp->data.period) { - case WESPTICPERIOD_HN: - this->subscription.period = emsp_hn; - break; - case WESPTICPERIOD_PM: - this->subscription.period = emsp_pm; - break; - default: - throw daemon_exception(); - } - break; - case WESPTICTARIF_TEMPO: - this->subscription.type = emst_tempo; - switch (resp->data.period) { - case WESPTICPERIOD_HCJB: - this->subscription.period = emsp_hcjb; - break; - case WESPTICPERIOD_HPJB: - this->subscription.period = emsp_hpjb; - break; - case WESPTICPERIOD_HCJW: - this->subscription.period = emsp_hcjw; - break; - case WESPTICPERIOD_HPJW: - this->subscription.period = emsp_hpjw; - break; - case WESPTICPERIOD_HCJR: - this->subscription.period = emsp_hcjr; - break; - case WESPTICPERIOD_HPJR: - this->subscription.period = emsp_hpjr; - break; - default: - throw daemon_exception(); - } - break; - default: - throw daemon_exception(); - } - - switch (resp->data.phmode) { - case WESPTICPHMODE_NONE: - this->phase_mode = empm_none; - break; - case WESPTICPHMODE_MONO: - this->phase_mode = empm_mono; - break; - case WESPTICPHMODE_TRI: - this->phase_mode = empm_tri; - break; - default: - throw daemon_exception(); - } - - /* TODO: other values */ -} - -void electricity_meter::gather(wes_base *parent_now, int num_now) -{ - if (this->num >= 0) - throw not_loaded_exception(); - - /* FIXME: vérifier si les arguments sont valides. */ - - this->parent = parent_now; - this->num = num_now; - - this->gather(); -} - -/* TODO: electricity_meter::update() */ |