@@ -78,7 +78,7 @@ func ProcessEM(importId string, zipReader *zip.Reader, zippedData []byte, destBu
7878 isCalTarget := strings .Contains (lowerId , "cal-target" ) || strings .Contains (lowerId , "cal_target" ) || strings .Contains (lowerId , "caltarget" )
7979
8080 // Create an RSI file from the sdf_raw file
81- genFiles , rtts , err := sdfToRSI .ConvertSDFtoRSIs (sdfLocalPath , localTemp )
81+ genFiles , rtts , err := sdfToRSI .ConvertSDFtoRSIs (sdfLocalPath , localTemp , logger )
8282
8383 if err != nil {
8484 return fmt .Errorf ("Failed to scan %v for RSI creation: %v" , sdfLocalPath , err )
@@ -100,7 +100,7 @@ func ProcessEM(importId string, zipReader *zip.Reader, zippedData []byte, destBu
100100
101101 // Every second file is a HK file not an actual RSI file... make sure we have the right prefix here
102102 if ! strings .HasPrefix (f , "RSI-" ) || ! strings .HasPrefix (hkFile , "HK-" ) {
103- logger .Errorf ("ConvertSDFtoRSIs generated : %v . Error: %v" , f , err )
103+ logger .Errorf ("ConvertSDFtoRSIs generated: \" %v \" . Error: %v" , f , err )
104104 continue
105105 }
106106
@@ -112,7 +112,7 @@ func ProcessEM(importId string, zipReader *zip.Reader, zippedData []byte, destBu
112112 continue
113113 }
114114
115- // Upoad the output files (beam locations, log and surface)
115+ // Upload the output files (beam locations, log and surface)
116116 files := []string {filepath .Join (localTemp , hkFile ), rxlPath , logPath , surfPath , rsiLocalPath }
117117 name := []string {"housekeeping" , "beam location" , "log" , "surface" , "rsi" }
118118 for i , file := range files {
@@ -234,24 +234,45 @@ func createBeamLocation(isCalTarget bool, rsiPath string, rtt int64, outputBeamL
234234 if _ , err := os .Stat (bgtPath + "BGT" ); err != nil {
235235 // Try the path used in local testing
236236 bgtPath = ".." + string (os .PathSeparator ) + ".." + string (os .PathSeparator ) + "beam-tool" + string (os .PathSeparator )
237+ if _ , err = os .Stat (bgtPath + "BGT" ); err != nil {
238+ return "" , "" , "" , errors .New ("BGT tool not found" )
239+ }
240+ }
241+
242+ // Ensure output files don't exist yet!
243+ toDel := []string {outSurfaceTop , outRXL , outLog }
244+ for _ , f := range toDel {
245+ err := os .Remove (f )
246+ if err != nil {
247+ logger .Errorf ("Error deleting existing \" %v\" : %v" , f , err )
248+ }
249+ }
250+
251+ // Find an absolute path because after Go 1.19 exec.Command doesn't work with relative paths... strange this wasn't noticed earlier!
252+ wd , err := os .Getwd ()
253+ if err != nil {
254+ return "" , "" , "" , fmt .Errorf ("Failed to get working dir: %v" , err )
237255 }
238256
239- if _ , err := os .Stat (bgtPath + "Geometry_PIXL_EM_Landing_25Jan2021.csv" ); err != nil {
257+ calibPath := path .Join (wd , bgtPath , "Geometry_PIXL_EM_Landing_25Jan2021.csv" )
258+
259+ if _ , err := os .Stat (calibPath ); err != nil {
240260 return "" , "" , "" , errors .New ("Calibration file not found" )
241261 }
242262 if _ , err := os .Stat (rsiPath ); err != nil {
243263 return "" , "" , "" , errors .New ("RSI not found" )
244264 }
245265
246- args := []string {bgtPath + "Geometry_PIXL_EM_Landing_25Jan2021.csv" , rsiPath , outSurfaceTop , outRXL }
266+ args := []string {calibPath , rsiPath , outSurfaceTop , outRXL }
247267 if isCalTarget {
248268 args = append (args , "-t" )
249269 }
250270 args = append (args , outLog )
251271
252- fmt . Printf ( "Executing: %v %v \n " , bgtPath + "BGT" , strings .Join (args , " " ) )
272+ exePath := path .Join (wd , bgtPath , "BGT" )
253273
254- cmd := exec .Command (bgtPath + "BGT" , args ... )
274+ fmt .Printf ("Executing: %v %v\n " , exePath , strings .Join (args , " " ))
275+ cmd := exec .Command (exePath , args ... )
255276
256277 // var out bytes.Buffer
257278 // var stderr bytes.Buffer
@@ -262,17 +283,30 @@ func createBeamLocation(isCalTarget bool, rsiPath string, rtt int64, outputBeamL
262283 // cmd.Stderr = os.Stderr
263284 cmd .Dir = bgtPath
264285
265- if out , err := cmd .CombinedOutput (); err != nil {
286+ errOut := false
287+ if out , cmdErr := cmd .CombinedOutput (); cmdErr != nil {
266288 logger .Infof ("CombinedOutput:\n %s" , out )
289+ err = cmdErr
290+ errOut = true // Don't return just yet, we want to print the log file if it exists..
267291 //if err := cmd.Run(); err != nil {
268292 // Dump std out
269293 // logger.Infof("BGT stdout:\n" + out.String())
270294 // logger.Errorf("BGT stderr:\n" + stderr.String())
271- return "" , "" , "" , fmt .Errorf ("BGT tool error: %v" , err )
272295 } else {
273296 logger .Infof ("CombinedOutput:\n %s" , out )
274297 }
275298
299+ // Dump the log file to the log here
300+ if bgtLog , logErr := os .ReadFile (outLog ); logErr != nil {
301+ logger .Infof ("Failed to read BGT log \" %v\" : %v" , outLog , logErr )
302+ } else {
303+ logger .Infof ("BGT Log Output:\n %s" , bgtLog )
304+ }
305+
306+ if errOut {
307+ return "" , "" , "" , fmt .Errorf ("BGT tool error: %v" , err )
308+ }
309+
276310 /*
277311 procAttr := new(os.ProcAttr)
278312 procAttr.Files = []*os.File{nil, nil, nil}
0 commit comments