Add output line drive and partial hardware sync
r1112 | dcl | 2006-09-07 16:48:08 +1000 (Thu, 07 Sep 2006) | 2 lines
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#define CMD_RE_CHECK 10
|
||||
#define CMD_RANGE_GATE 11
|
||||
#define CMD_RANGE_MODE 12
|
||||
#define CMD_OUTPUT 13
|
||||
#define CMD_SYNC 14
|
||||
|
||||
#define TXT_DIRECTION "DIRECTION"
|
||||
#define TXT_SCAN "SCAN"
|
||||
@@ -28,6 +30,8 @@
|
||||
#define TXT_RE_CHECK "RE_CHECK"
|
||||
#define TXT_RANGE_GATE "RANGE_GATE"
|
||||
#define TXT_RANGE_MODE "RANGE_MODE"
|
||||
#define TXT_OUTPUT "OUTPUT"
|
||||
#define TXT_SYNC "SYNC"
|
||||
|
||||
static struct param_command_t {
|
||||
int cmd;
|
||||
@@ -45,156 +49,166 @@ static struct param_command_t {
|
||||
{CMD_RE_CHECK, TXT_RE_CHECK},
|
||||
{CMD_RANGE_GATE, TXT_RANGE_GATE},
|
||||
{CMD_RANGE_MODE, TXT_RANGE_MODE},
|
||||
{CMD_OUTPUT, TXT_OUTPUT},
|
||||
{CMD_SYNC, TXT_SYNC},
|
||||
{0, NULL}
|
||||
};
|
||||
#define NUM_CMDS (sizeof(param_command)/sizeof(param_command[0]))
|
||||
|
||||
static int name_to_command(char* name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < NUM_CMDS; ++i) {
|
||||
if (param_command[i].txt == NULL)
|
||||
return -1;
|
||||
if (strcasecmp(name, param_command[i].txt) == 0)
|
||||
return param_command[i].cmd;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool param_set(pPARAMETERS pp, char* name, char* value)
|
||||
{
|
||||
bool result = false;
|
||||
switch (name[0])
|
||||
switch (name_to_command(name))
|
||||
{
|
||||
case 'd':
|
||||
case 'D':
|
||||
if (strcasecmp(name, TXT_DIRECTION) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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");
|
||||
}
|
||||
case CMD_DIRECTION:
|
||||
result = true;
|
||||
dprintf(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");
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (strcasecmp(name, TXT_INITIAL) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(0, "Initial=%llu", pp->initial_count);
|
||||
pp->initial_count = strtoull(value, NULL, 10);
|
||||
dprintf(0, "=>%llu\n", pp->initial_count);
|
||||
}
|
||||
case CMD_INITIAL:
|
||||
result = true;
|
||||
dprintf(0, "Initial=%llu", pp->initial_count);
|
||||
pp->initial_count = strtoull(value, NULL, 10);
|
||||
dprintf(0, "=>%llu\n", pp->initial_count);
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (strcasecmp(name, TXT_REPORT) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_MODE) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_GATE) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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",
|
||||
pp->range_gate_enable ? "Enabled" : "Disabled");
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RE_CHECK) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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",
|
||||
pp->range_check_enable ? "Enabled" : "Disabled");
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_HIGH) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_LOW) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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);
|
||||
}
|
||||
case CMD_OUTPUT:
|
||||
result = true;
|
||||
dprintf(0, "Direction=%s", pp->output_line == 2 ? "Inverted":
|
||||
pp->output_line == 1 ? "Enabled" : "Disabled");
|
||||
if (strcasecmp(value, "enabled") == 0)
|
||||
pp->output_line = 1;
|
||||
else if (strcasecmp(value, "inverted") == 0)
|
||||
pp->output_line = 2;
|
||||
else
|
||||
pp->output_line = 0;
|
||||
dprintf(0, "=>%s\n", pp->output_line == 2 ? "Inverted":
|
||||
pp->output_line == 1 ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
if (strcasecmp(name, TXT_SCAN) == 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_SAMPLE) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(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);
|
||||
}
|
||||
case CMD_REPORT:
|
||||
result = true;
|
||||
dprintf(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);
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
if (strcasecmp(name, TXT_TERMINAL) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(0, "Sample=%llu", pp->terminal_count);
|
||||
pp->terminal_count = strtoull(value, NULL, 10);
|
||||
dprintf(0, "=>%llu\n", pp->terminal_count);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_TE_CHECK) == 0)
|
||||
{
|
||||
result = true;
|
||||
dprintf(0, "TE_Check=%s",
|
||||
pp->terminal_check_type == 0 ? "None" :
|
||||
pp->terminal_check_type == 1 ? "Counter" :
|
||||
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
|
||||
if (strcasecmp(value, "counter") == 0)
|
||||
pp->terminal_check_type = 1;
|
||||
else if (strcasecmp(value, "timer") == 0)
|
||||
pp->terminal_check_type = 2;
|
||||
else
|
||||
pp->terminal_check_type = 0;
|
||||
dprintf(0, "=>%s\n",
|
||||
pp->terminal_check_type == 0 ? "None" :
|
||||
pp->terminal_check_type == 1 ? "Counter" :
|
||||
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
|
||||
}
|
||||
case CMD_RANGE_MODE:
|
||||
result = true;
|
||||
dprintf(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);
|
||||
break;
|
||||
case CMD_RANGE_GATE:
|
||||
result = true;
|
||||
dprintf(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",
|
||||
pp->range_gate_enable ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case CMD_RE_CHECK:
|
||||
result = true;
|
||||
dprintf(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",
|
||||
pp->range_check_enable ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case CMD_RANGE_HIGH:
|
||||
result = true;
|
||||
dprintf(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);
|
||||
break;
|
||||
case CMD_RANGE_LOW:
|
||||
result = true;
|
||||
dprintf(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);
|
||||
break;
|
||||
case CMD_SAMPLE:
|
||||
result = true;
|
||||
dprintf(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);
|
||||
break;
|
||||
case CMD_SYNC:
|
||||
result = true;
|
||||
dprintf(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");
|
||||
break;
|
||||
case CMD_TERMINAL:
|
||||
result = true;
|
||||
dprintf(0, "Sample=%llu", pp->terminal_count);
|
||||
pp->terminal_count = strtoull(value, NULL, 10);
|
||||
dprintf(0, "=>%llu\n", pp->terminal_count);
|
||||
break;
|
||||
case CMD_TE_CHECK:
|
||||
result = true;
|
||||
dprintf(0, "TE_Check=%s",
|
||||
pp->terminal_check_type == 0 ? "None" :
|
||||
pp->terminal_check_type == 1 ? "Counter" :
|
||||
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
|
||||
if (strcasecmp(value, "counter") == 0)
|
||||
pp->terminal_check_type = 1;
|
||||
else if (strcasecmp(value, "timer") == 0)
|
||||
pp->terminal_check_type = 2;
|
||||
else
|
||||
pp->terminal_check_type = 0;
|
||||
dprintf(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);
|
||||
@@ -257,10 +271,90 @@ bool param_get_cmd(pPARAMETERS pp, char* cmd, int n)
|
||||
}
|
||||
name[len] = '\0';
|
||||
|
||||
switch (name[0])
|
||||
switch (name_to_command(name))
|
||||
{
|
||||
case 'a':
|
||||
case 'A':
|
||||
case CMD_DIRECTION:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->direction ? "Down" : "Up");
|
||||
break;
|
||||
case CMD_INITIAL:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%llu", name,
|
||||
pp->initial_count);
|
||||
break;
|
||||
case CMD_OUTPUT:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->output_line == 2 ? "Inverted":
|
||||
pp->output_line == 1 ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case CMD_REPORT:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->report_period);
|
||||
break;
|
||||
case CMD_RANGE_GATE:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->range_gate_enable ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case CMD_RE_CHECK:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->range_check_enable ? "Enabled" : "Disabled");
|
||||
break;
|
||||
case CMD_RANGE_MODE:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->range_mode);
|
||||
break;
|
||||
case CMD_RANGE_HIGH:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%g", name,
|
||||
pp->range_high);
|
||||
break;
|
||||
case CMD_RANGE_LOW:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%g", name,
|
||||
pp->range_low);
|
||||
break;
|
||||
case CMD_SCAN:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->poll_period);
|
||||
break;
|
||||
case CMD_SAMPLE:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->sample_period);
|
||||
break;
|
||||
case CMD_TERMINAL:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%llu", name,
|
||||
pp->terminal_count);
|
||||
break;
|
||||
case CMD_TE_CHECK:
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->terminal_check_type == 0 ? "None" :
|
||||
pp->terminal_check_type == 1 ? "Counter" :
|
||||
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
|
||||
break;
|
||||
default:
|
||||
if (strcasecmp(name, "ALL") == 0)
|
||||
{
|
||||
int i;
|
||||
@@ -269,110 +363,8 @@ bool param_get_cmd(pPARAMETERS pp, char* cmd, int n)
|
||||
strcpy(buffer.body, "OK");
|
||||
result = true;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
if (strcasecmp(name, TXT_DIRECTION) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->direction ? "Down" : "Up");
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (strcasecmp(name, TXT_INITIAL) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%llu", name,
|
||||
pp->initial_count);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (strcasecmp(name, TXT_REPORT) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->report_period);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_GATE) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->range_gate_enable ? "Enabled" : "Disabled");
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RE_CHECK) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->range_check_enable ? "Enabled" : "Disabled");
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_MODE) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->range_mode);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_HIGH) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%g", name,
|
||||
pp->range_high);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_RANGE_LOW) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%g", name,
|
||||
pp->range_low);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
if (strcasecmp(name, TXT_SCAN) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->poll_period);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_SAMPLE) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%d", name,
|
||||
pp->sample_period);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
if (strcasecmp(name, TXT_TERMINAL) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%llu", name,
|
||||
pp->terminal_count);
|
||||
}
|
||||
else if (strcasecmp(name, TXT_TE_CHECK) == 0)
|
||||
{
|
||||
result = true;
|
||||
snprintf(buffer.body, sizeof(buffer.body),
|
||||
"GET %s=%s", name,
|
||||
pp->terminal_check_type == 0 ? "None" :
|
||||
pp->terminal_check_type == 1 ? "Counter" :
|
||||
pp->terminal_check_type == 2 ? "Timer" : "Unknown");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dprintf(0, "Unknown GET Parameter: \"%s\"\n", name);
|
||||
else
|
||||
dprintf(0, "Unknown GET Parameter: \"%s\"\n", name);
|
||||
break;
|
||||
}
|
||||
if (!result)
|
||||
|
||||
Reference in New Issue
Block a user