Skip to content

Commit

Permalink
DMX: Migrate to SubProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaru committed Jan 1, 2022
1 parent 84697cc commit 3125107
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 184 deletions.
271 changes: 153 additions & 118 deletions Watchdogd/Dmx/Dmx.c

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Watchdogd/Dmx/Dmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
DMX_Send_RDM_Discovery_Request = 11,
};

#define DMX_RETRY 100 /* 10 secondes entre chaque retry si pb de connexion */
#define DMX_RETRY_DELAI 100 /* 10 secondes entre chaque retry si pb de connexion */
#define DMX_CHANNEL 512

struct TRAME_DMX /* Definition d'une trame DMX */
Expand All @@ -60,13 +60,10 @@
guchar end_delimiter; /* (0xE7). Ne pas oublier le end_delimiter en fin de trame ! */
};

struct DMX_CONFIG /* Communication entre DLS et la DMX */
{ struct PROCESS *lib;
gchar tech_id[32]; /* Tech_id du module DMX */
gchar device[128]; /* Nom du device USB associé au canal DMX */
gint nbr_request; /* Nombre de requete par seconde */
struct DMX_VARS /* Communication entre DLS et la DMX */
{ gint nbr_request; /* Nombre de requete par seconde */
gint fd; /* File Descriptor d'accès au port USB DMX */
gboolean comm_status;
gint date_next_retry; /* Date de reconnexion */
struct DLS_AO Canal[DMX_CHANNEL]; /* Tableau dynamique d'accès aux bits internes */
gint taille_trame_dmx;
struct TRAME_DMX Trame_dmx;
Expand Down
75 changes: 30 additions & 45 deletions Watchdogd/Dmx/admin_dmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,43 @@

#include "watchdogd.h"
#include "Dmx.h"
extern struct DMX_CONFIG Cfg_dmx;

/******************************************************************************************************************************/
/* Admin_json_list : fonction appelée pour lister les modules dmx */
/* Entrée : les adresses d'un buffer json et un entier pour sortir sa taille */
/* Sortie : les parametres d'entrée sont mis à jour */
/* Admin_config : fonction appelé par le thread http lors d'une requete POST sur config PROCESS */
/* Entrée : la librairie, et le Json recu */
/* Sortie : la base de données est mise à jour */
/******************************************************************************************************************************/
static void Admin_json_dmx_status ( struct PROCESS *Lib, SoupMessage *msg )
{ if (msg->method != SOUP_METHOD_GET)
{ soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
return;
}
/************************************************ Préparation du buffer JSON **************************************************/
JsonNode *RootNode = Json_node_create ();
if (RootNode == NULL)
{ Info_new( Config.log, Lib->Thread_debug, LOG_ERR, "%s : JSon RootNode creation failed", __func__ );
soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "Memory Error");
void Admin_config ( struct PROCESS *lib, gpointer msg, JsonNode *request )
{ if ( ! (Json_has_member ( request, "uuid" ) && Json_has_member ( request, "tech_id" ) && Json_has_member ( request, "description" ) &&
Json_has_member ( request, "device" )
) )
{ soup_message_set_status_full (msg, SOUP_STATUS_BAD_REQUEST, "Mauvais parametres");
return;
}

Json_node_add_bool ( RootNode, "thread_is_running", Lib->Thread_run );

if (Lib->Thread_run) /* Warning : Cfg_smsg does not exist if thread is not running ! */
{ Json_node_add_string ( RootNode, "tech_id", Cfg_dmx.tech_id );
Json_node_add_string ( RootNode, "device", Cfg_dmx.device );
Json_node_add_int ( RootNode, "nbr_request", Cfg_dmx.nbr_request );
Json_node_add_int ( RootNode, "taille_trame_dmx", Cfg_dmx.taille_trame_dmx );
Json_node_add_bool ( RootNode, "comm", Cfg_dmx.comm_status );
gchar *uuid = Normaliser_chaine ( Json_get_string( request, "uuid" ) );
gchar *tech_id = Normaliser_chaine ( Json_get_string( request, "tech_id" ) );
gchar *description = Normaliser_chaine ( Json_get_string( request, "description" ) );
gchar *device = Normaliser_chaine ( Json_get_string( request, "device" ) );

if (Cfg_dmx.Canal)
{ for (gint cpt=0; cpt<64; cpt++)
{ gchar canal[12];
g_snprintf( canal, sizeof(canal), "canal_%d", cpt+1 );
Json_node_add_int ( RootNode, canal, Cfg_dmx.Trame_dmx.channel[cpt] ); /*Canal[cpt].val_avant_ech );*/
}
}
if (Json_has_member ( request, "id" ))
{ SQL_Write_new ( "UPDATE %s SET uuid='%s', tech_id='%s', description='%s', device='%s' "
"WHERE id='%d'",
lib->name, uuid, tech_id, description, device,
Json_get_int ( request, "id" ) );
Info_new( Config.log, lib->Thread_debug, LOG_NOTICE, "%s: subprocess '%s/%s' updated.", __func__, uuid, tech_id );
}
gchar *buf = Json_node_to_string ( RootNode );
json_node_unref(RootNode);
/*************************************************** Envoi au client **********************************************************/
soup_message_set_status (msg, SOUP_STATUS_OK);
soup_message_set_response ( msg, "application/json; charset=UTF-8", SOUP_MEMORY_TAKE, buf, strlen(buf) );
}
/******************************************************************************************************************************/
/* Admin_json : fonction appelé par le thread http lors d'une requete /run/ */
/* Entrée : les adresses d'un buffer json et un entier pour sortir sa taille */
/* Sortie : les parametres d'entrée sont mis à jour */
/******************************************************************************************************************************/
void Admin_json ( struct PROCESS *lib, SoupMessage *msg, const char *path, GHashTable *query, gint access_level )
{ if (access_level < 6)
{ soup_message_set_status_full (msg, SOUP_STATUS_FORBIDDEN, "Pas assez de privileges");
return;
else
{ SQL_Write_new ( "INSERT INTO %s SET uuid='%s', tech_id='%s', description='%s', device='%s'",
lib->name, uuid, tech_id, description, device );
Info_new( Config.log, lib->Thread_debug, LOG_NOTICE, "%s: subprocess '%s/%s' created.", __func__, uuid, tech_id );
}
if (!strcasecmp(path, "/status")) { Admin_json_dmx_status ( lib, msg ); }

g_free(uuid);
g_free(tech_id);
g_free(description);
g_free(device);

soup_message_set_status (msg, SOUP_STATUS_OK);
}
/*----------------------------------------------------------------------------------------------------------------------------*/
1 change: 0 additions & 1 deletion Watchdogd/Include/watchdogd.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
extern void Thread_init ( gchar *pr_name, gchar *classe, struct PROCESS *lib, gchar *version, gchar *description );
extern void Thread_end ( struct PROCESS *lib );
extern JsonNode *Thread_Listen_to_master ( struct PROCESS *lib );
extern void Thread_send_comm_to_master ( struct PROCESS *lib, gboolean etat );
extern JsonNode *SubProcess_Listen_to_master_new ( struct SUBPROCESS *module );
extern void SubProcess_send_comm_to_master_new ( struct SUBPROCESS *module, gboolean etat );
extern void Process_Load_one_subprocess (JsonArray *array, guint index_, JsonNode *element, gpointer user_data );
Expand Down
2 changes: 1 addition & 1 deletion Watchdogd/TeleinfoEDF/Teleinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
{ vars->mode = TINFO_RETRING;
vars->date_next_retry = 0;
vars->nbr_connexion = 0;
Info_new( Config.log, module->lib->Thread_debug, LOG_NOTICE, "%s: Retrying Connexion.", __func__ );
Info_new( Config.log, module->lib->Thread_debug, LOG_NOTICE, "%s: %s: Retrying Connexion.", __func__, tech_id );
}
}
else if (vars->mode == TINFO_RETRING)
Expand Down
12 changes: 0 additions & 12 deletions Watchdogd/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@
/* Thread_send_comm_to_master: appelé par chaque thread pour envoyer le statut de la comm au master */
/* Entrée: La structure afférente */
/* Sortie: aucune */
/******************************************************************************************************************************/
void Thread_send_comm_to_master ( struct PROCESS *lib, gboolean etat )
{ if (lib->comm_status != etat || lib->comm_next_update <= Partage->top)
{ Zmq_Send_WATCHDOG_to_master ( lib, lib->name, "IO_COMM", 900 );
lib->comm_next_update = Partage->top + 600; /* Toutes les minutes */
lib->comm_status = etat;
}
}
/******************************************************************************************************************************/
/* Thread_send_comm_to_master: appelé par chaque thread pour envoyer le statut de la comm au master */
/* Entrée: La structure afférente */
/* Sortie: aucune */
/******************************************************************************************************************************/
void SubProcess_send_comm_to_master_new ( struct SUBPROCESS *module, gboolean etat )
{ if (module->comm_status != etat || module->comm_next_update <= Partage->top)
Expand Down

0 comments on commit 3125107

Please sign in to comment.