diff options
author | itojun <itojun@pkgsrc.org> | 2001-07-19 20:23:43 +0000 |
---|---|---|
committer | itojun <itojun@pkgsrc.org> | 2001-07-19 20:23:43 +0000 |
commit | 807d414c81c9f59282d5a857f6aa38d60117e1ca (patch) | |
tree | dd1d77e9f333c09d96ef47e46466431119a27778 | |
parent | b4fa3a99c66dd66c72f6172d16ffb0a3e01d061c (diff) | |
download | pkgsrc-807d414c81c9f59282d5a857f6aa38d60117e1ca.tar.gz |
have -L (load average monitor) and -M (message with morse code).
bump pkgsrc version to 20010719.
-rw-r--r-- | sysutils/lambd/Makefile | 4 | ||||
-rw-r--r-- | sysutils/lambd/files/lambd.8 | 44 | ||||
-rw-r--r-- | sysutils/lambd/files/lambd.c | 161 |
3 files changed, 172 insertions, 37 deletions
diff --git a/sysutils/lambd/Makefile b/sysutils/lambd/Makefile index 4b1b9651cc8..05655e48438 100644 --- a/sysutils/lambd/Makefile +++ b/sysutils/lambd/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.3 2001/07/18 06:47:36 itojun Exp $ +# $NetBSD: Makefile,v 1.4 2001/07/19 20:23:43 itojun Exp $ -DISTNAME= lambd-20010718 +DISTNAME= lambd-20010719 CATEGORIES= sysutils MASTER_SITES= # none DISTFILES= # none diff --git a/sysutils/lambd/files/lambd.8 b/sysutils/lambd/files/lambd.8 index 2e52aa3c42e..5cb211ebf11 100644 --- a/sysutils/lambd/files/lambd.8 +++ b/sysutils/lambd/files/lambd.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: lambd.8,v 1.3 2001/07/18 06:47:37 itojun Exp $ +.\" $NetBSD: lambd.8,v 1.4 2001/07/19 20:23:43 itojun Exp $ .\" .\" Copyright (C) 2001 WIDE Project. All rights reserved. .\" @@ -34,7 +34,8 @@ .Nd shutdown switch monitoring daemon for Wildlab LAMB .Sh SYNOPSIS .Nm "" -.Op Fl dfn +.Op Fl Ldfn +.Op Fl M Ar str .Op Ar usec .Sh DESCRIPTION .Nm @@ -47,21 +48,32 @@ Normally .Nm becomes a daemon on invocation. .Pp -Three command line options, -.Fl dfn -are supplied for debugging purposes. -.Fl d -lets it generate more messages, and forbids it from shutting down the machine. -.Fl f -runs +The following options are available: +.Bl -tag -width indent +.It Fl L +Instead of heartbeat, LED will present the current load average. +A single blink means 0.5 in load average. +therefore, if you see 4 blinks, the current load average would be 2. +.Ar usec +argument decides the interval between LED blinks. +.It Fl M Ar str +Show an alphanumeric string, +.Ar str , +in morse code on LED. +.Ar usec +argument decides the speed of the morse code. +.It Fl d +The flag lets .Nm -in foreground mode. -.Fl n -avoids any hardware I/O accesses from +generate more messages, and forbids it from shutting down the machine +even if the shutdown button is pressed. +.It Fl f +.Nm +will run in foreground mode +.Pq do not become daemon . +.It Fl n +Avoid any hardware I/O accesses from .Nm Ns . +.El .Sh SEE ALSO .Pa http://www.wildlab.com/ -.Sh BUGS -.Nm -should use LED for more interesting purposes, -like indicating load average, morse code and such. diff --git a/sysutils/lambd/files/lambd.c b/sysutils/lambd/files/lambd.c index ec411abf7db..1d92903a711 100644 --- a/sysutils/lambd/files/lambd.c +++ b/sysutils/lambd/files/lambd.c @@ -1,4 +1,4 @@ -/* $NetBSD: lambd.c,v 1.2 2001/07/18 06:47:37 itojun Exp $ */ +/* $NetBSD: lambd.c,v 1.3 2001/07/19 20:23:43 itojun Exp $ */ /* * Copyright (C) 2001 WIDE Project. All rights reserved. @@ -35,6 +35,7 @@ #include <unistd.h> #include <stdio.h> #include <err.h> +#include <ctype.h> #include "lambio.h" @@ -42,11 +43,15 @@ int main __P((int, char **)); void usage __P((void)); -void mainloop __P((unsigned long)); +void mainloop __P((void)); void lsleep __P((unsigned long)); int monitor __P((void)); void led __P((int)); +int cycle __P((void)); +int loadavg __P((void)); +int morse __P((void)); + int foreground = 0; int debug = 0; #ifdef __i386__ @@ -54,6 +59,10 @@ int nohw = 0; #else const int nohw = 1; #endif +unsigned long delay = 1 * 1000000; +const char *morsestr = "LAMB"; + +int (*func) __P((void)) = cycle; int main(argc, argv) @@ -61,11 +70,17 @@ main(argc, argv) char **argv; { int ch; - unsigned long delay; char *p, *ep; - while ((ch = getopt(argc, argv, "dfn")) != -1) { + while ((ch = getopt(argc, argv, "LM:dfn")) != -1) { switch (ch) { + case 'L': + func = loadavg; + break; + case 'M': + func = morse; + morsestr = optarg; + break; case 'd': debug++; break; @@ -94,7 +109,6 @@ main(argc, argv) switch (argc) { case 0: - delay = 1 * 1000000; break; case 1: p = *argv; @@ -120,7 +134,7 @@ main(argc, argv) if (debug) fprintf(stderr, "delay=%lu\n", delay); - mainloop(delay); + mainloop(); /* NOTREACHED */ exit(0); /* silent gcc */ @@ -129,26 +143,16 @@ main(argc, argv) void usage() { - fprintf(stderr, "usage: lambd [-f] [usec]\n"); + fprintf(stderr, "usage: lambd [-LMdfn] [usec]\n"); } void -mainloop(delay) - unsigned long delay; +mainloop() { - delay /= 2; - led(0); while (1) { - if (monitor()) + if ((*func)()) break; - led(1); - lsleep(delay); - - if (monitor()) - break; - led(0); - lsleep(delay); } led(0); @@ -196,3 +200,122 @@ led(on) lamb_led(on); } + +/* + * define a interesting functions below! + */ + +int +cycle() +{ + if (monitor()) + return 1; + led(1); + lsleep(delay / 2); + + if (monitor()) + return 1; + led(0); + lsleep(delay / 2); + return 0; +} + +int +loadavg() +{ + double v; + int i; + unsigned long t = delay / 10; + + getloadavg(&v, 1); + if (debug) + fprintf(stderr, "loadavg=%g\n", v); + for (i = 0; i < v * 2; i++) { + if (monitor()) + return 1; + led(1); + lsleep(t); + led(0); + lsleep(t); + } + lsleep(t * 5); + return 0; +} + +static const char *const digit[] = { + "-----", + ".----", + "..---", + "...--", + "....-", + ".....", + "-....", + "--...", + "---..", + "----.", +}; +static const char *const alph[] = { + ".-", + "-...", + "-.-.", + "-..", + ".", + "..-.", + "--.", + "....", + "..", + ".---", + "-.-", + ".-..", + "--", + "-.", + "---", + ".--.", + "--.-", + ".-.", + "...", + "-", + "..-", + "...-", + ".--", + "-..-", + "-.--", + "--..", +}; + +int +morse() +{ + const char *p, *q; + int mark, blank; + unsigned long t = delay / 10; + + for (p = morsestr; *p; p++) { + if (isdigit(*p)) + q = digit[*p - '0']; + else if (isalpha(*p) && isupper(*p)) + q = alph[*p - 'A']; + else if (isalpha(*p) && islower(*p)) + q = alph[*p - 'a']; + + if (debug) + printf("%c <%s>\n", *p, q); + for (/*nothing*/; *q; q++) { + switch (*q) { + case '-': + mark = 3; blank = 1; break; + case '.': + mark = 1; blank = 1; break; + default: + mark = 0; blank = 3; break; + } + led(1); + lsleep(mark * t); + led(0); + lsleep(blank * t); + } + lsleep(1 * t); + } + lsleep(10 * t); + return 0; +} |