Index: branches/eam_branches/ipp-20220316/ippTools/share/Makefile.am
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/Makefile.am	(revision 42195)
+++ branches/eam_branches/ipp-20220316/ippTools/share/Makefile.am	(revision 42197)
@@ -543,3 +543,12 @@
 	remotetool_listcomponent.sql \
 	remotetool_doneprep.sql \
-	remotetool_updatepoll.sql
+	remotetool_updatepoll.sql \
+	fpcamtool_addprocessedexp.sql \
+	fpcamtool_find_cam_and_chip_id.sql \
+	fpcamtool_find_cam_id.sql \
+	fpcamtool_find_processedexp.sql \
+	fpcamtool_pendingexp.sql \
+	fpcamtool_queue_cam_id.sql \
+	fpcamtool_revertprocessedexp.sql \
+	fpcamtool_revertupdatedexp.sql
+
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_and_chip_id.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_and_chip_id.sql	(revision 42195)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_and_chip_id.sql	(revision 42197)
@@ -4,7 +4,6 @@
 (
  SELECT
-     chipRun.chip_id,
-     rawExp.ra,
-     rawExp.decl
+     exp_id,
+     chip_id,
  FROM chipRun
  JOIN rawExp
@@ -12,13 +11,23 @@
  WHERE
       chipRun.state = 'full'
- -- AND exp_id = 162
- -- AND chip_id = 140
+ -- WHERE HOOK for chip:
+  AND %s
 ) AS myChip
 JOIN
 (
 SELECT
+    exp_id,
+    camRun.chip_id as cam_chip_id,
     camRun.cam_id,
-    rawExp.ra,
-    rawExp.decl
+    camRun.state,
+    camRun.workdir,
+    camRun.workdir_state,
+    camRun.label,
+    camRun.data_group,
+    camRun.dist_group,
+    camRun.reduction,
+    camRun.dvodb,
+    camRun.software_ver,
+    camRun.note
 FROM camRun
 JOIN chipRun
@@ -28,8 +37,6 @@
 WHERE
      camRun.state = 'full'
--- AND exp_id = 162
--- AND cam_id = 234
+-- WHERE HOOK for cam:
+  AND %s
 ) AS myCam
 USING(exp_id)
