Compare commits
9 commits
b894e95aea
...
4ffc57261e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ffc57261e | ||
|
|
038a277a30 | ||
|
|
6b2dbcc791 | ||
|
|
c8e0501965 | ||
|
|
dc3d6f58e2 | ||
|
|
bd2aa34a54 | ||
|
|
56143654b2 | ||
|
|
07e0ed9a38 | ||
|
|
c699ad2166 |
7 changed files with 175 additions and 47 deletions
9
d3d.py
Executable file
9
d3d.py
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#! /usr/bin/python3
|
||||
import os, sys, os.path, time
|
||||
os.chdir(os.path.dirname(sys.argv[0]))
|
||||
os.system("screen ./d3d.rc")
|
||||
wd = open("d3d/irena-live", "w")
|
||||
while True:
|
||||
wd.write(".");
|
||||
wd.flush()
|
||||
time.sleep(10)
|
||||
2
d3d.rc
2
d3d.rc
|
|
@ -10,5 +10,5 @@ fct 32
|
|||
statusfile d3d/irena-status
|
||||
datafile d3d/irena-%Y-%m-%dT%H:%M:%SZ.dat
|
||||
counterfile d3d/irena-%Y-%m-%dT%H:%M:%SZ.hst
|
||||
socket unix irena-control interactive force
|
||||
socket unix d3d/irena-control interactive force
|
||||
cron next init 60 script d3dinit.rc
|
||||
|
|
|
|||
81
etc/inittab
Normal file
81
etc/inittab
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# /etc/inittab: init(8) configuration.
|
||||
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
|
||||
|
||||
# The default runlevel.
|
||||
id:2:initdefault:
|
||||
|
||||
# Boot-time system configuration/initialization script.
|
||||
# This is run first except when booting in emergency (-b) mode.
|
||||
si::sysinit:/etc/init.d/rcS
|
||||
|
||||
# What to do in single-user mode.
|
||||
~~:S:wait:/sbin/sulogin --force
|
||||
|
||||
# /etc/init.d executes the S and K scripts upon change
|
||||
# of runlevel.
|
||||
#
|
||||
# Runlevel 0 is halt.
|
||||
# Runlevel 1 is single-user.
|
||||
# Runlevels 2-5 are multi-user.
|
||||
# Runlevel 6 is reboot.
|
||||
|
||||
l0:0:wait:/etc/init.d/rc 0
|
||||
l1:1:wait:/etc/init.d/rc 1
|
||||
l2:2:wait:/etc/init.d/rc 2
|
||||
l3:3:wait:/etc/init.d/rc 3
|
||||
l4:4:wait:/etc/init.d/rc 4
|
||||
l5:5:wait:/etc/init.d/rc 5
|
||||
l6:6:wait:/etc/init.d/rc 6
|
||||
# Normally not reached, but fallthrough in case of emergency.
|
||||
z6:6:respawn:/sbin/sulogin --force
|
||||
|
||||
# What to do when CTRL-ALT-DEL is pressed.
|
||||
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
|
||||
|
||||
# Action on special keypress (ALT-UpArrow).
|
||||
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."
|
||||
|
||||
# What to do when the power fails/returns.
|
||||
pf::powerwait:/etc/init.d/powerfail start
|
||||
pn::powerfailnow:/etc/init.d/powerfail now
|
||||
po::powerokwait:/etc/init.d/powerfail stop
|
||||
|
||||
# /sbin/getty invocations for the runlevels.
|
||||
#
|
||||
# The "id" field MUST be the same as the last
|
||||
# characters of the device (after "tty").
|
||||
#
|
||||
# Format:
|
||||
# <id>:<runlevels>:<action>:<process>
|
||||
#
|
||||
# Note that on most Debian systems tty7 is used by the X Window System,
|
||||
# so if you want to add more getty's go ahead but skip tty7 if you run X.
|
||||
#
|
||||
|
||||
# Start the irena DAQ in a screen session
|
||||
# The watchdog on tty2 takes care that this is running properly
|
||||
gpio:234:wait:/home/etd3d1/d3d/d3direna/gpio.sh
|
||||
d3d:34:respawn:sudo -inu d3d screen -U -S IRENA -D -m /home/etd3d1/d3d/d3direna/d3d.py
|
||||
1:2345:respawn:/sbin/getty -J -a root 38400 tty1
|
||||
2:3:respawn:watchdog --config-file /home/etd3d1/d3d/d3direna/etc/watchdog.conf --foreground </dev/tty2 >/dev/tty2 2>&1
|
||||
3:234:respawn:/sbin/getty 38400 tty3
|
||||
4:234:respawn:/sbin/getty 38400 tty4
|
||||
5:234:respawn:/sbin/getty 38400 tty5
|
||||
6:234:respawn:/sbin/getty 38400 tty6
|
||||
|
||||
# Example how to put a getty on a serial line (for a terminal)
|
||||
#
|
||||
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
|
||||
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
|
||||
#
|
||||
# or on a USB serial line
|
||||
#U0:23:respawn:/sbin/getty -L ttyUSB0 9600 vt100
|
||||
|
||||
# Example how to put a getty on a modem line.
|
||||
#
|
||||
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
|
||||
|
||||
# Example for systemd-nspawn
|
||||
# Only /dev/console exists inside nspawn, so we need a getty on that.
|
||||
# Also make sure to comment out the gettys on tty* above.
|
||||
#C0:2345:respawn:/sbin/getty -8 --noclear --keep-baud console 115200,38400,9600
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
# chmod -v a+x /etc/rc.local
|
||||
# echo $0 >> /etc/rc.local
|
||||
|
||||
D3D="$(dirname $0)"
|
||||
D3D="$(dirname $(dirname $0))"
|
||||
IRENA=$D3D/d3d.rc
|
||||
IMON=$D3D/imonitor.py
|
||||
U=$(stat "$0" -c "%U")
|
||||
|
|
|
|||
55
gpio.sh
Executable file
55
gpio.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#! /bin/bash
|
||||
|
||||
function export_pwm () {
|
||||
chip="/sys/class/pwm/pwmchip$1"
|
||||
Name="$2"
|
||||
if [ ! -d $chip/pwm0 ]
|
||||
then
|
||||
echo 0 > $chip/export
|
||||
fi
|
||||
chgrp -v gpio $chip/pwm0/{enable,period,duty_cycle}
|
||||
chmod -v g+rw $chip/pwm0/{enable,period,duty_cycle}
|
||||
if [ -n "$Name" ]
|
||||
then
|
||||
mkdir -p /run/gpio/
|
||||
rm -f /run/gpio/"$Name"
|
||||
ln -vs $chip/pwm0 /run/gpio/"$Name"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE00="$(cat /sys/devices/platform/INT33FF:00/gpio/gpiochip*/base)"
|
||||
BASE01="$(cat /sys/devices/platform/INT33FF:01/gpio/gpiochip*/base)"
|
||||
BASE02="$(cat /sys/devices/platform/INT33FF:02/gpio/gpiochip*/base)"
|
||||
BASE03="$(cat /sys/devices/platform/INT33FF:03/gpio/gpiochip*/base)"
|
||||
|
||||
function export_gpio () {
|
||||
gpio="$1"
|
||||
Name="$2"
|
||||
Value="$3"
|
||||
if [ ! -d /sys/class/gpio/gpio$gpio ]
|
||||
then
|
||||
echo $gpio > /sys/class/gpio/export
|
||||
fi
|
||||
chgrp -v gpio /sys/class/gpio/gpio$gpio/{direction,value}
|
||||
chmod -v g+rw /sys/class/gpio/gpio$gpio/{direction,value}
|
||||
if [ -n "$Value" ]
|
||||
then
|
||||
echo out > /sys/class/gpio/gpio$gpio/direction
|
||||
echo $Value > /sys/class/gpio/gpio$gpio/value
|
||||
fi
|
||||
if [ -n "$Name" ]
|
||||
then
|
||||
mkdir -p /run/gpio/
|
||||
rm -f /run/gpio/"$Name"
|
||||
ln -vs /sys/class/gpio/gpio$gpio /run/gpio/"$Name"
|
||||
echo $gpio > /run/gpio/"$Name".gpio
|
||||
fi
|
||||
}
|
||||
|
||||
export_gpio "$(($BASE00 + 60))" EINT1 1
|
||||
export_gpio "$(($BASE00 + 63))" Reset 0
|
||||
export_pwm 0 Error_LED
|
||||
export_pwm 1 Rate_LED
|
||||
|
||||
rm -f /run/gpio/adc
|
||||
ln -vs /sys/devices/pci0000:00/808622C1:02/i2c-0/i2c-ADC081C:00/iio:device0/in_voltage_raw /run/gpio/adc
|
||||
47
irena.c
47
irena.c
|
|
@ -1072,14 +1072,14 @@ struct line_buffer {
|
|||
static inline
|
||||
void buffer_reset(struct line_buffer *b) { b->size = b->read = 0; }
|
||||
|
||||
void reprint_line(struct line_buffer *b)
|
||||
void reprint_line(FILE *f, struct line_buffer *b)
|
||||
{
|
||||
// in case the prompt was garbled
|
||||
int n = read(b->fd, b->buf + b->size, 4095 - b->size);
|
||||
if (n>0)
|
||||
b->size += n;
|
||||
b->buf[b->size] = 0;
|
||||
fprintf(mout, "%.*s", b->size - b->read, b->buf + b->read);
|
||||
fprintf(f, "%.*s", b->size - b->read, b->buf + b->read);
|
||||
}
|
||||
|
||||
char *get_line(struct line_buffer *b, unsigned int ev)
|
||||
|
|
@ -2515,23 +2515,29 @@ void print_asocket(FILE *mout)
|
|||
fprintf(mout, "%sunix socket connection\n", mode);
|
||||
}
|
||||
|
||||
int close_acmd_socket();
|
||||
|
||||
int open_cmd_socket(int na, char **av)
|
||||
{
|
||||
int force = 0;
|
||||
if (!strcmp(av[na-1], "force")) {
|
||||
if (na && !strcmp(av[na-1], "force")) {
|
||||
na--;
|
||||
force = 1;
|
||||
}
|
||||
if (!strcmp(av[na-1], "close")) {
|
||||
if (na && !strcmp(av[na-1], "kick")) {
|
||||
na--;
|
||||
close_acmd_socket();
|
||||
}
|
||||
if (na && !strcmp(av[na-1], "close")) {
|
||||
na--;
|
||||
close_cmd_socket();
|
||||
cmd_socket_flags &=~ SOCK_SHALL_BE_MOUT;
|
||||
}
|
||||
if (!strcmp(av[na-1], "interactive")) {
|
||||
if (na && !strcmp(av[na-1], "interactive")) {
|
||||
na--;
|
||||
cmd_socket_flags |= SOCK_SHALL_BE_MOUT;
|
||||
}
|
||||
else if (!strcmp(av[na-1], "noninteractive")) {
|
||||
else if (na && !strcmp(av[na-1], "noninteractive")) {
|
||||
na--;
|
||||
cmd_socket_flags &= ~SOCK_SHALL_BE_MOUT;
|
||||
}
|
||||
|
|
@ -2599,7 +2605,9 @@ int open_cmd_socket(int na, char **av)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int accept_cmd_socket(struct line_buffer *b, int fd)
|
||||
struct line_buffer s_buf;
|
||||
|
||||
int accept_cmd_socket(int fd)
|
||||
{
|
||||
unsigned int sa_len = sizeof(acmd_socket_addr);
|
||||
int sfd = accept(fd, &acmd_socket_addr.g, &sa_len);
|
||||
|
|
@ -2608,7 +2616,7 @@ int accept_cmd_socket(struct line_buffer *b, int fd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (b->fd >= 0) {
|
||||
if (s_buf.fd >= 0) {
|
||||
fprintf(mout, "command socket busy\n");
|
||||
close(sfd);
|
||||
return -1;
|
||||
|
|
@ -2620,8 +2628,8 @@ int accept_cmd_socket(struct line_buffer *b, int fd)
|
|||
close(sfd);
|
||||
return -1;
|
||||
}
|
||||
buffer_reset(b);
|
||||
b->fd = sfd;
|
||||
buffer_reset(&s_buf);
|
||||
s_buf.fd = sfd;
|
||||
|
||||
if (cmd_socket_flags & SOCK_SHALL_BE_MOUT) {
|
||||
int fd = dup(sfd);
|
||||
|
|
@ -2646,7 +2654,7 @@ int accept_cmd_socket(struct line_buffer *b, int fd)
|
|||
return sfd;
|
||||
}
|
||||
|
||||
int close_acmd_socket(struct line_buffer *b)
|
||||
int close_acmd_socket()
|
||||
{
|
||||
if (cmd_socket_flags & SOCK_IS_MOUT) {
|
||||
cmd_socket_flags &= ~SOCK_IS_MOUT;
|
||||
|
|
@ -2655,16 +2663,18 @@ int close_acmd_socket(struct line_buffer *b)
|
|||
if (r)
|
||||
merror("fclose socket");
|
||||
}
|
||||
if (s_buf.fd < 0)
|
||||
return 1;
|
||||
if (verbose(0)) {
|
||||
print_asocket(stderr);
|
||||
fprintf(stderr, "closing socket connection\n");
|
||||
}
|
||||
if (b->fd >= 0) {
|
||||
close(b->fd);
|
||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, b->fd, 0))
|
||||
if (s_buf.fd >= 0) {
|
||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, s_buf.fd, 0))
|
||||
merror("EPOLL_CTL_DEL acmd socket");
|
||||
close(s_buf.fd);
|
||||
}
|
||||
b->fd = -1;
|
||||
s_buf.fd = -1;
|
||||
cmd_socket_addr.g.sa_family = AF_UNSPEC;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3362,7 +3372,6 @@ int main(int argc, char **argv)
|
|||
|
||||
reset_priorities();
|
||||
|
||||
struct line_buffer s_buf;
|
||||
buffer_reset(&s_buf);
|
||||
s_buf.fd = -1;
|
||||
|
||||
|
|
@ -3376,7 +3385,7 @@ int main(int argc, char **argv)
|
|||
if (eev[i].events != EPOLLIN && verbose(2))
|
||||
fprintf(mout, "epoll: fd=%d events=0x%x\n", eev[i].data.fd, eev[i].events);
|
||||
if (eev[i].data.fd == cmd_socket_fd)
|
||||
accept_cmd_socket(&s_buf, cmd_socket_fd);
|
||||
accept_cmd_socket(cmd_socket_fd);
|
||||
else if (eev[i].data.fd == s_buf.fd) {
|
||||
char *l = get_line(&s_buf, eev[i].events);
|
||||
if (!l)
|
||||
|
|
@ -3392,8 +3401,8 @@ int main(int argc, char **argv)
|
|||
else {
|
||||
int do_read = eev[i].events;
|
||||
if (prompt && in_prompt==2 && do_read) {
|
||||
fprintf(mout, prompt);
|
||||
reprint_line(&c_buf);
|
||||
fprintf(stderr, prompt);
|
||||
reprint_line(stderr, &c_buf);
|
||||
in_prompt = 1;
|
||||
do_read = 0;
|
||||
}
|
||||
|
|
|
|||
26
rc.local
26
rc.local
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/bash -vx
|
||||
|
||||
## call this script from /etc/rc.local
|
||||
# chmod -v a+x /etc/rc.local
|
||||
# echo $0 >> /etc/rc.local
|
||||
|
||||
D3D="$(dirname $0)"
|
||||
IRENA=$D3D/d3d.rc
|
||||
IMON=$D3D/imonitor.py
|
||||
U=$(stat "$0" -c "%U")
|
||||
|
||||
## disable getty on $T
|
||||
# sed -i 's/^2:/#2:/' /etc/inittab
|
||||
|
||||
T=/dev/tty2
|
||||
|
||||
if [ -x "$IRENA" ]
|
||||
then
|
||||
cd $D3D
|
||||
sudo -inu $U screen -S IRENA -d -m $IRENA
|
||||
[ -x "$IMON" ] && sudo -inu $U screen -S IRENA -X screen $IMON
|
||||
chown $U $T
|
||||
sudo -inu $U setsid <$T >$T 2>&1 screen -S IRENA -x &
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue