#!/bin/sh
#
# First load the driver
#
# sudo dagload

#
# Make sure the Dag is in reset state
#
dagreset -d /dev/dag0

#
# Upload the latest Xilinx FPGA images
#
dagrom -rpd /dev/dag0 </usr/local/share/dag/xilinx/dag37tpci-hdlc-erf.bit

#
# Configure PHY layer settings
#
dagthree -d /dev/dag0 default

#
# Set capture (snap) length
#
# First option, full packet capture, notice slen has no effect for ATM
#
dagthree -d /dev/dag0 slen=1536 varlen

#
# Configure channels
# This requires a channel configuration file as described in the DAG 3.7T User Manual
dagchan -c chan.cfg || exit

#
# For Dag-Dag synchronization enable Dag0 -> Dag1 PPS output
#
#dagclock none overout

#
# Synchronize system time with NTP server, as required
#
#sudo ntpdate -b ntpserver.company.com

#
# Ready for capture
#

#dur="-s 60"
#dur=
dur="-s 10"

#ver=
ver=-v

stime=$(date +%Y%m%d-%H%M%S)

dagsnap -d /dev/dag0 $ver $dur -o $stime-0

#
# Stopping the capture when running
#
# Option 1: foreground: hit Control-C
# Option 2: background: killall -9 dagsnap

# For longer trace files and machines with 2GB file limit,
# split trace into 1GB files. Names will be /one/capture0001.erf,
# /one/capture0002.erf etc
#
#dagconvert $ver -d /dev/dag0 -r 1g -o /one/capture

#
# Inspecting the trace file
#
#dagbits -vvc print <~dag/$stime-0
