Refinement alongside Digital

r1198 | dcl | 2006-10-26 18:38:13 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
Douglas Clowes
2006-10-26 18:38:13 +10:00
parent 7e43aa3e16
commit 7dfa37057b
6 changed files with 75 additions and 109 deletions

View File

@@ -2,7 +2,7 @@
#include "utility.h"
#include "params.h"
#include "sock.h"
#include "cntr.h"
#include "device.h"
#include <ctype.h>
@@ -162,8 +162,8 @@ void put_form(int n)
dbg_printf(0, "put_form\n");
BUFFER html;
BUFFER buffer;
COUNTER* cp = (COUNTER*) sock_device(n);
PARAMETERS* pp = &cp->params;
DEVICE* device = (DEVICE*) sock_device(n);
PARAMETERS* pp = &device->params;
char *bp;
buffer.length = 0;
bp = &buffer.body[buffer.length];
@@ -323,24 +323,24 @@ void put_page(int n)
dbg_printf(0, "put_page\n");
BUFFER html;
BUFFER buffer;
COUNTER* cp = (COUNTER*) sock_device(n);
PARAMETERS* pp = &cp->params;
DEVICE* device = (DEVICE*) sock_device(n);
PARAMETERS* pp = &device->params;
SAMPLE* sp;
char *bp;
int refresh;
#if 1
{
refresh = (int) 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,
@@ -351,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);
@@ -382,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>";
@@ -439,6 +439,7 @@ void put_page(int n)
void process_form(int n, BUFFER* bp)
{
dbg_printf(0, "process_form\n");
DEVICE* device = (DEVICE*) sock_device(n);
int i, j;
int state;
char name[80];
@@ -446,7 +447,6 @@ void process_form(int n, BUFFER* bp)
char hex_str[3];
unsigned int hex_val;
char* tp;
COUNTER* cp = (COUNTER*) sock_device(n);
state = 0;
j = 0;
for (i = 0; i < bp->length; ++i)
@@ -498,7 +498,7 @@ void process_form(int n, BUFFER* bp)
if (state == 9)
{
dbg_printf(0, "name=\"%s\", value=\"%s\"\n", name, value);
if (param_set(&cp->params, name, value))
if (param_set(&device->params, name, value))
;
else if (strcmp(name, "xxx"))
{
@@ -522,16 +522,16 @@ void put_page_refresh(int n)
BUFFER html;
BUFFER buffer;
char* bp;
COUNTER* cp = (COUNTER*) sock_device(n);
DEVICE* device = (DEVICE*) sock_device(n);
int refresh;
#if 1
{
refresh = (int) cntr_time_to_next_report(cp) + 1;
refresh = (int) device_time_to_next_report(device) + 1;
}
#else
PARAMETERS* pp = &cp->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)
@@ -572,19 +572,19 @@ void put_page_refresh(int n)
void put_form_refresh(int n)
{
dbg_printf(0, "put_form_refresh\n");
DEVICE* device = (DEVICE*) sock_device(n);
BUFFER html;
BUFFER buffer;
char* bp;
COUNTER* cp = (COUNTER*) sock_device(n);
int refresh;
#if 1
{
refresh = (int) cntr_time_to_next_report(cp) + 1;
refresh = (int) device_time_to_next_report(device) + 1;
}
#else
PARAMETERS* pp = &cp->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)
@@ -625,13 +625,13 @@ void put_form_refresh(int n)
void process_command(int n, BUFFER* bp)
{
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* tp = bp->body;
COUNTER* cp = static_cast<COUNTER*>(sock_device(n));
while (isspace(*tp))
++tp;
len = 0;
@@ -659,13 +659,13 @@ void process_command(int n, BUFFER* bp)
while (isspace(*tp))
++tp;
if (strcasecmp(command, "START") == 0)
error = cntr_start(cp);
error = device_start(device);
else if (strcasecmp(command, "STOP") == 0)
error = cntr_stop(cp);
error = device_stop(device);
else if (strcasecmp(command, "PAUSE") == 0)
error = cntr_pause(cp);
error = device_pause(device);
else if (strcasecmp(command, "RESUME") == 0)
error = cntr_resume(cp);
error = device_resume(device);
else if (strcasecmp(command, "REPORT") == 0)
{
int match = 1;
@@ -688,23 +688,23 @@ void process_command(int n, BUFFER* bp)
{
/* set parameter */
dbg_printf(0, "SET %s\n", tp);
if (param_set_cmd(&cp->params, tp))
if (param_set_cmd(&device->params, tp))
error = 0;
}
else if (strcasecmp(command, "GET") == 0)
{
/* get parameter */
param_get_cmd(&cp->params, tp, n);
param_get_cmd(&device->params, tp, n);
return;
}
else if (strcasecmp(command, "READ") == 0)
{
cntr_read(cp, n);
device_read(device, n);
return;
}
else if (!sics)
{
cntr_send(cp, n);
device_send(device, n);
return;
}
if (error == 0)