#!/bin/bash

NODE="$1"

if test -z "$NODE"; then
  echo "Missing node"
  exit 1
fi



case $NODE in
  c01)
       DEVICE_ARG="-p m8515"
       HFUSE_ARG="-U hfuse:w:0xD1:m"
       LFUSE_ARG="-U lfuse:w:0xE4:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/c01/boot/c01_boot.hex"
       ;;
  c02)
       DEVICE_ARG="-p m644p"
       HFUSE_ARG="-U hfuse:w:0xD5:m"
       LFUSE_ARG="-U lfuse:w:0xE2:m"
       EFUSE_ARG="-U efuse:w:0xFF:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/c02/boot/c02_boot.hex"
       ;;
  c03)
       DEVICE_ARG="-p m644p"
       HFUSE_ARG="-U hfuse:w:0xD5:m"
       LFUSE_ARG="-U lfuse:w:0xE2:m"
       EFUSE_ARG="-U efuse:w:0xFF:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/c03/boot/c03_boot.hex"
       ;;
  n14)
       DEVICE_ARG="-p t85"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n14/boot/n14_boot.hex"
       ;;
  n16)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n16/boot/n16_boot.hex"
       ;;
  n21)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n21/boot/n21_boot.hex"
       ;;
  n24)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n24/boot/n24_boot.hex"
       ;;
  n25)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n25/boot/n25_boot.hex"
       ;;
  n26)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n26/boot/n26_boot.hex"
       ;;
  n27)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n27/boot/n27_boot.hex"
       ;;
  n28)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n28/boot/n28_boot.hex"
       ;;
  n29)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n29/boot/n29_boot.hex"
       ;;
  n30)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n30/boot/n30_boot.hex"
       ;;
  n31)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n31/boot/n31_boot.hex"
       ;;
  n32)
       DEVICE_ARG="-p t861"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG="-U lfuse:w:0x62:m"
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/n32/boot/n32_boot.hex"
       ;;

  r05)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/r05/boot/r05_boot.hex"
       ;;
  s03)
       DEVICE_ARG="-p m644p"
       HFUSE_ARG="-U hfuse:w:0x95:m"
       LFUSE_ARG="-U lfuse:w:0xdF:m"
       EFUSE_ARG="-U efuse:w:0xFF:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/s03/boot/s03_boot.hex"
       ;;
  t03)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/t03/boot/t03_boot.hex"
       ;;
  t04)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/t04/boot/t04_boot.hex"
       ;;

  e01)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e01/boot/e01_boot.hex"
       ;;

  e02)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e02/boot/e02_boot.hex"
       ;;

  e03)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e03/boot/e03_boot.hex"
       ;;

  e04)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e04/boot/e04_boot.hex"
       ;;

  e05)
       DEVICE_ARG="-p t84"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e05/boot/e05_boot.hex"
       ;;

  e06)
       DEVICE_ARG="-p t841"
       HFUSE_ARG="-U hfuse:w:0xD7:m"
       LFUSE_ARG=""
       EFUSE_ARG="-U efuse:w:0xFE:m"
       FILE_ARG="-U flash:w:./0-build/avr/devices/e06/boot/e06_boot.hex"
       ;;

  *)
       echo "Unknown node $NODE".
       exit 1
       ;;
esac


echo "avrdude -c stk500 -P /dev/ttyACM0 -B16 $DEVICE_ARG $HFUSE_ARG $LFUSE_ARG $EFUSE_ARG $FILE_ARG"
avrdude -c stk500 -P /dev/ttyACM0 -B16 $DEVICE_ARG $HFUSE_ARG $LFUSE_ARG $EFUSE_ARG $FILE_ARG


