gtdc/tdc_store.c

64 lines
1.1 KiB
C
Raw Normal View History

2008-03-17 18:36:41 +01:00
#include <stdio.h>
2008-03-18 19:30:21 +01:00
#include <stdlib.h>
2008-03-17 18:36:41 +01:00
#include <string.h>
#include "tdc_store.h"
2008-03-18 19:30:21 +01:00
#include "tdc_variable.h"
2008-03-17 21:16:52 +01:00
2008-03-18 19:30:21 +01:00
#include "gui_variable_tab.h"
2008-03-17 21:16:52 +01:00
2008-03-18 19:30:21 +01:00
static char *boardname[8];
static struct tdc_var *varmap[256];
2008-03-17 21:16:52 +01:00
2008-03-18 19:30:21 +01:00
void tdcstore_set_name(int address, char *name)
2008-03-17 21:40:12 +01:00
{
2008-03-18 19:30:21 +01:00
if (boardname[address & 0x7] != NULL)
free(boardname[address & 0x7]);
2008-03-17 21:40:12 +01:00
2008-03-18 19:30:21 +01:00
boardname[address & 0x7] = strdup(name);
printf("ADDR%d:%s\n", address, boardname[address & 0x7]);
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
char * tdcstore_get_name(int address)
2008-03-17 18:36:41 +01:00
{
2008-03-18 19:30:21 +01:00
return boardname[address & 0x7];
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
int tdcstore_set_var(int address, struct tdc_var *var)
2008-03-17 18:36:41 +01:00
{
2008-03-18 19:30:21 +01:00
if (varmap[var->id] != NULL) {
gui_vartab_remove_var(var);
tdcvar_destroy(varmap[var->id]);
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
varmap[var->id] = var;
gui_vartab_add_var(var);
2008-03-17 18:36:41 +01:00
2008-03-18 19:30:21 +01:00
return 0;
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
struct tdc_var * tdcstore_get_var(int address, int id)
2008-03-17 18:36:41 +01:00
{
2008-03-18 19:30:21 +01:00
return varmap[id & 0xFF];
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
void tdcstore_trigger_update(int address, int id)
2008-03-17 18:36:41 +01:00
{
2008-03-18 19:30:21 +01:00
gui_vartab_update_var(varmap[id & 0xFF]);
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
void tdcstore_flush(void)
2008-03-17 18:36:41 +01:00
{
int i;
2008-03-18 19:30:21 +01:00
for (i = 0; i < 8; i++) {
free(boardname[i]);
boardname[i] = NULL;
2008-03-17 18:36:41 +01:00
}
2008-03-18 19:30:21 +01:00
for (i = 0; i < 256; i++) {
gui_vartab_remove_var(varmap[i]);
tdcvar_destroy(varmap[i]);
varmap[i] = NULL;
2008-03-17 18:36:41 +01:00
}
}