#!/usr/bin/env bash

LENSES=(CALIN_057F18V001 CALIN_079F17V001 CALIN_164F16V001 SUNEX_014F22V001 SUNEX_025F15V001)
OUT="/tmp/$(date +%s)"
CONFIG=/etc/zoox/current_config/vehicle.json

echo "Saving to: $OUT"

mkdir -p $OUT
cd ~/driving

for lens in "${LENSES[@]}"
do
  FG=$(python3 -c "import json;f=open(\"$CONFIG\",'r');c=json.load(f);f.close();camera=[cam for cam in c['cameras'] if cam['lens'] == \"$lens\"][0];fg=camera['framegrabber'];card=fg['pcie_card'];port=fg['index'];print('%d-%d'%(card,port))")
  CARD=$(echo $FG | awk '{split($0,a,"-"); print a[1]}')
  PORT=$(echo $FG | awk '{split($0,a,"-"); print a[2]}')
  bazel run --config=cuda //production/cameras/tools/gw5/firmware_acceptance_testing:run_acceptance_test -- --savepath $OUT --name $lens --card $CARD --port $PORT --lens $lens --num_frames_drop_test 1000
done

ARCHIVE="$OUT.zip"
zip -r $ARCHIVE $OUT 
echo $ARCHIVE
