more conversion from counter to DIO

r1264 | dcl | 2006-11-09 11:09:03 +1100 (Thu, 09 Nov 2006) | 2 lines
This commit is contained in:
Douglas Clowes
2006-11-09 11:09:03 +11:00
parent 4b54c82d27
commit 9e9a165510
4 changed files with 36 additions and 112 deletions

View File

@@ -8,17 +8,17 @@ LDFLAGS += -g
TARGETS = Monitor
OBJS = Monitor.o params.o utility.o sock.o display.o device.o hware.o
ifeq ($(MAKECMDGOALS),rlp)
ifeq ($(wildcard /usr/local/lib/libnidaqmx.so),)
OBJECTS =
LIBS =
LIBFLAGS =
DDK_DIR = /home/dcl/nitest/nimhddk_linux26
OBJECTS += $(DDK_DIR)/osiBus.o
OBJECTS += $(DDK_DIR)/Linux26/osiUserCode.o
TIO_DIR = /home/dcl/nitest/NI660x
OBJECTS += $(TIO_DIR)/tTIO.o
DEV_DIR = /home/dcl/nitest/StaticDIO
OBJECTS += $(DEV_DIR)/osiBus.o
OBJECTS += $(DEV_DIR)/osiUserCode.o
OBJECTS += $(DEV_DIR)/tstaticDIO.o
IFLAGS = -I$(DDK_DIR)
IFLAGS += -I$(TIO_DIR)/ChipObjects/
IFLAGS += -I$(DEV_DIR)/ChipObjects/
CXXFLAGS += -DkLittleEndian=1 -DREGISTER_LEVEL_PROGRAMMING=1
LIBFLAGS += $(OBJECTS)
CXXFLAGS += $(IFLAGS)
@@ -39,7 +39,7 @@ Monitor : $(OBJS)
Monitor.o: Monitor.c Monitor.h params.h utility.h sock.h device.h
device.o: device.c device.h params.h sock.h
device.o: device.c device.h params.h sock.h hware.h
display.o: display.c display.h utility.h params.h sock.h device.h

View File

