aboutsummaryrefslogtreecommitdiff
path: root/daemon/dummy/if.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/dummy/if.c')
-rw-r--r--daemon/dummy/if.c195
1 files changed, 98 insertions, 97 deletions
diff --git a/daemon/dummy/if.c b/daemon/dummy/if.c
index a2a2650..3b2ed71 100644
--- a/daemon/dummy/if.c
+++ b/daemon/dummy/if.c
@@ -48,14 +48,12 @@ static int free_dummy_wes(wes_t *wes)
/* `add_dummy_wes()`: créer une ressource factice. */
-int add_dummy_wes(weslist_t *list, wes_t **wesp, wescreatedata_t *data)
+int add_dummy_wes(weslist_t *list, wes_t **wesp)
{
wes_t *wes;
char dummyname[20];
int err;
- (void)data;
-
/* Allocation de la ressource. */
wes = malloc(sizeof(wes_t));
@@ -81,121 +79,117 @@ int add_dummy_wes(weslist_t *list, wes_t **wesp, wescreatedata_t *data)
}
/* ---
- * Interactions avec l'heure du faux serveur WES (heure locale).
+ * Interactions avec la configuration du faux serveur WES (heure locale).
* --- */
-static int setfakename(wes_t *wes, const char *name)
-{
- /* En fait, on n'a pas d'appareil distant sur lequel définir le nom,
- * donc du coup c'est bon directement. Le serveur va se charger
- * de définir le nom dans la base de la ressource. */
-
- (void)wes;
- (void)name;
-
- return (WROK);
-}
+/* `getfakecfg()`: Récupération de la configuration depuis le serveur
+ * WES factice. */
-static int getfaketime(wes_t *wes, westime_object_t **dtp)
+static int getfakecfg(wes_t *wes, wescfgflags_t flags, wescfg_t **cfgp)
{
- static westime_object_t dt;
- time_t tp;
- struct tm *tm;
+ static wescfg_t cfg;
+ wesdt_t *dt;
+ time_t tp; struct tm *tm;
(void)wes;
+ (void)flags;
- /* Récupération de la représentation déconstruite du temps. */
+ /* Récupération de l'heure. */
time(&tp);
tm = gmtime(&tp);
- /* Sauvegarde de l'heure */
-
- dt.cfg.dt.year = tm->tm_year + 1900;
- dt.cfg.dt.mon = tm->tm_mon + 1;
- dt.cfg.dt.dom = tm->tm_mday;
- dt.cfg.dt.hour = tm->tm_hour;
- dt.cfg.dt.min = tm->tm_min;
- dt.cfg.dt.sec = tm->tm_sec;
- dt.cfg.dt.dow = tm->tm_wday ? tm->tm_wday - 1 : 6;
- dt.cfg.dt.sum = tm->tm_isdst;
- dt.cfg.dt.tzhour = 0;
- dt.cfg.dt.tzmin = 0;
+ /* Remplissage de la configuration.
+ * Le nom est rempli par le serveur. */
+
+ cfg.free = NULL;
+ dt = &cfg.current_time;
+ dt->year = tm->tm_year + 1900;
+ dt->mon = tm->tm_mon + 1;
+ dt->dom = tm->tm_mday;
+ dt->hour = tm->tm_hour;
+ dt->min = tm->tm_min;
+ dt->sec = tm->tm_sec;
+ dt->dow = tm->tm_wday ? tm->tm_wday - 1 : 6;
+ dt->sum = tm->tm_isdst;
+ dt->tzhour = 0;
+ dt->tzmin = 0;
/* On est bons ! */
- *dtp = &dt;
+ *cfgp = &cfg;
+ return (WROK);
+}
+
+/* `setfakecfg()`: application de la configuration sur le serveur
+ * WES factice. */
+
+static int setfakecfg(wes_t *wes, wescfgflags_t flags, wescfg_t const *cfg)
+{
+ /* On accepte direct, histoire que le nom soit accepté et que
+ * le reste de la configuration aussi, bien que rien de plus que
+ * le nom ne sera modifié. */
+
+ (void)wes;
+ (void)flags;
+ (void)cfg;
+
return (WROK);
}
/* ---
- * Interactions avec le faux compteur branché via TÉLÉINFO.
+ * Interactions avec les (faux) compteurs du WES factice.
* --- */
-static int getfaketic(wes_t *wes, int id, westic_object_t **ticp)
+/* Les compteurs simulés pour le WES factices sont les suivants :
+ * [1] Compteur branché via télé-information. */
+
+/* `getfakemeter()`: Récupération des données d'un compteur du serveur
+ * WES factice. */
+
+static int getfakemeter(wes_t *wes, int id, wesmetertype_t expected,
+ wesmeterflags_t flags, wesmetercfg_t **cfgp)
{
- static westic_object_t tic;
+ static wesmetercfg_t cfg;
static char name[20];
(void)wes;
+ (void)flags;
- if (id < 0 || id > 1)
+ if (id != 1 || expected != WESMETERTYPE_TELEINFO)
return (WROP);
- tic.free = NULL;
-
- sprintf(name, "Faux compteur #%d", id + 1);
- tic.cfg.name = name;
- tic.cfg.is_read = 1;
- tic.cfg.mode = id ? WESMODE_PROD : WESMODE_CONSO;
- tic.cfg.abo = 0.0;
- tic.cfg.prorata = 0;
-
- tic.cfg.tarif_base = 0.0;
- tic.cfg.tarif_hchp_hc = 0.0;
- tic.cfg.tarif_hchp_hp = 0.0;
- tic.cfg.tarif_ejp_hn = 0.0;
- tic.cfg.tarif_ejp_pm = 0.0;
- tic.cfg.tarif_tempo_hcjb = 0.0;
- tic.cfg.tarif_tempo_hpjb = 0.0;
- tic.cfg.tarif_tempo_hcjw = 0.0;
- tic.cfg.tarif_tempo_hpjw = 0.0;
- tic.cfg.tarif_tempo_hcjr = 0.0;
- tic.cfg.tarif_tempo_hpjr = 0.0;
-
- tic.cfg.bdpv_enabled = 0;
- tic.cfg.bdpv_hour = 2;
- tic.cfg.bdpv_min = 30;
-
- tic.data.is_plugged_in = 1;
- tic.data.is_standing_by = 0;
- memcpy(tic.data.adco, "\1\0\1\0\1\0\1\0\1\0\1\0", 12);
- tic.data.phases = 1;
- tic.data.tarif = WESTICTARIF_BASE;
- tic.data.period = WESTICPERIOD_HN;
-
- tic.data.isousc = 45;
- tic.data.pa = 9000;
- tic.data.iinst[0] = 2;
- tic.data.iinst[1] = 0;
- tic.data.iinst[2] = 0;
- tic.data.imax[0] = 5;
- tic.data.imax[1] = 0;
- tic.data.imax[2] = 0;
-
- tic.data.index_base = 624;
- tic.data.index_hchp_hc = 0;
- tic.data.index_hchp_hp = 0;
- tic.data.index_ejp_hn = 0;
- tic.data.index_ejp_pm = 0;
- tic.data.index_tempo_hcjb = 0;
- tic.data.index_tempo_hpjb = 0;
- tic.data.index_tempo_hcjw = 0;
- tic.data.index_tempo_hpjw = 0;
- tic.data.index_tempo_hcjr = 0;
- tic.data.index_tempo_hpjr = 0;
-
- *ticp = &tic;
+ cfg.free = NULL;
+
+ strcpy(name, "Faux compteur TIC");
+ cfg.name = name;
+ cfg.type = WESMETERTYPE_TELEINFO;
+ cfg.is_read = 1;
+ cfg.mode = WESMETERMODE_CONSO;
+ cfg.what = WESMETERWHAT_ELEC;
+
+ cfg.fixed_cost = 0.0;
+ cfg.prorata = 0;
+
+ cfg.more.teleinfo.cost_base_th = 0;
+ cfg.more.teleinfo.cost_hchp_hc = 0;
+ cfg.more.teleinfo.cost_hchp_hp = 0;
+ cfg.more.teleinfo.cost_tempo_hcjb = 0;
+ cfg.more.teleinfo.cost_tempo_hpjb = 0;
+ cfg.more.teleinfo.cost_tempo_hcjw = 0;
+ cfg.more.teleinfo.cost_tempo_hpjw = 0;
+ cfg.more.teleinfo.cost_tempo_hcjr = 0;
+ cfg.more.teleinfo.cost_tempo_hpjr = 0;
+ cfg.more.teleinfo.cost_ejp_hn = 0;
+ cfg.more.teleinfo.cost_ejp_pm = 0;
+
+ cfg.more.teleinfo.bdpv_enabled = 0;
+ cfg.more.teleinfo.bdpv_hour = 23;
+ cfg.more.teleinfo.bdpv_min = 45;
+ cfg.more.teleinfo.bdpv_username = "user.bdpv";
+ cfg.more.teleinfo.bdpv_password = "pw.bdpv";
+
+ *cfgp = &cfg;
return (WROK);
}
@@ -204,10 +198,17 @@ static int getfaketic(wes_t *wes, int id, westic_object_t **ticp)
* --- */
static wesif_t dumif = {
- free_dummy_wes,
- setfakename,
- NULL,
- getfaketime, NULL,
- NULL, NULL,
- getfaketic, NULL
+ WESTYPE_DUMMY, free_dummy_wes,
+
+ /* Interaction avec la configuration. */
+
+ getfakecfg, setfakecfg,
+
+ /* Interaction avec les compteurs. */
+
+ getfakemeter, NULL, NULL,
+
+ /* Listage des compteurs. */
+
+ NULL, NULL, NULL, NULL
};