use plotting_tool;
use logging_tool;
use shm_manager;
+use webpage;
# use manage_settings;
# use Switch;
}
+
sub main {
# go to other methods from here
my $isHttpReq = $ENV{HTTP_USER_AGENT};
- print header('text/html') if $isHttpReq;
my $self = shift;
# receive CGI query
my $return = $self->$action(%$args);
# does it return anything?
if(defined($return)){ # we get a return value
+
+ print header('text/plain') if $isHttpReq;
if(ref(\$return) eq "SCALAR"){ # just print it if it is a scalar
print "$return\n";
} else { # use Data::Dumper to display a hash
}
-
-
-
sub help {
my $self = shift;
my $verbose = shift;
exit;
}
-##################################################
-## Test routines ##
-##################################################
-
+sub create_shm_manager {
+ my $self = shift;
+ my $ttyID = $self->{tty};
+ $ttyID =~ s/^.*\///;
+ return shm_manager->new(shmName => $self->{appName}."-".$ttyID );
+}
+sub terminate_logging_tool {
+ my $self = shift;
+ my $shm_manager = $self->create_shm_manager();
+ $shm_manager->writeShm({ die => 1});
+}
-sub test_shm {
+sub clear_records {
my $self = shift;
-
- $self->{shm_manager} = shm_manager->new(
- shm => $self->{shm},
- dataDir => $self->{dataDir}
- );
-
-# $self->{shm_manager}->createShm();
-# $self->{shm_manager}->writeShm($self->CGI_parameters);
-# return $self->{shm_manager}->readShm();
- return $self->{shm_manager}->existShm();
+ my $shm_manager = $self->create_shm_manager();
+ $shm_manager->deleteShm();
+}
+sub dump_shm {
+ my $self = shift;
+ my $shm_manager = $self->create_shm_manager();
+ return $shm_manager->readShm();
}
+##################################################
+## Test routines ##
+##################################################
+
sub test {
my $self = shift;
my %options = @_;
exit;
}
-sub daemon_test {
- daemonize();
- sleep 20;
- system("echo 'demon output' > /u/maps/daemon_out.txt");
-}
-
-
-sub die_test {
- my $self = shift;
-
- my $ttyID = $self->{tty};
- $ttyID =~ s/^.*\///;
- my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID );
-
- $shm_manager->writeShm({ die => 1});
-
-}
-
-sub clear {
- my $self = shift;
-
- my $ttyID = $self->{tty};
- $ttyID =~ s/^.*\///;
- my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID );
-
- $shm_manager->deleteShm();
-}
-
sub log_test {
my $self = shift;
my %options = @_;
daemonize() if $options{daemonize};
-
- my $ttyID = $self->{tty};
- $ttyID =~ s/^.*\///;
- my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID );
+ my $shm_manager = $self->create_shm_manager();
my $serial_communication = serial_communication->new(
tty => $self->{tty},
my $logging_tool = logging_tool->new(
shm_manager => $shm_manager,
- serial_communication => $serial_communication
+ serial_communication => $serial_communication,
+ columnNames => $self->{columnNames}
);
- $logging_tool->set_columnNames($self->{columnNames});
$logging_tool->main(verbose => 1);
-
-
-
}
sub plot_test {
my $self = shift;
+ my %options = @_;
- my $ttyID = $self->{tty};
- $ttyID =~ s/^.*\///;
- my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID );
+ my $html = $options{html};
+ my $shm_manager = $self->create_shm_manager();
my $plotting_tool = plotting_tool->new(
columnNames => $self->{columnNames},
my $plotFile = $plotting_tool->plot();
$plotFile =~ s%/dev/%%;
+ print header('text/html');
+ if($html){
+ print <<EOF;
+ <meta http-equiv="refresh" content="1" />
+ <html>
+
+ <head>
+ <title>Temperature</title>
+ </head>
+
+ <body>
+ <h1>Temperature</h1>
+ <p>
+ <img src="$plotFile"></img>
+ </p>
+ </body>
+
+ </html>
+EOF
+ } else {
print qq%<img src="$plotFile"></img>%;
+ }
exit;
$self->{shmFile} = "/dev/shm/".$self->{shmName};
$self->{dataDir} = $self->{shmFile}."_data";
$self->{dataFile} = $self->{dataDir}."/data";
+
bless($self, $class);
my $self = shift;
if ( -e $self->{shmFile} ){
- return $self->{requests} = lock_retrieve($self->{shmFile});
+ return lock_retrieve($self->{shmFile});
} else {
die "shm does not exist!";
}
}
}
+sub updateShm {
+ my $self = shift;
+ my $shmHash = shift;
+ my $oldShmHash;
+ if ( -e $self->{shmFile} ){
+ $oldShmHash = lock_retrieve($self->{shmFile});
+ lock_store({%$oldShmHash,%$shmHash},$self->{shmFile});
+ } else {
+ die "shm does not exist!";
+ }
+}
+
1;
\ No newline at end of file
--- /dev/null
+package webpage;
+
+
+use strict;
+use warnings;
+use POSIX;
+use CGI ':standard';
+use CGI::Carp qw(fatalsToBrowser);
+
+sub new {
+ my $class = shift;
+ my %options = @_;
+ my $self = {
+ %options
+ };
+ bless($self, $class);
+}
+
+
+sub page_body {
+
+ my $self = shift;
+ my %options = @_;
+
+
+
+ print start_html(
+ -title=>'ADC Monitor',
+ -style=>[{'src'=>'../layout/styles.css'},
+ {'src'=>'../layout/jtageditor_blue.css'},
+ {'src'=>'../layout/adcmon.css'}
+ ],
+ -script=>[
+# { -type => 'text/javascript', -src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'},
+ { -type => 'text/javascript', -src => '../scripts/jquery.min.js'},
+ { -type => 'text/javascript', -src => './adcmon.js'},
+ { -type => 'text/javascript', -src => '../scripts/jquery.timer.js'}
+ ]
+ );
+
+
+
+
+}
+
+
+
+
+1;
\ No newline at end of file