flm01/mote/v2/openwrt/package/flukso/config/flukso.init

80 lines
1.6 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (c) 2011 Bart Van Der Meerssche
START=98
load_config()
{
uci set system.@system[0].key=$(hexdump -v -e '1/1 "%.2x"' -s $((0x11000)) -n 16 /dev/mtd6)
uci set system.@system[0].device=$(hexdump -v -e '1/1 "%.2x"' -s $((0x11020)) -n 16 /dev/mtd6)
uci set system.@system[0].hostname=flukso-$(hexdump -v -e '1/1 "%.2x"' -s $((0x11020)) -n 3 /dev/mtd6)
for i in `seq 6`;
do
ADDRESS=0x110$((i+2))0
uci set flukso.$i.id=$(hexdump -v -e '1/1 "%.2x"' -s $((ADDRESS)) -n 16 /dev/mtd6)
done
uci set system.@system[0].firstboot='0'
uci commit
logger 'configuring flukso device and sensor ids'
}
program_sensor_board()
{
AVRDUDE=fdude
MCU=atmega168p
PROGRAMMER=gpio
FLAGS="-p $MCU -c $PROGRAMMER"
FUSES="-U lfuse:w:0xEC:m -U hfuse:w:0xD6:m -U efuse:w:0x01:m"
AVRDIR=/usr/bin/avr
HEXFILE=$(find $AVRDIR/*.hex)
EEPFILE=$(find $AVRDIR/*.eep)
FLASH="-U flash:w:$HEXFILE"
EEPROM="-U eeprom:w:$EEPFILE"
$AVRDUDE $FLAGS $FUSES $FLASH $EEPROM
}
start()
{
FIRSTBOOT=$(uci get system.@system[0].firstboot)
if [ $FIRSTBOOT -eq '1' ]
then
load_config
program_sensor_board
fi
chmod 666 /dev/spidev0.0
/usr/sbin/spid
/usr/sbin/fluksod
HEARTBEAT=/usr/bin/heartbeat
FCHECK=/usr/bin/fcheck
MINUTE=$(date '+%M')
# Tell the server we've had a reset
$HEARTBEAT 1 >&- 2>&- <&-
# Configure cron
echo -e "$MINUTE * * * * $HEARTBEAT 0\n*/15 * * * * [ \$($FCHECK; echo \$?) -ne 0 ] && reboot" | crontab -
}
stop()
{
crontab -r
/usr/sbin/fluksod -k
/usr/sbin/spid -k
rm -rf /var/run/spid
rm -rf /var/run/fluksod
}