-
- 
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_id.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_id.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_cam_id.sql	(revision 42197)
@@ -0,0 +1,25 @@
+-- this needs to join a table of chipRuns and a table of camRuns based on exp_id
+
+SELECT
+     exp_id,
+     chip_id,
+     cam_id,
+     camRun.state,
+     camRun.workdir,
+     camRun.workdir_state,
+     camRun.label,
+     camRun.data_group,
+     camRun.dist_group,
+     camRun.reduction,
+     camRun.dvodb,
+     camRun.software_ver,
+     camRun.note
+FROM camRun
+JOIN chipRun
+     USING(chip_id)
+JOIN rawExp
+     USING(exp_id)
+WHERE
+     camRun.state = 'full'
+-- WHERE HOOK for cam:
+  AND %s
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_processedexp.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_processedexp.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_find_processedexp.sql	(revision 42197)
@@ -0,0 +1,27 @@
+SELECT
+    fpcamProcessedExp.*,
+    fpcamRun.workdir,
+    fpcamRun.label,
+    fpcamRun.data_group,
+    fpcamRun.state,
+    camRun.state as cam_state,
+    chipRun.state as chip_state,
+    rawExp.exp_tag,
+    rawExp.exp_name,
+    rawExp.exp_time,
+    rawExp.exp_id,
+    rawExp.camera,
+    rawExp.telescope,
+    rawExp.dateobs,
+    rawExp.filter,
+    rawExp.filelevel,
+    rawExp.comment
+FROM fpcamRun
+JOIN fpcamProcessedExp
+    USING(fpcam_id)
+JOIN camRun
+    USING(cam_id)
+JOIN chipRun
+    ON(fpcamRun.chip_id = chipRun.chip_id)
+JOIN rawExp
+    ON chipRun.exp_id = rawExp.exp_id
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_pendingexp.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_pendingexp.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_pendingexp.sql	(revision 42197)
@@ -0,0 +1,30 @@
+SELECT
+    fpcamRun.*,
+    rawExp.exp_tag,
+    rawExp.exp_id,
+    rawExp.exp_name,
+    rawExp.camera,
+    rawExp.telescope,
+    rawExp.filelevel,
+    fpcamProcessedExp.path_base,
+    IFNULL(Label.priority, 10000) AS priority
+FROM fpcamRun
+JOIN camRun
+    USING(cam_id)
+JOIN chipRun
+    ON(fpcamRun.chip_id = chipRun.chip_id)
+JOIN rawExp
+    USING(exp_id)
+LEFT JOIN fpcamProcessedExp
+    USING(fpcam_id)
+LEFT JOIN fpcamMask
+    ON fpcamRun.label = fpcamMask.label
+LEFT JOIN Label
+    ON fpcamRun.label = Label.label
+WHERE
+    chipRun.state = 'full'
+    AND camRun.state = 'full'
+    AND ((fpcamRun.state = 'new'    AND fpcamProcessedExp.cam_id IS NULL) OR
+         (fpcamRun.state = 'update' AND fpcamProcessedExp.fault = 0 AND fpcamProcessedExp.quality = 0))
+    AND fpcamMask.label IS NULL
+    AND (Label.active OR Label.active IS NULL)
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_queue_cam_id.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_queue_cam_id.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_queue_cam_id.sql	(revision 42197)
@@ -0,0 +1,32 @@
+-- fpcamtool only operates on exposures so we can safely queue more then one at a
+-- time without worrying about losing the track of the generated cam_id
+INSERT INTO fpcamRun
+  ( fpcam_id,
+    chip_id,
+    cam_id,
+    state,
+    workdir,
+    workdir_state,
+    label,
+    data_group,
+    dist_group,
+    reduction,
+    dvodb,
+    software_ver,
+    note)
+  VALUES
+  (
+        0,              -- fpcam_id
+	%lld,           -- chip_id
+        %lld,           -- cam_id
+        '%s',           -- state
+        '%s',           -- workdir
+        '%s',           -- workdir_state
+        '%s',           -- label
+        '%s',           -- data_group
+        '%s',           -- dist_group
+        '%s',           -- reduction
+        '%s',           -- dvodb
+        0,           -- software ver
+        '%s'            -- note           
+  )
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertprocessedexp.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertprocessedexp.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertprocessedexp.sql	(revision 42197)
@@ -0,0 +1,9 @@
+DELETE FROM fpcamProcessedExp
+USING fpcamProcessedExp, fpcamRun, camRun, chipRun, rawExp
+WHERE
+    fpcamRun.cam_id      = fpcamProcessedExp.cam_id
+    AND fpcamRun.cam_id  = camRun.cam_id
+    AND fpcamRun.chip_id = chipRun.chip_id
+    AND chipRun.exp_id   = rawExp.exp_id
+    AND fpcamProcessedExp.fault != 0
+    AND fpcamRun.state = 'new'
Index: branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertupdatedexp.sql
===================================================================
--- branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertupdatedexp.sql	(revision 42197)
+++ branches/eam_branches/ipp-20220316/ippTools/share/fpcamtool_revertupdatedexp.sql	(revision 42197)
@@ -0,0 +1,9 @@
+UPDATE fpcamProcessedExp
+    JOIN fpcamRun USING(fpcam_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun ON(fpcamRun.chip_id = chipRun.chip_id)
+    JOIN rawExp USING(exp_id)
+SET fpcamProcessedExp.fault = 0
+WHERE
+    fpcamRun.state = 'update'
+    AND fpcamProcessedExp.fault != 0
