Commit 979d90da authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema Committed by Administrator
Browse files

Choose model

parent 7fe069b1
......@@ -56,14 +56,13 @@ int cmd_port = CONSOLE_DT_MODEL_CMD_PORT;
/************************************/
static int load_ini(void)
static int load_ini(char* active_name)
{
GKeyFile *keyfile;
gboolean loaded = false;
gchar *keyfilename[] = { "/etc/dt/dt_model.ini", "dt_model.ini" };
int ret = 0;
int i;
char *active_name = "none";
struct dt_model_params params = {};
keyfile = g_key_file_new();
......@@ -86,11 +85,14 @@ static int load_ini(void)
for (i = 0; i < groups_nr; i++) {
if (!strcmp(groups[i], "global")) {
if (g_key_file_has_key(keyfile, groups[i], "active", NULL)) {
if (active_name != NULL) {
// Specified as function argument, not reading from file
}
else if (g_key_file_has_key(keyfile, groups[i], "active", NULL)) {
active_name =
g_key_file_get_string(keyfile, groups[i], "active", NULL);
printf("Active params: '%s'\n", active_name);
}
printf("Active params: '%s'\n", active_name);
}
}
for (i = 0; i < groups_nr; i++) {
......@@ -148,12 +150,14 @@ static int load_ini(void)
/************************************/
static int handle_cmd(char *name, char *val)
static int handle_cmd(char *command)
{
printf("name %s value %s\n", name, val);
if (!strcmp(name, "reload")) {
log_send(LOG_T_WARNING, "Reloading ini file");
load_ini();
char *cmd_name, *cmd_value, *ptr;
cmd_name = strtok_r(command, " \n\t\r", &ptr);
cmd_value = strtok_r(NULL, " \n\t\r", &ptr);
if (!strcmp(cmd_name, "reload")) {
log_send(LOG_T_WARNING, "Reloading ini file with model %s", cmd_value);
load_ini(cmd_value);
}
return 0;
......@@ -194,7 +198,7 @@ int main(int argc, char **argv)
dt_model_init_server();
load_ini();
load_ini(NULL);
signal(SIGPIPE, SIG_IGN);
......@@ -202,7 +206,7 @@ int main(int argc, char **argv)
if (!cmd_srv) {
printf("Could not open listen port for commands\n");
} else {
command_server_handler_set(cmd_srv, handle_cmd);
command_server_handler_raw_set(cmd_srv, handle_cmd);
}
stat_srv = status_server_create(stat_port, 0, 100);
......
......@@ -47,6 +47,7 @@ function model(element_name) {
this.lbl_b = new dt_ui_element(element_name + "_lbl_b");
this.lbl_za = new dt_ui_element(element_name + "_lbl_za");
this.lbl_aa = new dt_ui_element(element_name + "_lbl_aa");
this.lbl_select = new dt_ui_element(element_name + "_lbl_select");
this.val_name = new dt_ui_value(element_name + "_val_name");
this.val_a0 = new dt_ui_value(element_name + "_val_a0");
......@@ -56,16 +57,20 @@ function model(element_name) {
this.val_b = new dt_ui_value(element_name + "_val_b");
this.val_za = new dt_ui_value(element_name + "_val_za");
this.val_aa = new dt_ui_value(element_name + "_val_aa");
this.select_model = new dt_ui_select(element_name + "_select_model");
this.button_reload = new dt_ui_button(element_name + "_reload");
this.window.add([
this.lbl_select,
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa,
this.select_model,
this.val_name, this.val_a0, this.val_c1, this.val_c2,
this.val_e0, this.val_b, this.val_za, this.val_aa,
this.button_reload]);
this.lbl_select.text_set("New model");
this.lbl_name.text_set("Model name");
this.lbl_a0.text_set("parameter a0");
this.lbl_c1.text_set("parameter c1");
......@@ -75,6 +80,8 @@ function model(element_name) {
this.lbl_za.text_set("parameter za");
this.lbl_aa.text_set("parameter aa");
this.select_model.option_add("2010-08", null);
this.select_model.option_add("zero_test", null);
this.val_name.value_set("???__Unknown_name__????");
this.val_a0.value_set("??.????????");
this.val_c1.value_set("??");
......@@ -84,19 +91,21 @@ function model(element_name) {
this.val_za.value_set("??");
this.val_aa.value_set("??");
this.button_reload.text_set("Reload");
this.button_reload.text_set("Load new model");
this.window.resize_equal([
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa]);
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa,
this.lbl_select]);
this.window.resize_equal([
this.val_name, this.val_a0, this.val_c1, this.val_c2,
this.val_e0, this.val_b, this.val_za, this.val_aa]);
this.val_e0, this.val_b, this.val_za, this.val_aa,
this.select_model]);
this.window.align_horizontal([this.lbl_name, this.val_name], 5);
this.window.align_vertical([
this.lbl_name, this.lbl_a0, this.lbl_c1, this.lbl_c2,
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa], 5);
this.lbl_e0, this.lbl_b, this.lbl_za, this.lbl_aa,
this.lbl_select], 5);
this.window.align_horizontal([this.lbl_a0, this.val_a0], 5);
this.window.align_horizontal([this.lbl_c1, this.val_c1], 5);
this.window.align_horizontal([this.lbl_c2, this.val_c2], 5);
......@@ -104,8 +113,10 @@ function model(element_name) {
this.window.align_horizontal([this.lbl_b, this.val_b], 5);
this.window.align_horizontal([this.lbl_za, this.val_za], 5);
this.window.align_horizontal([this.lbl_aa, this.val_aa], 5);
this.window.align_horizontal([this.lbl_select, this.select_model], 5);
this.window.align_vertical([this.lbl_aa, this.button_reload], 10);
this.window.align_horizontal([this.lbl_name, this.val_name], 5);
this.window.align_vertical([this.lbl_select, this.button_reload], 10);
this.status = new status("dummy mode", "dt_model");
......@@ -158,7 +169,9 @@ function model(element_name) {
this.button_reload.onclick = function(elem )
{
model_this.command.send("reload=1")
var select_elem = model_this.select_model.element;
var new_model_name = select_elem.options[select_elem.selectedIndex].value;
model_this.command.send("reload " + new_model_name)
}
this.window.hide();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment