+ Changed protocol to 0.3 because we now accept both -foo and foo
as argument introducers. in 0.4-pre10, these were changed
from foo to -foo and this broke many clients. This change
should fix that and be backward/forward compatible.
+ Added a noop function to the protocol. This is useful for writing
shell script clients of LCDproc.
+ Changed the shared sock_send_string function to NOT send the
ending NUL ('\0') byte with the string. This was confusing
in Perl clients which saw NUL's as the first character of
each reply. WARNING: The LCDPROC client depended on this
behavior, your client may too. Use the newline instead.
See the code in clients/lcdproc/main.c (look for "switch(buf[i])")
to see one way to handle this. This should allow new clients
to connect to old servers and vice-versa.
+ Messed with include structure in .c files. It should no longer
be necessary to specify ../.. to get to shared code headers.
Also, since we are using automake, the global config.h can be
found with just #include "config.h" as it's location is included
in a -I to the compilers. As a result "make distcheck" now works.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
bin_PROGRAMS = lcdproc
|
||||
lcdproc_SOURCES = main.c main.h mode.c mode.h batt.c batt.h chrono.c chrono.h cpu.c cpu.h cpu_smp.c cpu_smp.h disk.c disk.h load.c load.h mem.c mem.h
|
||||
lcdproc_LDADD = ../../shared/libLCDstuff.a
|
||||
INCLUDES = -I$(top_srcdir)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "../../shared/sockets.h"
|
||||
#include "shared/sockets.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "mode.h"
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "../../shared/sockets.h"
|
||||
#include "../../shared/debug.h"
|
||||
#include "shared/sockets.h"
|
||||
#include "shared/debug.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "mode.h"
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../../shared/sockets.h"
|
||||
#include "../../shared/debug.h"
|
||||
#include "shared/sockets.h"
|
||||
#include "shared/debug.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "mode.h"
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#include "../../shared/sockets.h"
|
||||
#include "shared/sockets.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "mode.h"
|
||||
|
||||
+17
-19
@@ -230,25 +230,21 @@ main_loop (mode * sequence)
|
||||
argc = 0;
|
||||
newtoken = 1;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (buf[i]) // For regular letters, keep tokenizing...
|
||||
{
|
||||
switch (buf[i]) {
|
||||
case ' ':
|
||||
newtoken = 1;
|
||||
buf[i] = 0;
|
||||
break;
|
||||
case '\n':
|
||||
buf[i] = 0;
|
||||
default:
|
||||
if (newtoken) {
|
||||
argv[argc] = buf + i;
|
||||
argc++;
|
||||
}
|
||||
newtoken = 0;
|
||||
break;
|
||||
switch (buf[i]) {
|
||||
case ' ':
|
||||
newtoken = 1;
|
||||
buf[i] = 0;
|
||||
break;
|
||||
default: // regular chars, keep tokenizing
|
||||
if (newtoken) {
|
||||
argv[argc] = buf + i;
|
||||
argc++;
|
||||
}
|
||||
} else // If we've got a zero, it's the end of a string...
|
||||
{
|
||||
newtoken = 0;
|
||||
break;
|
||||
case '\0':
|
||||
case '\n':
|
||||
buf[i] = 0;
|
||||
if (argc > 0) {
|
||||
//printf("%s %s\n", argv[0], argv[1]);
|
||||
if (0 == strcmp (argv[0], "listen")) {
|
||||
@@ -293,9 +289,11 @@ main_loop (mode * sequence)
|
||||
}
|
||||
}
|
||||
|
||||
// Restart tokenizing
|
||||
argc = 0;
|
||||
newtoken = 1;
|
||||
}
|
||||
break ;
|
||||
} // switch( buf[i] )
|
||||
}
|
||||
|
||||
len = sock_recv (sock, buf, 8000);
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "../../shared/sockets.h"
|
||||
#include "../../shared/LL.h"
|
||||
#include "shared/sockets.h"
|
||||
#include "shared/LL.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "mode.h"
|
||||
@@ -19,7 +19,12 @@
|
||||
#include <strings.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/swap.h>
|
||||
#include <procfs.h>
|
||||
#ifdef HAVE_SYS_PROCFS_H
|
||||
# include <sys/procfs.h>
|
||||
#endif
|
||||
#ifdef HAVE_PROCFS_H
|
||||
# include <procfs.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
||||
@@ -75,29 +75,11 @@ print $remote "widget_add metar cloud string\n";
|
||||
print $remote "widget_add metar wind string\n";
|
||||
|
||||
# set metar source
|
||||
|
||||
my $ua = new LWP::UserAgent;
|
||||
|
||||
my $req = new HTTP::Request GET =>
|
||||
"http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=$site_code";
|
||||
|
||||
# fork data collector from socket handling
|
||||
|
||||
$kidpid = fork();
|
||||
|
||||
# Parent
|
||||
if ($kidpid) {
|
||||
|
||||
while (1==1) {
|
||||
# read socket
|
||||
my $lcdconnect = <$remote>;
|
||||
}
|
||||
|
||||
# child
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
# fetch weather information
|
||||
while (1==1) {
|
||||
|
||||
@@ -136,13 +118,13 @@ while (1==1) {
|
||||
my $metartime = $m->TIME;
|
||||
my $c_dew = $m->C_DEW;
|
||||
my $f_temp = $m->F_TEMP;
|
||||
my $wind_dir_eng = $m->WIND_DIR_DEG;
|
||||
my $wind_mph = $m->WIND_MPH;
|
||||
my $wind_dir_eng = $m->WIND_DIR_ENG;
|
||||
my $wind_mph = int($m->WIND_MPH);
|
||||
my $sky = $m->SKY;
|
||||
my $time = localtime(time);
|
||||
print $remote "widget_set metar title {Weather LOWG " . $metartime . "}\n";
|
||||
print $remote "widget_set metar temp 1 2 {Temp " .$c_temp. "C (" .$c_dew. "C Dew)}\n";
|
||||
print $remote "widget_set metar wind 1 3 {Wind " .$wind_dir_eng. "G, " .$wind_mph. "mph}\n";
|
||||
print $remote "widget_set metar title {Weather $site_code $metartime}\n";
|
||||
print $remote "widget_set metar temp 1 2 {Temp ${c_temp}C (${c_dew}C Dew)}\n";
|
||||
print $remote "widget_set metar wind 1 3 {Wind ${wind_dir_eng}, ${wind_mph}mph}\n";
|
||||
print $remote "widget_set metar cloud 1 4 {Sky " . join(',', @{$m->{sky}}) . "}\n";
|
||||
# print "The temperature at $site_code is $c_temp C as of $time.\n";
|
||||
# print "The wind blows to $wind_dir_eng, speed $wind_mph mph\n";
|
||||
@@ -150,13 +132,12 @@ while (1==1) {
|
||||
} # end else
|
||||
# eat all input from LCDd
|
||||
while(defined($input = <$remote>)) {
|
||||
if ( $input =~ /^success$/ ) next;
|
||||
next if ( $input =~ /^success$/ );
|
||||
#print $input;
|
||||
}
|
||||
print "Sleeping 15 minutes.\n";
|
||||
sleep 900;
|
||||
}
|
||||
}
|
||||
|
||||
close($remote);
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user