--- /dev/null
+#!/bin/sh
+
+DEVICE=/dev/ttyAMA0,b38400
+PORT=2323
+#OPTIONS="-ly -lh"
+#OPTIONS="-v -x"
+
+"`dirname "${0}"`"/init-coc
+
+while true; do
+ echo "Listening on port ${PORT} for new connection requests"
+ socat ${OPTIONS} "${DEVICE},raw,echo=0" "TCP-LISTEN:${PORT},reuseaddr"
+done
--- /dev/null
+#!/bin/sh
+
+#RPi v1: BUS=0
+#RPi v2: BUS=1
+#Auto: BUS=-1
+BUS=-1
+
+#BATTERY=0: trickle charger for supercap enabled
+#BATTERY=1: trickle charger for supercap disabled
+BATTERY=0
+
+if [ "`id -u`" != "0" ]; then
+ exec sudo "${0}" "${@}"
+fi
+
+if [ "${BUS}" = "-1" ]; then
+ rev="0x`awk '{if ($1 == "Revision") {print $NF};}' /proc/cpuinfo`"
+ rev=$((rev & 0xffff))
+ if [ "${rev}" -ge "4" ]; then
+ echo "RPi version 2 detected"
+ BUS=1
+ else
+ echo "RPi version 1 detected"
+ BUS=0
+ fi
+fi
+
+if [ ! -e "/dev/i2c-${BUS}" ]; then
+ modprobe i2c-dev
+fi
+
+if [ ! -e "/sys/bus/i2c/devices/${BUS}-0068" ]; then
+ echo "enabling RTC"
+ modprobe rtc-ds1307
+
+ tcharger="0xa5"
+ tchargertext="enabling"
+ if [ "${BATTERY}" = "1" ]; then
+ tcharger="0x00"
+ tchargertext="disabling"
+ fi
+
+ if [ "`i2cget -y "${BUS}" 0x68 0x10`" != "${tcharger}" ]; then
+ echo "${tchargertext} trickle-charger for supercap"
+ i2cset -y "${BUS}" 0x68 0x10 "${tcharger}"
+ fi
+ echo "ds1339 0x68" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
+fi
+
+if [ ! -e "/sys/bus/i2c/devices/1-0018" ]; then
+ echo "enabling 1wire"
+ modprobe ds2482
+ echo "ds2482 0x18" >"/sys/class/i2c-adapter/i2c-${BUS}/new_device"
+fi
+
+echo "resetting 868MHz extension..."
+if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
+if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
+echo out > /sys/class/gpio/gpio17/direction
+echo out > /sys/class/gpio/gpio18/direction
+echo 1 > /sys/class/gpio/gpio18/value
+echo 0 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio17/value
+sleep 1
--- /dev/null
+#!/bin/sh
+
+if [ "`id -u`" != "0" ]; then
+ exec sudo "${0}" "${@}"
+fi
+
+echo "calling COC bootloader..."
+if test ! -d /sys/class/gpio/gpio17; then echo 17 > /sys/class/gpio/export; fi
+if test ! -d /sys/class/gpio/gpio18; then echo 18 > /sys/class/gpio/export; fi
+echo out > /sys/class/gpio/gpio17/direction
+echo out > /sys/class/gpio/gpio18/direction
+echo 0 > /sys/class/gpio/gpio18/value
+echo 0 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio17/value
+sleep 1
+echo 1 > /sys/class/gpio/gpio18/value
+
+avrdude -v -p atmega1284p -P /dev/ttyAMA0 -b 38400 -c avr109 -U flash:w:COC.hex