Progressive refinement
r1199 | dcl | 2006-10-26 18:38:34 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "utility.h"
|
||||
#include "params.h"
|
||||
#include "sock.h"
|
||||
#include "dio.h"
|
||||
#include "device.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -159,10 +159,11 @@ static void add_counter(BUFFER* buffer, char* title, char* name, uint64 value)
|
||||
*/
|
||||
void put_form(int n)
|
||||
{
|
||||
dprintf(0, "put_form\n");
|
||||
dbg_printf(0, "put_form\n");
|
||||
BUFFER html;
|
||||
BUFFER buffer;
|
||||
PARAMETERS* pp = &counter.params;
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
PARAMETERS* pp = &device->params;
|
||||
char *bp;
|
||||
buffer.length = 0;
|
||||
bp = &buffer.body[buffer.length];
|
||||
@@ -203,6 +204,12 @@ void put_form(int n)
|
||||
add_option(&buffer, "Sample", "1", pp->range_mode == 1);
|
||||
add_option(&buffer, "Poll", "2", pp->range_mode == 2);
|
||||
add_select_end(&buffer);
|
||||
add_select_begin(&buffer, "Source", "source");
|
||||
add_option(&buffer, "External", "0", pp->source == 0);
|
||||
add_option(&buffer, "Clock_1 20MHz", "1", pp->source == 1);
|
||||
add_option(&buffer, "Clock_2 100KHz", "2", pp->source == 2);
|
||||
add_option(&buffer, "Clock_3 80MHz", "3", pp->source == 3);
|
||||
add_select_end(&buffer);
|
||||
add_select_begin(&buffer, "Output Line", "output");
|
||||
add_option(&buffer, "Disabled", "disabled", pp->output_line == 0);
|
||||
add_option(&buffer, "Enabled", "enabled", pp->output_line == 1);
|
||||
@@ -237,7 +244,7 @@ void put_form(int n)
|
||||
sock_send(n, &html);
|
||||
}
|
||||
|
||||
static void show_text(BUFFER* buffer, char* title, char* value)
|
||||
static void show_text(BUFFER* buffer, const char* title, const char* value)
|
||||
{
|
||||
char* bp = &buffer->body[buffer->length];
|
||||
snprintf(bp, sizeof(buffer->body) - buffer->length,
|
||||
@@ -313,27 +320,27 @@ static void show_time(BUFFER* buffer,
|
||||
*/
|
||||
void put_page(int n)
|
||||
{
|
||||
dprintf(0, "put_page\n");
|
||||
dbg_printf(0, "put_page\n");
|
||||
BUFFER html;
|
||||
BUFFER buffer;
|
||||
COUNTER* cp = &counter;
|
||||
PARAMETERS* pp = &counter.params;
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
PARAMETERS* pp = &device->params;
|
||||
SAMPLE* sp;
|
||||
char *bp;
|
||||
int refresh;
|
||||
#if 1
|
||||
{
|
||||
refresh = cntr_time_to_next_report(cp) + 1;
|
||||
refresh = (int) device_time_to_next_report(device) + 1;
|
||||
}
|
||||
#else
|
||||
make_report(cp);
|
||||
make_report(device);
|
||||
refresh = (pp->poll_period * pp->sample_period * pp->report_period + 500) / 1000;
|
||||
#endif
|
||||
if (refresh < MIN_REFRESH)
|
||||
refresh = MIN_REFRESH;
|
||||
if (refresh > MAX_REFRESH)
|
||||
refresh = MAX_REFRESH;
|
||||
sp = &cp->report;
|
||||
sp = &device->report;
|
||||
buffer.length = 0;
|
||||
bp = &buffer.body[buffer.length];
|
||||
snprintf(bp, sizeof(buffer.body) - buffer.length,
|
||||
@@ -344,25 +351,25 @@ void put_page(int n)
|
||||
"<tr><th align=\"right\">Field</th>\r\n"
|
||||
"<th align=\"left\">Value</th></tr>\r\n");
|
||||
buffer.length += strlen(bp);
|
||||
show_text(&buffer, "State", cp->state == counter_stopped ? "STOPPED" :
|
||||
cp->state == counter_running ? "RUNNING" :
|
||||
cp->state == counter_paused ? "PAUSED" : "IDLE");
|
||||
show_text(&buffer, "State", device->state == counter_stopped ? "STOPPED" :
|
||||
device->state == counter_running ? "RUNNING" :
|
||||
device->state == counter_paused ? "PAUSED" : "IDLE");
|
||||
show_text(&buffer, "Direction", pp->direction == COUNT_UP ? "UP" : "DOWN");
|
||||
show_int(&buffer, "Scan", pp->poll_period);
|
||||
show_int(&buffer, "Sample", pp->sample_period);
|
||||
show_int(&buffer, "Report", pp->report_period);
|
||||
show_time(&buffer, "Start Time", &cp->start_time, false);
|
||||
show_time(&buffer, "Current Time", &cp->current_time, false);
|
||||
show_time(&buffer, "Start Time", &device->start_time, false);
|
||||
show_time(&buffer, "Current Time", &device->current_time, false);
|
||||
{
|
||||
struct timeval tv = cp->stop_time;
|
||||
if (cp->state == counter_running || cp->state == counter_paused)
|
||||
struct timeval tv = device->stop_time;
|
||||
if (device->state == counter_running || device->state == counter_paused)
|
||||
{
|
||||
tv = cp->current_time;
|
||||
tv = device->current_time;
|
||||
}
|
||||
time_sub(&tv, &cp->start_time);
|
||||
time_sub(&tv, &device->start_time);
|
||||
show_time(&buffer, "Elapsed", &tv, true);
|
||||
}
|
||||
show_time(&buffer, "Runtime", &cp->accumulated, true);
|
||||
show_time(&buffer, "Runtime", &device->accumulated, true);
|
||||
show_time(&buffer, "Report Time", &sp->timestamp, false);
|
||||
show_counter(&buffer, "Counter", sp->counter_value);
|
||||
show_int(&buffer, "Num Polls", sp->num_polls);
|
||||
@@ -375,9 +382,9 @@ void put_page(int n)
|
||||
if (pp->range_check_enable)
|
||||
{
|
||||
char* result;
|
||||
if (cp->range_error == 1)
|
||||
if (device->range_error == 1)
|
||||
result = "<font color=\"BLUE\">LOW</font>";
|
||||
else if (cp->range_error == 2)
|
||||
else if (device->range_error == 2)
|
||||
result = "<font color=\"RED\">HIGH</font>";
|
||||
else
|
||||
result = "<font color=\"GREEN\">OK</font>";
|
||||
@@ -431,54 +438,55 @@ void put_page(int n)
|
||||
*/
|
||||
void process_form(int n, BUFFER* bp)
|
||||
{
|
||||
dprintf(0, "process_form\n");
|
||||
dbg_printf(0, "process_form\n");
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
int i, j;
|
||||
int state;
|
||||
char name[80];
|
||||
char value[80];
|
||||
char hex_str[3];
|
||||
unsigned int hex_val;
|
||||
char* cp;
|
||||
char* tp;
|
||||
state = 0;
|
||||
j = 0;
|
||||
for (i = 0; i < bp->length; ++i)
|
||||
{
|
||||
cp = &bp->body[i];
|
||||
tp = &bp->body[i];
|
||||
if (state == 0)
|
||||
{
|
||||
if (*cp == '=')
|
||||
if (*tp == '=')
|
||||
{
|
||||
name[j++] = '\0';
|
||||
j = 0;
|
||||
state = 1;
|
||||
}
|
||||
else if (j < 80 - 1)
|
||||
name[j++] = tolower(*cp);
|
||||
name[j++] = tolower(*tp);
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
if (*cp == '&')
|
||||
if (*tp == '&')
|
||||
{
|
||||
value[j++] = '\0';
|
||||
j = 0;
|
||||
state = 9;
|
||||
}
|
||||
else if (*cp == '%')
|
||||
else if (*tp == '%')
|
||||
{
|
||||
hex_str[0] = '\0';
|
||||
state = 2;
|
||||
}
|
||||
else if (j < 80 - 1)
|
||||
value[j++] = tolower(*cp);
|
||||
value[j++] = tolower(*tp);
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
hex_str[0] = tolower(*cp);
|
||||
hex_str[0] = tolower(*tp);
|
||||
state = 3;
|
||||
}
|
||||
else if (state == 3)
|
||||
{
|
||||
hex_str[1] = tolower(*cp);
|
||||
hex_str[1] = tolower(*tp);
|
||||
hex_str[2] = '\0';
|
||||
hex_val = strtoul(hex_str, NULL, 16);
|
||||
if (hex_val < ' ' || hex_val > '~')
|
||||
@@ -489,8 +497,8 @@ void process_form(int n, BUFFER* bp)
|
||||
}
|
||||
if (state == 9)
|
||||
{
|
||||
dprintf(0, "name=\"%s\", value=\"%s\"\n", name, value);
|
||||
if (param_set(&counter.params, name, value))
|
||||
dbg_printf(0, "name=\"%s\", value=\"%s\"\n", name, value);
|
||||
if (param_set(&device->params, name, value))
|
||||
;
|
||||
else if (strcmp(name, "xxx"))
|
||||
{
|
||||
@@ -510,20 +518,20 @@ void process_form(int n, BUFFER* bp)
|
||||
*/
|
||||
void put_page_refresh(int n)
|
||||
{
|
||||
dprintf(0, "put_page_refresh\n");
|
||||
dbg_printf(0, "put_page_refresh\n");
|
||||
BUFFER html;
|
||||
BUFFER buffer;
|
||||
char* bp;
|
||||
COUNTER* cp = &counter;
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
|
||||
int refresh;
|
||||
#if 1
|
||||
{
|
||||
refresh = cntr_time_to_next_report(cp) + 1;
|
||||
refresh = (int) device_time_to_next_report(device) + 1;
|
||||
}
|
||||
#else
|
||||
PARAMETERS* pp = &counter.params;
|
||||
make_report(cp);
|
||||
PARAMETERS* pp = &device->params;
|
||||
make_report(device);
|
||||
refresh = (pp->poll_period * pp->sample_period * pp->report_period + 500) / 1000;
|
||||
#endif
|
||||
if (refresh < MIN_REFRESH)
|
||||
@@ -563,20 +571,20 @@ void put_page_refresh(int n)
|
||||
*/
|
||||
void put_form_refresh(int n)
|
||||
{
|
||||
dprintf(0, "put_form_refresh\n");
|
||||
dbg_printf(0, "put_form_refresh\n");
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
BUFFER html;
|
||||
BUFFER buffer;
|
||||
char* bp;
|
||||
COUNTER* cp = &counter;
|
||||
|
||||
int refresh;
|
||||
#if 1
|
||||
{
|
||||
refresh = cntr_time_to_next_report(cp) + 1;
|
||||
refresh = (int) device_time_to_next_report(device) + 1;
|
||||
}
|
||||
#else
|
||||
PARAMETERS* pp = &counter.params;
|
||||
make_report(cp);
|
||||
PARAMETERS* pp = &device->params;
|
||||
make_report(device);
|
||||
refresh = (pp->poll_period * pp->sample_period * pp->report_period + 500) / 1000;
|
||||
#endif
|
||||
if (refresh < MIN_REFRESH)
|
||||
@@ -616,47 +624,48 @@ void put_form_refresh(int n)
|
||||
*/
|
||||
void process_command(int n, BUFFER* bp)
|
||||
{
|
||||
dprintf(0, "process_command(%d, %s)\n", n, bp->body);
|
||||
dbg_printf(0, "process_command(%d, %s)\n", n, bp->body);
|
||||
DEVICE* device = (DEVICE*) sock_device(n);
|
||||
bool sics = false;
|
||||
int error = 1;
|
||||
char command[80];
|
||||
char param[80];
|
||||
int len = 0;
|
||||
char* cp = bp->body;
|
||||
while (isspace(*cp))
|
||||
++cp;
|
||||
char* tp = bp->body;
|
||||
while (isspace(*tp))
|
||||
++tp;
|
||||
len = 0;
|
||||
while (*cp && !isspace(*cp))
|
||||
while (*tp && !isspace(*tp))
|
||||
{
|
||||
if (len < 80 - 1)
|
||||
command[len++] = *cp;
|
||||
++cp;
|
||||
command[len++] = *tp;
|
||||
++tp;
|
||||
}
|
||||
command[len] = '\0';
|
||||
if (strcasecmp(command, "SICS") == 0)
|
||||
{
|
||||
sics = true;
|
||||
while (isspace(*cp))
|
||||
++cp;
|
||||
while (isspace(*tp))
|
||||
++tp;
|
||||
len = 0;
|
||||
while (*cp && !isspace(*cp))
|
||||
while (*tp && !isspace(*tp))
|
||||
{
|
||||
if (len < 80 - 1)
|
||||
command[len++] = *cp;
|
||||
++cp;
|
||||
command[len++] = *tp;
|
||||
++tp;
|
||||
}
|
||||
command[len] = '\0';
|
||||
}
|
||||
while (isspace(*cp))
|
||||
++cp;
|
||||
while (isspace(*tp))
|
||||
++tp;
|
||||
if (strcasecmp(command, "START") == 0)
|
||||
error = cntr_start(&counter);
|
||||
error = device_start(device);
|
||||
else if (strcasecmp(command, "STOP") == 0)
|
||||
error = cntr_stop(&counter);
|
||||
error = device_stop(device);
|
||||
else if (strcasecmp(command, "PAUSE") == 0)
|
||||
error = cntr_pause(&counter);
|
||||
error = device_pause(device);
|
||||
else if (strcasecmp(command, "RESUME") == 0)
|
||||
error = cntr_resume(&counter);
|
||||
error = device_resume(device);
|
||||
else if (strcasecmp(command, "REPORT") == 0)
|
||||
{
|
||||
int match = 1;
|
||||
@@ -664,11 +673,11 @@ void process_command(int n, BUFFER* bp)
|
||||
if (sics)
|
||||
match = 2;
|
||||
len = 0;
|
||||
while (*cp && !isspace(*cp))
|
||||
while (*tp && !isspace(*tp))
|
||||
{
|
||||
if (len < 80 - 1)
|
||||
param[len++] = *cp;
|
||||
++cp;
|
||||
param[len++] = *tp;
|
||||
++tp;
|
||||
}
|
||||
param[len] = '\0';
|
||||
if (strcasecmp(param, "OFF") == 0)
|
||||
@@ -678,24 +687,24 @@ void process_command(int n, BUFFER* bp)
|
||||
else if (strcasecmp(command, "SET") == 0)
|
||||
{
|
||||
/* set parameter */
|
||||
dprintf(0, "SET %s\n", cp);
|
||||
if (param_set_cmd(&counter.params, cp))
|
||||
dbg_printf(0, "SET %s\n", tp);
|
||||
if (param_set_cmd(&device->params, tp))
|
||||
error = 0;
|
||||
}
|
||||
else if (strcasecmp(command, "GET") == 0)
|
||||
{
|
||||
/* get parameter */
|
||||
param_get_cmd(&counter.params, cp, n);
|
||||
param_get_cmd(&device->params, tp, n);
|
||||
return;
|
||||
}
|
||||
else if (strcasecmp(command, "READ") == 0)
|
||||
{
|
||||
cntr_read(&counter, n);
|
||||
device_read(device, n);
|
||||
return;
|
||||
}
|
||||
else if (!sics)
|
||||
{
|
||||
cntr_send(&counter, n);
|
||||
device_send(device, n);
|
||||
return;
|
||||
}
|
||||
if (error == 0)
|
||||
|
||||
Reference in New Issue
Block a user