@@ -168,57 +168,16 @@ void put_form(int n)
buffer.length = 0;
bp = &buffer.body[buffer.length];
snprintf(bp, sizeof(buffer.body) - buffer.length,
"<html><head><title>Counter Form</title></head>\r\n"
"<html><head><title>Device Form</title></head>\r\n"
"<body>\r\n"
"<form method=\"post\" action=\"/form\">\r\n"
"<table align=\"center\" border=\"0\">\r\n"
"<tr><th align=\"right\">Field</th>\r\n"
"<th align=\"left\">Value</th></tr>\r\n");
buffer.length += strlen(bp);
add_select_begin(&buffer, "Direction", "direction");
add_option(&buffer, "Up", "up", pp->direction == COUNT_UP);
add_option(&buffer, "Down", "down", !pp->direction == COUNT_UP);
add_select_end(&buffer);
add_int(&buffer, "Scan", "scan", pp->poll_period);
add_int(&buffer, "Sample", "sample", pp->sample_period);
add_int(&buffer, "Report", "report", pp->report_period);
add_counter(&buffer, "Initial", "initial", pp->initial_count);
add_counter(&buffer, "Terminal", "terminal", pp->terminal_count);
add_select_begin(&buffer, "Terminal Event", "te_check");
add_option(&buffer, "None", "none", pp->terminal_check_type == 0);
add_option(&buffer, "Counter", "counter", pp->terminal_check_type == 1);
add_option(&buffer, "Timer", "timer", pp->terminal_check_type == 2);
add_select_end(&buffer);
add_double(&buffer, "Range Low", "range_low", pp->range_low);
add_double(&buffer, "Range High", "range_high", pp->range_high);
add_select_begin(&buffer, "Range Event", "re_check");
add_option(&buffer, "Disabled", "disabled", pp->range_check_enable == false);
add_option(&buffer, "Enabled", "enabled", pp->range_check_enable == true);
add_select_end(&buffer);
add_select_begin(&buffer, "Range Gate", "range_gate");
add_option(&buffer, "Disabled", "disabled", pp->range_gate_enable == false);
add_option(&buffer, "Enabled", "enabled", pp->range_gate_enable == true);
add_select_end(&buffer);
add_select_begin(&buffer, "Range Mode", "range_mode");
add_option(&buffer, "Report", "0", pp->range_mode == 0);
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);
add_option(&buffer, "Inverted", "inverted", pp->output_line == 2);
add_select_end(&buffer);
add_select_begin(&buffer, "Sync", "sync");
add_option(&buffer, "Internal", "internal", pp->sync == false);
add_option(&buffer, "External", "external", pp->sync == true);
add_select_end(&buffer);
bp = &buffer.body[buffer.length];
snprintf(bp, sizeof(buffer.body) - buffer.length,
"<tr><td>\r\n"
@@ -268,6 +227,18 @@ static void show_int(BUFFER* buffer, char* title, int value)
buffer->length += strlen(bp);
}
static void show_hex(BUFFER* buffer, char* title, int value)
{
char* bp = &buffer->body[buffer->length];
snprintf(bp, sizeof(buffer->body) - buffer->length,
"<tr><td>%s</td>"
"<td>0x%06X</td>"
"</tr>\r\n",
title,
value & 0xffffff);
buffer->length += strlen(bp);
}
static void show_real(BUFFER* buffer, char* title, double value)
{
char* bp = &buffer->body[buffer->length];
@@ -325,7 +296,6 @@ void put_page(int n)
BUFFER buffer;
DEVICE* device = (DEVICE*) sock_device(n);
PARAMETERS* pp = &device->params;
SAMPLE* sp;
char *bp;
int refresh;
#if 1
@@ -340,74 +310,30 @@ void put_page(int n)
refresh = MIN_REFRESH;
if (refresh > MAX_REFRESH)
refresh = MAX_REFRESH;
sp = &device->report;
buffer.length = 0;
bp = &buffer.body[buffer.length];
snprintf(bp, sizeof(buffer.body) - buffer.length,
"<html><head><title>Counter Page</title></head>\r\n"
"<html><head><title>Device Page</title></head>\r\n"
"<body>\r\n"
"<table align=\"center\" border=\"0\"><tr><td>\r\n"
"<table align=\"center\" border=\"0\">\r\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", device->state == counter_stopped ? "STOPPED" :
device->state == counter_running ? "RUNNING" :
device->state == counter_paused ? "PAUSED" : "IDLE");
show_text(&buffer, "State", device->state == device_stopped ? "STOPPED" :
device->state == device_running ? "RUNNING" :
device->state == device_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", &device->start_time, false);
show_time(&buffer, "Current Time", &device->current_time, false);
{
struct timeval tv = device->stop_time;
if (device->state == counter_running || device->state == counter_paused)
{
tv = device->current_time;
}
time_sub(&tv, &device->start_time);
show_time(&buffer, "Elapsed", &tv, 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);
show_int(&buffer, "Poll Number", sp->poll_counter);
show_int(&buffer, "Sample Number", sp->sample_counter);
show_real(&buffer, "Rate", sp->counter_rate);
show_real(&buffer, "Min", sp->minimum_rate);
show_real(&buffer, "Ave", sp->average_rate);
show_real(&buffer, "Max", sp->maximum_rate);
if (pp->range_check_enable)
{
char* result;
if (device->range_error == 1)
result = "<font color=\"BLUE\">LOW</font>";
else if (device->range_error == 2)
result = "<font color=\"RED\">HIGH</font>";
else
result = "<font color=\"GREEN\">OK</font>";
show_text(&buffer, "Range Check", result);
}
else
show_text(&buffer, "Range Check", "Disabled");
show_hex(&buffer, "Value", device->value);
show_int(&buffer, "Poll Counter", device->poll_counter);
add_text(&buffer, "</table></td><td valign=\"top\"><table>\r\n");
add_text(&buffer, "<tr><td><a href=\"/form\">\r\n"
"<button>Form</button>\r\n"
"</a></td></tr>\r\n");
add_text(&buffer, "<tr><td><a href=\"/cmd=start\">\r\n"
"<button>Start</button>\r\n"
"</a></td></tr>\r\n");
add_text(&buffer, "<tr><td><a href=\"/cmd=stop\">\r\n"
"<button>Stop</button>\r\n"
"</a></td></tr>\r\n");
add_text(&buffer, "<tr><td><a href=\"/cmd=pause\">\r\n"
"<button>Pause</button>\r\n"
"</a></td></tr>\r\n");
add_text(&buffer, "<tr><td><a href=\"/cmd=continue\">\r\n"
"<button>Continue</button>\r\n"
"</a></td></tr>\r\n");
add_text(&buffer, "</table></td></tr>\r\n");
add_text(&buffer, "</table>\r\n"
"</body>\r\n"
@@ -658,15 +584,7 @@ void process_command(int n, BUFFER* bp)
}
while (isspace(*tp))
++tp;
if (strcasecmp(command, "START") == 0)
error = device_start(device);
else if (strcasecmp(command, "STOP") == 0)
error = device_stop(device);
else if (strcasecmp(command, "PAUSE") == 0)
error = device_pause(device);
else if (strcasecmp(command, "RESUME") == 0)
error = device_resume(device);
else if (strcasecmp(command, "REPORT") == 0)
if (strcasecmp(command, "REPORT") == 0)
{
int match = 1;
error = 0;
@@ -702,6 +620,11 @@ void process_command(int n, BUFFER* bp)
device_read(device, n);
return;
}
else if (strcasecmp(command, "WRITE") == 0)
{
device_write(device, n, tp);
return;
}
else if (!sics)
{
device_send(device, n);

View File

@@ -457,13 +457,14 @@ void sock_send(int n, BUFFER* bp)
*
* \param bp pointer to buffer containing report
* \param match value to match for this report
* \param dev device to match
*/
void sock_report(BUFFER* bp, int match)
void sock_report(BUFFER* bp, int match, void* dev)
{
int i;
for (i = 1; i < num_fds; ++i)
{
if (fdv[i].match == match)
if (fdv[i].match == match && fdv[i].device == dev)
sock_send(i, bp);
}
}

View File

@@ -10,7 +10,7 @@ void sock_line(int n);
void sock_input(int n);
void sock_accept(int n);
void sock_send(int n, BUFFER* buffer);
void sock_report(BUFFER* bp, int match);
void sock_report(BUFFER* bp, int match, void* dev);
void sock_set_match(int n, int match);
void sock_ok(int n);
void sock_err(int n);