Progressive refinement

r1199 | dcl | 2006-10-26 18:38:34 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
Douglas Clowes
2006-10-26 18:38:34 +10:00
parent 7dfa37057b
commit 4623b25ccd
8 changed files with 261 additions and 172 deletions

View File

@@ -17,6 +17,7 @@
#define CMD_RANGE_MODE 12
#define CMD_OUTPUT 13
#define CMD_SYNC 14
#define CMD_SOURCE 15
#define TXT_DIRECTION "DIRECTION"
#define TXT_SCAN "SCAN"
@@ -32,6 +33,7 @@
#define TXT_RANGE_MODE "RANGE_MODE"
#define TXT_OUTPUT "OUTPUT"
#define TXT_SYNC "SYNC"
#define TXT_SOURCE "SOURCE"
static struct param_command_t {
int cmd;
@@ -51,9 +53,10 @@ static struct param_command_t {
{CMD_RANGE_MODE, TXT_RANGE_MODE},
{CMD_OUTPUT, TXT_OUTPUT},
{CMD_SYNC, TXT_SYNC},
{CMD_SOURCE, TXT_SOURCE},
{0, NULL}
};
#define NUM_CMDS (sizeof(param_command)/sizeof(param_command[0]))
#define NUM_CMDS ((int) ((sizeof(param_command)/sizeof(param_command[0]))))
static int name_to_command(char* name)
{
@@ -74,22 +77,22 @@ bool param_set(pPARAMETERS pp, char* name, char* value)
{
case CMD_DIRECTION:
result = true;
dprintf(0, "Direction=%s", pp->direction ? "Down" : "Up");
dbg_printf(0, "Direction=%s", pp->direction ? "Down" : "Up");
if (strcasecmp(value, "down") == 0)
pp->direction = COUNT_DOWN;
else
pp->direction = COUNT_UP;
dprintf(0, "=>%s\n", pp->direction ? "Down" : "Up");
dbg_printf(0, "=>%s\n", pp->direction ? "Down" : "Up");
break;
case CMD_INITIAL:
result = true;
dprintf(0, "Initial=%llu", pp->initial_count);
dbg_printf(0, "Initial=%llu", pp->initial_count);
pp->initial_count = strtoull(value, NULL, 10);
dprintf(0, "=>%llu\n", pp->initial_count);
dbg_printf(0, "=>%llu\n", pp->initial_count);
break;
case CMD_OUTPUT:
result = true;
dprintf(0, "Direction=%s", pp->output_line == 2 ? "Inverted":
dbg_printf(0, "Output=%s", pp->output_line == 2 ? "Inverted":
pp->output_line == 1 ? "Enabled" : "Disabled");
if (strcasecmp(value, "enabled") == 0)
pp->output_line = 1;
@@ -97,105 +100,115 @@ bool param_set(pPARAMETERS pp, char* name, char* value)
pp->output_line = 2;
else
pp->output_line = 0;
dprintf(0, "=>%s\n", pp->output_line == 2 ? "Inverted":
dbg_printf(0, "=>%s\n", pp->output_line == 2 ? "Inverted":
pp->output_line == 1 ? "Enabled" : "Disabled");
break;
case CMD_REPORT:
result = true;
dprintf(0, "Report=%d", pp->report_period);
dbg_printf(0, "Report=%d", pp->report_period);
pp->report_period = strtol(value, NULL, 10);
if (pp->report_period < 1)
pp->report_period = 1;
else if (pp->report_period > 1000)
pp->report_period = 1000;
dprintf(0, "=>%d\n", pp->report_period);
dbg_printf(0, "=>%d\n", pp->report_period);
break;
case CMD_RANGE_MODE:
result = true;
dprintf(0, "range_mode=%d", pp->range_mode);
dbg_printf(0, "range_mode=%d", pp->range_mode);
pp->range_mode = strtol(value, NULL, 10);
if (pp->range_mode < 0)
pp->range_mode = 0;
else if (pp->range_mode > 2)
pp->range_mode = 0;
dprintf(0, "=>%d\n", pp->range_mode);
dbg_printf(0, "=>%d\n", pp->range_mode);
break;
case CMD_RANGE_GATE:
result = true;
dprintf(0, "range_gate=%s",
dbg_printf(0, "range_gate=%s",
pp->range_gate_enable ? "Enabled" : "Disabled");
if (strcasecmp(value, "enabled") == 0)
pp->range_gate_enable = true;
else
pp->range_gate_enable = false;
dprintf(0, "=>%s\n",
dbg_printf(0, "=>%s\n",
pp->range_gate_enable ? "Enabled" : "Disabled");
break;
case CMD_RE_CHECK:
result = true;
dprintf(0, "RE_Check=%s",
dbg_printf(0, "RE_Check=%s",
pp->range_check_enable ? "Enabled" : "Disabled");
if (strcasecmp(value, "enabled") == 0)
pp->range_check_enable = true;
else
pp->range_check_enable = false;
dprintf(0, "=>%s\n",
dbg_printf(0, "=>%s\n",
pp->range_check_enable ? "Enabled" : "Disabled");
break;
case CMD_RANGE_HIGH:
result = true;
dprintf(0, "RangeHigh=%g", pp->range_high);
dbg_printf(0, "RangeHigh=%g", pp->range_high);
pp->range_high = strtod(value, NULL);
if (pp->range_high < 0.0)
pp->range_high = 0.0;
dprintf(0, "=>%g\n", pp->range_high);
dbg_printf(0, "=>%g\n", pp->range_high);
break;
case CMD_RANGE_LOW:
result = true;
dprintf(0, "RangeLow=%g", pp->range_low);
dbg_printf(0, "RangeLow=%g", pp->range_low);
pp->range_low = strtod(value, NULL);
if (pp->range_low < 0.0)
pp->range_low = 0.0;
dprintf(0, "=>%g\n", pp->range_low);
break;
case CMD_SCAN:
result = true;
dprintf(0, "Scan=%d", pp->poll_period);
pp->poll_period = strtol(value, NULL, 10);
if (pp->poll_period < 1)
pp->poll_period = 1;
else if (pp->poll_period > 1000)
pp->poll_period = 1000;
dprintf(0, "=>%d\n", pp->poll_period);
dbg_printf(0, "=>%g\n", pp->range_low);
break;
case CMD_SAMPLE:
result = true;
dprintf(0, "Sample=%d", pp->sample_period);
dbg_printf(0, "Sample=%d", pp->sample_period);
pp->sample_period = strtol(value, NULL, 10);
if (pp->sample_period < 1)
pp->sample_period = 1;
else if (pp->sample_period > 1000)
pp->sample_period = 1000;
dprintf(0, "=>%d\n", pp->sample_period);
dbg_printf(0, "=>%d\n", pp->sample_period);
break;
case CMD_SCAN:
result = true;
dbg_printf(0, "Scan=%d", pp->poll_period);
pp->poll_period = strtol(value, NULL, 10);
if (pp->poll_period < 1)
pp->poll_period = 1;
else if (pp->poll_period > 1000)
pp->poll_period = 1000;
dbg_printf(0, "=>%d\n", pp->poll_period);
break;
case CMD_SOURCE:
result = true;
dbg_printf(0, "Source=%d", pp->source);
pp->source = strtol(value, NULL, 10);
if (pp->source < 1)
pp->source = 0;
else if (pp->source > 1000)
pp->source = 0;
dbg_printf(0, "=>%d\n", pp->source);
break;
case CMD_SYNC:
result = true;
dprintf(0, "Sync=%s", pp->sync ? "External" : "Internal");
dbg_printf(0, "Sync=%s", pp->sync ? "External" : "Internal");
if (strcasecmp(value, "external") == 0)
pp->sync = true;
else
pp->sync = false;
dprintf(0, "=>%s\n", pp->sync ? "External" : "Internal");
dbg_printf(0, "=>%s\n", pp->sync ? "External" : "Internal");
break;
case CMD_TERMINAL:
result = true;
dprintf(0, "Sample=%llu", pp->terminal_count);
dbg_printf(0, "Terminal=%llu", pp->terminal_count);
pp->terminal_count = strtoull(value, NULL, 10);
dprintf(0, "=>%llu\n", pp->terminal_count);
dbg_printf(0, "=>%llu\n", pp->terminal_count);
break;
case CMD_TE_CHECK:
result = true;
dprintf(0, "TE_Check=%s",
dbg_printf(0, "TE_Check=%s",
pp->terminal_check_type == 0 ? "None" :
pp->terminal_check_type == 1 ? "Counter" :
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
@@ -205,13 +218,13 @@ bool param_set(pPARAMETERS pp, char* name, char* value)
pp->terminal_check_type = 2;
else
pp->terminal_check_type = 0;
dprintf(0, "=>%s\n",
dbg_printf(0, "=>%s\n",
pp->terminal_check_type == 0 ? "None" :
pp->terminal_check_type == 1 ? "Counter" :
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
break;
default:
dprintf(0, "Unknown Parameter: \"%s\" = \"%s\"\n", name, value);
dbg_printf(0, "Unknown Parameter: \"%s\" = \"%s\"\n", name, value);
break;
}
return result;
@@ -328,17 +341,29 @@ bool param_get_cmd(pPARAMETERS pp, char* cmd, int n)
"GET %s=%g", name,
pp->range_low);
break;
case CMD_SAMPLE:
result = true;
snprintf(buffer.body, sizeof(buffer.body),
"GET %s=%d", name,
pp->sample_period);
break;
case CMD_SCAN:
result = true;
snprintf(buffer.body, sizeof(buffer.body),
"GET %s=%d", name,
pp->poll_period);
break;
case CMD_SAMPLE:
case CMD_SOURCE:
result = true;
snprintf(buffer.body, sizeof(buffer.body),
"GET %s=%d", name,
pp->sample_period);
pp->source);
break;
case CMD_SYNC:
result = true;
snprintf(buffer.body, sizeof(buffer.body),
"GET %s=%s", name,
pp->sync ? "External" : "Internal");
break;
case CMD_TERMINAL:
result = true;
@@ -364,7 +389,7 @@ bool param_get_cmd(pPARAMETERS pp, char* cmd, int n)
result = true;
}
else
dprintf(0, "Unknown GET Parameter: \"%s\"\n", name);
dbg_printf(0, "Unknown GET Parameter: \"%s\"\n", name);
break;
}
if (!result)