blob: 7b7a091b2b1d5d572512f03cc5083f7b59c553c9 [file] [log] [blame]
#!/bin/sh
. /etc/utils.sh
laser_channel_file="/sys/devices/platform/gpon/misc/laserChannel"
platform=$(cat /etc/platform)
prev_laser_channel=-1
# Initially be very aggressive about acquiring a channel, then back off once
# we've tuned.
sleep_timeout=1
log()
{
echo "$@" >&2
}
if ! startswith "$platform" "GFLT3"; then
# not all fiberjacks have a tunable laser.
exit 0
fi
while true; do
if [ ! -e "$laser_channel_file" ]; then
log "$laser_channel_file is missing."
sleep $sleep_timeout
continue
fi
laser_channel=$(cat "$laser_channel_file")
if [ -z "$laser_channel" ]; then
log "$laser_channel_file is empty?"
sleep $sleep_timeout
continue
fi
# Valid laser channels start from 0.
if [ "$laser_channel" -eq "-1" ]; then
prev_laser_channel="-1"
sleep_timeout=1
sleep $sleep_timeout
continue
fi
# If the laser channel has not changed since we last ran, then go back to
# sleep as there is nothing to do.
if [ "$prev_laser_channel" -eq "$laser_channel" ]; then
sleep "$sleep_timeout"
continue
else
echo "$0: Laser channel changed: $prev_laser_channel to $laser_channel"
fi
# The laser channel has either changed or its the first time we are running.
log "New laser channel discovered: Ch. $laser_channel!"
result=$(set_laser_channel $laser_channel)
exit_status="$?"
echo "$exit_status" >/tmp/laser_i2c_status
if [ "$exit_status" -ne "0" ]; then
log "Failed to set laser channel! Error: $result"
sleep $sleep_timeout
continue
fi
log "New laser channel programmed successfully!"
prev_laser_channel=$laser_channel
sleep_timeout=15
sleep $sleep_timeout
done