#!/bin/sh

# export DBGLVL=10; procd -h /etc/hotplug.json
CP210_PRODID="10c4/ea60/100"

if [ "${PRODUCT}" = "${CP210_PRODID}" ]; then
   if [ "${ACTION}" = "bind" ]; then
      slot=0
      if [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.1/1-1.1:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.1/1-2.1:1.0" ]; then
         slot=1
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.2/1-1.2:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.2/1-2.2:1.0" ]; then
         slot=2
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.3/1-1.3:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.3/1-2.3:1.0" ]; then
         slot=3
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.4/1-1.4:1.0" ]; then
         slot=4
      fi
      if [ ${slot} -ne 0 ]; then
         logger -t Hotplug Device name of cp210 is $DEVICE_NAME at slot $slot
         sh /lib/dyiot/bin/cp210x.sh add --slot $slot
      fi
   fi
fi

if [ "${PRODUCT}" = "${CP210_PRODID}" ]; then
   if [ "${ACTION}" = "unbind" ]; then
      slot=0
      if [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.1/1-1.1:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.1/1-2.1:1.0" ]; then
         slot=1
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.2/1-1.2:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.2/1-2.2:1.0" ]; then
         slot=2
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.3/1-1.3:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.3/1-2.3:1.0" ]; then
         slot=3
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.4/1-1.4:1.0" ]; then
         slot=4
      fi
      if [ ${slot} -ne 0 ]; then
         sh /lib/dyiot/bin/cp210x.sh remove --slot $slot
      fi
   fi
fi
